コード例 #1
0
ファイル: Loop.php プロジェクト: raincious/facula
 /**
  * Parse the tag according to given information
  *
  * @param context $context The context object of current tag
  * @param string $content The content for parse
  * @param array $wildcards Data in the wildcards
  * @param array $assigned Assigned data for rendering
  * @param array $shared Shared inter-exchange data for rendering
  * @param array $export Data will be outputted with render result.
  *
  * @return string Return the string of parsed data
  */
 public function parse(Context $context, $content, array &$wildcards, array $assigned, array &$shared, array &$export)
 {
     $data = array();
     $finalResult = '';
     if (!isset($wildcards[0], $wildcards[1])) {
         return '';
     }
     if (!isset($assigned['Loop'][$wildcards[0]]) || !is_array($assigned['Loop'][$wildcards[0]])) {
         return '';
     }
     foreach ($assigned['Loop'][$wildcards[0]] as $loopDatas) {
         $render = new Render($context->subs(), $content);
         foreach ($loopDatas as $dataKey => $dataVal) {
             $render->assign($dataKey, $dataVal);
         }
         $rendered = $render->renderSub();
         $finalResult .= ltrim($rendered[Render::RESULT_STRING]);
         if (!empty($rendered[Render::RESULT_DATA])) {
             $data[$wildcards[0]][] = $rendered[Render::RESULT_DATA];
         }
     }
     $export = $data;
     return rtrim($finalResult);
 }
コード例 #2
0
ファイル: ContextTest.php プロジェクト: raincious/facula
 public function testAnalyzeTrimed()
 {
     $tagHandlerA = new FakeTags\VariableTag(static::getDummyConfig());
     $tagHandlerB = new FakeTags\VariableShortTag(static::getDummyConfig());
     $tagHandlerC = new FakeTags\PercentTag(static::getDummyConfig());
     $tag = new Tags();
     $tag->register($tagHandlerA);
     $tag->register($tagHandlerB);
     $tag->register($tagHandlerC);
     $config = array('MaxTags' => 9999, 'MaxNestingLevel' => 3, 'TolerateInvalid' => false);
     $string = '${TAG}(AA)';
     $contexts = Context::analyze(Tree::analyze($tag, $string, $config), $config);
     $expects = array(array(array(array(Consts::CONTEXT_ID => '', Consts::CONTEXT_TYPE => Consts::CONTEXT_TYPE_WILDCARD, Consts::CONTEXT_START => 2, Consts::CONTEXT_END => 5, Consts::CONTEXT_CONTEXT => null)), array(array(Consts::CONTEXT_ID => '', Consts::CONTEXT_TYPE => Consts::CONTEXT_TYPE_WILDCARD, Consts::CONTEXT_START => 7, Consts::CONTEXT_END => 9, Consts::CONTEXT_CONTEXT => null))), array(array(array(Consts::CONTEXT_ID => '0/0/0', Consts::CONTEXT_TYPE => Consts::CONTEXT_TYPE_CHILD, Consts::CONTEXT_START => 0, Consts::CONTEXT_END => 10, Consts::CONTEXT_CONTEXT => 'Facula\\Unit\\Formated\\Base\\Analyzer\\Context'))));
     foreach ($contexts as $contextKey => $context) {
         foreach ($context->steps() as $wildcardKey => $wildcardData) {
             foreach ($wildcardData as $stepsKey => $steps) {
                 // Consts::CONTEXT_ID
                 $this->assertSame($expects[$contextKey][$wildcardKey][$stepsKey][Consts::CONTEXT_ID], $steps[Consts::CONTEXT_ID]);
                 // Consts::CONTEXT_TYPE
                 $this->assertSame($expects[$contextKey][$wildcardKey][$stepsKey][Consts::CONTEXT_TYPE], $steps[Consts::CONTEXT_TYPE]);
                 // Consts::CONTEXT_START
                 $this->assertSame($expects[$contextKey][$wildcardKey][$stepsKey][Consts::CONTEXT_START], $steps[Consts::CONTEXT_START]);
                 // Consts::CONTEXT_END
                 $this->assertSame($expects[$contextKey][$wildcardKey][$stepsKey][Consts::CONTEXT_END], $steps[Consts::CONTEXT_END]);
                 // Consts::CONTEXT_CONTEXT
                 if ($expects[$contextKey][$wildcardKey][$stepsKey][Consts::CONTEXT_ID] === '') {
                     $this->assertSame(true, is_null($steps[Consts::CONTEXT_CONTEXT]));
                 } else {
                     $this->assertSame($expects[$contextKey][$wildcardKey][$stepsKey][Consts::CONTEXT_CONTEXT], get_class($steps[Consts::CONTEXT_CONTEXT]));
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: Analyzer.php プロジェクト: raincious/facula
 /**
  * Analyze syntax
  *
  * @param string $content Content string for analyze
  *
  * @return array Return the syntax tree
  */
 public function analyze($content)
 {
     $tree = Tree::analyze($this->tags, $content, $this->config);
     return Context::analyze($tree, $this->config);
 }