/var/www/html/vendor/dibi/dibi/src/Dibi/Translator.php
case 'in': // deprecated
trigger_error('Modifier %in is deprecated, use %iN.', E_USER_DEPRECATED);
// break omitted
case 'iN': // signed int or null
if ($value == '') {
$value = null;
}
// break omitted
case 'i': // signed int
case 'u': // unsigned int, ignored
if ($value === null) {
return 'NULL';
} elseif (is_string($value)) {
if (preg_match('#[+-]?\d++(?:e\d+)?\z#A', $value)) {
return $value; // support for long numbers - keep them unchanged
} elseif (substr($value, 1, 1) === 'x' && is_numeric($value)) {
trigger_error('Support for hex strings has been deprecated.', E_USER_DEPRECATED);
return (string) hexdec($value);
} else {
throw new Exception("Expected number, '$value' given.");
}
} else {
return (string) (int) $value;
}
// break omitted
case 'f': // float
if ($value === null) {
return 'NULL';
} elseif (is_string($value)) {
if (is_numeric($value) && substr($value, 1, 1) !== 'x') {
return $value; // support for long numbers - keep them unchanged
} else {
throw new Exception("Expected number, '$value' given.");
}
} else {
return rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
}
// break omitted
case 'd': // date
case 't': // datetime
/var/www/html/vendor/dibi/dibi/src/Dibi/Translator.php
} elseif ($this->comment) {
return "(limit $arg)";
} else {
$this->limit = Helpers::intVal($arg);
}
return '';
} elseif ($mod === 'ofs') { // apply offset
$arg = $this->args[$cursor++];
if ($arg === null) {
} elseif ($this->comment) {
return "(offset $arg)";
} else {
$this->offset = Helpers::intVal($arg);
}
return '';
} else { // default processing
$cursor++;
return $this->formatValue($this->args[$cursor - 1], $mod);
}
}
if ($this->comment) {
return '...';
}
if ($matches[1]) { // SQL identifiers: `ident`
return $this->identifiers->{$matches[1]};
} elseif ($matches[2]) { // SQL identifiers: [ident]
return $this->identifiers->{$matches[2]};
} elseif ($matches[3]) { // SQL strings: '...'
return $this->driver->escapeText(str_replace("''", "'", $matches[4]));
} elseif ($matches[5]) { // SQL strings: "..."
return $this->driver->escapeText(str_replace('""', '"', $matches[6]));
} elseif ($matches[7]) { // string quote
/var/www/html/vendor/dibi/dibi/src/Dibi/Translator.php
$sql[] = $arg;
} else {
$sql[] = substr($arg, 0, $toSkip)
/*
. preg_replace_callback('/
(?=[`[\'":%?]) ## speed-up
(?:
`(.+?)`| ## 1) `identifier`
\[(.+?)\]| ## 2) [identifier]
(\')((?:\'\'|[^\'])*)\'| ## 3,4) 'string'
(")((?:""|[^"])*)"| ## 5,6) "string"
(\'|")| ## 7) lone quote
:(\S*?:)([a-zA-Z0-9._]?)| ## 8,9) :substitution:
%([a-zA-Z~][a-zA-Z0-9~]{0,5})|## 10) modifier
(\?) ## 11) placeholder
)/xs',
*/ // note: this can change $this->args & $this->cursor & ...
. preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\?))/s',
[$this, 'cb'],
substr($arg, $toSkip)
);
if (preg_last_error()) {
throw new PcreException;
}
}
continue;
}
if ($comment) {
$sql[] = '...';
continue;
}
if ($arg instanceof \Traversable) {
$arg = iterator_to_array($arg);
}
if (is_array($arg) && is_string(key($arg))) {
// associative array -> autoselect between SET or VALUES & LIST
if ($commandIns === null) {
/var/www/html/vendor/dibi/dibi/src/Dibi/Connection.php
$args = func_get_args();
return new DataSource($this->translateArgs($args), $this);
}
/**
* Generates SQL query.
* @param array
* @return string
*/
protected function translateArgs($args)
{
if (!$this->connected) {
$this->connect();
}
if (!$this->translator) {
$this->translator = new Translator($this);
}
$translator = clone $this->translator;
return $translator->translate($args);
}
/**
* Executes the SQL query.
* @param string SQL statement.
* @return Result|int result set or number of affected rows
* @throws Exception
*/
final public function nativeQuery($sql)
{
if (!$this->connected) {
$this->connect();
}
\dibi::$sql = $sql;
$event = $this->onEvent ? new Event($this, Event::QUERY, $sql) : null;
try {
$res = $this->driver->query($sql);
/var/www/html/vendor/dibi/dibi/src/Dibi/Connection.php
*/
final public function getDriver()
{
if (!$this->connected) {
$this->connect();
}
return $this->driver;
}
/**
* Generates (translates) and executes SQL query.
* @param array|mixed one or more arguments
* @return Result|int result set or number of affected rows
* @throws Exception
*/
final public function query($args)
{
$args = func_get_args();
return $this->nativeQuery($this->translateArgs($args));
}
/**
* Generates SQL query.
* @param array|mixed one or more arguments
* @return string
* @throws Exception
*/
final public function translate($args)
{
$args = func_get_args();
return $this->translateArgs($args);
}
/**
* Generates and prints SQL query.
* @param array|mixed one or more arguments
* @return bool
/var/www/html/vendor/dibi/dibi/src/Dibi/Connection.php
{
return strpos($value, ':') === false
? $value
: preg_replace_callback('#:([^:\s]*):#', function ($m) { return $this->substitutes->{$m[1]}; }, $value);
}
/********************* shortcuts ****************d*g**/
/**
* Executes SQL query and fetch result - shortcut for query() & fetch().
* @param array|mixed one or more arguments
* @return Row|false
* @throws Exception
*/
public function fetch($args)
{
$args = func_get_args();
return $this->query($args)->fetch();
}
/**
* Executes SQL query and fetch results - shortcut for query() & fetchAll().
* @param array|mixed one or more arguments
* @return Row[]|array[]
* @throws Exception
*/
public function fetchAll($args)
{
$args = func_get_args();
return $this->query($args)->fetchAll();
}
/**
* Executes SQL query and fetch first column - shortcut for query() & fetchSingle().
* @param array|mixed one or more arguments
* @return mixed
/var/www/html/controllers/catalog.php
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
class catalog extends controller {
function get_view(Request $request) {
$path = trim($request->getPathInfo(), '/');
$id = str_replace('catalog/view/', '', $path);
$tpl = $this->common();
$item = $this->app['db']->fetch('
SELECT *
FROM catalog
WHERE id = %i
', $id);
if (!$item) {
return $this->app['/error']->get($request, 404);
}
//группа, подгруппа товара
$item['group'] = $this->app['db']->fetch('
SELECT * FROM catalog_groups WHERE id_1c = %s
', $item['group']);
if ($item['group']['parent_id_1c']) {
$item['subgroup'] = $this->app['db']->fetch('
SELECT * FROM catalog_groups WHERE id_1c = %s
', $item['group']['parent_id_1c']);
}
//все фотографии
//сначала ищем с конкретным цветом
$photos = $this->app['db']->fetchAll('
/var/www/html/router.php
//front контроллер
if (empty($path)) $path = 'front';
$path_parts = explode('/', $path);
//части пути от длинной к короткой
for ($i=count($path_parts); $i > 0; $i--) {
$guess_controller = '/'.implode('/', array_slice($path_parts, 0, $i));
if (isset($this->app[$guess_controller])) { //нашли подходящий контролер
$controller = $this->app[$guess_controller];
//ищем подходящий метод
$method_parts = array_merge([strtolower($method)], array_slice($path_parts, $i));
for ($j=count($method_parts); $j > 0; $j--) {
$guess_method = implode('_', array_slice($method_parts, 0, $j));
if (method_exists($controller, $guess_method)) {
if ($answer = $controller->pre_request($request)) return $answer; //pre_request
$pre_method = 'pre_'.strtolower($method); if ($answer = $controller->$pre_method($request)) return $answer; //pre_get, pre_post...
//return $controller->$guess_method($request);
if ($ret = $controller->$guess_method($request)) return $ret;
}
}
}
}
//контроллер по умолчанию
if ($response = $this->app['/pages']->get($request)) return $response;
//404
return $this->app['/error']->get($request, 404);
}
/*public function process($request) {
$method = $request->getMethod();
$path = $request->getPathInfo();
$path = trim($path, '/');
/var/www/html/public/index.php
<?php
define('APP_START', microtime(true));
$app = require_once __DIR__.'/../app.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
if (isset($whoops)) {
$request = Request::createFromGlobals();
$response = $app['router']->process($request);
} else try {
$request = Request::createFromGlobals();
$response = $app['router']->process($request);
} catch (Exception $e) {
$response = new Response('An error occurred<br><pre>'.$e->getTraceAsString().'</pre>', 500);
}
$response->send();
//if ($env != 'prod') echo '<!--' . (microtime(true)-APP_START) . ' sec -->';