Compare commits

...
Sign in to create a new pull request.

1 commit

4 changed files with 45 additions and 19 deletions

View file

@ -103,13 +103,15 @@ class Component
$default = $config->get('site', 'template'); $default = $config->get('site', 'template');
$template = ($this->template) ? $this->template : $this->getTemplateName($config); $template = ($this->template) ? $this->template : $this->getTemplateName($config);
// Определение пути к шаблону
$selected = null; $selected = null;
$tpl = null; $tpl = null;
foreach ($this->viewPath as $index => $viewPath) { foreach ($this->viewPath as $index => $viewPath) {
// Загружать шаблон по умолчанию если не найден текущий // Загружать шаблон по умолчанию если не найден текущий
$dir = Path::join($this->viewPath[$index], 'templates', $template); $dir = Path::join($this->viewPath[$index], 'templates', $template);
if(is_dir($dir)) { 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); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
$selected = $index; $selected = $index;
break; break;
@ -119,7 +121,8 @@ class Component
if ($selected === null) { if ($selected === null) {
// Последний вариант viewPath, путь к папке компонента // Последний вариант viewPath, путь к папке компонента
$selected = count($this->viewPath) - 1; $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); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
$template = 'modern'; $template = 'modern';
} }
@ -136,6 +139,7 @@ class Component
} }
$tpl->set('base', $this->config->get('site', 'web')); $tpl->set('base', $this->config->get('site', 'web'));
$tpl->set('source__', $source);
$tpl->set('component_base', $this->webPath[$selected]); $tpl->set('component_base', $this->webPath[$selected]);
$tpl->set('component', Path::join($this->webPath[$selected], 'templates', $template)); $tpl->set('component', Path::join($this->webPath[$selected], 'templates', $template));
$tpl->set('component_id', $this->component_id); $tpl->set('component_id', $this->component_id);

View file

@ -46,10 +46,11 @@ class Database extends PDO
static function getConnection(array $dsn) static function getConnection(array $dsn)
{ {
/** @var Database|null */
$connection = null; $connection = null;
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') { if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : ""; $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') { if ($dsn['phptype'] == 'pgsql') {
$connection->query('SET client_encoding="UTF-8"'); $connection->query('SET client_encoding="UTF-8"');
} }
@ -57,9 +58,11 @@ class Database extends PDO
if (isset($dsn['schema'])) { if (isset($dsn['schema'])) {
$connection->query('SET search_path TO ' . $dsn['schema']); $connection->query('SET search_path TO ' . $dsn['schema']);
} }
} } elseif ($dsn['phptype'] == 'sqlite::memory') {
if ($dsn['phptype'] == 'sqlite') { $connection = new self("{$dsn['phptype']}:");
$connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}"); $connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
} elseif ($dsn['phptype'] == 'sqlite') {
$connection = new self("{$dsn['phptype']}:{$dsn['database']}");
$connection->setAttribute(PDO::ATTR_TIMEOUT, 5); $connection->setAttribute(PDO::ATTR_TIMEOUT, 5);
$mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL'; $mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL';
$connection->query("PRAGMA journal_mode=$mode"); $connection->query("PRAGMA journal_mode=$mode");

View file

@ -228,7 +228,7 @@ class Path
} }
/** /**
* Находит путь относительно текущего путя * Находит путь относительно текущего пути
* *
* @param string $name Полный путь к файлу * @param string $name Полный путь к файлу
* *

View file

@ -11,7 +11,7 @@ use PHPTAL_Php_TalesInternal,
PHPTAL_Tales, PHPTAL_Tales,
PHPTAL_TalesRegistry; PHPTAL_TalesRegistry;
class Tales_DateTime implements PHPTAL_Tales class Tales_Inline implements PHPTAL_Tales
{ {
static public function date($expression, $nothrow = false) { static public function date($expression, $nothrow = false) {
return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path($expression).")"; 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) { static public function time($expression, $nothrow = false) {
return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path($expression).")"; return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path($expression).")";
} }
}
class Tales_Component implements PHPTAL_Tales
{
static public function component($expression, $nothrow = false) static public function component($expression, $nothrow = false)
{ {
$s = PHPTAL_Php_TalesInternal::string($expression); $s = PHPTAL_Php_TalesInternal::string($expression);
return "ctiso\\Tales::phptal_component(" . $s . ")"; return "ctiso\\Tales::phptal_component(" . $s . ")";
} }
}
class Tales_Assets implements PHPTAL_Tales
{
static public function assets($expression, $nothrow = false) static public function assets($expression, $nothrow = false)
{ {
$s = PHPTAL_Php_TalesInternal::string($expression); $s = PHPTAL_Php_TalesInternal::string($expression);
return "ctiso\\Tales::phptal_asset(" . $s . ")"; 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 { class Tales {
@ -56,6 +56,24 @@ class Tales {
return ""; 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);
// Присвоить значения
// <tal:block tal:define="" />
$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 = PHPTAL_TalesRegistry::getInstance();
$tales->registerPrefix('component', ['ctiso\\Tales_Component', 'component']); $tales->registerPrefix('component', ['ctiso\\Tales_Inline', 'component']);
$tales->registerPrefix('date', ['ctiso\\Tales_DateTime', 'date']); $tales->registerPrefix('date', ['ctiso\\Tales_Inline', 'date']);
$tales->registerPrefix('time', ['ctiso\\Tales_DateTime', 'time']); $tales->registerPrefix('time', ['ctiso\\Tales_Inline', 'time']);
$tales->registerPrefix('assets', ['ctiso\\Tales_Assets', 'assets']); $tales->registerPrefix('assets', ['ctiso\\Tales_Inline', 'assets']);
$tales->registerPrefix('module', ['ctiso\\Tales_Inline', 'module']);
} }
} }