Committing all the shit.

This commit is contained in:
Ilya Bakhlin 2022-01-08 21:59:36 +01:00
parent 3b31eb8d08
commit ca311a53cc
6 changed files with 168 additions and 152 deletions

View file

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
namespace Chandler\Extensions;
use Chandler\Patterns\TSimpleSingleton;
use Chandler\Classes\Singleton;
use Chandler\MVC\Routing\Router;
use Nette\Utils\Finder;
@ -13,14 +13,14 @@ if(CHANDLER_ROOT_CONF["extensions"]["allEnabled"]) {
define("CHANDLER_EXTENSIONS_ENABLED", CHANDLER_EXTENSIONS . "/enabled", false);
}
class ExtensionManager
class ExtensionManager extends Singleton
{
private $extensions = [];
private $router = NULL;
private $rootApp = NULL;
private $eventLoop = NULL;
private function __construct()
protected function __construct()
{
foreach(Finder::findDirectories("*")->in(CHANDLER_EXTENSIONS_AVAILABLE) as $directory) {
$extensionName = $directory->getFilename();
@ -125,6 +125,4 @@ class ExtensionManager
if(!symlink($path, str_replace("available", "enabled", $path))) throw new \Exception("Could not enable extension");
}
use TSimpleSingleton;
}

View file

@ -4,24 +4,26 @@ declare(strict_types = 1);
namespace Chandler\MVC\Routing;
use Chandler\Classes\Singleton;
use Chandler\MVC\Exceptions\InterruptedException;
use Chandler\MVC\IPresenter;
use Chandler\Patterns\TSimpleSingleton;
use Chandler\Session\Session;
use mysql_xdevapi\Exception;
use Nette\DI;
use Nette\DI\Config\Adapters\NeonAdapter;
use Nette\DI\Config\Loader;
use SodiumException;
class Router
class Router extends Singleton
{
const ALIAS_REGEX = "%{(\??\!?([A-z]++))}%";
const HANDLER_DELIMITER = "%([#@❤]|\->)%";
private $events;
private $routes = [];
/**
* @var array
*/
private array $routes = [];
private $scope = [];
@ -154,7 +156,7 @@ class Router
function delegateStatic(string $namespace, string $path): string
{
$static = $static = $this->statics[$namespace];
$static = $this->statics[$namespace];
if (!isset($static)) return "Fatal error: no route";
if (!file_exists($file = "$static/$path"))
return "Fatal error: no resource";
@ -220,7 +222,30 @@ class Router
$this->statics[$namespace] = $path;
}
function readRoutes(string $filename, string $namespace, bool $autoprefix = true): void
/**
* TODO: Add a description.
*
* @param string $route
*
* @return array
*/
public function split(string $route): array // IMPROVE: Make this method private.
{
if (($split = preg_split("/@/", $route)) === false) {
throw new Exception(); // TODO: Add an exception message.
} else {
return $split;
}
}
/**
* @param string $filename
* @param string $namespace
* @param bool $autoprefix
*
* @return void
*/
public function readRoutes(string $filename, string $namespace, bool $autoprefix = true): void
{
$config = chandler_parse_yaml($filename);
if (isset($config["static"]))
@ -231,7 +256,7 @@ class Router
foreach ($config["routes"] as $route) {
$route = (object)$route;
$placeholders = $route->placeholders ?? [];
[$presenter, $action] = preg_split(Router::HANDLER_DELIMITER, $route->handler);
[$presenter, $action] = $this->split($route->handler);
$this->push($autoprefix ? $namespace : null, $route->url, $namespace, $presenter, $action, $placeholders);
}
}
@ -242,7 +267,7 @@ class Router
[$namespace, $hotlink] = $j;
else
$namespace = explode("\\", $this->scope["parentModule"])[0];
[$presenter, $action] = preg_split(Router::HANDLER_DELIMITER, $hotlink);
[$presenter, $action] = $this->split($hotlink);
foreach ($this->routes as $route) {
if ($route->namespace !== $namespace || $route->presenter !== $presenter) continue;
if (!is_null($action) && $route->action != $action) continue;
@ -256,5 +281,7 @@ class Router
return null;
}
use TSimpleSingleton;
public function __construct()
{
}
}

View file

@ -1,7 +1,8 @@
{
"autoload": {
"classmap": [
"chandler/Patterns/TSimpleSingleton.php"
"chandler",
"extensions"
],
"files": [
"chandler/procedural/db_busy.php",
@ -25,7 +26,7 @@
"name": "openvk/chanlder",
"require": {
"ext-yaml": "*",
"php": "^7.3",
"php": "^7.4",
"nette/utils": "^3.0",
"nette/di": "^3.0",
"nette/database": "^3.0",
@ -37,8 +38,7 @@
"symfony/translation": "^5.0",
"symfony/yaml": "^5.3",
"guzzlehttp/guzzle": "^6.0",
"wildbit/postmark-php": "^4.0",
"tracy/tracy": "2.9"
"wildbit/postmark-php": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5"

197
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ec942d4b143e30d41b04837c5d8c09cf",
"content-hash": "162f9b1c78fbb0a1c83c26ddf9971316",
"packages": [
{
"name": "doctrine/lexer",
@ -478,16 +478,16 @@
},
{
"name": "latte/latte",
"version": "v2.10.7",
"version": "v2.10.8",
"source": {
"type": "git",
"url": "https://github.com/nette/latte.git",
"reference": "a69d0b9598652438b5754ae5c1abc217d5003d98"
"reference": "596b28bf098ebb852732d60b00538139a009c4db"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/latte/zipball/a69d0b9598652438b5754ae5c1abc217d5003d98",
"reference": "a69d0b9598652438b5754ae5c1abc217d5003d98",
"url": "https://api.github.com/repos/nette/latte/zipball/596b28bf098ebb852732d60b00538139a009c4db",
"reference": "596b28bf098ebb852732d60b00538139a009c4db",
"shasum": ""
},
"require": {
@ -556,9 +556,9 @@
],
"support": {
"issues": "https://github.com/nette/latte/issues",
"source": "https://github.com/nette/latte/tree/v2.10.7"
"source": "https://github.com/nette/latte/tree/v2.10.8"
},
"time": "2021-12-21T11:22:49+00:00"
"time": "2022-01-04T14:13:28+00:00"
},
{
"name": "nette/caching",
@ -1055,16 +1055,16 @@
},
{
"name": "nette/safe-stream",
"version": "v2.4.2",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/nette/safe-stream.git",
"reference": "921bd889860cf697a022642e628d086c9048ca67"
"reference": "8bbbeda8415b8352642d7566dfa18169d40c2e54"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/safe-stream/zipball/921bd889860cf697a022642e628d086c9048ca67",
"reference": "921bd889860cf697a022642e628d086c9048ca67",
"url": "https://api.github.com/repos/nette/safe-stream/zipball/8bbbeda8415b8352642d7566dfa18169d40c2e54",
"reference": "8bbbeda8415b8352642d7566dfa18169d40c2e54",
"shasum": ""
},
"require": {
@ -1078,7 +1078,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -1102,19 +1102,21 @@
"homepage": "https://nette.org/contributors"
}
],
"description": "Nette SafeStream: atomic and safe manipulation with files via native PHP functions.",
"description": "Nette SafeStream: provides isolation for thread safe manipulation with files via native PHP functions.",
"homepage": "https://nette.org",
"keywords": [
"atomic",
"filesystem",
"isolation",
"nette",
"safe"
"safe",
"thread safe"
],
"support": {
"issues": "https://github.com/nette/safe-stream/issues",
"source": "https://github.com/nette/safe-stream/tree/v2.4.2"
"source": "https://github.com/nette/safe-stream/tree/v2.5.0"
},
"time": "2021-06-02T14:42:24+00:00"
"time": "2022-01-03T23:13:32+00:00"
},
{
"name": "nette/schema",
@ -1561,21 +1563,24 @@
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.23.0",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce"
"reference": "30885182c981ab175d4d034db0f6f469898070ab"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce",
"reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab",
"reference": "30885182c981ab175d4d034db0f6f469898070ab",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-ctype": "*"
},
"suggest": {
"ext-ctype": "For best performance"
},
@ -1620,7 +1625,7 @@
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0"
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0"
},
"funding": [
{
@ -1636,25 +1641,28 @@
"type": "tidelift"
}
],
"time": "2021-02-19T12:13:01+00:00"
"time": "2021-10-20T20:35:02+00:00"
},
{
"name": "symfony/polyfill-iconv",
"version": "v1.23.0",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-iconv.git",
"reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933"
"reference": "f1aed619e28cb077fc83fac8c4c0383578356e40"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/63b5bb7db83e5673936d6e3b8b3e022ff6474933",
"reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933",
"url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/f1aed619e28cb077fc83fac8c4c0383578356e40",
"reference": "f1aed619e28cb077fc83fac8c4c0383578356e40",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-iconv": "*"
},
"suggest": {
"ext-iconv": "For best performance"
},
@ -1700,7 +1708,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-iconv/tree/v1.23.0"
"source": "https://github.com/symfony/polyfill-iconv/tree/v1.24.0"
},
"funding": [
{
@ -1716,20 +1724,20 @@
"type": "tidelift"
}
],
"time": "2021-05-27T09:27:20+00:00"
"time": "2022-01-04T09:04:05+00:00"
},
{
"name": "symfony/polyfill-intl-idn",
"version": "v1.23.0",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-idn.git",
"reference": "65bd267525e82759e7d8c4e8ceea44f398838e65"
"reference": "749045c69efb97c70d25d7463abba812e91f3a44"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/65bd267525e82759e7d8c4e8ceea44f398838e65",
"reference": "65bd267525e82759e7d8c4e8ceea44f398838e65",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44",
"reference": "749045c69efb97c70d25d7463abba812e91f3a44",
"shasum": ""
},
"require": {
@ -1787,7 +1795,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.23.0"
"source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.24.0"
},
"funding": [
{
@ -1803,11 +1811,11 @@
"type": "tidelift"
}
],
"time": "2021-05-27T09:27:20+00:00"
"time": "2021-09-14T14:02:44+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.23.0",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
@ -1871,7 +1879,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.23.0"
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.24.0"
},
"funding": [
{
@ -1891,21 +1899,24 @@
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.23.1",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6"
"reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6",
"reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825",
"reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-mbstring": "*"
},
"suggest": {
"ext-mbstring": "For best performance"
},
@ -1951,7 +1962,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1"
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.24.0"
},
"funding": [
{
@ -1967,11 +1978,11 @@
"type": "tidelift"
}
],
"time": "2021-05-27T12:26:48+00:00"
"time": "2021-11-30T18:21:41+00:00"
},
{
"name": "symfony/polyfill-php72",
"version": "v1.23.0",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php72.git",
@ -2027,7 +2038,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php72/tree/v1.23.0"
"source": "https://github.com/symfony/polyfill-php72/tree/v1.24.0"
},
"funding": [
{
@ -2047,16 +2058,16 @@
},
{
"name": "symfony/polyfill-php80",
"version": "v1.23.1",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be"
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be",
"reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9",
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9",
"shasum": ""
},
"require": {
@ -2110,7 +2121,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1"
"source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0"
},
"funding": [
{
@ -2126,7 +2137,7 @@
"type": "tidelift"
}
],
"time": "2021-07-28T13:41:28+00:00"
"time": "2021-09-13T13:58:33+00:00"
},
{
"name": "symfony/translation",
@ -2378,80 +2389,6 @@
],
"time": "2021-12-16T21:58:21+00:00"
},
{
"name": "tracy/tracy",
"version": "v2.9.0",
"source": {
"type": "git",
"url": "https://github.com/nette/tracy.git",
"reference": "551a7d936dfbd7075ced9a604b9527d1f7bfa8b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/tracy/zipball/551a7d936dfbd7075ced9a604b9527d1f7bfa8b4",
"reference": "551a7d936dfbd7075ced9a604b9527d1f7bfa8b4",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-session": "*",
"php": ">=7.2 <8.2"
},
"conflict": {
"nette/di": "<3.0"
},
"require-dev": {
"latte/latte": "^2.5",
"nette/di": "^3.0",
"nette/mail": "^3.0",
"nette/tester": "^2.2",
"nette/utils": "^3.0",
"phpstan/phpstan": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.9-dev"
}
},
"autoload": {
"classmap": [
"src"
],
"files": [
"src/Tracy/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.",
"homepage": "https://tracy.nette.org",
"keywords": [
"Xdebug",
"debug",
"debugger",
"nette",
"profiler"
],
"support": {
"issues": "https://github.com/nette/tracy/issues",
"source": "https://github.com/nette/tracy/tree/v2.9.0"
},
"time": "2021-12-20T18:19:46+00:00"
},
{
"name": "wildbit/postmark-php",
"version": "4.0.2",
@ -2895,16 +2832,16 @@
},
{
"name": "phpdocumentor/type-resolver",
"version": "1.5.1",
"version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae"
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae",
"reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"shasum": ""
},
"require": {
@ -2939,9 +2876,9 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1"
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
},
"time": "2021-10-02T14:08:47+00:00"
"time": "2022-01-04T19:58:01+00:00"
},
{
"name": "phpspec/prophecy",

View file

@ -2,9 +2,7 @@
<phpunit bootstrap="vendor/autoload.php" cacheResultFile="tests/cache/result.json" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
<coverage cacheDirectory="tests/cache" processUncoveredFiles="true">
<include>
<file>chandler/Eventing/Events/Event.php</file>
<file>chandler/Eventing/EventDispatcher.php</file>
<file>chandler/Patterns/TSimpleSingleton.php</file>
<directory>src</directory>
</include>
</coverage>
<testsuites>

View file

@ -0,0 +1,56 @@
<?php
declare(strict_types = 1);
namespace Chandler\Tests\Chandler\MVC\Routing;
use Chandler\MVC\Routing\Router;
use PHPUnit\Framework\TestCase;
/**
* @package Chandler\Tests\Chandler\MVC\Routing
*/
class RouterTest extends TestCase
{
/**
* @return array
*/
public function provideMethodSplit(): array
{
return [
[
"expected" => ["Index", "index"],
"givenRoute" => "Index@index",
],
];
}
/**
* @dataProvider provideMethodSplit
*
* @param array $expected
* @param string $givenRoute
*
* @return void
*/
public function testMethodSplit(array $expected, string $givenRoute): void
{
$this->assertSame($expected, Router::getInstance()->split($givenRoute));
}
/**
* @return void
*/
public function testMethodGetInstance(): void
{
$this->assertSame(Router::getInstance(), Router::getInstance());
}
/**
* @return void
*/
public function testMethodGetMatchingRouteDefault(): void
{
$this->assertSame(null, Router::getInstance()->getMatchingRoute(""));
}
}