Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 5.4.0.0 #686

Merged
merged 20 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0cb7fc4
Merge pull request #629 from skipperbent/v5-release
skipperbent Feb 9, 2023
89b766f
Merge pull request #631 from skipperbent/v5-release
skipperbent Feb 11, 2023
515fbc1
Merge pull request #633 from skipperbent/v5-release
skipperbent Feb 13, 2023
e5b5b08
Merge pull request #640 from skipperbent/v5-release
skipperbent Mar 25, 2023
72ebada
Merge pull request #643 from skipperbent/v5-release
skipperbent Mar 30, 2023
578fa10
Merge pull request #646 from skipperbent/v5-release
skipperbent Apr 2, 2023
5dc3e99
Merge pull request #648 from skipperbent/v5-release
skipperbent Apr 2, 2023
0ff9258
Merge pull request #653 from skipperbent/v5-release
skipperbent Apr 7, 2023
97b61fb
Merge pull request #656 from skipperbent/v5-release
skipperbent Apr 8, 2023
f565014
Merge pull request #659 from skipperbent/v5-release
skipperbent Apr 21, 2023
8ffa108
Merge pull request #662 from skipperbent/v5-release
skipperbent Apr 24, 2023
12b6e3c
Merge pull request #669 from skipperbent/v5-release
skipperbent May 6, 2023
cd891d5
Merge pull request #671 from skipperbent/v5-release
skipperbent May 6, 2023
adfe70f
Added @return never to Response.php
ATC-4K Jul 10, 2023
cdf165d
Fixed the php-di integration example
ms-afk Sep 30, 2023
5986dc9
fixed rare double execution of rewrite routes in exception handler
ms-afk Oct 3, 2023
08d78c8
Added support for input stream when not json encoded
skipperbent Nov 21, 2023
49b132d
Merge pull request #672 from ATC-4K/patch-1
skipperbent Nov 21, 2023
0970bd0
Merge pull request #682 from ms-afk/fix-readme-php-di
skipperbent Nov 21, 2023
4d1cadd
Merge pull request #683 from ms-afk/bugfix-rewrite-route-executed-twice
skipperbent Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1762,51 +1763,38 @@ 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);
}

/**
* Called when loading class method
* @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);
}

/**
* Load closure
*
* @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);
}
}
```
Expand Down
22 changes: 12 additions & 10 deletions src/Pecee/Http/Input/InputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function parseInputs(): void
if ($post !== false) {
$this->originalPost += $post;
}
} else {
parse_str($contents, $this->originalPost);
}
}

Expand All @@ -108,7 +110,7 @@ public function parseFiles(array $files, ?string $parentKey = null): array
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;
}
Expand Down Expand Up @@ -161,12 +163,12 @@ protected function rearrangeFile(array $values, array &$index, ?array $original)
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) {
Expand Down Expand Up @@ -231,7 +233,7 @@ public function find(string $index, ...$methods)
{
$element = null;

if(count($methods) > 0) {
if (count($methods) > 0) {
$methods = is_array(...$methods) ? array_values(...$methods) : $methods;
}

Expand Down Expand Up @@ -303,9 +305,9 @@ public function value(string $index, $defaultValue = null, ...$methods)
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;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Pecee/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function httpCode(int $code): self
*
* @param string $url
* @param ?int $httpCode
*
* @return never
*/
public function redirect(string $url, ?int $httpCode = null): void
{
Expand Down Expand Up @@ -127,4 +129,4 @@ public function headers(array $headers): self
return $this;
}

}
}
1 change: 1 addition & 0 deletions src/Pecee/SimpleRouter/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ protected function handleException(Exception $e): ?string

if ($this->request->getRewriteRoute() !== null) {
$this->processedRoutes[] = $this->request->getRewriteRoute();
$this->request->setHasPendingRewrite(false);
}

return $this->routeRequest();
Expand Down
Loading