Back to FeedFactory class

Method registerParser

public \Joomla\CMS\Feed\FeedFactory
registerParser
(mixed $tagName, mixed $className, mixed $overwrite = false)
Method to register a FeedParser class for a given root tag name.
Parameters
  • string $tagName The root tag name for which to register the parser class.
  • string $className The FeedParser class name to register for a root tag name.
  • bool $overwrite True to overwrite the parser class if one is already registered.
Returns
  • \Joomla\CMS\Feed\FeedFactory
Since
  • 3.1.4
-
  • \InvalidArgumentException
Class: FeedFactory
Project: Joomla

Method registerParser - Source code

/**
 * Method to register a FeedParser class for a given root tag name.
 *
 * @param   string   $tagName    The root tag name for which to register the parser class.
 * @param   string   $className  The FeedParser class name to register for a root tag name.
 * @param   boolean  $overwrite  True to overwrite the parser class if one is already registered.
 *
 * @return  FeedFactory
 *
 * @since   3.1.4
 * @throws  \InvalidArgumentException
 */
public function registerParser($tagName, $className, $overwrite = false)
{
    // Verify that the class exists.
    if (!class_exists($className)) {
        throw new \InvalidArgumentException('The feed parser class ' . $className . ' does not exist.');
    }
    // Validate that the tag name is valid.
    if (!preg_match('/\\A(?!XML)[a-z][\\w0-9-]*/i', $tagName)) {
        throw new \InvalidArgumentException('The tag name ' . $tagName . ' is not valid.');
    }
    // Register the given parser class for the tag name if nothing registered or the overwrite flag set.
    if (empty($this->parsers[$tagName]) || (bool) $overwrite) {
        $this->parsers[(string) $tagName] = (string) $className;
    }
    return $this;
}