1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.application.core-functionality.resource-resourceabstract">
4 <title>Zend_Application_Resource_ResourceAbstract</title>
7 <classname>Zend_Application_Resource_ResourceAbstract</classname> is an abstract
8 class implementing <link
9 linkend="zend.application.core-functionality.resource-resource">Zend_Application_Resource_Resource</link>,
10 and is a good starting point for creating your own custom plugin
15 Note: this abstract class does not implement the <methodname>init()</methodname>
16 method; this is left for definition in concrete extensions of the
20 <table id="zend.application.core-functionality.resource-resourceabstract.api">
21 <title>Zend_Application_Resource_ResourceAbstract Methods</title>
27 <entry>Return Value</entry>
28 <entry>Parameters</entry>
29 <entry>Description</entry>
35 <entry><methodname>__construct($options = null)</methodname></entry>
36 <entry><type>Void</type></entry>
41 <varname>$options</varname>: <emphasis>optional</emphasis>.
42 Options with which to set resource state.
50 The constructor should allow passing options with which to initialize
58 <methodname>setBootstrap(Zend_Application_Bootstrap_Bootstrapper
59 $bootstrap)</methodname>
62 <entry><classname>Zend_Application_Resource_ResourceAbstract</classname></entry>
68 <varname>$bootstrap</varname>: <emphasis>required</emphasis>.
69 Parent bootstrap initializing this resource.
76 <para>Should allow registering the parent bootstrap object.</para>
81 <entry><methodname>getBootstrap()</methodname></entry>
82 <entry><classname>Zend_Application_Bootstrap_Bootstrapper</classname></entry>
84 <entry><para>Retrieve the registered bootstrap instance.</para></entry>
88 <entry><methodname>setOptions(array $options)</methodname></entry>
89 <entry><classname>Zend_Application_Resource_ResourceAbstract</classname></entry>
95 <varname>$options</varname>: <emphasis>required</emphasis>.
96 Options with which to set state.
102 <entry><para>Set resource state.</para></entry>
106 <entry><methodname>getOptions()</methodname></entry>
107 <entry><type>Array</type></entry>
109 <entry><para>Retrieve registered options.</para></entry>
115 <sect3 id="zend.application.core-functionality.resource-resourceabstract.names">
116 <title>Resource Names</title>
119 When registering plugin resources, one issue that arises is how you
120 should refer to them from the parent bootstrap class. There are
121 three different mechanisms that may be used, depending on how you
122 have configured the bootstrap and its plugin resources.
126 First, if your plugins are defined within a defined prefix path, you
127 may refer to them simply by their "short name" -- i.e., the portion
128 of the class name following the class prefix. As an example, the
129 class "<classname>Zend_Application_Resource_View</classname>" may be referenced as
130 simply "View", as the prefix path "<classname>Zend_Application_Resource</classname>"
131 is already registered. You may register them using the full class name or the
135 <programlisting language="php"><![CDATA[
136 $app = new Zend_Application(APPLICATION_ENV, array(
137 'pluginPaths' => array(
138 'My_Resource' => 'My/Resource/',
140 'resources' => array(
141 // if the following class exists:
142 'My_Resource_View' => array(),
144 // then this is equivalent:
151 In each case, you can then bootstrap the resource and retrieve it
152 later using the short name:
155 <programlisting language="php"><![CDATA[
156 $bootstrap->bootstrap('view');
157 $view = $bootstrap->getResource('view');
161 Second, if no matching plugin path is defined, you may still pass a
162 resource by the full class name. In this case, you can reference it
163 using the resource's full class name:
166 <programlisting language="php"><![CDATA[
167 $app = new Zend_Application(APPLICATION_ENV, array(
168 'resources' => array(
169 // This will load the standard 'View' resource:
172 // While this loads a resource with a specific class name:
173 'My_Resource_View' => array(),
179 Obviously, this makes referencing the resource much more verbose:
182 <programlisting language="php"><![CDATA[
183 $bootstrap->bootstrap('My_Resource_View');
184 $view = $bootstrap->getResource('My_Resource_View');
188 This brings us to the third option. You can specify an explicit name
189 that a given resource class will register as. This can be done by
190 adding a public <varname>$_explicitType</varname> property to the resource
191 plugin class, with a string value; that value will then be used
192 whenever you wish to reference the plugin resource via the
193 bootstrap. As an example, let's define our own view class:
196 <programlisting language="php"><![CDATA[
197 class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
199 public $_explicitType = 'My_View';
201 public function init()
203 // do some initialization...
209 We can then bootstrap that resource or retrieve it by the name
210 "<classname>My_View</classname>":
213 <programlisting language="php"><![CDATA[
214 $bootstrap->bootstrap('My_View');
215 $view = $bootstrap->getResource('My_View');
219 Using these various naming approaches, you can override existing
220 resources, add your own, mix multiple resources to achieve complex
221 initialization, and more.