. */ /** * Handles template tag registry. * * @since 4.6.0 * @package Tag */ namespace Textpattern\Tag; class Registry implements \Textpattern\Container\ReusableInterface { /** * Stores registered tags. * * @var array */ private $tags = array(); /** * Registers a tag. * * * Txp::get('\Textpattern\Tag\Registry')->register(array('class', 'method'), 'tag'); * * * @param callback $callback The tag callback * @param string|null $tag The tag name * @return \Textpattern\Tag\Registry */ public function register($callback, $tag = null) { // is_callable only checks syntax here to avoid autoloading if (is_callable($callback, true)) { if ($tag === null && is_string($callback)) { $tag = $callback; } if ($tag) { $this->tags[$tag] = $callback; } } return $this; } /** * Processes a tag by name. * * @param string $tag The tag * @param array|null $atts An array of Attributes * @param string|null $thing The contained statement * @return string|bool The tag's results (string) or FALSE on unknown tags */ public function process($tag, array $atts = null, $thing = null) { if ($this->isRegistered($tag)) { return (string) call_user_func($this->tags[$tag], (array)$atts, $thing); } else { return false; } } /** * Checks if a tag is registered. * * @param string $tag The tag * @return bool TRUE if the tag exists */ public function isRegistered($tag) { return isset($this->tags[$tag]) && is_callable($this->tags[$tag]); } /** * Lists registered tags. * * @return array */ public function getRegistered() { return $this->tags; } }