mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
@@ -77,6 +77,7 @@ You can donate any amount of your choice by [clicking here](https://www.paypal.c
|
|||||||
- [Get parameter object](#get-parameter-object)
|
- [Get parameter object](#get-parameter-object)
|
||||||
- [Managing files](#managing-files)
|
- [Managing files](#managing-files)
|
||||||
- [Get all parameters](#get-all-parameters)
|
- [Get all parameters](#get-all-parameters)
|
||||||
|
- [Check if parameters exists](#check-if-parameters-exists)
|
||||||
- [Events](#events)
|
- [Events](#events)
|
||||||
- [Available events](#available-events)
|
- [Available events](#available-events)
|
||||||
- [Registering new event](#registering-new-event)
|
- [Registering new event](#registering-new-event)
|
||||||
@@ -1236,8 +1237,11 @@ $values = input()->all([
|
|||||||
All object implements the `IInputItem` interface and will always contain these methods:
|
All object implements the `IInputItem` interface and will always contain these methods:
|
||||||
|
|
||||||
- `getIndex()` - returns the index/key of the input.
|
- `getIndex()` - returns the index/key of the input.
|
||||||
|
- `setIndex()` - set the index/key of the input.
|
||||||
- `getName()` - returns a human friendly name for the input (company_name will be Company Name etc).
|
- `getName()` - returns a human friendly name for the input (company_name will be Company Name etc).
|
||||||
|
- `setName()` - sets a human friendly name for the input (company_name will be Company Name etc).
|
||||||
- `getValue()` - returns the value of the input.
|
- `getValue()` - returns the value of the input.
|
||||||
|
- `setValue()` - sets the value of the input.
|
||||||
|
|
||||||
`InputFile` has the same methods as above along with some other file-specific methods like:
|
`InputFile` has the same methods as above along with some other file-specific methods like:
|
||||||
|
|
||||||
@@ -1253,6 +1257,24 @@ All object implements the `IInputItem` interface and will always contain these m
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### Check if parameters exists
|
||||||
|
|
||||||
|
You can easily if multiple items exists by using the `exists` method. It's simular to `value` as it can be used
|
||||||
|
to filter on request-methods and supports both `string` and `array` as parameter value.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```php
|
||||||
|
if(input()->exists(['name', 'lastname'])) {
|
||||||
|
// Do stuff
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Similar to code above */
|
||||||
|
if(input()->exists('name') && input()->exists('lastname')) {
|
||||||
|
// Do stuff
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# Events
|
# Events
|
||||||
|
|
||||||
This section will help you understand how to register your own callbacks to events in the router.
|
This section will help you understand how to register your own callbacks to events in the router.
|
||||||
|
|||||||
@@ -293,14 +293,26 @@ class InputHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a input-item exist
|
* Check if a input-item exist.
|
||||||
|
* If an array is as $index parameter the method returns true if all elements exist.
|
||||||
*
|
*
|
||||||
* @param string $index
|
* @param string|array $index
|
||||||
* @param array ...$methods
|
* @param array ...$methods
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function exists(string $index, ...$methods): bool
|
public function exists($index, ...$methods): bool
|
||||||
{
|
{
|
||||||
|
// Check array
|
||||||
|
if(is_array($index) === true) {
|
||||||
|
foreach($index as $key) {
|
||||||
|
if($this->value($key, null, ...$methods) === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->value($index, null, ...$methods) !== null;
|
return $this->value($index, null, ...$methods) !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,18 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
return $this->url;
|
return $this->url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if group is defined and matches the given url.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param Request $request
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function matchGroup(string $url, Request $request): bool
|
||||||
|
{
|
||||||
|
return ($this->getGroup() === null || $this->getGroup()->matchRoute($url, $request) === true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find url that matches method, parameters or name.
|
* Find url that matches method, parameters or name.
|
||||||
* Used when calling the url() helper.
|
* Used when calling the url() helper.
|
||||||
@@ -203,9 +215,9 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
* Sets the router name, which makes it easier to obtain the url or router at a later point.
|
* Sets the router name, which makes it easier to obtain the url or router at a later point.
|
||||||
* Alias for LoadableRoute::setName().
|
* Alias for LoadableRoute::setName().
|
||||||
*
|
*
|
||||||
* @see LoadableRoute::setName()
|
|
||||||
* @param string|array $name
|
* @param string|array $name
|
||||||
* @return static
|
* @return static
|
||||||
|
* @see LoadableRoute::setName()
|
||||||
*/
|
*/
|
||||||
public function name($name): ILoadableRoute
|
public function name($name): ILoadableRoute
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
|||||||
|
|
||||||
public function matchRoute(string $url, Request $request): bool
|
public function matchRoute(string $url, Request $request): bool
|
||||||
{
|
{
|
||||||
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
|
if ($this->matchGroup($url, $request) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
|||||||
|
|
||||||
public function matchRoute(string $url, Request $request): bool
|
public function matchRoute(string $url, Request $request): bool
|
||||||
{
|
{
|
||||||
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
|
if ($this->matchGroup($url, $request) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user