static function createByAnnotations($file, $class, $annotations) { if (!isset($annotations['tag'])) { throw new lmbMacroException("@tag annotation is missing for class '{$class}'"); } $tag = $annotations['tag']; $info = new lmbMacroTagInfo($tag, $class); $info->setFile($file); if (isset($annotations['forbid_end_tag'])) { $info->setForbidEndtag(true); } if (isset($annotations['restrict_self_nesting'])) { $info->setRestrictSelfNesting(true); } if (isset($annotations['parent_tag_class'])) { $info->setParentClass(trim($annotations['parent_tag_class'])); } if (isset($annotations['req_attributes'])) { $req_attributes = explode(',', $annotations['req_attributes']); $req_attributes = array_map('trim', $req_attributes); $info->setRequiredAttributes($req_attributes); } if (isset($annotations['aliases'])) { $filter_aliases = explode(',', $annotations['aliases']); $filter_aliases = array_map('trim', $filter_aliases); $info->setAliases($filter_aliases); } return $info; }
function testRegisterFromFile() { $rnd = mt_rand(); $contents = <<<EOD <?php /** * @tag foo_{$rnd} * @req_attributes attr1, attr2 * @restrict_self_nesting * @parent_tag_class SomeParentTagClass * @aliases foo1_{$rnd}, foo2_{$rnd} * @forbid_end_tag */ class Foo{$rnd}Tag extends lmbMacroTag{} /** * @tag bar_{$rnd} */ class Bar{$rnd}Tag extends lmbMacroTag{} EOD; $config = $this->_createMacroConfig(); $config->tags_scan_dirs = array($this->cache_dir); file_put_contents($file = $config->tags_scan_dirs[0] . $rnd . '.tag.php', $contents); $tag_info1 = new lmbMacroTagInfo("foo_{$rnd}", "Foo{$rnd}Tag"); $tag_info1->setFile($file); $tag_info1->setForbidEndtag(true); $tag_info1->setAliases(array("foo1_{$rnd}", "foo2_{$rnd}")); $tag_info1->setRestrictSelfNesting(true); $tag_info1->setParentClass('SomeParentTagClass'); $tag_info1->setRequiredAttributes(array('attr1', 'attr2')); $tag_info2 = new lmbMacroTagInfo("bar_{$rnd}", "Bar{$rnd}Tag"); $tag_info2->setFile($file); $dictionary = new lmbMacroTagDictionary(); $dictionary->registerFromFile($file); $this->assertEqual($dictionary->findTagInfo("foo_{$rnd}"), $tag_info1); $this->assertEqual($dictionary->findTagInfo("foo1_{$rnd}"), $tag_info1); $this->assertEqual($dictionary->findTagInfo("bar_{$rnd}"), $tag_info2); }