<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.application.core-functionality.resource-resourceabstract">
    <title>Zend_Application_Resource_ResourceAbstract</title>

    <para>
        <classname>Zend_Application_Resource_ResourceAbstract</classname> is an abstract
        class implementing <link
            linkend="zend.application.core-functionality.resource-resource">Zend_Application_Resource_Resource</link>,
        and is a good starting point for creating your own custom plugin
        resources.
    </para>

    <para>
        Note: this abstract class does not implement the <methodname>init()</methodname>
        method; this is left for definition in concrete extensions of the
        class.
    </para>

    <table id="zend.application.core-functionality.resource-resourceabstract.api">
        <title>Zend_Application_Resource_ResourceAbstract Methods</title>

        <tgroup cols="4">
            <thead>
                <row>
                    <entry>Method</entry>
                    <entry>Return Value</entry>
                    <entry>Parameters</entry>
                    <entry>Description</entry>
                </row>
            </thead>

            <tbody>
                <row>
                    <entry><methodname>__construct($options = null)</methodname></entry>
                    <entry><type>Void</type></entry>
                    <entry>
                        <itemizedlist>
                            <listitem>
                                <para>
                                    <varname>$options</varname>: <emphasis>optional</emphasis>.
                                    Options with which to set resource state.
                                </para>
                            </listitem>
                        </itemizedlist>
                    </entry>

                    <entry>
                        <para>
                            The constructor should allow passing options with which to initialize
                            state.
                        </para>
                    </entry>
                </row>

                <row>
                    <entry>
                        <methodname>setBootstrap(Zend_Application_Bootstrap_Bootstrapper
                            $bootstrap)</methodname>
                    </entry>

                    <entry><classname>Zend_Application_Resource_ResourceAbstract</classname></entry>

                    <entry>
                        <itemizedlist>
                            <listitem>
                                <para>
                                    <varname>$bootstrap</varname>: <emphasis>required</emphasis>.
                                    Parent bootstrap initializing this resource.
                                </para>
                            </listitem>
                        </itemizedlist>
                    </entry>

                    <entry>
                        <para>Should allow registering the parent bootstrap object.</para>
                    </entry>
                </row>

                <row>
                    <entry><methodname>getBootstrap()</methodname></entry>
                    <entry><classname>Zend_Application_Bootstrap_Bootstrapper</classname></entry>
                    <entry>N/A</entry>
                    <entry><para>Retrieve the registered bootstrap instance.</para></entry>
                </row>

                <row>
                    <entry><methodname>setOptions(array $options)</methodname></entry>
                    <entry><classname>Zend_Application_Resource_ResourceAbstract</classname></entry>

                    <entry>
                        <itemizedlist>
                            <listitem>
                                <para>
                                    <varname>$options</varname>: <emphasis>required</emphasis>.
                                    Options with which to set state.
                                </para>
                            </listitem>
                        </itemizedlist>
                    </entry>

                    <entry><para>Set resource state.</para></entry>
                </row>

                <row>
                    <entry><methodname>getOptions()</methodname></entry>
                    <entry><type>Array</type></entry>
                    <entry>N/A</entry>
                    <entry><para>Retrieve registered options.</para></entry>
                </row>
            </tbody>
        </tgroup>
    </table>

    <sect3 id="zend.application.core-functionality.resource-resourceabstract.names">
        <title>Resource Names</title>

        <para>
            When registering plugin resources, one issue that arises is how you
            should refer to them from the parent bootstrap class. There are
            three different mechanisms that may be used, depending on how you
            have configured the bootstrap and its plugin resources.
        </para>

        <para>
            First, if your plugins are defined within a defined prefix path, you
            may refer to them simply by their "short name" -- i.e., the portion
            of the class name following the class prefix. As an example, the
            class "<classname>Zend_Application_Resource_View</classname>" may be referenced as
            simply "View", as the prefix path "<classname>Zend_Application_Resource</classname>"
            is already registered. You may register them using the full class name or the
            short name:
        </para>

        <programlisting language="php"><![CDATA[
$app = new Zend_Application(APPLICATION_ENV, array(
    'pluginPaths' => array(
        'My_Resource' => 'My/Resource/',
    ),
    'resources' => array(
        // if the following class exists:
        'My_Resource_View' => array(),

        // then this is equivalent:
        'View' => array(),
    ),
));
]]></programlisting>

        <para>
            In each case, you can then bootstrap the resource and retrieve it
            later using the short name:
        </para>

        <programlisting language="php"><![CDATA[
$bootstrap->bootstrap('view');
$view = $bootstrap->getResource('view');
]]></programlisting>

        <para>
            Second, if no matching plugin path is defined, you may still pass a
            resource by the full class name. In this case, you can reference it
            using the resource's full class name:
        </para>

        <programlisting language="php"><![CDATA[
$app = new Zend_Application(APPLICATION_ENV, array(
    'resources' => array(
        // This will load the standard 'View' resource:
        'View' => array(),

        // While this loads a resource with a specific class name:
        'My_Resource_View' => array(),
    ),
));
]]></programlisting>

        <para>
            Obviously, this makes referencing the resource much more verbose:
        </para>

        <programlisting language="php"><![CDATA[
$bootstrap->bootstrap('My_Resource_View');
$view = $bootstrap->getResource('My_Resource_View');
]]></programlisting>

        <para>
            This brings us to the third option. You can specify an explicit name
            that a given resource class will register as. This can be done by
            adding a public <varname>$_explicitType</varname> property to the resource
            plugin class, with a string value; that value will then be used
            whenever you wish to reference the plugin resource via the
            bootstrap. As an example, let's define our own view class:
        </para>

        <programlisting language="php"><![CDATA[
class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
    public $_explicitType = 'My_View';

    public function init()
    {
        // do some initialization...
    }
}
]]></programlisting>

        <para>
            We can then bootstrap that resource or retrieve it by the name
            "<classname>My_View</classname>":
        </para>

        <programlisting language="php"><![CDATA[
$bootstrap->bootstrap('My_View');
$view = $bootstrap->getResource('My_View');
]]></programlisting>

        <para>
            Using these various naming approaches, you can override existing
            resources, add your own, mix multiple resources to achieve complex
            initialization, and more.
        </para>
    </sect3>
</sect2>
