in /var/www/mikefinch/data/www/do-travel.world/vendor/yiisoft/yii2/db/Connection.php at line 600
$token = 'Opening DB connection: ' . $this->dsn; try { Yii::info($token, __METHOD__); Yii::beginProfile($token, __METHOD__); $this->pdo = $this->createPdoInstance(); $this->initConnection(); Yii::endProfile($token, __METHOD__); } catch (\PDOException $e) { Yii::endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->errorInfo, (int) $e->getCode(), $e); } } /** * Closes the currently active DB connection. * It does nothing if the connection is already closed. */ public function close() {
* Returns the PDO instance for the currently active master connection. * This method will open the master DB connection and then return [[pdo]]. * @return PDO the PDO instance for the currently active master connection. */ public function getMasterPdo() { $this->open(); return $this->pdo; } /** * Returns the currently active slave connection. * If this method is called the first time, it will try to open a slave connection when [[enableSlaves]] is true.
* is available and `$fallbackToMaster` is false. */ public function getSlavePdo($fallbackToMaster = true) { $db = $this->getSlave(false); if ($db === null) { return $fallbackToMaster ? $this->getMasterPdo() : null; } else { return $db->pdo; } } /**
public function quoteValue($str) { if (!is_string($str)) { return $str; } if (($value = $this->db->getSlavePdo()->quote($str)) !== false) { return $value; } else { // the driver doesn't support quote (e.g. oci) return "'" . addcslashes(str_replace("'", "''", $str), "\000\n\r\\\032") . "'"; } }
* @param string $value string to be quoted * @return string the properly quoted string * @see http://www.php.net/manual/en/function.PDO-quote.php */ public function quoteValue($value) { return $this->getSchema()->quoteValue($value); } /** * Quotes a table name for use in a query. * If the table name contains schema prefix, the prefix will also be properly quoted. * If the table name is already quoted or contains special characters including '(', '[[' and '{{',
$params = []; foreach ($this->params as $name => $value) { if (is_string($name) && strncmp(':', $name, 1)) { $name = ':' . $name; } if (is_string($value)) { $params[$name] = $this->db->quoteValue($value); } elseif (is_bool($value)) { $params[$name] = ($value ? 'TRUE' : 'FALSE'); } elseif ($value === null) { $params[$name] = 'NULL'; } elseif (!is_object($value) && !is_resource($value)) { $params[$name] = $value;
* @return mixed the method execution result * @throws Exception if the query causes any problem * @since 2.0.1 this method is protected (was private before). */ protected function queryInternal($method, $fetchMode = null) { $rawSql = $this->getRawSql(); Yii::info($rawSql, 'yii\db\Command::query'); if ($method !== '') { $info = $this->db->getQueryCacheInfo($this->queryCacheDuration, $this->queryCacheDependency); if (is_array($info)) {
* @return array|false the first row (in terms of an array) of the query result. False is returned if the query * results in nothing. * @throws Exception execution failed */ public function queryOne($fetchMode = null) { return $this->queryInternal('fetch', $fetchMode); } /** * Executes the SQL statement and returns the value of the first column in the first row of data. * This method is best used when only a single value is needed for a query. * @return string|null|false the value of the first column in the first row of the query result.
* If this parameter is not given, the `db` application component will be used. * @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query * results in nothing. */ public function one($db = null) { return $this->createCommand($db)->queryOne(); } /** * Returns the query result as a scalar value. * The value returned will be the first column in the first row of the query results. * @param Connection $db the database connection used to generate the SQL statement.
* @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]], * the query result may be either an array or an ActiveRecord object. Null will be returned * if the query results in nothing. */ public function one($db = null) { $row = parent::one($db); if ($row !== false) { $models = $this->populate([$row]); return reset($models) ?: null; } else { return null; }
Yii::$app->response->cookies->add(new Cookie([ 'name' => 'currency', 'value' => $currency, ])); } Yii::$app->params['currency'] = Currency::find()->where(['code' => $currency])->one(); } }
use yii\web\Cookie; class LanguageSwitcher { public function __construct() { $this->setLanguage(); $this->setCurrency(); } private function setLanguage() { // Стандартный язык $lang = "en-US";
foreach ($params as $index => $param) { $dependencies[$index] = $param; } $dependencies = $this->resolveDependencies($dependencies, $reflection); if (empty($config)) { return $reflection->newInstanceArgs($dependencies); } if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten) $dependencies[count($dependencies) - 1] = $config; return $reflection->newInstanceArgs($dependencies);
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
{ if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return static::$container->invoke($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); } else { throw new InvalidConfigException('Unsupported configuration type: ' . gettype($type));
if (isset($this->_definitions[$id])) { $definition = $this->_definitions[$id]; if (is_object($definition) && !$definition instanceof Closure) { return $this->_components[$id] = $definition; } else { return $this->_components[$id] = Yii::createObject($definition); } } elseif ($throwException) { throw new InvalidConfigException("Unknown component ID: $id"); } else { return null; }
} foreach ($this->bootstrap as $class) { $component = null; if (is_string($class)) { if ($this->has($class)) { $component = $this->get($class); } elseif ($this->hasModule($class)) { $component = $this->getModule($class); } elseif (strpos($class, '\\') === false) { throw new InvalidConfigException("Unknown bootstrapping component ID: $class"); } }
protected function bootstrap() { $request = $this->getRequest(); Yii::setAlias('@webroot', dirname($request->getScriptFile())); Yii::setAlias('@web', $request->getBaseUrl()); parent::bootstrap(); } /** * Handles the specified request. * @param Request $request the request to be handled * @return Response the resulting response
/** * @inheritdoc */ public function init() { $this->state = self::STATE_INIT; $this->bootstrap(); } /** * Initializes extensions and executes bootstrap components. * This method is called by [[init()]] after the application has been fully configured. * If you override this method, make sure you also call the parent implementation.
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
$this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); } /** * Pre-initializes the application. * This method is called at the beginning of the application constructor. * It initializes several important application properties.
require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../components/functions.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/../config/web.php'); (new yii\web\Application($config))->run();