Модули c namespace

This commit is contained in:
CORP\phedor 2018-03-27 17:31:49 +03:00
parent 0f4b2fb722
commit e9f7c23990
11 changed files with 92 additions and 80 deletions

View file

@ -1,5 +1,7 @@
<?php
namespace ctiso;
/**
* Интерфейс к массиву и обьекту как к коллекции
*/

View file

@ -1,5 +1,7 @@
<?php
namespace ctiso;
class Arr {
static function get($data, $key, $default = null) {
return isset($data[$key]) ? $data[$key] : $default;

View file

@ -1,4 +1,6 @@
<?php
namespace ctiso;
/**
* Коллекция
*

View file

@ -53,7 +53,9 @@ class Controller_Front extends Controller_Action
$moduleFile = Shortcut::getUrl($this->shortcut, $name, $name); // ModuleLoader (2)
}
$module = $this->loadClass($moduleFile, null, 'Module_');
$ucname = ucfirst($name);
$moduleClass = "Module\\$ucname\\$ucname";
$module = new $moduleClass();//$this->loadClass($moduleFile, null, 'Module\\');
if ($module) {
// Инициализация модуля
$module->viewPath = Shortcut::getUrl('modulepath', $name);

View file

@ -46,7 +46,7 @@ class Controller_Service
return $model;
}
public function options($key, $val, $res) {
public function options($key, $val, /*.Database_PDOStatement.*/$res) {
$result = array();
while($res->next()) {
$result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val));

View file

@ -1,6 +1,6 @@
<?php
///<reference path="Database/PDOStatement.php" />
require_once "Database/PDOStatement.php";
namespace ctiso;
/**
* Класс оболочка для PDO для замены Creole

View file

@ -1,13 +1,16 @@
<?php
class Database_PDOStatement extends PDOStatement implements IteratorAggregate
namespace ctiso\Database\PDOStatement;
use ctiso\Database\StatementIterator;
class PDOStatement extends \PDOStatement implements \IteratorAggregate
{
protected $cursorPos = 0;
public $cache = array();
public $fields;
function getIterator() {
return new Database_StatementIterator($this);
return new StatementIterator($this);
}
protected function __construct() {

View file

@ -88,7 +88,7 @@ class __compose {
class Functions {
static function partial() {
static function partial($_rest) {
$closure = new __partial(func_get_args());
return array($closure, 'apply');
}
@ -101,7 +101,7 @@ class Functions {
*
* @return array[int]mixed
*/
static function compose() {
static function compose($_rest) {
$closure = new __compose(func_get_args());
return array($closure, 'apply');
}

View file

@ -30,7 +30,7 @@ class Layout_Manager extends Filter_Filter
$this->addCondition(Functions::rcurry(array($this, 'checkXHR'), $get), $layout);
}
public function checkGet($request, $get)
public function checkGet(/*.HttpRequest.*/$request, $get)
{
if (is_array($get)) {
foreach ($get as $key => $value) {
@ -42,7 +42,7 @@ class Layout_Manager extends Filter_Filter
return true;
}
public function checkXHR($request, $get)
public function checkXHR(/*.HttpRequest.*/$request, $get)
{
return $request->isAjax() && $this->checkGet($request, $get);
}

72
src/Tales.php Normal file
View file

@ -0,0 +1,72 @@
<?php
/**
* Расширения для PHPTAL для отображения времени и даты
*/
class DateTime_Tales implements PHPTAL_Tales
{
static public function date($expression, $nothrow = false)
{
return "Tales::phptal_date(".PHPTAL_Php_TalesInternal::path ($expression).")";
}
static public function time($expression, $nothrow = false)
{
return "Tales::phptal_time(".PHPTAL_Php_TalesInternal::path ($expression).")";
}
}
/**
* TALES для подключения компонентов
* component:name?param1=value1&param2=value2
*/
class Component_Tales implements PHPTAL_Tales
{
static public function component($expression, $nothrow = false)
{
$s = PHPTAL_Php_TalesInternal::string($expression);
return "Tales::phptal_component(" . $s . ")";
}
}
class Tales {
static function phptal_date ($e) {
return date("d.m.Y", $e);
}
static function phptal_time ($e) {
return date("H:i", $e);
}
/**
* Функция подключения компонента
*/
static function phptal_component ($expression) {
$begin = floatval(microtime(true));
/*.Controller_Component.*/$component = null;
if (class_exists("Controller_Site")) { //Если мы в CMS2
$component = Controller_Site::loadComponent($expression);
} else {
global $db, $registry; // Иначе обращаемся к глобальным переменным
$component = Controller_Component::loadComponent($expression, $db, $registry);
}
$req = new HttpRequest();
$result = $component->execute($req);
echo "<!-- ", $expression, ", ", round(floatval(microtime(true)) - $begin, 4), "sec -->";
return $result;
}
static function register() {
/* Регистрация нового префикса для подключения компонента */
$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'));
}
}

View file

@ -1,71 +0,0 @@
<?php
/**
* Расширения для PHPTAL для отображения времени и даты
*/
class DateTime_Tales implements PHPTAL_Tales
{
static public function date($expression, $nothrow = false)
{
return "phptal_date(".PHPTAL_Php_TalesInternal::path ($expression).")";
}
static public function time($expression, $nothrow = false)
{
return "phptal_time(".PHPTAL_Php_TalesInternal::path ($expression).")";
}
}
/**
* TALES для подключения компонентов
* component:name?param1=value1&param2=value2
*/
class Component_Tales implements PHPTAL_Tales
{
static public function component($expression, $nothrow = false)
{
$s = PHPTAL_Php_TalesInternal::string($expression);
return "phptal_component(" . $s . ")";
}
}
function phptal_date ($e)
{
return date("d.m.Y", $e);
}
function phptal_time ($e)
{
return date("H:i", $e);
}
/**
* Функция подключения компонента
*/
function phptal_component ($expression) {
$begin = floatval(microtime(true));
/*.Controller_Component.*/$component = null;
if (class_exists("Controller_Site")) { //Если мы в CMS2
$component = Controller_Site::loadComponent($expression);
} else {
global $db, $registry; // Иначе обращаемся к глобальным переменным
$component = Controller_Component::loadComponent($expression, $db, $registry);
}
$req = new HttpRequest();
$result = $component->execute($req);
echo "<!-- ", $expression, ", ", round(floatval(microtime(true)) - $begin, 4), "sec -->";
return $result;
}
/* Регистрация нового префикса для подключения компонента */
$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'));