Overview

Namespaces

  • Deimos
    • Flow
      • Extension
        • TBlock
        • TFor
        • TForeach
        • TIF
        • TLiteral
        • TPHP
        • TSimple
        • TTry
        • TWhile
      • Traits
  • PHP

Classes

  • Deimos\Flow\Block
  • Deimos\Flow\Configure
  • Deimos\Flow\DefaultConfig
  • Deimos\Flow\DefaultContainer
  • Deimos\Flow\Extension\TBlock\TBlockStart
  • Deimos\Flow\Extension\TBlock\TEndBlock
  • Deimos\Flow\Extension\TFor\TEndFor
  • Deimos\Flow\Extension\TFor\TFor
  • Deimos\Flow\Extension\TForeach\TElseForeach
  • Deimos\Flow\Extension\TForeach\TEndForeach
  • Deimos\Flow\Extension\TForeach\TForeach
  • Deimos\Flow\Extension\TIF\TELSE
  • Deimos\Flow\Extension\TIF\TELSEIF
  • Deimos\Flow\Extension\TIF\TEndIF
  • Deimos\Flow\Extension\TIF\TIF
  • Deimos\Flow\Extension\TLiteral\TLiteral
  • Deimos\Flow\Extension\TPHP\TEndPHP
  • Deimos\Flow\Extension\TPHP\TPHP
  • Deimos\Flow\Extension\TSimple\TAssign
  • Deimos\Flow\Extension\TSimple\TBreak
  • Deimos\Flow\Extension\TSimple\TContinue
  • Deimos\Flow\Extension\TSimple\TExtends
  • Deimos\Flow\Extension\TSimple\TInclude
  • Deimos\Flow\Extension\TSimple\TPartial
  • Deimos\Flow\Extension\TSimple\TVariable
  • Deimos\Flow\Extension\TTry\TCatch
  • Deimos\Flow\Extension\TTry\TEndTry
  • Deimos\Flow\Extension\TTry\TFinally
  • Deimos\Flow\Extension\TTry\TTry
  • Deimos\Flow\Extension\TWhile\TEndWhile
  • Deimos\Flow\Extension\TWhile\TWhile
  • Deimos\Flow\Flow
  • Deimos\Flow\FlowForeach
  • Deimos\Flow\FlowFunction
  • Deimos\Flow\ForeachState
  • Deimos\Flow\Lexer
  • Deimos\Flow\LexerConst
  • Deimos\Flow\Tokenizer

Interfaces

  • Throwable

Traits

  • Deimos\Flow\Traits\Block
  • Deimos\Flow\Traits\FileSystem
  • Deimos\Flow\Traits\Tokenizer

Exceptions

  • BadFunctionCallException
  • Exception
  • InvalidArgumentException
  • LogicException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: namespace Deimos\Flow\Traits;
  4: 
  5: use Deimos\Flow\Configure;
  6: use Deimos\Flow\Flow;
  7: 
  8: trait Block
  9: {
 10: 
 11:     /**
 12:      * @var Configure
 13:      */
 14:     protected $configure;
 15: 
 16:     /**
 17:      * @var array
 18:      */
 19:     protected $blocks = [];
 20: 
 21:     /**
 22:      * @var string
 23:      */
 24:     protected $lastName;
 25: 
 26:     /**
 27:      * @var string
 28:      */
 29:     protected $type;
 30: 
 31:     /**
 32:      * @var string
 33:      */
 34:     protected $selectView;
 35: 
 36:     /**
 37:      * @var bool
 38:      */
 39:     protected $isStarted;
 40: 
 41:     /**
 42:      * @param Flow   $flow
 43:      * @param string $name
 44:      * @param string $type
 45:      */
 46:     public function start($flow, $name, $type = 'inner')
 47:     {
 48:         $this->isStarted  = true;
 49:         $this->lastName   = $name;
 50:         $this->selectView = $flow->selectView();
 51:         $this->type       = $type;
 52: 
 53:         if (!isset($this->blocks[$this->lastName]))
 54:         {
 55:             $this->blocks[$this->lastName] = '';
 56:         }
 57: 
 58:         ob_start();
 59:     }
 60: 
 61:     /**
 62:      * @throws \InvalidArgumentException
 63:      */
 64:     public function end()
 65:     {
 66:         if (!$this->isStarted)
 67:         {
 68:             throw new \InvalidArgumentException('Block not started!');
 69:         }
 70: 
 71:         $this->isStarted = false;
 72: 
 73:         $result = ob_get_clean();
 74: 
 75:         if ($this->type === 'inner')
 76:         {
 77:             if (
 78:                 empty($this->blocks[$this->lastName]) ||
 79:                 empty($this->configure->getExtendsAll($this->selectView))
 80:             )
 81:             {
 82:                 // default value
 83:                 $this->blocks[$this->lastName] = $result;
 84:             }
 85:         }
 86:         else
 87:         {
 88: 
 89:             if ($this->type === 'append')
 90:             {
 91:                 $this->blocks[$this->lastName] .= $result;
 92:             }
 93: 
 94:             if ($this->type === 'prepend')
 95:             {
 96:                 $this->blocks[$this->lastName]
 97:                     = $result . $this->blocks[$this->lastName];
 98:             }
 99: 
100:         }
101: 
102:         $this->display();
103: 
104:     }
105: 
106:     protected function display()
107:     {
108:         if (!empty($this->configure->getExtendsAll($this->selectView)))
109:         {
110:             echo $this->getBlock($this->lastName);
111: 
112:             return;
113:         }
114:     }
115: 
116:     /**
117:      * @param $name
118:      *
119:      * @return mixed
120:      */
121:     public function getBlock($name)
122:     {
123:         return $this->blocks[$name];
124:     }
125: 
126: }
API documentation generated by ApiGen