From c94204a506ab353162e261cea63d63626fe81487 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Fri, 18 Oct 2024 20:26:28 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=9A=D0=BE=D0=BD=D1=86=D0=B5=D0=BF?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20css=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 8 +++++-- src/Database.php | 11 +++++---- src/Path.php | 2 +- src/Tales.php | 43 ++++++++++++++++++++++++++---------- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 386d6ac..9ab1a00 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -103,13 +103,15 @@ class Component $default = $config->get('site', 'template'); $template = ($this->template) ? $this->template : $this->getTemplateName($config); + // Определение пути к шаблону $selected = null; $tpl = null; foreach ($this->viewPath as $index => $viewPath) { // Загружать шаблон по умолчанию если не найден текущий $dir = Path::join($this->viewPath[$index], 'templates', $template); if(is_dir($dir)) { - $tpl = new PHPTAL(Path::join($this->viewPath[$index], 'templates', $template, $name)); + $source = Path::join($this->viewPath[$index], 'templates', $template, $name); + $tpl = new PHPTAL($source); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION); $selected = $index; break; @@ -119,7 +121,8 @@ class Component if ($selected === null) { // Последний вариант viewPath, путь к папке компонента $selected = count($this->viewPath) - 1; - $tpl = new PHPTAL(Path::join($this->viewPath[$selected], 'templates', 'modern', $name)); + $source = Path::join($this->viewPath[$selected], 'templates', 'modern', $name); + $tpl = new PHPTAL($source); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION); $template = 'modern'; } @@ -136,6 +139,7 @@ class Component } $tpl->set('base', $this->config->get('site', 'web')); + $tpl->set('source__', $source); $tpl->set('component_base', $this->webPath[$selected]); $tpl->set('component', Path::join($this->webPath[$selected], 'templates', $template)); $tpl->set('component_id', $this->component_id); diff --git a/src/Database.php b/src/Database.php index 3f61550..e5e4d6a 100644 --- a/src/Database.php +++ b/src/Database.php @@ -46,10 +46,11 @@ class Database extends PDO static function getConnection(array $dsn) { + /** @var Database|null */ $connection = null; if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') { $port = (isset($dsn['port'])) ? "port={$dsn['port']};" : ""; - $connection/*: Database*/ = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']); + $connection = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']); if ($dsn['phptype'] == 'pgsql') { $connection->query('SET client_encoding="UTF-8"'); } @@ -57,9 +58,11 @@ class Database extends PDO if (isset($dsn['schema'])) { $connection->query('SET search_path TO ' . $dsn['schema']); } - } - if ($dsn['phptype'] == 'sqlite') { - $connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}"); + } elseif ($dsn['phptype'] == 'sqlite::memory') { + $connection = new self("{$dsn['phptype']}:"); + $connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1); + } elseif ($dsn['phptype'] == 'sqlite') { + $connection = new self("{$dsn['phptype']}:{$dsn['database']}"); $connection->setAttribute(PDO::ATTR_TIMEOUT, 5); $mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL'; $connection->query("PRAGMA journal_mode=$mode"); diff --git a/src/Path.php b/src/Path.php index 09d7e29..b36fe6b 100644 --- a/src/Path.php +++ b/src/Path.php @@ -228,7 +228,7 @@ class Path } /** - * Находит путь относительно текущего путя + * Находит путь относительно текущего пути * * @param string $name Полный путь к файлу * diff --git a/src/Tales.php b/src/Tales.php index 6538d86..26437e4 100644 --- a/src/Tales.php +++ b/src/Tales.php @@ -11,7 +11,7 @@ use PHPTAL_Php_TalesInternal, PHPTAL_Tales, PHPTAL_TalesRegistry; -class Tales_DateTime implements PHPTAL_Tales +class Tales_Inline implements PHPTAL_Tales { static public function date($expression, $nothrow = false) { return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path($expression).")"; @@ -20,24 +20,24 @@ class Tales_DateTime implements PHPTAL_Tales static public function time($expression, $nothrow = false) { return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path($expression).")"; } -} -class Tales_Component implements PHPTAL_Tales -{ static public function component($expression, $nothrow = false) { $s = PHPTAL_Php_TalesInternal::string($expression); return "ctiso\\Tales::phptal_component(" . $s . ")"; } -} - -class Tales_Assets implements PHPTAL_Tales -{ + static public function assets($expression, $nothrow = false) { $s = PHPTAL_Php_TalesInternal::string($expression); return "ctiso\\Tales::phptal_asset(" . $s . ")"; } + + static public function module($expression, $nothrow = false) + { + $s = PHPTAL_Php_TalesInternal::string($expression); + return "ctiso\\Tales::phptal_module(" . $s . ", \$ctx)"; + } } class Tales { @@ -56,6 +56,24 @@ class Tales { return ""; } + static function phptal_module($s, $ctx) { + $dir = dirname($ctx->source__); + $web = $ctx->component; + $file = \realpath($dir . '/' . $s); + error_log($web); + // Для модулей использовать только локальный путь + // Преобразовать в url + self::$site->addStyleSheet(Path::join($web, $s)); + // Получить карту с ассоциациями для модуля + // file_get_contents($file); + // Присвоить значения + // + $data = file_get_contents(strtr($file, ['.css' => '.json'])); + error_log($data); + + return json_decode($data, true); + } + /** * Функция подключения компонента */ @@ -77,9 +95,10 @@ class Tales { /* Регистрация нового префикса для подключения компонента */ $tales = PHPTAL_TalesRegistry::getInstance(); - $tales->registerPrefix('component', ['ctiso\\Tales_Component', 'component']); - $tales->registerPrefix('date', ['ctiso\\Tales_DateTime', 'date']); - $tales->registerPrefix('time', ['ctiso\\Tales_DateTime', 'time']); - $tales->registerPrefix('assets', ['ctiso\\Tales_Assets', 'assets']); + $tales->registerPrefix('component', ['ctiso\\Tales_Inline', 'component']); + $tales->registerPrefix('date', ['ctiso\\Tales_Inline', 'date']); + $tales->registerPrefix('time', ['ctiso\\Tales_Inline', 'time']); + $tales->registerPrefix('assets', ['ctiso\\Tales_Inline', 'assets']); + $tales->registerPrefix('module', ['ctiso\\Tales_Inline', 'module']); } }