mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-25 04:29:16 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 36dda20bbe | |||
| a275366a90 | |||
| e22ea70047 | |||
| 4d1caddce4 | |||
| 0970bd00c6 | |||
| 49b132da93 | |||
| 08d78c8f71 | |||
| 5986dc9a08 | |||
| cdf165d0f4 | |||
| adfe70f191 | |||
| cd891d5334 | |||
| 12b6e3c1ab | |||
| 8ffa1088ab | |||
| f565014dff | |||
| 97b61fb8bf | |||
| 0ff9258776 | |||
| 5dc3e99d6e | |||
| 578fa10fc9 | |||
| 72ebada821 | |||
| e5b5b0898f | |||
| 515fbc173c | |||
| 89b766ff2f | |||
| 0cb7fc416d |
@@ -1742,6 +1742,7 @@ SimpleRouter::setCustomClassLoader(new MyCustomClassLoader());
|
||||
php-di support was discontinued by version 4.3, however you can easily add it again by creating your own class-loader like the example below:
|
||||
|
||||
```php
|
||||
use Pecee\SimpleRouter\ClassLoader\IClassLoader;
|
||||
use Pecee\SimpleRouter\Exceptions\ClassNotFoundHttpException;
|
||||
|
||||
class MyCustomClassLoader implements IClassLoader
|
||||
@@ -1762,19 +1763,14 @@ class MyCustomClassLoader implements IClassLoader
|
||||
*
|
||||
* @param string $class
|
||||
* @return object
|
||||
* @throws NotFoundHttpException
|
||||
* @throws ClassNotFoundHttpException
|
||||
*/
|
||||
public function loadClass(string $class)
|
||||
{
|
||||
if (class_exists($class) === false) {
|
||||
throw new NotFoundHttpException(sprintf('Class "%s" does not exist', $class), 404);
|
||||
if ($this->container->has($class) === false) {
|
||||
throw new ClassNotFoundHttpException($class, null, sprintf('Class "%s" does not exist', $class), 404, null);
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->container->get($class);
|
||||
} catch (\Exception $e) {
|
||||
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
|
||||
}
|
||||
return $this->container->get($class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1782,15 +1778,11 @@ class MyCustomClassLoader implements IClassLoader
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return object
|
||||
* @return string
|
||||
*/
|
||||
public function loadClassMethod($class, string $method, array $parameters)
|
||||
{
|
||||
try {
|
||||
return $this->container->call([$class, $method], $parameters);
|
||||
} catch (\Exception $e) {
|
||||
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
|
||||
}
|
||||
return (string)$this->container->call([$class, $method], $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1798,15 +1790,11 @@ class MyCustomClassLoader implements IClassLoader
|
||||
*
|
||||
* @param Callable $closure
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public function loadClosure(callable $closure, array $parameters)
|
||||
{
|
||||
try {
|
||||
return $this->container->call($closure, $parameters);
|
||||
} catch (\Exception $e) {
|
||||
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
|
||||
}
|
||||
return (string)$this->container->call($closure, $parameters);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -82,6 +82,10 @@ class InputHandler
|
||||
if ($post !== false) {
|
||||
$this->originalPost += $post;
|
||||
}
|
||||
} else {
|
||||
$post = [];
|
||||
parse_str($contents, $post);
|
||||
$this->originalPost += $post;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +112,7 @@ class InputHandler
|
||||
foreach ($files as $key => $value) {
|
||||
|
||||
// Parse multi dept file array
|
||||
if(isset($value['name']) === false && is_array($value) === true) {
|
||||
if (isset($value['name']) === false && is_array($value) === true) {
|
||||
$list[$key] = $this->parseFiles($value, $key);
|
||||
continue;
|
||||
}
|
||||
@@ -161,12 +165,12 @@ class InputHandler
|
||||
try {
|
||||
|
||||
$file = InputFile::createFromArray([
|
||||
'index' => ($key === '' && $originalIndex !== '') ? $originalIndex : $key,
|
||||
'name' => $original['name'][$key],
|
||||
'error' => $original['error'][$key],
|
||||
'index' => ($key === '' && $originalIndex !== '') ? $originalIndex : $key,
|
||||
'name' => $original['name'][$key],
|
||||
'error' => $original['error'][$key],
|
||||
'tmp_name' => $original['tmp_name'][$key],
|
||||
'type' => $original['type'][$key],
|
||||
'size' => $original['size'][$key],
|
||||
'type' => $original['type'][$key],
|
||||
'size' => $original['size'][$key],
|
||||
]);
|
||||
|
||||
if (isset($output[$key]) === true) {
|
||||
@@ -231,7 +235,7 @@ class InputHandler
|
||||
{
|
||||
$element = null;
|
||||
|
||||
if(count($methods) > 0) {
|
||||
if (count($methods) > 0) {
|
||||
$methods = is_array(...$methods) ? array_values(...$methods) : $methods;
|
||||
}
|
||||
|
||||
@@ -303,9 +307,9 @@ class InputHandler
|
||||
public function exists($index, ...$methods): bool
|
||||
{
|
||||
// Check array
|
||||
if(is_array($index) === true) {
|
||||
foreach($index as $key) {
|
||||
if($this->value($key, null, ...$methods) === null) {
|
||||
if (is_array($index) === true) {
|
||||
foreach ($index as $key) {
|
||||
if ($this->value($key, null, ...$methods) === null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ class Response
|
||||
*
|
||||
* @param string $url
|
||||
* @param ?int $httpCode
|
||||
*
|
||||
* @return never
|
||||
*/
|
||||
public function redirect(string $url, ?int $httpCode = null): void
|
||||
{
|
||||
@@ -127,4 +129,4 @@ class Response
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,6 +562,7 @@ class Router
|
||||
|
||||
if ($this->request->getRewriteRoute() !== null) {
|
||||
$this->processedRoutes[] = $this->request->getRewriteRoute();
|
||||
$this->request->setHasPendingRewrite(false);
|
||||
}
|
||||
|
||||
return $this->routeRequest();
|
||||
|
||||
Reference in New Issue
Block a user