Отступы
This commit is contained in:
parent
cdf7527c43
commit
085820d78c
5 changed files with 71 additions and 62 deletions
|
|
@ -57,6 +57,7 @@ class Controller_Component
|
|||
public /*.Settings.*/$registry;
|
||||
public /*.Database.*/$db;
|
||||
public /*.Collection.*/$parameter;
|
||||
static public $ID;
|
||||
|
||||
public $module;
|
||||
public $item_module;
|
||||
|
|
@ -223,7 +224,7 @@ class Controller_Component
|
|||
if (file_exists($path)) {
|
||||
require_once ($path);
|
||||
|
||||
$component = new $className();
|
||||
$component = new $className();
|
||||
$component->db = $db;
|
||||
$component->registry = $registry;
|
||||
|
||||
|
|
@ -244,13 +245,18 @@ class Controller_Component
|
|||
$component->webPath = array(COMPONENTS_WEB . '/' . $name, SITE_WWW_PATH . '/components/' . $name);
|
||||
$component->COMPONENTS_WEB = COMPONENTS_WEB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
|
||||
$stmt->setString(1, $expression);
|
||||
$cid = $stmt->executeQuery();
|
||||
if ($cid->next()) {
|
||||
$component->component_id = $cid->getInt('id_component');
|
||||
// Нужно для отличия компонентов на странице нужно извлекать id для всей страницы сразу?
|
||||
// Просто вести глобальный счетчик для компонентов
|
||||
|
||||
$component->component_id = self::$ID++;
|
||||
/*
|
||||
$stmt = $db->prepare("SELECT * FROM component WHERE code = :code");
|
||||
$stmt->execute(['code' => $expression]);
|
||||
$cid = $stmt->fetch();
|
||||
if ($cid) {
|
||||
$component->component_id = $cid['id_component'];
|
||||
} else {
|
||||
$last = $db->getIdGenerator();
|
||||
if ($last->isBeforeInsert()) {
|
||||
|
|
@ -269,6 +275,7 @@ class Controller_Component
|
|||
}
|
||||
$component->component_id = $result;
|
||||
}
|
||||
*/
|
||||
|
||||
$params = new Collection();
|
||||
$params->import(array_merge($_GET, $arguments));
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ class Database extends PDO
|
|||
static function getConnection(array $dsn)
|
||||
{
|
||||
|
||||
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
|
||||
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
|
||||
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']);
|
||||
if ($dsn['phptype'] == 'pgsql') {
|
||||
$connection->query('SET client_encoding="UTF-8"');
|
||||
|
|
@ -100,8 +100,7 @@ class Database extends PDO
|
|||
return $sth->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
private static function assignQuote($x, $y)
|
||||
{
|
||||
function assignQuote($x, $y) {
|
||||
return $x . "=" . $this->quote($y);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,9 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate
|
|||
|
||||
function execute($args = null) {
|
||||
$result = parent::execute($args);
|
||||
if (class_exists('Log')) {
|
||||
Log::add('execute', [$this->queryString, $args]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ class Tools_SQLStatementExtractor {
|
|||
trigger_error("substring(), Endindex out of bounds must be $startpos<n<".($len-1), E_USER_ERROR);
|
||||
}
|
||||
if ($startpos === $endpos) {
|
||||
return (string) $string{$startpos};
|
||||
return (string) $string[$startpos];
|
||||
} else {
|
||||
$len = $endpos-$startpos;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,66 +1,66 @@
|
|||
<?php
|
||||
|
||||
|
||||
class Tools_String {
|
||||
|
||||
|
||||
// from creole
|
||||
static function strToArray($str) {
|
||||
$str = substr($str, 1, -1); // remove { }
|
||||
$res = array();
|
||||
|
||||
$subarr = array();
|
||||
$in_subarr = 0;
|
||||
|
||||
$toks = explode(',', $str);
|
||||
foreach($toks as $tok) {
|
||||
if ($in_subarr > 0) { // already in sub-array?
|
||||
$subarr[$in_subarr][] = $tok;
|
||||
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
|
||||
$res[] = static::strToArray(implode(',', $subarr[$in_subarr]));
|
||||
$in_subarr--;
|
||||
}
|
||||
} elseif ($tok{0} === '{') { // we're inside a new sub-array
|
||||
if ('}' !== substr($tok, -1, 1)) {
|
||||
$in_subarr++;
|
||||
// if sub-array has more than one element
|
||||
$subarr[$in_subarr] = array();
|
||||
$subarr[$in_subarr][] = $tok;
|
||||
} else {
|
||||
$res[] = static::strToArray($tok);
|
||||
}
|
||||
} else { // not sub-array
|
||||
$val = trim($tok, '"'); // remove " (surrounding strings)
|
||||
// perform type castng here?
|
||||
$res[] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
$str = substr($str, 1, -1); // remove { }
|
||||
$res = array();
|
||||
|
||||
$subarr = array();
|
||||
$in_subarr = 0;
|
||||
|
||||
$toks = explode(',', $str);
|
||||
foreach($toks as $tok) {
|
||||
if ($in_subarr > 0) { // already in sub-array?
|
||||
$subarr[$in_subarr][] = $tok;
|
||||
if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component
|
||||
$res[] = static::strToArray(implode(',', $subarr[$in_subarr]));
|
||||
$in_subarr--;
|
||||
}
|
||||
} elseif ($tok[0] === '{') { // we're inside a new sub-array
|
||||
if ('}' !== substr($tok, -1, 1)) {
|
||||
$in_subarr++;
|
||||
// if sub-array has more than one element
|
||||
$subarr[$in_subarr] = array();
|
||||
$subarr[$in_subarr][] = $tok;
|
||||
} else {
|
||||
$res[] = static::strToArray($tok);
|
||||
}
|
||||
} else { // not sub-array
|
||||
$val = trim($tok, '"'); // remove " (surrounding strings)
|
||||
// perform type castng here?
|
||||
$res[] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
//Нормализация строк на русском
|
||||
static function normalizeRussian($str) {
|
||||
$result = preg_replace('/\s+/',' ', $str);
|
||||
if (is_string($result)) {
|
||||
$result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям
|
||||
$result = mb_strtolower($result);
|
||||
$result = preg_replace('/ё/','е', $str); //е на ё
|
||||
$result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям
|
||||
$result = mb_strtolower($result);
|
||||
$result = preg_replace('/ё/','е', $str); //е на ё
|
||||
}
|
||||
return $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
//Проверка равенства двух строк на русском языке.
|
||||
static function equalRussianCheck($str1,$str2) {
|
||||
return self::normalizeRussian($str1) == self::normalizeRussian($str2);
|
||||
return self::normalizeRussian($str1) == self::normalizeRussian($str2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Попадает ли строка в список вариантов
|
||||
* input: $str="foo1" $variants="foo1|foo2|foo3"
|
||||
* output: true
|
||||
* input: $str="foo" $variants="foo1|foo2|foo3"
|
||||
* output: false
|
||||
*/
|
||||
*/
|
||||
static function compare_string_to_variants($str, $variants){
|
||||
$variants_array = explode('|', $variants);
|
||||
$founded = false;
|
||||
|
|
@ -69,15 +69,15 @@ class Tools_String {
|
|||
}
|
||||
return $founded;
|
||||
}
|
||||
|
||||
|
||||
static function mb_str_split($str) {
|
||||
return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
|
||||
static function mb_strtr($str, $from, $to) {
|
||||
return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static function encodestring($st) {
|
||||
$st = self::mb_strtr($st,"абвгдеёзийклмнопрстуфхъыэ !+-()", "abvgdeeziyklmnoprstufh_ie______");
|
||||
$st = self::mb_strtr($st,"АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ", "ABVGDEEZIYKLMNOPRSTUFH_IE");
|
||||
|
|
@ -95,16 +95,16 @@ class Tools_String {
|
|||
"*" => '_',
|
||||
"ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
|
||||
"щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya",
|
||||
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
|
||||
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
|
||||
"Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA",
|
||||
"Й"=>"i", "й"=>"ie", "ё"=>"Ye",
|
||||
"№"=>"N"
|
||||
));
|
||||
return strtolower($st);
|
||||
}
|
||||
|
||||
|
||||
static function validate_encoded_string($st) {
|
||||
$enc_st = self::encodestring($st);
|
||||
return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue