From 9a9c04512e5dcb77c7fe5d850e3f2a0250cc160e Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 18 Jan 2017 20:07:16 +0100 Subject: * Motor Sport Magazine feed provider --- lib/querypath/src/QueryPath/ExtensionRegistry.php | 130 ++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 lib/querypath/src/QueryPath/ExtensionRegistry.php (limited to 'lib/querypath/src/QueryPath/ExtensionRegistry.php') diff --git a/lib/querypath/src/QueryPath/ExtensionRegistry.php b/lib/querypath/src/QueryPath/ExtensionRegistry.php new file mode 100644 index 0000000..963edd3 --- /dev/null +++ b/lib/querypath/src/QueryPath/ExtensionRegistry.php @@ -0,0 +1,130 @@ +getMethods(); + foreach ($methods as $method) { + self::$extensionMethodRegistry[$method->getName()] = $classname; + } + } + + /** + * Check to see if a method is known. + * This checks to see if the given method name belongs to one of the + * registered extensions. If it does, then this will return TRUE. + * + * @param string $name + * The name of the method to search for. + * @return boolean + * TRUE if the method exists, false otherwise. + */ + public static function hasMethod($name) { + return isset(self::$extensionMethodRegistry[$name]); + } + + /** + * Check to see if the given extension class is registered. + * Given a class name for a QueryPath::Extension class, this + * will check to see if that class is registered. If so, it will return + * TRUE. + * + * @param string $name + * The name of the class. + * @return boolean + * TRUE if the class is registered, FALSE otherwise. + */ + public static function hasExtension($name) { + return in_array($name, self::$extensionRegistry); + } + + /** + * Get the class that a given method belongs to. + * Given a method name, this will check all registered extension classes + * to see if any of them has the named method. If so, this will return + * the classname. + * + * Note that if two extensions are registered that contain the same + * method name, the last one registred will be the only one recognized. + * + * @param string $name + * The name of the method. + * @return string + * The name of the class. + */ + public static function getMethodClass($name) { + return self::$extensionMethodRegistry[$name]; + } + + /** + * Get extensions for the given Query object. + * + * Given a Query object, this will return + * an associative array of extension names to (new) instances. + * Generally, this is intended to be used internally. + * + * @param Query $qp + * The Query into which the extensions should be registered. + * @return array + * An associative array of classnames to instances. + */ + public static function getExtensions(Query $qp) { + $extInstances = array(); + foreach (self::$extensionRegistry as $ext) { + $extInstances[$ext] = new $ext($qp); + } + return $extInstances; + } + + public static function extensionNames() { + return self::$extensionRegistry; + } + + /** + * Enable or disable automatic extension loading. + * + * If extension autoloading is disabled, then QueryPath will not + * automatically load all registred extensions when a new Query + * object is created using qp(). + */ + public static function autoloadExtensions($boolean = TRUE) { + self::$useRegistry = $boolean; + } +} -- cgit v1.2.3