Skip to content

Commit

Permalink
Added ability to configure PluginBroker and PluginSpecBroker via cons…
Browse files Browse the repository at this point in the history
…tructor
  • Loading branch information
weierophinney committed Oct 28, 2010
1 parent 4ba41f7 commit 3575650
Show file tree
Hide file tree
Showing 8 changed files with 626 additions and 5 deletions.
113 changes: 108 additions & 5 deletions documentation/manual/en/module_specs/Zend_Loader-PluginBroker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,64 @@ $broker->register('url', $urlHelper);
<sect2 id="zend.loader.plugin-broker.options">
<title>Configuration Options</title>


<para>
This class has no constructor options, nor a <methodname>setOptions()</methodname>
method.
</para>
<variablelist>
<title>PluginBroker Options</title>

<varlistentry>
<term>class_loader</term>

<listitem>
<para>
The value of this option may be one of the following:
</para>

<itemizedlist>
<listitem>
<para>A string indicating a fully qualified class name to use for the
class loader. The class must implement
<interfacename>ShortNameLocater</interfacename>.</para>
</listitem>

<listitem>
<para>An object implementing
<interfacename>ShortNameLocater</interfacename>.</para>
</listitem>

<listitem>
<para>An array or <interfacename>Traversable</interfacename> object
containing the keys <varname>class</varname> and optionally
<varname>options</varname>. An object of the type described in
<varname>class</varname> will be instantiated, with the
<varname>options</varname> provided, if any. The class must
implement <interfacename>ShortNameLocater</interfacename>.</para>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>

<varlistentry>
<term>plugins</term>

<listitem>
<para>
The value of this option should be an array or
<interfacename>Traversable</interfacename> object, containing plugin
name/plugin object pairs.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>validator</term>

<listitem>
<para>
The value must be a valid callback, and will be used as a validator for
loaded and registered plugins.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>

<sect2 id="zend.loader.plugin-broker.methods">
Expand Down Expand Up @@ -189,6 +242,56 @@ $broker->register('url', $urlHelper);
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-broker.methods.get-plugins">
<refnamediv>
<refname>getPlugins</refname>
<refpurpose>Retrieve all loaded plugins</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>getPlugins</methodname>
<methodparam>
<funcparams></funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>getPlugins()</title>

<para>
Retrieves a set of name/plugin pairs, indicating all currently loaded plugins.
</para>
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-broker.methods.is-loaded">
<refnamediv>
<refname>isLoaded</refname>
<refpurpose>Determine if a given plugin has been loaded</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>isLoaded</methodname>
<methodparam>
<funcparams>$name</funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>isLoaded()</title>

<para>
Returns <constant>true</constant> if the plugin referenced by
<varname>$name</varname> has been loaded by the broker previously,
<constant>false</constant> otherwise.
</para>
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-broker.methods.set-class-loader">
<refnamediv>
<refname>setClassLoader</refname>
Expand Down
240 changes: 240 additions & 0 deletions documentation/manual/en/module_specs/Zend_Loader-PluginSpecBroker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.loader.plugin-spec-broker">
<title>The PluginSpecBroker</title>

<sect2 id="zend.loader.plugin-spec-broker.intro">
<title>Overview</title>

<para>
This class is an extension of <link linkend="zend.loader.plugin-broker">the
PluginBroker</link>. It provides the additional ability of allowing the registration
of plugin <emphasis>names</emphasis> with related options, for the purposes of allowing
lazy-loading of plugins and/or specifying default options.
</para>
</sect2>

<sect2 id="zend.loader.plugin-spec-broker.quick-start">
<title>Quick Start</title>

<para>
Typically, a component will define an extension to the
<classname>PluginSpecBroker</classname>. In these cases, you instantiate the broker,
optionally providing specifications.
</para>

<programlisting language="php"><![CDATA[
use Zend\Application\ResourceBroker;
$broker = new ResourceBroker(array(
'router' => array('routes' => array(
'foo' => array(
'route' => '/foo/:id',
'defaults' => array(
'module' => 'foo',
'controller' => 'products',
'action' => 'item',
),
'reqs' => array(
'id' => '\d+',
),
),
)),
));
$router = $broker->load('router');
// routes will be configured per specification
]]></programlisting>
</sect2>

