Merge pull request #686 from skipperbent/v5-development

Version 5.4.0.0
This commit is contained in:
Simon Sessingø
2023-11-21 16:15:48 +01:00
committed by GitHub
4 changed files with 25 additions and 32 deletions
+8 -20
View File
@@ -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-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 ```php
use Pecee\SimpleRouter\ClassLoader\IClassLoader;
use Pecee\SimpleRouter\Exceptions\ClassNotFoundHttpException; use Pecee\SimpleRouter\Exceptions\ClassNotFoundHttpException;
class MyCustomClassLoader implements IClassLoader class MyCustomClassLoader implements IClassLoader
@@ -1762,19 +1763,14 @@ class MyCustomClassLoader implements IClassLoader
* *
* @param string $class * @param string $class
* @return object * @return object
* @throws NotFoundHttpException * @throws ClassNotFoundHttpException
*/ */
public function loadClass(string $class) public function loadClass(string $class)
{ {
if (class_exists($class) === false) { if ($this->container->has($class) === false) {
throw new NotFoundHttpException(sprintf('Class "%s" does not exist', $class), 404); throw new ClassNotFoundHttpException($class, null, sprintf('Class "%s" does not exist', $class), 404, null);
} }
try {
return $this->container->get($class); return $this->container->get($class);
} catch (\Exception $e) {
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
}
} }
/** /**
@@ -1782,15 +1778,11 @@ class MyCustomClassLoader implements IClassLoader
* @param object $class * @param object $class
* @param string $method * @param string $method
* @param array $parameters * @param array $parameters
* @return object * @return string
*/ */
public function loadClassMethod($class, string $method, array $parameters) public function loadClassMethod($class, string $method, array $parameters)
{ {
try { return (string)$this->container->call([$class, $method], $parameters);
return $this->container->call([$class, $method], $parameters);
} catch (\Exception $e) {
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
}
} }
/** /**
@@ -1798,15 +1790,11 @@ class MyCustomClassLoader implements IClassLoader
* *
* @param Callable $closure * @param Callable $closure
* @param array $parameters * @param array $parameters
* @return mixed * @return string
*/ */
public function loadClosure(callable $closure, array $parameters) public function loadClosure(callable $closure, array $parameters)
{ {
try { return (string)$this->container->call($closure, $parameters);
return $this->container->call($closure, $parameters);
} catch (\Exception $e) {
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
}
} }
} }
``` ```
+7 -5
View File
@@ -82,6 +82,8 @@ class InputHandler
if ($post !== false) { if ($post !== false) {
$this->originalPost += $post; $this->originalPost += $post;
} }
} else {
parse_str($contents, $this->originalPost);
} }
} }
@@ -108,7 +110,7 @@ class InputHandler
foreach ($files as $key => $value) { foreach ($files as $key => $value) {
// Parse multi dept file array // 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); $list[$key] = $this->parseFiles($value, $key);
continue; continue;
} }
@@ -231,7 +233,7 @@ class InputHandler
{ {
$element = null; $element = null;
if(count($methods) > 0) { if (count($methods) > 0) {
$methods = is_array(...$methods) ? array_values(...$methods) : $methods; $methods = is_array(...$methods) ? array_values(...$methods) : $methods;
} }
@@ -303,9 +305,9 @@ class InputHandler
public function exists($index, ...$methods): bool public function exists($index, ...$methods): bool
{ {
// Check array // Check array
if(is_array($index) === true) { if (is_array($index) === true) {
foreach($index as $key) { foreach ($index as $key) {
if($this->value($key, null, ...$methods) === null) { if ($this->value($key, null, ...$methods) === null) {
return false; return false;
} }
} }
+2
View File
@@ -32,6 +32,8 @@ class Response
* *
* @param string $url * @param string $url
* @param ?int $httpCode * @param ?int $httpCode
*
* @return never
*/ */
public function redirect(string $url, ?int $httpCode = null): void public function redirect(string $url, ?int $httpCode = null): void
{ {
+1
View File
@@ -562,6 +562,7 @@ class Router
if ($this->request->getRewriteRoute() !== null) { if ($this->request->getRewriteRoute() !== null) {
$this->processedRoutes[] = $this->request->getRewriteRoute(); $this->processedRoutes[] = $this->request->getRewriteRoute();
$this->request->setHasPendingRewrite(false);
} }
return $this->routeRequest(); return $this->routeRequest();