public function enter($idx, &$char) { $result = parent::enter($idx, $char); if (is_object($result[static::NEXTSTEP_NODE])) { $this->debugLevelArray[$idx] = array($char, $result[static::NEXTSTEP_NODE]->level()); } else { $this->debugLevelArray[$idx] = array($char, '-'); } return $result; }
public function testPreviousNextParent() { $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' => 2, 'TolerateInvalid' => false); $targetString = 'There is ${TAG1} ${TAG2}(%{TAG4} and ${TAG5}).'; $tree = Tree::analyze($tag, $targetString, $config)->wildcard(0); $this->assertSame($tree->child(0)->next(), $tree->child(1)->previous()->next()); $this->assertSame($tagHandlerA, $tree->child(0)->next()->handler()); $this->assertSame($tagHandlerB, $tree->child(0)->next()->previous()->handler()); $this->assertSame($tagHandlerB, $tree->child(1)->wildcard(1)->child(0)->next()->handler()); $this->assertSame($tagHandlerC, $tree->child(1)->wildcard(1)->child(0)->next()->previous()->handler()); $this->assertSame($tagHandlerA, $tree->child(1)->wildcard(1)->child(0)->parent()->parent()->handler()); }
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])); } } } } }
/** * 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); }
/** * Get the sub childs of current context * * @return Tree[] Return the childs */ public function childs() { return $this->tree->childs(); }