Оптимизации и исправления топов.

This commit is contained in:
CORP\phedor 2018-03-23 12:35:10 +03:00
parent 77fa3dbd5e
commit 0f4b2fb722
25 changed files with 109 additions and 53 deletions

View file

@ -58,17 +58,17 @@ class Collection implements ArrayAccess
public function getInt($key, $default = 0) public function getInt($key, $default = 0)
{ {
return intval($this->get($key, $default)); return (int)$this->get($key, $default);
} }
public function getString($key, $default = '') public function getString($key, $default = '')
{ {
return ((string) $this->get($key, $default)); return (string)$this->get($key, $default);
} }
public function getNat($key, $default = 1) public function getNat($key, $default = 1)
{ {
$result = intval($this->get($key, $default)); $result = (int)$this->get($key, $default);
return (($result > 0) ? $result : $default); return (($result > 0) ? $result : $default);
} }

View file

@ -36,12 +36,12 @@ class Connection_HttpResponse
if (isset($this->param['Transfer-Encoding']) && $this->param['Transfer-Encoding'] == 'chunked') { if (isset($this->param['Transfer-Encoding']) && $this->param['Transfer-Encoding'] == 'chunked') {
//$this->data = substr($this->response, $this->offset); //$this->data = substr($this->response, $this->offset);
$line = hexdec($this->getLine()); $index = hexdec($this->getLine());
$chunk = array(); $chunk = array();
while ($line > 0) { while ($index > 0) {
$chunk [] = substr($this->response, $this->offset, $line); $chunk [] = substr($this->response, $this->offset, $index);
$this->offset += $line; $this->offset += $index;
$line = hexdec($this->getLine()); $index = hexdec($this->getLine());
} }
$this->data = implode("", $chunk); $this->data = implode("", $chunk);

View file

@ -38,6 +38,23 @@ class ComponentRequest {
} }
} }
class FakeTemplate {
public $_data = [];
public $_name = '';
function __construct($name) {
$this->_name = $name;
}
function __set($key, $value) {
$this->_data[$key] = $value;
}
function execute() {
return $this->_data;
}
}
/** /**
* Класс компонента * Класс компонента
*/ */
@ -56,6 +73,7 @@ class Controller_Component
public /*.Settings.*/$registry; public /*.Settings.*/$registry;
public /*.Database.*/$db; public /*.Database.*/$db;
public /*.Collection.*/$parameter; public /*.Collection.*/$parameter;
public $output = 'html';
public $module; public $module;
public $item_module; public $item_module;
@ -86,6 +104,10 @@ class Controller_Component
public function getView($name) public function getView($name)
{ {
if ($this->output == 'json') {
return new FakeTemplate($name);
}
// //
/*.Settings.*/$registry = $this->registry; /*.Settings.*/$registry = $this->registry;
$template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template')); $template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template'));
@ -164,8 +186,18 @@ class Controller_Component
return $result; return $result;
} }
function findFile($pathList, $name) {
foreach($pathList as $item) {
$filename = Path::join($item, $name);
if (file_exists($filename)) {
return $filename;
}
}
return null;
}
function getInfo() { function getInfo() {
$filename = Path::join($this->viewPath[0], 'install.json'); $filename = $this->findFile($this->viewPath, 'install.json');
if (file_exists($filename)) { if (file_exists($filename)) {
$settings = json_decode(File::getContents($filename), true); $settings = json_decode(File::getContents($filename), true);
return $settings; return $settings;
@ -262,13 +294,13 @@ class Controller_Component
} }
$params = new Collection(); $params = new Collection();
$params->import(array_merge($_GET, $arguments)); $params->import($arguments);
$component->parameter = $params; $component->parameter = $params;
$component->template = $params->get('template', false); $component->template = $params->get('template', false);
$editor = $component->getEditUrl(); $editor = $component->getEditUrl();
if ($editor) { if ($editor) {
if(class_exists("Controller_Site")){ //Если мы в CMS2 if(class_exists("Controller_Site")) { //Если мы в CMS2
$instance = Controller_Site::getInstance(); $instance = Controller_Site::getInstance();
$instance->componentsConfig[] = $editor; $instance->componentsConfig[] = $editor;
} else { } else {

View file

@ -40,7 +40,7 @@ class Controller_Front extends Controller_Action
* @param request $request Имя модуля * @param request $request Имя модуля
* @return string * @return string
*/ */
public function loadModule($name, Collection $request, $controller = false) public function loadModule($name, Collection $request, $controller = null)
{ {
if ($this->isLoaded($name)) { if ($this->isLoaded($name)) {
$module = $this->modules[$name]; $module = $this->modules[$name];
@ -93,13 +93,13 @@ class Controller_Front extends Controller_Action
$this->default = $name; $this->default = $name;
} }
public function execute(HTTPRequest $request) public function execute(HttpRequest $request)
{ {
$name = explode("_", $request->get($this->_param, $this->default)); $name = explode("_", $request->get($this->_param, $this->default));
if (count($name) >= 2) { if (count($name) >= 2) {
$controller = $name[1]; $controller = $name[1];
} else { } else {
$controller = false; $controller = null;
} }
try{ try{
return $this->loadModule($name[0], $request, $controller); return $this->loadModule($name[0], $request, $controller);

View file

@ -1,13 +1,17 @@
<?php <?php
class Controller_Request { class Controller_Request {
function __construct($request, $id) { public $r;
public $id;
function __construct(/*.HttpRequest.*/$request, $id) {
$this->r = $request; $this->r = $request;
$this->id = $id; $this->id = $id;
} }
function get($name) { function get($name, $def) {
$v = $this->r->get($name); $v = $this->r->get($name);
$id = $this->id;
if ($id && is_array($v)) { if ($id && is_array($v)) {
return isset($v[$id]) ? $v[$id] : $def; return isset($v[$id]) ? $v[$id] : $def;
} }

View file

@ -5,12 +5,15 @@
*/ */
class Controller_Service class Controller_Service
{ {
public $viewPath = array(); public $viewPath = [];
public $webPath = [];
public $registry; // Registry->getInstance public $registry; // Registry->getInstance
public $template; public $template;
public $templatePath; public $templatePath;
public $COMPONENTS_WEB; public $COMPONENTS_WEB;
public $db;
public function getTemplatePath($name) public function getTemplatePath($name)
{ {
return Path::join($this->viewPath[0], 'templates', 'modern', $name); return Path::join($this->viewPath[0], 'templates', 'modern', $name);

View file

@ -21,6 +21,6 @@ class Database_IdGenerator {
} else { } else {
$result = $this->db->fetchOneArray("SELECT last_insert_rowid() AS nextval"); $result = $this->db->fetchOneArray("SELECT last_insert_rowid() AS nextval");
} }
return intval($result['nextval']); return (int)$result['nextval'];
} }
} }

View file

@ -66,7 +66,7 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate
} }
function getInt($name) { function getInt($name) {
return intval($this->fields[$name]); return (int)$this->fields[$name];
} }
function getBlob($name) { function getBlob($name) {

View file

@ -6,7 +6,7 @@ class Excel_DateTime
function __construct($value) function __construct($value)
{ {
$this->value = intval($value); $this->value = (int)$value;
} }
function getString() function getString()

View file

@ -6,7 +6,7 @@ class Excel_Number
function __construct($value) function __construct($value)
{ {
$this->value = intval($value); $this->value = (int)$value;
} }
function getString() function getString()

View file

@ -50,7 +50,7 @@ class Excel_Table
function __construct() function __construct()
{ {
$this->name = "Page " . intval(self::$index ++); $this->name = "Page " . ((int)self::$index ++);
} }
/** /**
@ -230,7 +230,7 @@ class Excel_Table
} else { } else {
$doc->writeAttribute('ss:Type', "Number"); $doc->writeAttribute('ss:Type', "Number");
} }
$doc->writeCData($this->encode($value)); $doc->writeCdata($this->encode($value));
} }
$doc->endElement(); $doc->endElement();
$doc->endElement(); $doc->endElement();

View file

@ -13,6 +13,7 @@ class Filter_Login extends Filter_Filter
const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#'; const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#';
const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign'; const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign';
public $mode = 'ajax'; public $mode = 'ajax';
public $user;
//AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики //AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики
public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"], public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"],

View file

@ -53,7 +53,8 @@ class __partial {
function apply() { function apply() {
$params = func_get_args(); $params = func_get_args();
$result = array(); $result = array();
for($i = 0, $j = 0; $i < count($this->params); $i++) { $count = count($this->params);
for($i = 0, $j = 0; $i < $count; $i++) {
if ($this->params[$i] == __) { if ($this->params[$i] == __) {
$result [] = $params[$j]; $result [] = $params[$j];
$j++; $j++;
@ -77,7 +78,8 @@ class __compose {
function apply () { function apply () {
$params = func_get_args (); $params = func_get_args ();
$result = call_user_func_array($this->fns[0], $params); $result = call_user_func_array($this->fns[0], $params);
for ($i = 1; $i < count($this->fns); $i++) { $count = count($this->fns);
for ($i = 1; $i < $count; $i++) {
$result = call_user_func($this->fns[$i], $result); $result = call_user_func($this->fns[$i], $result);
} }
return $result; return $result;
@ -306,7 +308,8 @@ class Functions {
assert(is_int($length)); assert(is_int($length));
$result = array(); $result = array();
for($i = 0; $i < count($array); $i += $length) { $count = count($array);
for($i = 0; $i < $count; $i += $length) {
$result [] = array_slice($array, $i, $length); $result [] = array_slice($array, $i, $length);
} }
return $result; return $result;

View file

@ -15,7 +15,8 @@ class Numbers
static function prefix($prefix, array $array, $key = false) static function prefix($prefix, array $array, $key = false)
{ {
$result = array(); $result = array();
for ($i = 0; $i < count($array); $i++) { $count = count($array);
for ($i = 0; $i < $count; $i++) {
$result [] = call_user_func($prefix, $i + 1) . '. ' . $array[$i]; $result [] = call_user_func($prefix, $i + 1) . '. ' . $array[$i];
} }
return $result; return $result;

View file

@ -160,8 +160,9 @@ class Path
// Сравнение двух путей на равентство // Сравнение двух путей на равентство
public function equal(/*.Path.*/ $path) public function equal(/*.Path.*/ $path)
{ {
if (count($this->path) == count($path->path)) { $count = count($this->path);
for ($i = 0; $i < count($this->path); $i++) { if ($count == count($path->path)) {
for ($i = 0; $i < $count; $i++) {
if ($this->path[$i] != $path->path[$i]) { if ($this->path[$i] != $path->path[$i]) {
return false; return false;
} }
@ -207,8 +208,9 @@ class Path
if (isset($this->url['host']) && isset($path->url['host']) if (isset($this->url['host']) && isset($path->url['host'])
&& ($this->url['host'] != $path->url['host'])) return false; && ($this->url['host'] != $path->url['host'])) return false;
if (count($path->path) > count($this->path)) { $count = count($this->path);
for ($i = 0; $i < count($this->path); $i++) { if (count($path->path) > $count) {
for ($i = 0; $i < $count; $i++) {
if ($path->path[$i] != $this->path[$i]) { if ($path->path[$i] != $this->path[$i]) {
return false; return false;
} }
@ -252,15 +254,18 @@ class Path
$list_path = $list->getParts(); $list_path = $list->getParts();
$result = array(); $result = array();
for ($i = 0; $i < count($list_path); $i++) { $count = count($list_path);
for ($i = 0; $i < $count; $i++) {
if (($i >= count($self_path)) || $list_path[$i] != $self_path[$i]) { if (($i >= count($self_path)) || $list_path[$i] != $self_path[$i]) {
break; break;
} }
} }
for($j = $i; $j < count($list_path); $j++) { $list_count = count($list_path);
for($j = $i; $j < $list_count; $j++) {
array_push($result, '..'); array_push($result, '..');
} }
for($j = $i; $j < count($self_path); $j++) { $self_count = count($self_path);
for($j = $i; $j < $self_count; $j++) {
array_push($result, $self_path[$j]); array_push($result, $self_path[$j]);
} }
return implode("/", $result); return implode("/", $result);

View file

@ -48,9 +48,9 @@ class Primitive {
if (!empty($tmp)) { if (!empty($tmp)) {
if (count($tmp) != 3) return $result; if (count($tmp) != 3) return $result;
$year = intval($tmp[2]); $year = (int)$tmp[2];
$month = intval($tmp[1]); $month = (int)$tmp[1];
$day = intval($tmp[0]); $day = (int)$tmp[0];
if ($month != 0 && $day != 0 && $year != 0) { if ($month != 0 && $day != 0 && $year != 0) {
if (checkdate($month, $day, $year)) { if (checkdate($month, $day, $year)) {

View file

@ -40,7 +40,8 @@ class Tools_Drawing
$first_word = true; $first_word = true;
$last_width = 0; $last_width = 0;
for ($i = 0; $i < count($words); $i++) { $count = count($words);
for ($i = 0; $i < $count; $i++) {
$item = $words[$i]; $item = $words[$i];
$dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item); $dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item);
$line_width = $dimensions[2] - $dimensions[0]; $line_width = $dimensions[2] - $dimensions[0];

View file

@ -111,7 +111,7 @@ class Tools_SQLStatementExtractor {
if ($check === "" || $check === $string) { if ($check === "" || $check === $string) {
return true; return true;
} else { } else {
return (strpos($string, $check) === 0) ? true : false; return (strpos($string, $check) === 0);
} }
} }
@ -125,7 +125,7 @@ class Tools_SQLStatementExtractor {
if ($check === "" || $check === $string) { if ($check === "" || $check === $string) {
return true; return true;
} else { } else {
return (strpos(strrev($string), strrev($check)) === 0) ? true : false; return (strpos(strrev($string), strrev($check)) === 0);
} }
} }

View file

@ -15,7 +15,7 @@ class Tools_String {
if ($in_subarr > 0) { // already in sub-array? if ($in_subarr > 0) { // already in sub-array?
$subarr[$in_subarr][] = $tok; $subarr[$in_subarr][] = $tok;
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
$res[] = strToArray(implode(',', $subarr[$in_subarr])); $res[] = self::strToArray(implode(',', $subarr[$in_subarr]));
$in_subarr--; $in_subarr--;
} }
} elseif ($tok{0} === '{') { // we're inside a new sub-array } elseif ($tok{0} === '{') { // we're inside a new sub-array
@ -25,7 +25,7 @@ class Tools_String {
$subarr[$in_subarr] = array(); $subarr[$in_subarr] = array();
$subarr[$in_subarr][] = $tok; $subarr[$in_subarr][] = $tok;
} else { } else {
$res[] = strToArray($tok); $res[] = self::strToArray($tok);
} }
} else { // not sub-array } else { // not sub-array
$val = trim($tok, '"'); // remove " (surrounding strings) $val = trim($tok, '"'); // remove " (surrounding strings)

View file

@ -33,13 +33,16 @@ class Tools_TemplateImage
protected $data = array(); protected $data = array();
protected $base = "c:\\windows\\fonts\\"; protected $base = "c:\\windows\\fonts\\";
protected $image; protected $image;
protected $prepare = true; protected $_prepare = true;
public $debug = false; public $debug = false;
function __construct ($template = false) public $resource;
public $filename;
function __construct ($template = null)
{ {
// assert(is_string($src)); // assert(is_string($src));
if($template) { if ($template) {
$this->data = $template; $this->data = $template;
} }
} }
@ -116,7 +119,7 @@ class Tools_TemplateImage
return ""; return "";
} }
function imageText($text, $value) function imageText($text, /*.stdClass.*/$value)
{ {
assert(is_string($text)); assert(is_string($text));
@ -134,7 +137,7 @@ class Tools_TemplateImage
} }
if ($value->valign[0]) { if ($value->valign[0]) {
$valign = Drawing::ALIGN_TOP; $valign = Tools_Drawing::ALIGN_TOP;
} elseif ($value->valign[1]) { } elseif ($value->valign[1]) {
$valign = Tools_Drawing::ALIGN_CENTER; $valign = Tools_Drawing::ALIGN_CENTER;
} else { } else {
@ -159,7 +162,7 @@ class Tools_TemplateImage
{ {
$width = imagesx($this->image); $width = imagesx($this->image);
$height = imagesy($this->image); $height = imagesy($this->image);
if($new_height == false) { if ($new_height == null) {
$new_height = ceil($height * $new_width / $width); $new_height = ceil($height * $new_width / $width);
} }
@ -171,8 +174,8 @@ class Tools_TemplateImage
} }
function prepare() { function prepare() {
if($this->prepare) { if($this->_prepare) {
$this->prepare = false; $this->_prepare = false;
foreach ($this->data as $value) { foreach ($this->data as $value) {
$this->imageText($value->text, $value); // break; $this->imageText($value->text, $value); // break;
} }

View file

@ -25,7 +25,8 @@ class Validator_Rule_Code extends Validator_Rule_Abstract
$name = $this->field; $name = $this->field;
if (is_array($_POST[$name . '_code_genre'])) { if (is_array($_POST[$name . '_code_genre'])) {
for($n = 0; $n < count($_POST[$name . '_code_genre']); $n++) { $count = count($_POST[$name . '_code_genre']);
for($n = 0; $n < $count; $n++) {
$code = array( $code = array(
$_POST[$name . '_code_genre'][$n], $_POST[$name . '_code_genre'][$n],
$_POST[$name . '_code_f'][$n], $_POST[$name . '_code_f'][$n],

View file

@ -6,7 +6,7 @@
class Validator_Rule_Count extends Validator_Rule_Abstract class Validator_Rule_Count extends Validator_Rule_Abstract
{ {
public $size = 1; public $size = 1;
public $max = false; public $max = null;
public function getErrorMsg() public function getErrorMsg()
{ {

View file

@ -15,6 +15,7 @@ class Validator_Rule_Date extends Validator_Rule_Abstract
public function isValid(Collection $container, $status = null) public function isValid(Collection $container, $status = null)
{ {
$pattern = "/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/"; $pattern = "/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/";
$matches = [];
return (preg_match($pattern, $container->get($this->field), $matches) return (preg_match($pattern, $container->get($this->field), $matches)
&& checkdate($matches[2], $matches[1], $matches[3])); && checkdate($matches[2], $matches[1], $matches[3]));
} }

View file

@ -23,7 +23,7 @@ class Validator_Rule_Time extends Validator_Rule_Abstract
{ {
$tmp = explode($this->split, $container->get($this->field), 2); $tmp = explode($this->split, $container->get($this->field), 2);
if ($tmp) { if ($tmp) {
if (self::checktime ($tmp[0], $tmp[1])) { if (self::checktime ((int)$tmp[0], (int)$tmp[1])) {
return true; return true;
} }
} }

View file

@ -1,6 +1,7 @@
<?php <?php
function loadConfig($filename) { function loadConfig($filename) {
$settings = null;
if (@include($filename)) { if (@include($filename)) {
return $settings; return $settings;
} }