Skip to content

Commit 319ce7a

Browse files
authored
Merge pull request #559 from skipperbent/v4-development
Version 4.3.5.0
2 parents d4de7fc + 4dff400 commit 319ce7a

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ You can donate any amount of your choice by [clicking here](https://www.paypal.c
7777
- [Get parameter object](#get-parameter-object)
7878
- [Managing files](#managing-files)
7979
- [Get all parameters](#get-all-parameters)
80+
- [Check if parameters exists](#check-if-parameters-exists)
8081
- [Events](#events)
8182
- [Available events](#available-events)
8283
- [Registering new event](#registering-new-event)
@@ -1236,8 +1237,11 @@ $values = input()->all([
12361237
All object implements the `IInputItem` interface and will always contain these methods:
12371238

12381239
- `getIndex()` - returns the index/key of the input.
1240+
- `setIndex()` - set the index/key of the input.
12391241
- `getName()` - returns a human friendly name for the input (company_name will be Company Name etc).
1242+
- `setName()` - sets a human friendly name for the input (company_name will be Company Name etc).
12401243
- `getValue()` - returns the value of the input.
1244+
- `setValue()` - sets the value of the input.
12411245

12421246
`InputFile` has the same methods as above along with some other file-specific methods like:
12431247

@@ -1253,6 +1257,24 @@ All object implements the `IInputItem` interface and will always contain these m
12531257

12541258
---
12551259

1260+
### Check if parameters exists
1261+
1262+
You can easily if multiple items exists by using the `exists` method. It's simular to `value` as it can be used
1263+
to filter on request-methods and supports both `string` and `array` as parameter value.
1264+
1265+
**Example:**
1266+
1267+
```php
1268+
if(input()->exists(['name', 'lastname'])) {
1269+
// Do stuff
1270+
}
1271+
1272+
/* Similar to code above */
1273+
if(input()->exists('name') && input()->exists('lastname')) {
1274+
// Do stuff
1275+
}
1276+
```
1277+
12561278
# Events
12571279

12581280
This section will help you understand how to register your own callbacks to events in the router.

src/Pecee/Http/Input/InputHandler.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,26 @@ public function value(string $index, $defaultValue = null, ...$methods)
293293
}
294294

295295
/**
296-
* Check if a input-item exist
296+
* Check if a input-item exist.
297+
* If an array is as $index parameter the method returns true if all elements exist.
297298
*
298-
* @param string $index
299+
* @param string|array $index
299300
* @param array ...$methods
300301
* @return bool
301302
*/
302-
public function exists(string $index, ...$methods): bool
303+
public function exists($index, ...$methods): bool
303304
{
305+
// Check array
306+
if(is_array($index) === true) {
307+
foreach($index as $key) {
308+
if($this->value($key, null, ...$methods) === null) {
309+
return false;
310+
}
311+
}
312+
313+
return true;
314+
}
315+
304316
return $this->value($index, null, ...$methods) !== null;
305317
}
306318

src/Pecee/SimpleRouter/Route/LoadableRoute.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ public function getUrl(): string
100100
return $this->url;
101101
}
102102

103+
/**
104+
* Returns true if group is defined and matches the given url.
105+
*
106+
* @param string $url
107+
* @param Request $request
108+
* @return bool
109+
*/
110+
protected function matchGroup(string $url, Request $request): bool
111+
{
112+
return ($this->getGroup() === null || $this->getGroup()->matchRoute($url, $request) === true);
113+
}
114+
103115
/**
104116
* Find url that matches method, parameters or name.
105117
* Used when calling the url() helper.
@@ -203,9 +215,9 @@ public function getMatch(): string
203215
* Sets the router name, which makes it easier to obtain the url or router at a later point.
204216
* Alias for LoadableRoute::setName().
205217
*
206-
* @see LoadableRoute::setName()
207218
* @param string|array $name
208219
* @return static
220+
* @see LoadableRoute::setName()
209221
*/
210222
public function name($name): ILoadableRoute
211223
{

src/Pecee/SimpleRouter/Route/RouteController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function findUrl(?string $method = null, $parameters = null, ?string $nam
8888

8989
public function matchRoute(string $url, Request $request): bool
9090
{
91-
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
91+
if ($this->matchGroup($url, $request) === false) {
9292
return false;
9393
}
9494

src/Pecee/SimpleRouter/Route/RouteResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function call($method): bool
8585

8686
public function matchRoute(string $url, Request $request): bool
8787
{
88-
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
88+
if ($this->matchGroup($url, $request) === false) {
8989
return false;
9090
}
9191

0 commit comments

Comments
 (0)