Постфиксная запись типов вместо префиксной

This commit is contained in:
CORP\phedor 2018-05-04 14:57:52 +03:00
parent 04662a94df
commit 11370eecc9
33 changed files with 95 additions and 79 deletions

View file

@ -42,7 +42,7 @@ class Collection implements \ArrayAccess
*
* @return void
*/
public function set(/*.string.*/$key, /*.any.*/$value)
public function set($key/*: string*/, $value/*: any*/)
{
$this->data[$key] = $value;
}

View file

@ -47,8 +47,8 @@ class Action
private $helpers = array(); // Помошники для действий
public $part = null; // Параметры для ссылки
public /*.Registry.*/$config; // Ссылка на настройки
public /*.User.*/$user; // Обьект пользователя
public $config/*: Registry*/; // Ссылка на настройки
public $user/*: User*/; // Обьект пользователя
// Для Widgets
public $view = null;
@ -124,7 +124,7 @@ class Action
if(file_exists($template)) { break; }
}
/*.Composite.*/$tpl = new $viewClass($template);
$tpl/*: Composite*/ = new $viewClass($template);
$tpl->config = $this->config;
$stylePath = Path::join($webPath, "assets", "css");
@ -215,7 +215,7 @@ class Action
*/
public function nUrl($name, array $param = array())
{
/*.ActionAccess.*/$access = $this->access;
$access/*: ActionAccess*/ = $this->access;
$url = new Url();
if ($access == null || $access->checkAction($name)) {
@ -334,7 +334,7 @@ class Action
if ($view instanceof View) {
$this->view->assignValues($this->ctrlValues);
/*.Composite.*/$node = null;
$node/*: Composite*/ = null;
foreach ($this->childNodes as $name => $node) {
$node->make($this);
$this->view->setView($name, $node->view);
@ -373,7 +373,7 @@ class Action
$this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction());
}
function redirect(/*.string.*/$action) {
function redirect($action/*: string*/) {
header('location: ' . $action);
exit();
}

View file

@ -49,9 +49,9 @@ class Component
public $COMPONENTS_WEB;
public /*.Registry.*/$config;
public /*.Database.*/$db;
public /*.Collection.*/$parameter;
public $config/*: Registry*/;
public $db/*: Database*/;
public $parameter/*: Collection*/;
public $output = 'html';
@ -94,7 +94,7 @@ class Component
return new FakeTemplate($name);
}
/*.Registry.*/$config = $this->config;
$config/*: Registry*/ = $this->config;
$default = $config->get('site', 'template');
$template = ($this->template) ? $this->template : $default;
@ -157,7 +157,7 @@ class Component
return $model;
}
public function options($key, $val, /*.PDOStatement.*/$res) {
public function options($key, $val, $res/*: PDOStatement*/) {
$result = array();
while($res->next()) {
$result[] = array('value' => $res->getString($key), 'name' => $res->getString($val));
@ -195,7 +195,7 @@ class Component
/**
* Генерация интерфейса для выбора галлереи фотографии
*/
public function setParameters(/*.Composite.*/ $view, $options = null)
public function setParameters($view/*: Composite*/, $options = null)
{
$form = new Form();
@ -207,7 +207,7 @@ class Component
$view->component_title = $settings['title'];
}
static function loadComponent($expression, /*.SiteInterface.*/ $site)
static function loadComponent($expression, $site/*: SiteInterface*/)
{
$expression = htmlspecialchars_decode($expression);
@ -227,7 +227,7 @@ class Component
$path = Path::join ($this->config->get('site', 'path'), 'components', $name, $name . '.php');
$className = 'Component_' . $name;
/*.Component.*/$component = null;
$component/*: Component*/ = null;
if (file_exists($path)) {
require_once ($path);
@ -297,12 +297,12 @@ class Component
return null;
}
function raw_query(/*.ComponentRequest.*/ $request)
function raw_query($request/*: ComponentRequest*/)
{
$arr = $request->r->export('get');
$param = array();
/*.Collection.*/$parameter = $this->parameter;
$parameter/*: Collection*/ = $this->parameter;
foreach($parameter->export() as $key => $value) {
$param[$key] = $value;
}
@ -320,7 +320,7 @@ class Component
}
function query(/*.ComponentRequest.*/ $request, $list)
function query($request/*: ComponentRequest*/, $list)
{
$arr = $request->r->export('get');
@ -336,6 +336,6 @@ class Component
$this->site->addRequireJsPath($name, $path, $shim);
}
function actionIndex(/*.ComponentRequest.*/ $request) {
function actionIndex($request/*: ComponentRequest*/) {
}
}

View file

@ -7,7 +7,7 @@ class Request {
public $r;
public $id;
function __construct(/*.HttpRequest.*/$request, $id) {
function __construct($request/*: HttpRequest*/, $id) {
$this->r = $request;
$this->id = $id;
}

View file

@ -12,7 +12,7 @@ class Service
{
public $viewPath = [];
public $webPath = [];
public /*.Registry.*/$config;
public $config/*: Registry*/;
public $template;
public $templatePath;
public $COMPONENTS_WEB;
@ -51,7 +51,7 @@ class Service
return $model;
}
public function options($key, $val, /*.PDOStatement.*/$res) {
public function options($key, $val, $res/*: PDOStatement*/) {
$result = array();
while($res->next()) {
$result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val));

View file

@ -44,13 +44,13 @@ class Database extends PDO
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
/*.Database.*/$connection = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
$connection/*: Database*/ = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
if ($dsn['phptype'] == 'pgsql') {
$connection->query('SET client_encoding="UTF-8"');
}
}
if ($dsn['phptype'] == 'sqlite') {
/*.Database.*/$connection = new static("{$dsn['phptype']}:{$dsn['database']}");
$connection/*: Database*/ = new static("{$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");
@ -62,7 +62,7 @@ class Database extends PDO
public function executeQuery($query, $values=null)
{
/*.PDOStatement.*/$stmt = $this->prepare($query);
$stmt/*: PDOStatement*/ = $this->prepare($query);
$stmt->execute($values);
$stmt->cache = $stmt->fetchAll(PDO::FETCH_ASSOC);
@ -80,7 +80,7 @@ class Database extends PDO
*/
public function fetchAllArray($query, $values = null)
{
/*.PDOStatement.*/$sth = $this->prepare($query);
$sth/*: PDOStatement*/ = $this->prepare($query);
$prep = $this->prepareValues($values);
$sth->execute($prep);
return $sth->fetchAll(PDO::FETCH_ASSOC);
@ -91,7 +91,7 @@ class Database extends PDO
*/
public function fetchOneArray($query, $values = null)
{
/*.PDOStatement.*/$sth = $this->prepare($query);
$sth/*: PDOStatement*/ = $this->prepare($query);
$prep = $this->prepareValues($values);
$sth->execute($prep);
return $sth->fetch(PDO::FETCH_ASSOC);
@ -182,7 +182,7 @@ class Database extends PDO
}
function prepare($query, $options = NULL) {
/*.PDOStatement.*/$result = parent::prepare($query);
$result/*: PDOStatement*/ = parent::prepare($query);
return $result;
}

View file

@ -43,7 +43,7 @@ class JsonInstall {
}
//Создать таблицы
function initDataBase(/*.array.*/$initActions, $dbinit_path) {
function initDataBase($initActions/*: array*/, $dbinit_path) {
$pg = $this->db_manager->db->isPostgres();
if (!$pg) {
$refs = [];

View file

@ -8,13 +8,13 @@ use ctiso\Database,
class Manager
{
public /*.Database.*/$db;
public $db/*: Database*/;
function __construct(Database $db) {
$this->db = $db;
}
public function ExecuteAction(/*.array.*/$action, $db_file = "") {
public function ExecuteAction($action/*: array*/, $db_file = "") {
switch($action["type"]) {
case "dropTable":
$this->DropTableQuery($action["table_name"], true);
@ -100,7 +100,7 @@ class Manager
return;
}
/*.array.*/$data = $this->DumpTable($table);
$data/*: array*/ = $this->DumpTable($table);
$this->db->query("ALTER TABLE ".$table." RENAME TO ".$tmp_table.";");
$table_info[$new_name] = $table_info[$old_name];
@ -147,7 +147,7 @@ class Manager
$this->db->query($q);
}
function getConstraintDef(/*.array.*/$c) {
function getConstraintDef($c/*: array*/) {
if ($c['type'] == 'unique') {
return "UNIQUE(" . implode(", ", $c['fields']) . ")";
}
@ -175,8 +175,8 @@ class Manager
public function DumpTable($table_name) {
$pg = $this->db->isPostgres();
/*.array.*/$result = array();
/*.array.*/$data = $this->db->fetchAllArray("SELECT * FROM ".$table_name.";");
$result/*: array*/ = array();
$data/*: array*/ = $this->db->fetchAllArray("SELECT * FROM ".$table_name.";");
if (!$pg) {
$table_fields = $this->TableInfo($table_name);
@ -184,7 +184,7 @@ class Manager
$type = strtolower($value['type']);
if ($type == "boolean") {
foreach ($data as &$row) {
/*.array.*/$row = $row;
$row/*: array*/ = $row;
if (isset($row[$name])) {
$row[$name] = boolval($row[$name]);
}

View file

@ -16,7 +16,7 @@ class Statement
protected $conn;
protected $query;
function __construct($query, /*.Database.*/ $conn) {
function __construct($query, $conn/*: Database*/) {
$this->query = $query;
$this->conn = $conn;
}
@ -51,7 +51,7 @@ class Statement
if ($this->limit) {
$this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}";
}
/*.PDOStatement.*/$stmt = $this->conn->prepare($this->query);
$stmt/*: PDOStatement*/ = $this->conn->prepare($this->query);
foreach ($this->binds as $bind) {
list($n, $value, $type) = $bind;
$stmt->bindValue($n, $value, (int) $type);

View file

@ -11,7 +11,7 @@ class StatementIterator implements \Iterator
private $fetchmode;
private $row_count;
public function __construct(/*.PDOStatement.*/ $rs) {
public function __construct($rs/*: PDOStatement*/) {
$this->result = $rs;
$this->row_count = $rs->getRecordCount();
}

View file

@ -43,7 +43,7 @@ class Document {
if ($type == 'Borders') {
$doc->startElement('Borders');
foreach ($s as $border) {
/*.array.*/$border = $border;
$border/*: array*/ = $border;
$doc->startElement('Border');
foreach ($border as $key => $value) {
$doc->writeAttribute('ss:' . $key, $value);

View file

@ -69,7 +69,7 @@ class Table
if(! isset($this->rows[$x])) {
$this->rows[$x] = new TableRow();
}
/*.TableRow.*/$row = $this->rows[$x];
$row/*: TableRow*/ = $this->rows[$x];
$row->setCell($y, $value);
}
@ -123,7 +123,7 @@ class Table
assert(is_numeric($x) && $x > 0);
assert(is_numeric($cell) && $cell > 0);
/*.TableRow.*/$row = $this->rows[$x];
$row/*: TableRow*/ = $this->rows[$x];
$row->cells[$cell]->merge = $merge;
}
@ -158,7 +158,7 @@ class Table
*/
function getRows()
{
/*.array.*/$keys = array_keys($this->rows);
$keys/*: array*/ = array_keys($this->rows);
return max($keys);
}
@ -169,7 +169,7 @@ class Table
*/
function getRowCells(TableRow $row)
{
/*.array.*/$keys = array_keys($row->cells);
$keys/*: array*/ = array_keys($row->cells);
return max($keys);
}
@ -207,7 +207,7 @@ class Table
/**
* Генерация клетки таблицы (Переработать)
*/
function createCell (TableCell $ncell, XMLWriter $doc, $j, /*.any.*/$value, $setIndex) {
function createCell (TableCell $ncell, XMLWriter $doc, $j, $value/*: any*/, $setIndex) {
$doc->startElement("Cell");
if ($ncell->style) {
@ -267,7 +267,7 @@ class Table
$doc->writeAttribute('ss:Height', $this->rows[$i]->height);
}
/*.TableRow.*/$nrow = $this->rows[$i];
$nrow/*: TableRow*/ = $this->rows[$i];
// Флаг индикатор подстановки номера столбца
$setIndex = false;
for ($j = 1; $j <= $columns; $j++) {

View file

@ -12,9 +12,9 @@ class ActionAccess
{
public $access = array();
public $processor;
public /*.User.*/$user;
public $user/*: User*/;
function __construct(/*.Filter.*/$processor, $user) {
function __construct($processor/*: Filter*/, $user) {
$this->processor = $processor;
$this->user = $user;
}

View file

@ -1,7 +1,8 @@
<?php
namespace ctiso\Filter;
use ctiso\HttpRequest;
use ctiso\Role\UserInterface,
ctiso\HttpRequest;
/* Переделать формат Логов на список json */
class ActionLogger
@ -12,7 +13,7 @@ class ActionLogger
public $action;
public $processor;
function __construct(/*.Filter.*/$processor, $logPath, $user) {
function __construct($processor/*: Filter*/, $logPath, $user/*: UserInterface*/) {
$this->processor = $processor;
$this->user = $user;
@ -27,7 +28,7 @@ class ActionLogger
function execute(HttpRequest $request) {
$action = $request->getAction();
if(in_array($action, $this->before)) {
$message = ["time" => date("r", time()), "query" => array_merge($_POST, $_GET), "user" => $this->user->name];
$message = ["time" => date("r", time()), "query" => array_merge($_POST, $_GET), "user" => $this->user->getName()];
fwrite($this->file, json_encode($message) . "\n");
}
return $this->processor->execute($request);

View file

@ -11,7 +11,7 @@ use ctiso\Controller\Action,
class Filter
{
public $processor;
public function __construct(/*.Action.*/$processor)
public function __construct($processor/*: Action*/)
{
$this->processor = $processor;
}

View file

@ -23,7 +23,7 @@ class Login extends Filter
public $mode = 'ajax';
public $user;
public /*.User.*/$role;
public $role/*: User*/;
public $whitelist;
function __construct($processor, $role, $whitelist = []) {

View file

@ -40,7 +40,7 @@ class Field
}
}
function setValue(/*.any.*/$value)
function setValue($value/*: any*/)
{
$this->value = $value;
}

View file

@ -226,7 +226,7 @@ class Functions {
*
* @return mixed
*/
static function key_values($key, /*array|ArrayIterator*/ $array) {
static function key_values($key, $array/*: array|ArrayIterator*/) {
$result = array();
foreach($array as $item) {
@ -235,7 +235,7 @@ class Functions {
return $result;
}
static function key_values_object($key, /*array|ArrayIterator*/ $array) {
static function key_values_object($key, $array/*: array|ArrayIterator*/) {
$result = array();
foreach($array as $item) {
@ -260,7 +260,7 @@ class Functions {
return $result;
}
static function _get($key, /*.any.*/$value, /*.array.*/$array) {
static function _get($key, $value/*: any*/, $array/*: array*/) {
foreach ($array as $item) {
if ($item[$key] == $value) return $item;
}
@ -373,7 +373,7 @@ class Functions {
* Преобразует ключи элементов для многомерного массива
* @return mixed
*/
static function hash_key ($key_name,/*. array .*/ $array) {
static function hash_key ($key_name,$array/*: array */) {
$result = array();
foreach($array as $value) {

View file

@ -56,7 +56,7 @@ class HttpRequest extends Collection implements ArrayAccess
return $this->_session;
}
function set($key, /*.any.*/$value)
function set($key, $value/*: any*/)
{
return parent::get('data')->set($key, $value);
}

View file

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

View file

@ -51,7 +51,7 @@ class MailAlt
/**
* Тема письма
*/
function subject(/*.string.*/$subject)
function subject($subject/*: string*/)
{
$this->mailer->Subject = $subject;
}

View file

@ -160,7 +160,7 @@ class Path
}
// Сравнение двух путей на равентство
public function equal(/*.Path.*/ $path)
public function equal($path/*: Path*/)
{
$count = count($this->path);
if ($count == count($path->path)) {
@ -205,7 +205,7 @@ class Path
*
* @return boolean
*/
public function isParent(/*.Path.*/ $path)
public function isParent($path/*: Path*/)
{
if (isset($this->url['host']) && isset($path->url['host'])
&& ($this->url['host'] != $path->url['host'])) return false;

View file

@ -5,7 +5,7 @@ use ctiso\Database,
ctiso\Database\Statement;
// Класс должен быть в библиотеке приложения
class User
class User implements UserInterface
{
const LIFE_TIME = 1800; // = 30min * 60sec;
@ -26,6 +26,10 @@ class User
$this->db = $db;
}
public function getName() {
return $this->name;
}
public function getUserByQuery(Statement $stmt)
{
$result = $stmt->executeQuery();

View file

@ -0,0 +1,11 @@
<?php
namespace ctiso\Role;
interface UserInterface {
function getUserByQuery(Statement $stmt);
function getUserByLogin($login);
function getUserById($id);
function getName();
function setSID();
}

View file

@ -123,7 +123,7 @@ class Setup
return;
}
/*.\SimpleXMLElement.*/$item = $this->stack[count($this->stack) - 1];
$item/*: \SimpleXMLElement*/ = $this->stack[count($this->stack) - 1];
$root = $item->children();
foreach ($root as $node)
{
@ -200,7 +200,7 @@ class Setup
/**
* Выполнение Списка SQL команд
*/
function batchSQLZip(/*.Database.*/ $conn, $file)
function batchSQLZip($conn/*: Database*/, $file)
{
$stmtList = SQLStatementExtractor::extract($this->zip->getFromName($file));
foreach ($stmtList as $stmt) {
@ -208,7 +208,7 @@ class Setup
}
}
static function batchSQL(/*.Database.*/ $conn, $file)
static function batchSQL($conn/*: Database*/, $file)
{
$stmtList = SQLStatementExtractor::extractFile($file);
foreach ($stmtList as $stmt) {

View file

@ -32,7 +32,7 @@ class Tales_Component implements PHPTAL_Tales
}
class Tales {
static /*.SiteInterface.*/$site;
static $site/*: SiteInterface*/;
static function phptal_date ($e) {
return date("d.m.Y", $e);
@ -47,7 +47,7 @@ class Tales {
*/
static function phptal_component ($expression) {
$begin = floatval(microtime(true));
/*.Component.*/$component = null;
$component/*: Component*/ = null;
$component = self::$site->loadComponent($expression);
$req = new HttpRequest();

View file

@ -124,7 +124,7 @@ class SQLStatementExtractor {
* @param string $string The string to check in (haystack).
* @return boolean True if $string ends with $check, or they are equal, or $check is empty.
*/
protected static function endsWith(/*.string.*/$check, $string) {
protected static function endsWith($check/*: string*/, $string) {
if ($check === "" || $check === $string) {
return true;
} else {

View file

@ -122,7 +122,7 @@ class TemplateImage
return "";
}
function imageText($text, /*.\stdClass.*/$value)
function imageText($text, $value/*: \stdClass*/)
{
assert(is_string($text));

View file

@ -4,7 +4,7 @@ namespace ctiso;
class Url {
public $parts = [];
public /*.Url.*/$parent;
public $parent/*: Url*/;
function __construct() {
}

View file

@ -74,7 +74,7 @@ class Validator
}
}
public function addRule(/*.any.*/$rule) {
public function addRule($rule/*: any*/) {
if (is_array($rule)) {
$this->chain = array_merge($this->chain, $rule);
} else {
@ -82,7 +82,7 @@ class Validator
}
}
public function skip(/*.AbstractRule.*/$rule, /*.Collection.*/$container) // -> Rule_Abstract
public function skip($rule/*: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract
{
if ($rule->skipEmpty()) {
$data = $container->get($rule->field);

View file

@ -10,7 +10,7 @@ class Page extends View
{
private $counter;
public $text;
public /*.SiteInterface.*/$site;
public $site/*: SiteInterface*/;
function __construct($data, $site)
{
@ -55,7 +55,7 @@ class Page extends View
function replaceContent($match, $offset)
{
/*.Component.*/$component = $this->site->loadComponent($match);
$component/*: Component*/ = $this->site->loadComponent($match);
$req = new HttpRequest();
unset($req['active_page']);

View file

@ -33,7 +33,7 @@ class Pages
* @param $onpage int количество элем на странице
* @return string
*/
static function getLimit(/*.number.*/$page, /*.number.*/$onpage) {
static function getLimit($page/*: number*/, $onpage/*: number*/) {
if ($page <= 0) { $page = 1; }
return "LIMIT $onpage OFFSET " . ($page - 1) * $onpage;
}

View file

@ -102,7 +102,7 @@ class Top extends Composite {
$init = array();
foreach($s->_section as $key => $item) {
/*.View.*/$ss = $item;
$ss/*: View*/ = $item;
if ($ss->codeGenerator !== null) {
// функцию которая вычисляет а не результат
$part = call_user_func($ss->codeGenerator, $this, $key, $value);