Обьединение с namespace

This commit is contained in:
CORP\phedor 2018-03-28 11:15:16 +03:00
commit 8b38b2a3cc
90 changed files with 601 additions and 222 deletions

View file

@ -3,34 +3,36 @@
/**
* Расширения для PHPTAL для отображения времени и даты
*/
class DateTime_Tales implements PHPTAL_Tales
namespace ctiso;
use PHPTAL_Php_TalesInternal,
ctiso\Controller\Site,
ctiso\Controller\Component,
ctiso\HttpRequest,
PHPTAL_TalesRegistry;
class Tales_DateTime_ implements PHPTAL_Tales
{
static public function date($expression, $nothrow = false)
{
return "Tales::phptal_date(".PHPTAL_Php_TalesInternal::path ($expression).")";
static public function date($expression, $nothrow = false) {
return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path ($expression).")";
}
static public function time($expression, $nothrow = false)
{
return "Tales::phptal_time(".PHPTAL_Php_TalesInternal::path ($expression).")";
static public function time($expression, $nothrow = false) {
return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path ($expression).")";
}
}
/**
* TALES для подключения компонентов
* component:name?param1=value1&param2=value2
*/
class Component_Tales implements PHPTAL_Tales
class Tales_Component implements PHPTAL_Tales
{
static public function component($expression, $nothrow = false)
{
$s = PHPTAL_Php_TalesInternal::string($expression);
return "Tales::phptal_component(" . $s . ")";
return "ctiso\\Tales::phptal_component(" . $s . ")";
}
}
class Tales {
static $db;
static $registry;
static function phptal_date ($e) {
return date("d.m.Y", $e);
@ -47,14 +49,12 @@ class Tales {
$begin = floatval(microtime(true));
/*.Controller_Component.*/$component = null;
if (class_exists("Controller_Site")) { //Если мы в CMS2
$component = Controller_Site::loadComponent($expression);
if (class_exists("ctiso\\Controller\\Site")) { //Если мы в CMS2
$component = Site::loadComponent($expression);
} else {
global $db, $registry; // Иначе обращаемся к глобальным переменным
$component = Controller_Component::loadComponent($expression, $db, $registry);
$component = Component::loadComponent($expression, self::$db, self::$registry);
}
$req = new HttpRequest();
$req = new HttpRequest();
$result = $component->execute($req);
echo "<!-- ", $expression, ", ", round(floatval(microtime(true)) - $begin, 4), "sec -->";
@ -62,11 +62,14 @@ class Tales {
}
static function register() {
static function register($db, $registry) {
self::$db = $db;
self::$registry = $registry;
/* Регистрация нового префикса для подключения компонента */
$tales = PHPTAL_TalesRegistry::getInstance();
$tales->registerPrefix('component', array('Component_Tales', 'component'));
$tales->registerPrefix('date', array('DateTime_Tales', 'date'));
$tales->registerPrefix('time', array('DateTime_Tales', 'time'));
$tales->registerPrefix('component', array('ctiso\\Component_Tales', 'component'));
$tales->registerPrefix('date', array('ctiso\\DateTime_Tales', 'date'));
$tales->registerPrefix('time', array('ctiso\\DateTime_Tales', 'time'));
}
}