Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,15 @@ jobs:
- name: Install dependencies
run: composer install --no-interaction --no-progress --no-suggest --prefer-dist

- name: Install dependencies for basic example
working-directory: examples/basic
run: composer install --no-interaction --no-progress --no-suggest --prefer-dist

- name: PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --dry-run --diff

- name: PHPStan
run: vendor/bin/phpstan analyse --no-progress

- name: PHPStan (examples)
run: vendor/bin/phpstan analyse --no-progress -c phpstan.examples.neon
32 changes: 18 additions & 14 deletions chandler/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);
use Tracy\Debugger;

define("CHANDLER_VER", "0.1.0", false);
define("CHANDLER_VER", "0.1.0");

/**
* Bootstrap class, that is called during framework starting phase.
Expand All @@ -27,18 +27,22 @@ public function __construct(?string $projectRoot = null, bool $skipExtensions =

private function ensureDirectoriesCreated(): void
{
function makeDir($path)
{
return is_dir($path) || mkdir($path);
$dirs = [
"/logs",
"/tmp",
"/tmp/cache",
"/tmp/cache/database",
"/tmp/cache/templates",
"/tmp/cache/yaml",
"/tmp/plugins-artifacts",
];

foreach ($dirs as $dir) {
$path = $this->projectRoot . $dir;
if (!is_dir($path)) {
mkdir($path);
}
}

makeDir($this->projectRoot . "/logs");
makeDir($this->projectRoot . "/tmp");
makeDir($this->projectRoot . "/tmp/cache");
makeDir($this->projectRoot . "/tmp/cache/database");
makeDir($this->projectRoot . "/tmp/cache/templates");
makeDir($this->projectRoot . "/tmp/cache/yaml");
makeDir($this->projectRoot . "/tmp/plugins-artifacts");
}

/**
Expand Down Expand Up @@ -118,7 +122,7 @@ private function defineIP(): void
$ip = $_SERVER["REMOTE_ADDR"];
}

define("CONNECTING_IP", $ip, false);
define("CONNECTING_IP", $ip);
}

/**
Expand Down Expand Up @@ -190,7 +194,7 @@ private function initCaptcha(): void
public function ignite(bool $headless = false): void
{
if (!defined("CHANDLER_ROOT")) {
define("CHANDLER_ROOT", $this->projectRoot, false);
define("CHANDLER_ROOT", $this->projectRoot);
}

chandler_init_yaml_cache();
Expand Down
2 changes: 1 addition & 1 deletion chandler/Captcha/CaptchaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Chandler\Session\Session;
use Chandler\Patterns\TSimpleSingleton;

class CaptchaManager
final class CaptchaManager
{
use TSimpleSingleton;

Expand Down
2 changes: 1 addition & 1 deletion chandler/Database/DatabaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Nette\Caching\Storages\FileStorage;
use Nette\Database\Conventions\DiscoveredConventions;

class DatabaseConnection
final class DatabaseConnection
{
private static $self = null;

Expand Down
7 changes: 1 addition & 6 deletions chandler/Database/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ public function getTypeNom(): string

public function getObjectType(): string
{
$type = tr("log_" . $this->getObjectTable());
if ($type === "@log_" . $this->getObjectTable()) {
return str_replace(CHANDLER_ROOT_CONF["preferences"]["logs"]["entitiesNamespace"], "", $this->getRecord()->object_model);
} else {
return $type;
}
return str_replace(CHANDLER_ROOT_CONF["preferences"]["logs"]["entitiesNamespace"], "", $this->getRecord()->object_model);
}

public function getObjectName(): string
Expand Down
6 changes: 3 additions & 3 deletions chandler/Eventing/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Chandler\Patterns\TSimpleSingleton;

class EventDispatcher
final class EventDispatcher
{
use TSimpleSingleton;
private $hooks = [];
Expand All @@ -20,15 +20,15 @@ public function addListener($hook): bool

public function pushEvent(Events\Event $event): Events\Event
{
foreach ($hooks as $hook) {
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, $methodName)) {
if (!method_exists($hook, $method)) {
continue;
}

Expand Down
2 changes: 0 additions & 2 deletions chandler/Eventing/Events/Cancelable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

interface Cancelable
{
protected $cancelled;

public function cancel(): void;

public function isCancelled(): bool;
Expand Down
6 changes: 3 additions & 3 deletions chandler/Extensions/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Chandler\Patterns\TSimpleSingleton;
use Chandler\MVC\Routing\Router;

class ExtensionManager
final class ExtensionManager
{
use TSimpleSingleton;
private $extensions = [];
Expand Down Expand Up @@ -68,10 +68,10 @@ private function init(): void

$constName = str_replace("-", "_", mb_strtoupper($name));
if (!defined($constName . "_ROOT")) {
define($constName . "_ROOT", $extPath, false);
define($constName . "_ROOT", $extPath);
}
if (!defined($constName . "_ROOT_CONF")) {
define($constName . "_ROOT_CONF", chandler_parse_yaml("$extPath/$name.yml"), false);
define($constName . "_ROOT_CONF", chandler_parse_yaml("$extPath/$name.yml"));
}

Router::setExtensionPath($name, $extPath);
Expand Down
5 changes: 3 additions & 2 deletions chandler/MVC/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Chandler\MVC\IPresenter;
use Nette\DI;

class Router
final class Router
{
use TSimpleSingleton;
public const HANDLER_DELIMITER = "%([#@❤]|\->)%";
Expand Down Expand Up @@ -221,7 +221,8 @@ public function delegateStatic(string $namespace, string $path, ?array $queryPar
$hash = "W/\"" . hash_file("snefru", $file) . "\"";
if (isset($_SERVER["HTTP_IF_NONE_MATCH"])) {
if ($_SERVER["HTTP_IF_NONE_MATCH"] === $hash) {
exit(header("HTTP/1.1 304"));
header("HTTP/1.1 304");
exit;
}
}

Expand Down
4 changes: 2 additions & 2 deletions chandler/Patterns/TSimpleSingleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

trait TSimpleSingleton
{
private static $self = null;
private static ?self $self = null;

private function __construct() {}
private function __clone() {}
public function __wakeup() {}

public static function i()
public static function i(): static
{
return static::$self ?? static::$self = new static();
}
Expand Down
6 changes: 2 additions & 4 deletions chandler/Security/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Chandler\Patterns\TSimpleSingleton;
use Chandler\Database\DatabaseConnection;

class Authenticator
final class Authenticator
{
use TSimpleSingleton;
private $db;
Expand All @@ -23,8 +23,6 @@ private function __construct()
$this->session = Session::i();
}

private function verifySuRights(string $uId): bool {}

private function makeToken(string $user, string $ip, string $ua): string
{
$data = ["user" => $user, "ip" => $ip, "ua" => $ua];
Expand Down Expand Up @@ -74,7 +72,7 @@ public function getUser(): ?User

$su = $this->session->get("_su");
$cacheKey = $token . "\x00" . ($su ?? "");
return @$this->cache[$cacheKey] ??= $this->resolveUser($token, $su);
return @self::$cache[$cacheKey] ??= $this->resolveUser($token, $su);
}

private function resolveUser(string $token, $su)
Expand Down
1 change: 1 addition & 0 deletions chandler/Security/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* User class.
*
* @author kurotsun <celestine@vriska.ru>
* @phpstan-consistent-constructor
*/
class User
{
Expand Down
2 changes: 1 addition & 1 deletion chandler/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @author kurotsun <celestine@vriska.ru>
*/
class Session
final class Session
{
use TSimpleSingleton;
/**
Expand Down
6 changes: 3 additions & 3 deletions chandler/Signaling/SignalManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author kurotsun <celestine@vriska.ru>
* @author Vladimir Barinov <veselcraft@icloud.com>
*/
class SignalManager
final class SignalManager
{
use TSimpleSingleton;

Expand Down Expand Up @@ -163,7 +163,7 @@ public function listen(\Closure $callback, int $for, int $time = 25): void
"updates" => [],
]));
}
} catch (Exception $e) {
} catch (\Exception $e) {
error_log("Couldn't connect to Redis server, fallback to old sqlite method. Exception Message: " . $e->getMessage());
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public function triggerEvent(object $event, int $for): bool
try {
$redisClient = new RedisClient(CHANDLER_ROOT_CONF["redisUrl"]);
$redisClient->publish('im' . $for, json_encode([$id, $event]));
} catch (Exception $e) {
} catch (\Exception $e) {
error_log("Couldn't connect to Redis server and push the event. Exception Message: " . $e->getMessage());
}
}
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
},
"scripts": {
"fix": "php-cs-fixer fix",
"lint": "php-cs-fixer fix --dry-run --diff --verbose"
"lint": "php-cs-fixer fix --dry-run --diff --verbose",
"analyse": "phpstan analyse --no-progress",
"analyse:examples": "phpstan analyse --no-progress -c phpstan.examples.neon"
},
"require": {
"php": "~8.2",
Expand Down Expand Up @@ -43,6 +45,7 @@
]
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.90"
"friendsofphp/php-cs-fixer": "^3.90",
"phpstan/phpstan": "^2.2"
}
}
66 changes: 65 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/basic/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// ── Project root ─────────────────────────────────────────────────
// Tells Chandler where to find logs/, tmp/, cache/, etc.
define("CHANDLER_ROOT", __DIR__, false);
define("CHANDLER_ROOT", __DIR__);

// ── YAML cache ───────────────────────────────────────────────────
// Must be called before any config parsing.
Expand All @@ -29,7 +29,7 @@
// A single YAML file holds both Chandler framework settings
// (chandler:) and app-specific settings (helloapp:).
$config = chandler_parse_yaml(__DIR__ . "/helloapp.yml");
define("CHANDLER_ROOT_CONF", $config["chandler"], false);
define("CHANDLER_ROOT_CONF", $config["chandler"]);

// ── Register the app as a builtin extension ──────────────────────
// Once registered, ExtensionManager will:
Expand Down
Loading
Loading