public function testTagAssign() { $config = array(); $v = new FakeTags\VariableTag($config); $expectedMap = array(Consts::TAG_MAP_SUBS => array('${' => array(Consts::TAG_MAP_SUBS => array(Consts::TAG_WILDCARD => array(Consts::TAG_MAP_SUBS => array('}' => array(Consts::TAG_MAP_SUBS => array(), Consts::TAG_MAP_TAGLENGTHS => array(), Consts::TAG_MAP_HANDLER => $v, Consts::TAG_MAP_CHECKS => array())), Consts::TAG_MAP_TAGLENGTHS => array(1 => 1), Consts::TAG_MAP_HANDLER => null, Consts::TAG_MAP_CHECKS => array('}' => true))), Consts::TAG_MAP_TAGLENGTHS => array(), Consts::TAG_MAP_HANDLER => null, Consts::TAG_MAP_CHECKS => array())), Consts::TAG_MAP_TAGLENGTHS => array(2 => 2), Consts::TAG_MAP_HANDLER => null, Consts::TAG_MAP_CHECKS => array('$' => true)); $tag = new Tags(); $tag->register($v); $this->assertSame($expectedMap, $tag->getMap()); }
protected static function match($testString, Tags $tag, &$nestLevel = '') { $total = 0; $nestLevels = array(); $testStringLen = strlen($testString); $index = 0; $tagMap = $tag->getMap(); $stepInfo = array(TreeDummy::NEXTSTEP_INDEX => 0, TreeDummy::NEXTSTEP_NODE => null); $root = new TreeDummy($tagMap, $tagMap, $total); $stepInfo[TreeDummy::NEXTSTEP_NODE] = $root->startoverWildcard(); $stepInfo[TreeDummy::NEXTSTEP_NODE]->debugLevelArray($nestLevels); while ($testStringLen > $stepInfo[TreeDummy::NEXTSTEP_INDEX]) { $stepInfo = $stepInfo[TreeDummy::NEXTSTEP_NODE]->enter($stepInfo[TreeDummy::NEXTSTEP_INDEX], $testString); $stepInfo[TreeDummy::NEXTSTEP_NODE]->debugLevelArray($nestLevels); } ksort($nestLevels); foreach ($nestLevels as $v) { $nestLevel .= $v[1]; } return $root; }
/** * Analyze tree according to specified Tags and content * * @param Tags $t Tags object * @param string $content Refer to the content string * @param array $config Configuration for tree analyze * * @throws Exception\TooManyTags * @throws Exception\NestTooDeep * * @return static Return the root tree object */ public static function analyze(Tags $t, &$content, array &$config) { $totalTags = 0; $tagMap = $t->getMap(); $contentLength = strlen($content); $stepInfo = array(static::NEXTSTEP_INDEX => 0, static::NEXTSTEP_NODE => null); $root = new static($tagMap, $tagMap, $totalTags); $stepInfo[static::NEXTSTEP_NODE] = $root->startover($root->wildcards); while ($contentLength > $stepInfo[static::NEXTSTEP_INDEX]) { $stepInfo = $stepInfo[static::NEXTSTEP_NODE]->enter($stepInfo[static::NEXTSTEP_INDEX], $content); if ($stepInfo[static::NEXTSTEP_NODE]->level > $config['MaxNestingLevel']) { throw new Exception\NestTooDeep($stepInfo[static::NEXTSTEP_NODE]->startPos, $stepInfo[static::NEXTSTEP_NODE]->level, $config['MaxNestingLevel']); } if ($totalTags > $config['MaxTags']) { throw new Exception\TooManyTags($stepInfo[static::NEXTSTEP_NODE]->startPos, $config['MaxTags']); } } // Refresh the position information of the last picking // branch while ($stepInfo[static::NEXTSTEP_NODE]->parent !== null) { $stepInfo[static::NEXTSTEP_NODE]->endPos = $stepInfo[static::NEXTSTEP_INDEX]; $stepInfo[static::NEXTSTEP_NODE] = $stepInfo[static::NEXTSTEP_NODE]->parent; } return $root; }