PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Zend_Application_Resource_ResourceAbstract

Zend_Application_Resource_ResourceAbstract is an abstract class implementing Zend_Application_Resource_Resource, and is a good starting point for creating your own custom plugin resources.

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

Table 8. Zend_Application_Resource_ResourceAbstract Methods

Method Return Value Parameters Description
__construct($options = null) Void
  • $options: optional. Options with which to set resource state.

The constructor should allow passing options with which to initialize state.

setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) Zend_Application_Resource_ResourceAbstract
  • $bootstrap: required. Parent bootstrap initializing this resource.

Should allow registering the parent bootstrap object.

getBootstrap() Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the registered bootstrap instance.

setOptions(array $options) Zend_Application_Resource_ResourceAbstract
  • $options: required. Options with which to set state.

Set resource state.

getOptions() Array N/A

Retrieve registered options.


Resource Names

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.

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 "Zend_Application_Resource_View" may be referenced as simply "View", as the prefix path "Zend_Application_Resource" is already registered. You may register them using the full class name or the short name:

<?php
$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(),
    ),
));

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

<?php
$bootstrap
->bootstrap('view');
$view $bootstrap->getResource('view');

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:

<?php
$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(),
    ),
));

Obviously, this makes referencing the resource much more verbose:

<?php
$bootstrap
->bootstrap('My_Resource_View');
$view $bootstrap->getResource('My_Resource_View');

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 $_explicitType 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:

<?php
class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
    public 
$_explicitType 'My_View';

    public function 
init()
    {
        
// do some initialization...
    
}
}

We can then bootstrap that resource or retrieve it by the name "My_View":

<?php
$bootstrap
->bootstrap('My_View');
$view $bootstrap->getResource('My_View');

Using these various naming approaches, you can override existing resources, add your own, mix multiple resources to achieve complex initialization, and more.

Zend Framework