Interface QueryPathExtension

(line 70)

Description


Located in File: /src/QueryPath/QueryPathExtension.php

A QueryPathExtension is a tool that extends the capabilities of a QueryPath object.

Extensions to QueryPath should implement the QueryPathExtension interface. The only requirement is that the extension provide a constructor that takes a QueryPath object as a parameter.

Here is an example QueryPath extension:

  1. <?php
  2.  class StubExtensionOne implements QueryPathExtension {
  3.    private $qp = NULL;
  4.    public function __construct(QueryPath $qp{
  5.      $this->qp $qp;
  6.    }
  7.  
  8.    public function stubToe({
  9.      $this->qp->find(':root')->append('<toe/>')->end();
  10.      return $this->qp;
  11.    }
  12.  }
  13.  QueryPathExtensionRegistry::extend('StubExtensionOne');
  14.  ?>
In this example, the StubExtensionOne class implements QueryPathExtension. The constructor stores a local copyof the QueryPath 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 internally, and remains part of the fluent interface by returning the $qp object.

Notice that beneath the class, there is a single call to register the extension with QueryPath's registry. Your extension should end with a line similar to this.

How is a QueryPath extension called?

QueryPath extensions are called like regular QueryPath functions. For example, the extension above can be called like this:

  1.  qp('some.xml')->stubToe();
Since it returns the QueryPath ($qp) object, chaining is supported:
  1.  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 QueryPath object. Between that and the extension registry, this will provide the best developer experience.



Class Variables

Summary:

Class Constants

Summary:

Method Detail

Summary:
QueryPathExtension __construct (QueryPath $qp)

Constructor __construct (line 71)

QueryPathExtension __construct( QueryPath $qp)

Parameters

Info

  • access - public

Inherited Variables

Inherited Class Variable Summary

Inherited Methods

Inherited Method Summary


Documentation generated on Sun, 25 Jul 2010 16:09:11 -0500 by phpDocumentor 1.4.3