Ejemplo n.º 1
0
 /**
  *
  * @param string $id the ID of this action
  * @param Controller $controller the controller that owns this action
  * @param string $actionMethod the controller method that this inline action is associated with
  * @param array $config name-value pairs that will be used to initialize the object properties
  */
 public function __construct($id, $controller, $actionMethod, $config = [])
 {
     $this->actionMethod = $actionMethod;
     parent::__construct($id, $controller, $config);
 }
Ejemplo n.º 2
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;
     }
 }