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\Extension\TSimple;
  4: 
  5: use Deimos\Flow\FlowFunction;
  6: 
  7: class TVariable extends FlowFunction
  8: {
  9: 
 10:     /**
 11:      * @var array
 12:      */
 13:     protected $attributes = [];
 14: 
 15:     /**
 16:      * @return string
 17:      */
 18:     protected function callback()
 19:     {
 20:         $callback    = '';
 21:         $isCallback  = array_shift($this->data) === '|';
 22:         $isAttribute = false;
 23:         $iteration   = 0;
 24: 
 25:         foreach ($this->data as $dataValue)
 26:         {
 27:             if ($isCallback)
 28:             {
 29: 
 30:                 if ($dataValue === ':')
 31:                 {
 32:                     $isAttribute = true;
 33:                     $isCallback  = false;
 34:                     continue;
 35:                 }
 36: 
 37:                 $callback .= $dataValue;
 38:                 continue;
 39:             }
 40:             else if ($isAttribute)
 41:             {
 42:                 if ($dataValue === ':')
 43:                 {
 44:                     $iteration++;
 45:                     continue;
 46:                 }
 47: 
 48:                 if (empty($this->attributes[$iteration]))
 49:                 {
 50:                     $this->attributes[$iteration] = '';
 51:                 }
 52: 
 53:                 $this->attributes[$iteration] .= $dataValue;
 54:             }
 55: 
 56:             $isCallback = $dataValue === '|';
 57:         }
 58: 
 59:         return $callback;
 60:     }
 61: 
 62:     public function view()
 63:     {
 64: 
 65:         $data = implode($this->data);
 66:         preg_match('~^(?<variable>' . self::REGEXP_VARIABLE . ')~', $data, $variable);
 67: 
 68:         if (empty($variable['variable']))
 69:         {
 70:             $variable = array_shift($this->data);
 71:         }
 72:         else
 73:         {
 74:             $variable = $variable['variable'];
 75:         }
 76: 
 77:         $variable = $this->variable($variable);
 78: 
 79:         $callback = $this->callback();
 80: 
 81:         $isDefault = $callback === 'default';
 82: 
 83:         if (empty($callback) || $isDefault)
 84:         {
 85:             $callback = 'escape';
 86:         }
 87: 
 88:         if ($isDefault && $variable{0} === '$')
 89:         {
 90:             $storage = sprintf(
 91:                 '(empty(%s)?$this->configure->di()->escape(%s):$this->configure->di()->escape(%s))',
 92:                 $variable,
 93:                 array_shift($this->attributes),
 94:                 $variable
 95:             );
 96:         }
 97:         else
 98:         {
 99:             $storage = '$this->configure->di()->call(\'' . $callback . '\', ';
100:             $export  = var_export(array_merge([$variable], $this->attributes), true);
101:             $regExp  = sprintf('~\'(%s)\'~', self::REGEXP_VARIABLE);
102:             $export  = preg_replace($regExp, '$1', $export);
103:             $export  = preg_replace('~\'(-?[\d\.]+)\'~', '$1', $export);
104:             $storage .= str_replace(["\n", "\r"], '', $export) . ')';
105:         }
106: 
107:         return '<?php echo ' . $storage . '; ?>';
108:     }
109: 
110: }
API documentation generated by ApiGen