mirror of
https://github.com/openvk/chandler.git
synced 2025-03-31 21:43:59 +03:00
Removing the event system from the framework as nobody uses it.
Closes #8.
This commit is contained in:
parent
a4dd0c40ed
commit
19bf47d799
18 changed files with 124 additions and 377 deletions
6
.gitattributes
vendored
6
.gitattributes
vendored
|
@ -2,6 +2,12 @@
|
|||
.gitattributes text eol=lf export-ignore
|
||||
.gitignore text eol=lf export-ignore
|
||||
|
||||
# PHP
|
||||
*.php text eol=lf
|
||||
|
||||
# JSON
|
||||
*.json text eol=lf
|
||||
*.lock text eol=lf
|
||||
|
||||
# YAML
|
||||
*.yml text eol=lf
|
||||
|
|
16
.gitignore
vendored
16
.gitignore
vendored
|
@ -1,3 +1,8 @@
|
|||
# Chandler
|
||||
/extensions/available/
|
||||
/extensions/enabled/
|
||||
/chandler.yml
|
||||
|
||||
# Composer
|
||||
/vendor/
|
||||
/composer.phar
|
||||
|
@ -8,13 +13,6 @@
|
|||
# PHPUnit
|
||||
/tests/cache/
|
||||
|
||||
/chandler.yml
|
||||
|
||||
/extensions/available/*
|
||||
/extensions/enabled/*
|
||||
!/extensions/available/.gitkeep
|
||||
!/extensions/enabled/.gitkeep
|
||||
|
||||
/tmp/cache/di_*
|
||||
/tmp/plugin_artifacts/*
|
||||
/tmp/cache/database/*
|
||||
|
@ -25,9 +23,5 @@
|
|||
!/tmp/cache/templates/.gitkeep
|
||||
!/tmp/cache/yaml/.gitkeep
|
||||
|
||||
/htdocs/*
|
||||
!/htdocs/.htaccess
|
||||
!/htdocs/index.php
|
||||
|
||||
/logs/*
|
||||
!/logs/.gitkeep
|
||||
|
|
|
@ -42,7 +42,7 @@ class Bootstrap
|
|||
*/
|
||||
private function igniteExtensions(): void
|
||||
{
|
||||
Chandler\Extensions\ExtensionManager::i();
|
||||
Chandler\Extensions\ExtensionManager::getInstance();
|
||||
}
|
||||
|
||||
private function loadConfig(): void
|
||||
|
@ -103,7 +103,7 @@ class Bootstrap
|
|||
private function route(string $url): void
|
||||
{
|
||||
ob_start();
|
||||
$router = Chandler\MVC\Routing\Router::i();
|
||||
$router = Chandler\MVC\Routing\Router::getInstance();
|
||||
if (($output = $router->execute($url, null)) !== null)
|
||||
echo $output;
|
||||
else
|
||||
|
|
|
@ -3,7 +3,7 @@ use Chandler\Security\Authenticator;
|
|||
|
||||
return (function(): ?bool
|
||||
{
|
||||
$auth = Authenticator::i();
|
||||
$auth = Authenticator::getInstance();
|
||||
$user = $auth->getUser();
|
||||
if(!$user) return NULL;
|
||||
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Chandler\Eventing;
|
||||
|
||||
use Chandler\Patterns\TSimpleSingleton;
|
||||
|
||||
/**
|
||||
* @package Chandler\Eventing
|
||||
*/
|
||||
class EventDispatcher
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $hooks = [];
|
||||
|
||||
/**
|
||||
* @param mixed $hook
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function addListener($hook): bool
|
||||
{
|
||||
$this->hooks[] = $hook;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Chandler\Eventing\Events\Event $event
|
||||
*
|
||||
* @return \Chandler\Eventing\Events\Event
|
||||
*/
|
||||
function pushEvent(Events\Event $event): Events\Event
|
||||
{
|
||||
foreach ($this->hooks as $hook) {
|
||||
if ($event instanceof Events\Cancelable)
|
||||
if ($event->isCancelled())
|
||||
break;
|
||||
$method = "on" . str_replace("Event", "", get_class($event));
|
||||
if (!method_exists($hook, $method)) continue;
|
||||
$hook->$method($event);
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
use TSimpleSingleton;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Chandler\Eventing\Events;
|
||||
|
||||
/**
|
||||
* @package Chandler\Eventing\Events
|
||||
*/
|
||||
interface Cancelable
|
||||
{
|
||||
public function cancel(): void;
|
||||
|
||||
public function isCancelled(): bool;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Chandler\Eventing\Events;
|
||||
|
||||
/**
|
||||
* @package Chandler\Eventing\Events
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $pristine = true;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $time;
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCode(): float
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getData(): string
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTime(): int
|
||||
{
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isTainted(): bool
|
||||
{
|
||||
return !$this->pristine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param float $code
|
||||
*/
|
||||
public function __construct(string $data = "", float $code = 0.0)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->code = $code;
|
||||
$this->time = time();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace Chandler\Extensions;
|
||||
use Chandler\Eventing\EventDispatcher;
|
||||
use Chandler\Patterns\TSimpleSingleton;
|
||||
use Chandler\MVC\Routing\Router;
|
||||
use Nette\Utils\Finder;
|
||||
|
@ -59,8 +58,7 @@ class ExtensionManager
|
|||
}
|
||||
|
||||
$this->rootApp = CHANDLER_ROOT_CONF["rootApp"];
|
||||
$this->eventLoop = EventDispatcher::i();
|
||||
$this->router = Router::i();
|
||||
$this->router = Router::getInstance();
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types = 1);
|
|||
|
||||
namespace Chandler\MVC\Routing;
|
||||
|
||||
use Chandler\Eventing\EventDispatcher;
|
||||
use Chandler\MVC\Exceptions\InterruptedException;
|
||||
use Chandler\MVC\IPresenter;
|
||||
use Chandler\Patterns\TSimpleSingleton;
|
||||
|
@ -199,7 +198,7 @@ class Router
|
|||
{
|
||||
$key = hash("snefru", CHANDLER_ROOT_CONF["security"]["secret"] . bin2hex($nonce));
|
||||
$data = $route->namespace;
|
||||
$data .= Session::i()->get("tok", -1);
|
||||
$data .= Session::getInstance()->get("tok", -1);
|
||||
return hash_hmac("snefru", $data, $key) . "#" . bin2hex($nonce);
|
||||
}
|
||||
|
||||
|
@ -257,10 +256,5 @@ class Router
|
|||
return null;
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->events = EventDispatcher::i();
|
||||
}
|
||||
|
||||
use TSimpleSingleton;
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ abstract class SimplePresenter implements IPresenter
|
|||
protected function pass(string $to, ...$args): void
|
||||
{
|
||||
$args = array_merge([$to], $args);
|
||||
$router = \Chandler\MVC\Routing\Router::i();
|
||||
$router = \Chandler\MVC\Routing\Router::getInstance();
|
||||
$__out = $router->execute($router->reverse(...$args), "libchandler:absolute.0");
|
||||
exit($__out);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ trait TSimpleSingleton
|
|||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function i(): self
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (is_null(static::$instance)) {
|
||||
return static::$instance = new static();
|
||||
|
|
|
@ -12,7 +12,7 @@ class Authenticator
|
|||
private function __construct()
|
||||
{
|
||||
$this->db = DatabaseConnection::i()->getContext();
|
||||
$this->session = Session::i();
|
||||
$this->session = Session::getInstance();
|
||||
}
|
||||
|
||||
private function verifySuRights(string $uId): bool
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
{
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"chandler/Eventing/Events/Event.php"
|
||||
]
|
||||
"chandler/Patterns/TSimpleSingleton.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Chandler\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
|
@ -14,6 +17,7 @@
|
|||
"minimum-stability": "stable",
|
||||
"name": "openvk/chanlder",
|
||||
"require": {
|
||||
"ext-yaml": "*",
|
||||
"php": "^7.3",
|
||||
"nette/utils": "^3.0",
|
||||
"nette/di": "^3.0",
|
||||
|
|
|
@ -14,7 +14,7 @@ server {
|
|||
listen [::]:443 ssl http2;
|
||||
server_name domain.tld;
|
||||
|
||||
root /opt/chandler/htdocs;
|
||||
root /opt/chandler/public;
|
||||
|
||||
client_max_body_size 100m;
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
<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>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
require_once(dirname(__DIR__) . "/vendor/autoload.php");
|
||||
|
||||
$bootstrap = require("../chandler/Bootstrap.php");
|
||||
|
||||
$bootstrap->ignite();
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Chandler\Tests\Chandler\Eventing;
|
||||
|
||||
use Chandler\Eventing\EventDispatcher;
|
||||
use Chandler\Eventing\Events\Event;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @package Chandler\Tests\Chandler\Eventing
|
||||
*/
|
||||
class EventDispatcherTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function provideMethodAddListener(): array // IMPROVE: Add more values.
|
||||
{
|
||||
return [
|
||||
[
|
||||
null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function provideMethodPushEvent(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
new Event(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideMethodAddListener
|
||||
*
|
||||
* @param mixed $hook
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMethodAddListener($hook): void
|
||||
{
|
||||
$this->assertTrue(EventDispatcher::i()->addListener($hook));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMethodI(): void
|
||||
{
|
||||
$this->assertSame(EventDispatcher::i(), EventDispatcher::i());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideMethodPushEvent
|
||||
*
|
||||
* @param \Chandler\Eventing\Events\Event $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMethodPushEvent(Event $event): void
|
||||
{
|
||||
$this->assertSame($event, EventDispatcher::i()->pushEvent($event));
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Chandler\Tests\Chandler\Eventing\Events;
|
||||
|
||||
use Chandler\Eventing\Events\Event;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @package Chandler\Tests\Chandler\Eventing\Events
|
||||
*/
|
||||
class EventTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testPropertyCode(): void
|
||||
{
|
||||
$this->assertClassHasAttribute("code", Event::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testPropertyData(): void
|
||||
{
|
||||
$this->assertClassHasAttribute("data", Event::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testPropertyPristine(): void
|
||||
{
|
||||
$this->assertClassHasAttribute("pristine", Event::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testPropertyTime(): void
|
||||
{
|
||||
$this->assertClassHasAttribute("time", Event::class);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue