Exemplo n.º 1
0
 /**
  * Used internally to keep engine status updated.
  * Using events is possible to keep in sync template flow with engine status without giving
  * to templates write access to Engine status.
  *
  * @access private
  */
 private function statusTransitions()
 {
     $this->status = self::STATUS_IN_LAYOUT;
     $this->events->on('f.template.layout', function () {
         if ($this->status & self::STATUS_IN_PARTIAL) {
             throw new LogicException('Is not possible to use $this->layout() in partials.');
         }
         $this->status = self::STATUS_IN_TEMPLATE;
     });
     $this->events->on('f.template.renderlayout', function () {
         $this->status = self::STATUS_IN_LAYOUT;
     });
     $this->events->on('f.template.prepartial', function () {
         $this->status |= self::STATUS_IN_PARTIAL;
     });
     $this->events->on('f.template.afterpartial', function () {
         $this->status ^= self::STATUS_IN_PARTIAL;
     });
     $this->events->on('f.template.renderered', function () {
         $this->stack()->pop();
         if ($this->stack()->count() === 0) {
             $this->status = self::STATUS_RENDERED | self::STATUS_IDLE;
             $this->events->fire('f.renderered', $this);
         }
     });
 }
Exemplo n.º 2
0
 /**
  * Provide data by collecting it from contexts in the collection that accepts current template.
  * After having collected data from a context, an event is fired allowing to add some data
  * that depends on that specific context data.
  * {@inheritdoc}
  */
 public function provide()
 {
     $data = $this->data();
     $template = $this->template();
     if (empty($template)) {
         return $data;
     }
     $storage = $this->storage();
     $storage->rewind();
     while ($storage->valid()) {
         $context = $storage->current();
         if ($context->accept($template)) {
             $data = array_merge($data, $context->provide());
             $this->events->fire('f.context.provided', $context, $this);
         }
         $storage->next();
     }
     $this->events->fire('f.context.allprovided', $this);
     return $data;
 }
Exemplo n.º 3
0
 /**
  * Close a section and replace any content already set for the same section.
  * Provide a name is optional, if provided function will check it is the current section.
  *
  * @param string|void $name Section to close
  */
 public function replace($name = null)
 {
     $section = $this->end($name);
     $section->replace();
     $this->events->fire('f.sections.content', $this->last, $section->content());
 }