$behavior->$name = $value; return; } } if (method_exists($this, 'get' . $name)) { throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name); } throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name); } /** * Checks if a property is set, i.e. defined and not null. * * This method will check in the following order and act accordingly: * * - a property defined by a setter: return whether the property is set * - a property of a behavior: return whether the property is set
* @param array $properties the property initial values given in terms of name-value pairs. * @return object the object itself */ public static function configure($object, $properties) { foreach ($properties as $name => $value) { $object->$name = $value; } return $object; } /**
* * @param array $config name-value pairs that will be used to initialize the object properties */ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object.
$config = $this->resolveDependencies($config); 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); } $object = $reflection->newInstanceArgs($dependencies); foreach ($config as $name => $value) { $object->$name = $value; }
$class = $class->id; } 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));
return static::$container->get($class, $params, $type); } if (isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } throw new InvalidConfigException('Object configuration must be an array containing a "class" or "__class" element.'); } private static $_logger;
* @param boolean $i18n * @param array $args * @return \luya\admin\ngrest\base\Plugin */ public static function createPluginObject($className, $name, $alias, $i18n, $args = []) { return Yii::createObject(array_merge([ 'class' => $className, 'name' => $name, 'alias' => $alias, 'i18n' => $i18n, ], $args)); }
* @param string $tableName * @return \luya\admin\ngrest\base\Plugin */ private static function findPluginInstance($field, array $plugin, $tableName) { if (!isset(self::$_pluginInstances[$tableName][$field])) { self::$_pluginInstances[$tableName][$field] = NgRest::createPluginObject($plugin['type']['class'], $plugin['name'], $plugin['alias'], $plugin['i18n'], $plugin['type']['args']); } return self::$_pluginInstances[$tableName][$field]; } }
* * @param \yii\base\Event $event */ public function bindPluginEvents(Event $event) { foreach ($this->plugins as $field => $plugin) { $plugin = self::findPluginInstance($field, $plugin, $event->sender->tableName()); foreach ($plugin->events() as $on => $handler) { $event->sender->on($on, is_string($handler) ? [$plugin, $handler] : $handler); } } }
$event->sender = $this; } $event->handled = false; $event->name = $name; foreach ($eventHandlers as $handler) { $event->data = $handler[1]; call_user_func($handler[0], $event); // stop further handling if the event is handled if ($event->handled) { return; } } }
* This method is called at the end of the constructor. * The default implementation will trigger an [[EVENT_INIT]] event. */ public function init() { parent::init(); $this->trigger(self::EVENT_INIT); } /** * This method is called when the AR object is created and populated with the query result. * The default implementation will trigger an [[EVENT_AFTER_FIND]] event. * When overriding this method, make sure you call the parent implementation to ensure the
*/ 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.
], 'LogBehavior' => [ 'class' => LogBehavior::className(), 'api' => static::ngRestApiEndpoint(), ], ]); return parent::__construct($config); } /** * @inheritdoc */ public function scenarios()
* you may implement the so-called single-table inheritance mapping. * @param array $row row data to be populated into the record. * @return static the newly created active record */ public static function instantiate($row) { return new static(); } /** * Returns whether there is an element at the specified offset. * This method is required by the interface [[\ArrayAccess]]. * @param mixed $offset the offset to check on
return $rows; } else { $models = []; /* @var $class ActiveRecord */ $class = $this->modelClass; foreach ($rows as $row) { $model = $class::instantiate($row); $modelClass = get_class($model); $modelClass::populateRecord($model, $row); $models[] = $model; } return $models; }
public function populate($rows) { if (empty($rows)) { return []; } $models = $this->createModels($rows); if (!empty($this->join) && $this->indexBy === null) { $models = $this->removeDuplicatedModels($models); } if (!empty($this->with)) { $this->findWith($this->with, $models); }
* 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; } return null; }
* @return \luya\admin\models\StorageImage|false Returns the storage image model on success, otherwise false. */ public function createImage($fileId, $filterId) { gc_collect_cycles(); $image = StorageImage::find()->where(['file_id' => $fileId, 'filter_id' => $filterId])->one(); // the image exists already in the database and the file system if ($image && $image->fileExists) { return $image; }
if (Yii::$app->storage->autoFixMissingImageSources === false) { return false; } // The image source does not exist, probably it has been deleted due to filter changes. // storage component is going go try to re-create this image now. $apply = Yii::$app->storage->createImage($this->getFileId(), $this->getFilterId()); } $fileName = $this->getFilterId() . '_' . $this->getFile()->getSystemFileName(); return $scheme ? Yii::$app->storage->fileAbsoluteHttpPath($fileName) : Yii::$app->storage->fileHttpPath($fileName); }
* @see __set() */ public function __get($name) { $getter = 'get' . $name; if (method_exists($this, $getter)) { return $this->$getter(); } elseif (method_exists($this, 'set' . $name)) { throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name); } throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name); }
* @return array the array representation of the object */ public function toArray(array $fields = [], array $expand = [], $recursive = true) { $data = []; foreach ($this->resolveFields($fields, $expand) as $field => $definition) { $attribute = is_string($definition) ? $this->$definition : $definition($this, $field); if ($recursive) { $nestedFields = $this->extractFieldsFor($fields, $field); $nestedExpand = $this->extractFieldsFor($expand, $field); if ($attribute instanceof Arrayable) { $attribute = $attribute->toArray($nestedFields, $nestedExpand);
} } if ($returnObject) { return $image; } return $image->toArray(); } /** * Get the full array for the specific zaa-file-image-upload type * * ```php
/** * @inheritdoc */ public function extraVars() { return [ 'image' => BlockHelper::imageUpload($this->getVarValue('imageId')), 'imageAdmin' => BlockHelper::imageUpload($this->getVarValue('imageId', 'medium-thumbnail')), 'text' => $this->getText(), 'link' => $this->getLinkObject(), ]; }
/** * @inheritdoc */ public function getExtraVarValues() { $this->_extraVars = ArrayHelper::merge($this->extraVars(), $this->_extraVars); return $this->_extraVars; } private bool $_assignExtraVars = false; /**
* @param string $default * @return string|mixed */ public function getExtraValue($key, $default = false) { if (!$this->_assignExtraVars) { $this->getExtraVarValues(); $this->_assignExtraVars = true; } return $this->_extraVars[$key] ?? $default; }
* @param string $defaultValue Env value is not found this value will be returned. * @param string $template Provde a template which replaces the current variable if value is not `empty()`. e.g. `<p>{{variable}}≤/p>` See {{luya\cms\base\PhpBlockView::wrapTemplate}}. * @return mixed */ public function extraValue($key, $defaultValue = null, $template = false) { return $this->wrapTemplate($key, $this->context->getExtraValue($key, $defaultValue), $template); } /** * Get an array with extracted informations to register in the view * @return array * @since 1.0.5
use yii\helpers\Html; /** * @var $this \luya\cms\base\PhpBlockView */ ?> <?php if ($this->extraValue('image')): $imageCaption = $this->extraValue('image')['caption']; ?> <div class="image<?= $this->cfgValue('divCssClass', null, ' {{divCssClass}}'); ?>"> <figure> <?php if ($this->extraValue('link')): ?> <a class="text-teaser" href="<?= $this->extraValue('link')->href; ?>" target="<?= $this->extraValue('link')->target; ?>"> <?php endif; ?> <?= Html::tag('img', '', [
{ $_obInitialLevel_ = ob_get_level(); ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); try { require $_file_; return ob_get_clean(); } catch (\Exception $e) { while (ob_get_level() > $_obInitialLevel_) { if (!@ob_end_clean()) { ob_clean(); }
$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 InvalidCallException if the view cannot be resolved. * @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](guide:concept-aliases) of the view file. Please refer to [[render()]] * on how to specify this parameter.
/** * @inheritdoc */ public function frontend() { return $this->view->render($this->getViewFileName('php'), [], $this); } /** * @inheritdoc */ public function renderFrontend()
/** * @inheritdoc */ public function renderFrontend() { $this->injectorSetup(); return $this->frontend(); } /** * @inheritdoc */ public function renderAdmin()
} $blockObject->setPlaceholderValues($insertedHolders); // output buffer the rendered frontend method of the block if ($layoutBlockInstance) { $blockResponse = $layoutBlockInstance->placeholderRenderIteration($blockObject); } else { $blockResponse = $blockObject->renderFrontend(); } if ($isCachingEnabled) { $this->setHasCache($cacheKey, $blockResponse, null, $blockObject->getCacheExpirationTime()); $blockObject->onRegister();
* * @param string $placeholderName The Cmslayout placeholder identifier * @return string */ public function renderPlaceholder($placeholderName) { return $this->renderPlaceholderRecursive($this->id, $placeholderName, 0); } /** * Returns whether admin user is working in frontend context. * * @return boolean Whether caching should be enabled or not.
throw new InvalidConfigException("Unable to find the requested cms layout '{$this->layout_id}' for nav item page id '{$this->id}'. Make sure your page does not have an old inactive/deleted cms layout selected."); } $placholders = []; foreach ($this->layout->getJsonConfig('placeholders') as $row) { foreach ($row as $item) { $placholders[$item['var']] = $this->renderPlaceholder($item['var']); } } // check whether the layout view file should be renderd trough active context or as file. // if the view_file starts with / or @ it can be renderd as renderFile() otherwise using render() with active context. $viewFile = $this->layout->view_file;
$typeModel->setOptions([ 'navItemId' => $navItemId, 'restString' => $appendix, ]); $content = $typeModel->getContent(); if ($content instanceof Response) { return Yii::$app->end(0, $content); } // it seems to be a json response as it is an array
} // set status 404 and render the item Yii::$app->response->statusCode = 404; } $content = $this->renderItem($current->id, Yii::$app->menu->currentAppendix); // It seems to be a json response. Yii::$app->response->format should be FORMAT_JSON or FORMAT_JSONP if (is_array($content)) { return $this->asJson($content); }
$args = $this->controller->bindActionParams($this, $params); Yii::debug('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); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
// apply strict, hsts and x-* headers Yii::$app->response->headers->set('Strict-Transport-Security', 'max-age=31536000'); Yii::$app->response->headers->set('X-XSS-Protection', "1; mode=block"); Yii::$app->response->headers->set('X-Frame-Options', "SAMEORIGIN"); } return parent::handleRequest($request); } /** * @inheritdoc */ public function coreComponents()
{ 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 = $this->getConfigArray(); $this->includeYii(); $mergedConfig = ArrayHelper::merge($config, ['bootstrap' => ['luya\web\Bootstrap']]); $this->app = new WebApplication($mergedConfig); if (!$this->mockOnly) { return $this->app->run(); } } /** * Returns the path to luya core files *
public function run() { if ($this->getIsCli()) { return $this->applicationConsole(); } return $this->applicationWeb(); } /** * Run Cli-Application based on the provided config file. */ public function applicationConsole()
// composer autoload include require(__DIR__ . '/../vendor/autoload.php'); // use the luya boot wrapping class $boot = new \luya\Boot(); $boot->setBaseYiiFile(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $boot->run();
$_GET = [ 'path' => 'blog/idea-and-scenario-of-the-holiday', ];