/** * Recursively removing expired cache files under a directory. * This method is mainly used by [[gc()]]. * @param string $path the directory under which expired cache files are removed. * @param boolean $expiredOnly whether to only remove expired cache files. If false, all files * under `$path` will be removed. */ protected function gcRecursive($path, $expiredOnly) { if (($handle = opendir($path)) !== false) { while (($file = readdir($handle)) !== false) { if ($file[0] === '.') { continue; } $fullPath = $path . DIRECTORY_SEPARATOR . $file; if (is_dir($fullPath)) { $this->gcRecursive($fullPath, $expiredOnly); if (!$expiredOnly) { if (!@rmdir($fullPath)) {
* @param string $path the directory under which expired cache files are removed. * @param boolean $expiredOnly whether to only remove expired cache files. If false, all files * under `$path` will be removed. */ protected function gcRecursive($path, $expiredOnly) { if (($handle = opendir($path)) !== false) { while (($file = readdir($handle)) !== false) { if ($file[0] === '.') { continue; } $fullPath = $path . DIRECTORY_SEPARATOR . $file; if (is_dir($fullPath)) {
while (($file = readdir($handle)) !== false) { if ($file[0] === '.') { continue; } $fullPath = $path . DIRECTORY_SEPARATOR . $file; if (is_dir($fullPath)) { $this->gcRecursive($fullPath, $expiredOnly); if (!$expiredOnly) { if (!@rmdir($fullPath)) { $error = error_get_last(); Yii::warning("Unable to remove directory '{$fullPath}': {$error['message']}", __METHOD__); } }
* @param boolean $expiredOnly whether to removed expired cache files only. * If false, all cache files under [[cachePath]] will be removed. */ public function gc($force = false, $expiredOnly = true) { if ($force || mt_rand(0, 1000000) < $this->gcProbability) { $this->gcRecursive($this->cachePath, $expiredOnly); } } /** * Recursively removing expired cache files under a directory. * This method is mainly used by [[gc()]].
* Deletes all values from cache. * This is the implementation of the method declared in the parent class. * @return boolean whether the flush operation was successful. */ protected function flushValues() { $this->gc(true, false); return true; } /** * Removes expired cache files.
* Deletes all values from cache. * Be careful of performing this operation if the cache is shared among multiple applications. * @return boolean whether the flush operation was successful. */ public function flush() { return $this->flushValues(); } /** * Retrieves a value from cache with a specified key. * This method should be implemented by child classes to retrieve the data * from specific cache storage.
class TranslationEventHandler { public static function handleMissingTranslation(MissingTranslationEvent $event) { if(trim($event->message) and intval(Yii::$app->params['translation_counter']) < 1 ){ Yii::$app->cache->flush(); $lang = strtolower(explode('-',$event->language)[0]);
$event->sender = $this; } $event->handled = false; $event->name = $name; foreach ($this->_events[$name] as $handler) { $event->data = $handler[1]; call_user_func($handler[0], $event); // stop further handling if the event is handled if ($event->handled) { return; } } }
} elseif ($this->hasEventHandlers(self::EVENT_MISSING_TRANSLATION)) { $event = new MissingTranslationEvent([ 'category' => $category, 'message' => $message, 'language' => $language, ]); $this->trigger(self::EVENT_MISSING_TRANSLATION, $event); if ($event->translatedMessage !== null) { return $this->_messages[$key][$message] = $event->translatedMessage; } } return $this->_messages[$key][$message] = false;
* @param string $language the target language * @return string|boolean the translated message or false if translation wasn't found or isn't required */ public function translate($category, $message, $language) { if ($this->forceTranslation || $language !== $this->sourceLanguage) { return $this->translateMessage($category, $message, $language); } else { return false; } } /**
* @param string $language the language code (e.g. `en-US`, `en`). * @return string the translated and formatted message. */ public function translate($category, $message, $params, $language) { $messageSource = $this->getMessageSource($category); $translation = $messageSource->translate($category, $message, $language); if ($translation === false) { return $this->format($message, $params, $messageSource->sourceLanguage); } else { return $this->format($translation, $params, $language); } }
* [[\yii\base\Application::language|application language]] will be used. * @return string the translated message. */ public static function t($category, $message, $params = [], $language = null) { if (static::$app !== null) { return static::$app->getI18n()->translate($category, $message, $params, $language ?: static::$app->language); } else { $p = []; foreach ((array) $params as $name => $value) { $p['{' . $name . '}'] = $value; }
public function getBrandNameTranslated() { if(strcasecmp($this->brand_name, Yii::t('eng', $this->brand_name))) return Yii::t('eng', $this->brand_name); } public function getModelNameTranslated() { $arr_model = explode(' ', strtolower($this->model_name));
*/ public function __get($name) { $getter = 'get' . $name; if (method_exists($this, $getter)) { // read property, e.g. getName() return $this->$getter(); } else { // behavior property $this->ensureBehaviors(); foreach ($this->_behaviors as $behavior) { if ($behavior->canGetProperty($name)) { return $behavior->$name;
} elseif ($this->hasAttribute($name)) { return null; } else { if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) { return $this->_related[$name]; } $value = parent::__get($name); if ($value instanceof ActiveQueryInterface) { return $this->_related[$name] = $value->findFor($name, $this); } else { return $value; } }
public function getSeoFullName() { $arr_text[] = $this->full_name; if($this->brandNameTranslated){ if($this->modelNameTranslated){ $arr_text[] = $this->brandNameTranslated.' '.$this->modelNameTranslated; }else{
*/ public function __get($name) { $getter = 'get' . $name; if (method_exists($this, $getter)) { // read property, e.g. getName() return $this->$getter(); } else { // behavior property $this->ensureBehaviors(); foreach ($this->_behaviors as $behavior) { if ($behavior->canGetProperty($name)) { return $behavior->$name;
} elseif ($this->hasAttribute($name)) { return null; } else { if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) { return $this->_related[$name]; } $value = parent::__get($name); if ($value instanceof ActiveQueryInterface) { return $this->_related[$name] = $value->findFor($name, $this); } else { return $value; } }
<tr> <td class="<?=$item_image_class?>"> <?=Html::a('<img width="100%" src="'.$model->imageUrl.'" alt="'.$model->full_name.'" data-toggle="tooltip" title="'.$model->seoFullName.'">', $model->url)?> </td> <td>
*/ public function renderPhpFile($_file_, $_params_ = []) { ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); require($_file_); return ob_get_clean(); } /** * Renders dynamic content returned by the given PHP statements.
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]); } /* @var $renderer ViewRenderer */ $renderer = $this->renderers[$ext]; $output = $renderer->render($this, $viewFile, $params); } else { $output = $this->renderPhpFile($viewFile, $params); } $this->afterRender($viewFile, $params, $output); } array_pop($this->_viewFiles); $this->context = $oldContext;
* @throws InvalidParamException if the view cannot be resolved or the view file does not exist. * @see renderFile() */ public function render($view, $params = [], $context = null) { $viewFile = $this->findViewFile($view, $context); return $this->renderFile($viewFile, $params, $context); } /** * Finds the view file based on the given view name. * @param string $view the view name or the path alias of the view file. Please refer to [[render()]] * on how to specify this parameter.
* @param array $params the parameters (name-value pairs) that should be made available in the view. * @return string the rendering result. * @throws InvalidParamException if the view file does not exist. */ public function render($view, $params = []) { return $this->getView()->render($view, $params, $this); } /** * Renders a view file. * @param string $file the view file to be rendered. This can be either a file path or a path alias. * @param array $params the parameters (name-value pairs) that should be made available in the view.
public function run() { return $this->render('item/view', [ 'model' => $this->details, 'versus' => $this->versus_details, ]); } }
ob_start(); ob_implicit_flush(false); try { /* @var $widget Widget */ $config['class'] = get_called_class(); $widget = Yii::createObject($config); $out = $widget->run(); } catch (\Exception $e) { // close the output buffer opened above if it has not been closed already if (ob_get_level() > 0) { ob_end_clean(); } throw $e;
<div class="container"> <h3 class="primary-color"><?=Yii::t('app','Best Phones')?></h3> <div class="row"> <?php foreach ($items['phone_best'] as $item_detail){ echo('<div class="col-lg-3 col-md-4 col-sm-6">'); echo(Itemwidget::widget(['details'=>$item_detail])); echo('</div>'); } ?> </div>
*/ public function renderPhpFile($_file_, $_params_ = []) { ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); require($_file_); return ob_get_clean(); } /** * Renders dynamic content returned by the given PHP statements.
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]); } /* @var $renderer ViewRenderer */ $renderer = $this->renderers[$ext]; $output = $renderer->render($this, $viewFile, $params); } else { $output = $this->renderPhpFile($viewFile, $params); } $this->afterRender($viewFile, $params, $output); } array_pop($this->_viewFiles); $this->context = $oldContext;
* @throws InvalidParamException if the view cannot be resolved or the view file does not exist. * @see renderFile() */ public function render($view, $params = [], $context = null) { $viewFile = $this->findViewFile($view, $context); return $this->renderFile($viewFile, $params, $context); } /** * Finds the view file based on the given view name. * @param string $view the view name or the path alias of the view file. Please refer to [[render()]] * on how to specify this parameter.
* These parameters will not be available in the layout. * @return string the rendering result. * @throws InvalidParamException if the view file or the layout file does not exist. */ public function render($view, $params = []) { $content = $this->getView()->render($view, $params, $this); return $this->renderContent($content); } /** * Renders a static string by applying a layout. * @param string $content the static string being rendered
return $this->render('index',[ 'thread'=>$thread, 'soon'=>$soon, 'items'=>$items, 'sale'=>$sale, ]); }
$args = $this->controller->bindActionParams($this, $params); Yii::trace('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); Yii::$app->controller = $oldController; return $result; } else { $id = $this->getUniqueId(); throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
$params = $this->catchAll; unset($params[0]); } try { Yii::trace("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } else { $response = $this->getResponse(); if ($result !== null) { $response->data = $result;
try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
$config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/../../common/config/main.php'), require(__DIR__ . '/../config/main.php') ); $application = new yii\web\Application($config); $application->run();
$_SESSION = [ '__flash' => [], '__returnUrl' => '/en', ];