<sect2 id="zend.loader.plugin-spec-broker.options">
<title>Configuration Options</title>

<para>
All <link linkend="zend.loader.plugin-broker.options">PluginBroker options</link> are
supported, in addition to those listed below.
</para>

<variablelist>
<title>PluginSpecBroker Options</title>

<varlistentry>
<term>specs</term>

<listitem>
<para>
The value of this option should be an array or
<interfacename>Traversable</interfacename> object, containing plugin
name/configuration pairs.
</para>
</listitem>
</varlistentry>
</sect2>

<sect2 id="zend.loader.plugin-spec-broker.methods">
<title>Available Methods</title>

<para>
All <link linkend="zend.loader.plugin-broker.methods">PluginBroker methods</link> are
available. The methods below either differ in capabilities, or are specific to this
implementation.
</para>

<refentry id="zend.loader.plugin-spec-broker.methods.load">
<refnamediv>
<refname>load</refname>
<refpurpose>Resolve a plugin name to an object instance</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>load</methodname>
<methodparam>
<funcparams>$plugin, array $options = null</funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>load()</title>

<para>
This method acts like <link
linkend="zend.loader.plugin-broker.methods.load">parent</link> in all ways.
However, if a specification has been loaded previously via the constructor,
<methodname>setOptions()</methodname>, or
<methodname>registerSpec()</methodname>, those options will be used if
<varname>$options</varname> is null.
</para>
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-spec-broker.methods.register-spec">
<refnamediv>
<refname>registerSpec</refname>
<refpurpose>Register a plugin specification by name</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>registerSpec</methodname>
<methodparam>
<funcparams>$name, array $spec = null</funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>registerSpec()</title>

<para>
Registers a plugin specification using the given <varname>$name</varname>. The
specification is simply a set of arguments to pass to the object constructor
when first loaded by the broker.
</para>
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-spec-broker.methods.register-specs">
<refnamediv>
<refname>registerSpecs</refname>
<refpurpose>Register many plugin specifications at once</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>registerSpecs</methodname>
<methodparam>
<funcparams>$specs</funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>registerSpecs()</title>

<para>
Registers many plugin specifications at once. <varname>$specs</varname> must be
an array or <interfacename>Traversable</interfacename> object. It is iterated,
and the key/value pairs are passed as arguments to
<methodname>registerSpec()</methodname>.
</para>
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-spec-broker.methods.unregister-spec">
<refnamediv>
<refname>unregisterSpec</refname>
<refpurpose>Unregister a plugin specification</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>unregisterSpec</methodname>
<methodparam>
<funcparams>$name</funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>unregisterSpec()</title>

<para>
If a plugin specficiation referenced by <varname>$name</varname> has been
previously registered, that specification is removed.
</para>
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-spec-broker.methods.get-registered-plugins">
<refnamediv>
<refname>getRegisteredPlugins</refname>
<refpurpose>Retrieve all registered plugins and specifications</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>getRegisteredPlugins</methodname>
<methodparam>
<funcparams></funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>getRegisteredPlugins()</title>

<para>
Retrieves the names of all loaded plugins, as well as all plugin specifications
registered.
</para>
</refsect1>
</refentry>

<refentry id="zend.loader.plugin-spec-broker.methods.has-plugin">
<refnamediv>
<refname>hasPlugin</refname>
<refpurpose>Determine if a plugin has been loaded or registered</refpurpose>
</refnamediv>

<refsynopsisdiv>
<methodsynopsis>
<methodname>hasPlugin</methodname>
<methodparam>
<funcparams>$name</funcparams>
</methodparam>
</methodsynopsis>
</refsynopsisdiv>

<refsect1>
<title>hasPlugin()</title>

<para>
Use this method to determine whether or not the plugin by the name of
<varname>$name</varname> has been loaded or registered, or whether or not a
plugin specification has been provided.
</para>
</refsect1>
</refentry>
</sect2>
</sect1>
Loading

0 comments on commit 3575650

Please sign in to comment.