Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
6562680 committed Dec 8, 2024
1 parent 491c735 commit 7e20087
Show file tree
Hide file tree
Showing 23 changed files with 1,127 additions and 1,037 deletions.
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ composer require gzhegow/router;
```php
<?php

// require_once getenv('COMPOSER_HOME') . '/vendor/autoload.php';
require_once __DIR__ . '/vendor/autoload.php';


Expand All @@ -36,11 +37,14 @@ set_exception_handler(function (\Throwable $e) {
do {
echo "\n";

echo \Gzhegow\Router\Lib::debug_var_dump($current) . PHP_EOL;
echo \Gzhegow\Router\Lib\Lib::debug_var_dump($current) . PHP_EOL;
echo $current->getMessage() . PHP_EOL;

foreach ( $e->getTrace() as $traceItem ) {
echo "{$traceItem['file']} : {$traceItem['line']}" . PHP_EOL;
$file = $traceItem[ 'file' ] ?? '{file}';
$line = $traceItem[ 'line' ] ?? '{line}';

echo "{$file} : {$line}" . PHP_EOL;
}

echo PHP_EOL;
Expand All @@ -51,14 +55,14 @@ set_exception_handler(function (\Throwable $e) {


// > добавляем несколько функция для тестирования
function _dump($value, ...$values) : void
function _dump(...$values) : void
{
echo \Gzhegow\Router\Lib::debug_line([ 'with_ids' => false, 'with_objects' => false ], $value, ...$values);
echo implode(' | ', array_map([ \Gzhegow\Router\Lib\Lib::class, 'debug_value' ], $values));
}

function _dump_ln($value, ...$values) : void
function _dump_ln(...$values) : void
{
echo \Gzhegow\Router\Lib::debug_line([ 'with_ids' => false, 'with_objects' => false ], $value, ...$values) . PHP_EOL;
echo implode(' | ', array_map([ \Gzhegow\Router\Lib\Lib::class, 'debug_value' ], $values)) . PHP_EOL;
}

function _assert_call(\Closure $fn, array $expectResult = [], string $expectOutput = null) : void
Expand All @@ -75,7 +79,7 @@ function _assert_call(\Closure $fn, array $expectResult = [], string $expectOutp
$expect->output = $expectOutput;
}

$status = \Gzhegow\Router\Lib::assert_call($trace, $fn, $expect, $error, STDOUT);
$status = \Gzhegow\Router\Lib\Lib::assert_call($trace, $fn, $expect, $error, STDOUT);

if (! $status) {
throw new \Gzhegow\Router\Exception\LogicException();
Expand Down Expand Up @@ -292,12 +296,12 @@ $fn = function () use ($router) {
};
_assert_call($fn, [], <<<HEREDOC
"TEST 1"
"[ RESULT ]" | [ 1 => { object(Gzhegow\Router\Route\Route) }, 2 => { object(Gzhegow\Router\Route\Route) } ]
"[ RESULT ]" | 0 | [ 1 => { object(Gzhegow\Router\Route\Route) }, 2 => { object(Gzhegow\Router\Route\Route) }, 3 => { object(Gzhegow\Router\Route\Route) } ]
"[ RESULT ]" | 0 | [ 1 => { object(Gzhegow\Router\Route\Route) }, 2 => { object(Gzhegow\Router\Route\Route) }, 3 => { object(Gzhegow\Router\Route\Route) }, 4 => { object(Gzhegow\Router\Route\Route) }, 5 => { object(Gzhegow\Router\Route\Route) } ]
"[ RESULT ]" | { object(Gzhegow\Router\Route\Route) }
"[ RESULT ]" | { object(Gzhegow\Router\Route\Route) }
"[ RESULT ]" | { object(Gzhegow\Router\Route\Route) }
"[ RESULT ]" | [ 1 => "{ object # Gzhegow\Router\Route\Route }", 2 => "{ object # Gzhegow\Router\Route\Route }" ]
"[ RESULT ]" | 0 | [ 1 => "{ object # Gzhegow\Router\Route\Route }", 2 => "{ object # Gzhegow\Router\Route\Route }", 3 => "{ object # Gzhegow\Router\Route\Route }" ]
"[ RESULT ]" | 0 | [ 1 => "{ object # Gzhegow\Router\Route\Route }", 2 => "{ object # Gzhegow\Router\Route\Route }", 3 => "{ object # Gzhegow\Router\Route\Route }", 4 => "{ object # Gzhegow\Router\Route\Route }", 5 => "{ object # Gzhegow\Router\Route\Route }" ]
"[ RESULT ]" | { object # Gzhegow\Router\Route\Route }
"[ RESULT ]" | { object # Gzhegow\Router\Route\Route }
"[ RESULT ]" | { object # Gzhegow\Router\Route\Route }
""
HEREDOC
);
Expand Down Expand Up @@ -334,8 +338,8 @@ $fn = function () use ($router) {
};
_assert_call($fn, [], <<<HEREDOC
"TEST 2"
"[ RESULT ]" | 1 | { object(Gzhegow\Router\Route\Route) }
"[ RESULT ]" | 2 | { object(Gzhegow\Router\Route\Route) }
"[ RESULT ]" | 1 | { object # Gzhegow\Router\Route\Route }
"[ RESULT ]" | 2 | { object # Gzhegow\Router\Route\Route }
""
HEREDOC
);
Expand Down Expand Up @@ -456,7 +460,7 @@ _assert_call($fn, [], <<<HEREDOC
"TEST 6"
"[ CATCH ]" | "Gzhegow\Router\Exception\Exception\DispatchException" | "Unhandled exception occured during dispatch"
"[ CATCH ]" | "Gzhegow\Router\Exception\Runtime\NotFoundException" | "Route not found: `/api/v1/not-found/not-found` / `GET`"
"[ RESULT ]" | NULL
"[ RESULT ]" | { NULL }
""
HEREDOC
);
Expand Down
13 changes: 9 additions & 4 deletions src/Cache/RouterCacheConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Gzhegow\Router\Cache;

use Gzhegow\Router\Lib;
use Gzhegow\Router\Lib\Lib;
use Gzhegow\Router\Config\AbstractConfig;
use Gzhegow\Router\Exception\LogicException;

Expand Down Expand Up @@ -67,16 +67,21 @@ public function validate() : void
&& ! is_a($this->cacheAdapter, $class = '\Psr\Cache\CacheItemPoolInterface')
) {
throw new LogicException(
'The `cacheAdapter` should be instance of: ' . $class
. ' / ' . Lib::debug_dump($this->cacheAdapter)
[
'The `cacheAdapter` should be instance of: ' . $class,
$this->cacheAdapter,
]
);
}

if ((null !== $this->cacheDirpath)
&& (null === Lib::parse_dirpath($this->cacheDirpath))
) {
throw new LogicException(
'The `cacheDirpath` should be valid directory path: ' . $this->cacheDirpath
[
'The `cacheDirpath` should be valid directory path',
$this->cacheDirpath,
]
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Config/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Gzhegow\Router\Config;

use Gzhegow\Router\Lib;


abstract class AbstractConfig
{
Expand Down Expand Up @@ -81,8 +79,10 @@ public function configure(\Closure $fn) : void
|| (! is_a($current, get_class($section)))
) {
throw new \LogicException(
'Invalid section: ' . $key
. ' / ' . Lib::debug_dump($current)
[
'Invalid section: ' . $key,
$current,
]
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/Contract/RouterDispatchContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Gzhegow\Router\Contract;

use Gzhegow\Router\Lib;
use Gzhegow\Router\Lib\Lib;
use Gzhegow\Router\Route\Struct\HttpMethod;
use Gzhegow\Router\Exception\LogicException;

Expand Down Expand Up @@ -93,7 +93,8 @@ public static function tryFromArray($array) : ?self
if (null === ($_httpMethod = HttpMethod::tryFrom($httpMethod))) {
return Lib::php_error(
[
'The `from[0]` should be valid `httpMethod`: ' . Lib::debug_dump($httpMethod),
'The `from[0]` should be valid `httpMethod`',
$httpMethod,
$array,
]
);
Expand All @@ -102,7 +103,8 @@ public static function tryFromArray($array) : ?self
if (null === ($_requestUri = Lib::parse_path($requestUri))) {
return Lib::php_error(
[
'The `from[0]` should be valid `path`: ' . Lib::debug_dump($requestUri),
'The `from[0]` should be valid `path`',
$requestUri,
$array,
]
);
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/RouterMatchContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Gzhegow\Router\Contract;

use Gzhegow\Router\Lib;
use Gzhegow\Router\Lib\Lib;
use Gzhegow\Router\Exception\LogicException;


Expand Down
6 changes: 4 additions & 2 deletions src/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Gzhegow\Router\Exception;

use Gzhegow\Router\Lib\Lib;


class Exception extends \Exception
implements ExceptionInterface
Expand Down Expand Up @@ -30,9 +32,9 @@ class Exception extends \Exception
protected $code;


public function __construct(...$errors)
public function __construct(...$args)
{
foreach ( \Gzhegow\Router\Lib::php_throwable_args(...$errors) as $k => $v ) {
foreach ( Lib::php_throwable_args(...$args) as $k => $v ) {
if (property_exists($this, $k)) {
$this->{$k} = $v;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Exception/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Gzhegow\Router\Exception;

use Gzhegow\Router\Lib\Lib;


class LogicException extends \LogicException
implements ExceptionInterface
Expand Down Expand Up @@ -30,9 +32,9 @@ class LogicException extends \LogicException
protected $code;


public function __construct(...$errors)
public function __construct(...$args)
{
foreach ( \Gzhegow\Router\Lib::php_throwable_args(...$errors) as $k => $v ) {
foreach ( Lib::php_throwable_args(...$args) as $k => $v ) {
if (property_exists($this, $k)) {
$this->{$k} = $v;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Gzhegow\Router\Exception;

use Gzhegow\Router\Lib\Lib;


class RuntimeException extends \RuntimeException
implements ExceptionInterface
Expand Down Expand Up @@ -30,9 +32,9 @@ class RuntimeException extends \RuntimeException
protected $code;


public function __construct(...$errors)
public function __construct(...$args)
{
foreach ( \Gzhegow\Router\Lib::php_throwable_args(...$errors) as $k => $v ) {
foreach ( Lib::php_throwable_args(...$args) as $k => $v ) {
if (property_exists($this, $k)) {
$this->{$k} = $v;
}
Expand Down
Loading

0 comments on commit 7e20087

Please sign in to comment.