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/Extension.php | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lib/querypath/src/QueryPath/Extension.php (limited to 'lib/querypath/src/QueryPath/Extension.php') diff --git a/lib/querypath/src/QueryPath/Extension.php b/lib/querypath/src/QueryPath/Extension.php new file mode 100644 index 0000000..ec370ca --- /dev/null +++ b/lib/querypath/src/QueryPath/Extension.php @@ -0,0 +1,94 @@ + + * @license MIT + * @see Extension + * @see ExtensionRegistry::extend() + */ +namespace QueryPath; + +/** @addtogroup querypath_extensions Extensions + * The QueryPath extension system and bundled extensions. + * + * Much like jQuery, QueryPath provides a simple extension mechanism that allows + * extensions to auto-register themselves upon being loaded. For a simple example, see + * QPXML. For the internals, see QueryPath::Extension and QueryPath::with(). + */ + +/** + * A Extension is a tool that extends the capabilities of a Query object. + * + * Extensions to QueryPath should implement the Extension interface. The + * only requirement is that the extension provide a constructor that takes a + * Query object as a parameter. + * + * Here is an example QueryPath extension: + * @code + * qp = $qp; + * } + * + * public function stubToe() { + * $this->qp->find(':root')->append('')->end(); + * return $this->qp; + * } + * } + * ?> + * @endcode + * In this example, the StubExtensionOne class implements Extension. + * The constructor stores a local copyof the Query object. This is important + * if you are planning on fully integrating with QueryPath's Fluent Interface. + * + * Finally, the stubToe() function illustrates how the extension makes use of + * QueryPath's Query object internally, and remains part of the fluent interface by returning + * the $qp object. + * + * Enabling an Extension + * + * To enable an extension, call the QueryPath::enable() method. + * + * @code + * + * @endcode + * + * More complex management of extensions can be accomplished with the + * QueryPath::ExtensionRegistry class. + * + * How is a QueryPath extension called? + * + * QueryPath extensions are called like regular QueryPath functions. For + * example, the extension above can be called like this: + * + * qp('some.xml')->stubToe(); + * // or + * QueryPath::with('some.xml')->stubToe(); + * + * Since it returns the Query ($qp) object, chaining is supported: + * + * print qp('some.xml')->stubToe()->xml(); + * + * When you write your own extensions, anything that does not need to return a + * specific value should return the Query object. Between that and the + * extension registry, this will provide the best developer experience. + * + * @ingroup querypath_extensions + */ +interface Extension { + public function __construct(\QueryPath\Query $qp); +} -- cgit v1.2.3