Example #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->message['to'])) {
         throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.');
     }
     $this->mailer = Instance::ensure($this->mailer, 'Leaps\\Mail\\MailerInterface');
 }
 /**
  * Initializes the FragmentCache object.
  */
 public function init()
 {
     parent::init();
     $this->cache = $this->enabled ? Instance::ensure($this->cache, Cache::className()) : null;
     if ($this->cache instanceof Cache && $this->getCachedContent() === false) {
         $this->getView()->cacheStack[] = $this;
         ob_start();
         ob_implicit_flush(false);
     }
 }
Example #3
0
 /**
  * Generates the data needed to determine if dependency has been changed.
  * This method returns the value of the global state.
  * @param Cache $cache the cache component that is currently evaluating this dependency
  * @return mixed the data needed to determine if dependency has been changed.
  * @throws InvalidConfigException if [[db]] is not a valid application component ID
  */
 protected function generateDependencyData($cache)
 {
     $db = Instance::ensure($this->db, Connection::className());
     if ($this->sql === null) {
         throw new InvalidConfigException("DbDependency::sql must be set.");
     }
     if ($db->enableQueryCache) {
         // temporarily disable and re-enable query caching
         $db->enableQueryCache = false;
         $result = $db->createCommand($this->sql, $this->params)->queryOne();
         $db->enableQueryCache = true;
     } else {
         $result = $db->createCommand($this->sql, $this->params)->queryOne();
     }
     return $result;
 }
Example #4
0
 /**
  * Initializes the migration.
  * This method will set [[db]] to be the 'db' application component, if it is `null`.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     $this->db->getSchema()->refresh();
 }
 /**
  * Initializes the [[rules]] array by instantiating rule objects from configurations.
  */
 public function init()
 {
     parent::init();
     $this->user = Instance::ensure($this->user, User::className());
     foreach ($this->rules as $i => $rule) {
         if (is_array($rule)) {
             $this->rules[$i] = Leaps::createObject(array_merge($this->ruleConfig, $rule));
         }
     }
 }
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * It checks the existence of the [[migrationPath]].
  * @param \yii\base\Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($action->id !== 'create') {
             $this->db = Instance::ensure($this->db, Connection::className());
         }
         return true;
     } else {
         return false;
     }
 }
Example #7
0
 /**
  * Initializes generic database table based mutex implementation.
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
 }
Example #8
0
 /**
  * Returns the dependencies of the specified class.
  *
  * @param string $class class name, interface name or alias name
  * @return array the dependencies of the specified class.
  */
 protected function getDependencies($class)
 {
     if (isset($this->_reflections[$class])) {
         return [$this->_reflections[$class], $this->_dependencies[$class]];
     }
     $dependencies = [];
     $reflection = new ReflectionClass($class);
     $constructor = $reflection->getConstructor();
     if ($constructor !== null) {
         foreach ($constructor->getParameters() as $param) {
             if ($param->isDefaultValueAvailable()) {
                 $dependencies[] = $param->getDefaultValue();
             } else {
                 $c = $param->getClass();
                 $dependencies[] = Instance::of($c === null ? null : $c->getName());
             }
         }
     }
     $this->_reflections[$class] = $reflection;
     $this->_dependencies[$class] = $dependencies;
     return [$reflection, $dependencies];
 }
 /**
  * Initializes the DB connection component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  *
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     if ($this->sql === null) {
         throw new InvalidConfigException('The "sql" property must be set.');
     }
 }
 /**
  * Initializes the DbMessageSource component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * Configured [[cache]] component would also be initialized.
  * @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     if ($this->enableCaching) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
Example #11
0
 /**
  * Initializes the application component.
  */
 public function init()
 {
     parent::init();
     $this->cache = Instance::ensure($this->cache, Cache::className());
 }
Example #12
0
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * You may override this method to do last-minute preparation for the action.
  * @param Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (!$this->enabled) {
         return true;
     }
     $this->cache = Instance::ensure($this->cache, Cache::className());
     if (is_array($this->dependency)) {
         $this->dependency = Leaps::createObject($this->dependency);
     }
     $properties = [];
     foreach (['cache', 'duration', 'dependency', 'variations'] as $name) {
         $properties[$name] = $this->{$name};
     }
     $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
     $response = Leaps::$app->getResponse();
     ob_start();
     ob_implicit_flush(false);
     if ($this->view->beginCache($id, $properties)) {
         $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
         return true;
     } else {
         $data = $this->cache->get($this->calculateCacheKey());
         if (is_array($data)) {
             $this->restoreResponse($response, $data);
         }
         $response->content = ob_get_clean();
         return false;
     }
 }