QueryPath extensions should call the QueryPath::ExtensionRegistry::extend()
function to register their extension classes. The QueryPath library then
uses this information to determine what QueryPath extensions should be loaded and
executed.
Extensions are attached to a Query object.
To enable an extension (the easy way), use QueryPath::enable().
This class provides lower-level interaction with the extension
mechanism.
/** * @expectedException \QueryPath\Exception */ public function testAutoloadExtensions() { // FIXME: This isn't really much of a test. ExtensionRegistry::autoloadExtensions(FALSE); try { qp()->stubToe(); } catch (Exception $e) { ExtensionRegistry::autoloadExtensions(TRUE); throw $e; } }
/** * Get a list of all of the enabled extensions. * * This example dumps a list of extensions to standard output: * @code * <?php * $extensions = QueryPath::enabledExtensions(); * print_r($extensions); * ?> * @endcode * * @retval array * An array of extension names. * * @see QueryPath::ExtensionRegistry */ public static function enabledExtensions() { return \QueryPath\ExtensionRegistry::extensionNames(); }
/** * Call extension methods. * * This function is used to invoke extension methods. It searches the * registered extenstensions for a matching function name. If one is found, * it is executed with the arguments in the $arguments array. * * @throws QueryPath::Exception * An exception is thrown if a non-existent method is called. */ public function __call($name, $arguments) { if (!ExtensionRegistry::$useRegistry) { throw new \QueryPath\Exception("No method named {$name} found (Extensions disabled)."); } // Loading of extensions is deferred until the first time a // non-core method is called. This makes constructing faster, but it // may make the first invocation of __call() slower (if there are // enough extensions.) // // The main reason for moving this out of the constructor is that most // new DOMQuery instances do not use extensions. Charging qp() calls // with the additional hit is not a good idea. // // Also, this will at least limit the number of circular references. if (empty($this->ext)) { // Load the registry $this->ext = ExtensionRegistry::getExtensions($this); } // Note that an empty ext registry indicates that extensions are disabled. if (!empty($this->ext) && ExtensionRegistry::hasMethod($name)) { $owner = ExtensionRegistry::getMethodClass($name); $method = new \ReflectionMethod($owner, $name); return $method->invokeArgs($this->ext[$owner], $arguments); } throw new \QueryPath\Exception("No method named {$name} found. Possibly missing an extension."); }