Ejemplo n.º 1
0
 /**
  * The main Lex parser method.  Essentially acts as dispatcher to
  * all of the helper parser methods.
  *
  * @param  string       $text     Text to parse
  * @param  array|object $data     Array or object to use
  * @param  mixed        $callback Callback to use for Callback Tags
  * @return string
  */
 public function parse($text, $data = array(), $callback = false, $allowPhp = false)
 {
     $this->setupRegex();
     $this->allowPhp = $allowPhp;
     // Is this the first time parse() is called?
     if (self::$data === null) {
         // Let's store the local data array for later use.
         self::$data = $data;
     } else {
         // Let's merge the current data array with the local scope variables
         // So you can call local variables from within blocks.
         $data = array_merge(self::$data, $data);
         // Since this is not the first time parse() is called, it's most definately a callback,
         // let's store the current callback data with the the local data
         // so we can use it straight after a callback is called.
         self::$callbackData = $data;
     }
     // The parseConditionals method executes any PHP in the text, so clean it up.
     if (!$allowPhp) {
         $text = str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $text);
     }
     $text = $this->parseComments($text);
     $text = $this->extractNoparse($text);
     $text = $this->extractLoopedTags($text, $data, $callback);
     // Order is important here.  We parse conditionals first as to avoid
     // unnecessary code from being parsed and executed.
     $text = $this->parseConditionals($text, $data, $callback);
     $text = $this->injectExtractions($text, 'looped_tags');
     $text = $this->parseVariables($text, $data, $callback);
     // CMS Canvas parse variables again so we can support variables inside of variables ex: {{ {{ lang }}_title }}
     $text = $this->parseVariables($text, $data, $callback);
     $text = $this->injectExtractions($text, 'callback_blocks');
     // CMS Canvas fix to extract no parse from $data
     $text = $this->extractNoparse($text);
     if ($callback) {
         $text = $this->parseCallbackTags($text, $data, $callback);
     }
     // To ensure that {{ noparse }} is never parsed even during consecutive parse calls
     // set $cumulativeNoparse to true and use self::injectNoparse($text); immediately
     // before the final output is sent to the browser
     if (!$this->cumulativeNoparse) {
         $text = $this->injectExtractions($text);
     }
     return $text;
 }