-- keith Pope <[email protected]> wrote
(on Saturday, 28 February 2009, 08:27 PM +0000):
> Just doing some bits with Zend_App, In have two minor issues currently.
>
> When creating a bootstrap file, it keeps bugging me about abstract
> method unregisterPluginResource saying that it needs to be
> implemented.
I'm thinking you don't have an up-to-date checkout, or that you're
extending the wrong class.
unregisterPluginResource() is defined in
Zend_Application_Bootstrap_IResourceBootstrap, which is in turn
implemented in Zend_Application_Bootstrap_Base -- and it's clearly
defined (I'm looking at it right now -- lines 195-214 of that class
file).
So, either extend Zend_Application_Bootstrap_Base, or implement
Zend_Application_Bootstrap_IResourceBootstrap in your bootstrap class.
> Also to get the bootstrap to call my init methods they have to be
> public not protected, I have tracked this to:
>
> $options = $application->getOptions();
> $this->setOptions($options);
> foreach (get_class_methods($this) as $method) {
> if (5 < strlen($method) && '_init' === substr($method, 0, 5)) {
> $this->_classResources[strtolower(substr($method, 5))]
> = $method;
> }
> }
>
> The get_class_methods($this) seems to only return public methods?
> Seems maybe more a PHP bug than anything, the only bug I could find
> associated with this was http://bugs.php.net/bug.php?id=43483. My PHP
> version is 5.2.5.
get_class_methods() will return *all* methods when run on $this, and
only *public* methods when run over a concrete instance. As an example,
try the following:
class Foo
{
public function foo()
{
}
protected function _bar()
{
}
public function __call($method, $args)
{
$methods = get_class_methods($this);
echo "Methods internally:\n" . var_export($methods, 1) . "\n";
}
}
$o = new Foo;
$o->baz();
$methods = get_class_methods($o);
echo "Methods from instance:\n" . var_export($methods, 1) . "\n";
You should then get the following output:
Methods internally:
array (
0 => 'foo',
1 => '_bar',
2 => '__call',
)
Methods from instance:
array (
0 => 'foo',
1 => '__call',
)
The same behavior is true even when extending the class -- if you were
to define "class Bar extends Foo {}" and then substitute "$o = new Bar;"
above, you'd get the exact same behavior.
This has been the documented behavior of get_class_methods() since
5.0.0; if you're not seeing that, then I'm wondering if you've got a PHP
version with a vendor patch of some sort; if so, then you'll need to
make the methods public to work with your PHP version.
(BTW, Zend_View unit tests have relied on this behavior since before the
first public preview release of ZF...)
> My bootstrap:
>
> class Bootstrap extends Zend_Application_Bootstrap_Base
> {
> public function _initFrontController()
> {
> $this->front = Zend_Controller_Front::getInstance();
> }
>
> // not called???
> protected function _initControllers()
> {
> // runs _initFrontController() if not already run:
> $this->bootstrapFrontController();
>
> $this->front->addModuleDirectory(MODULE_PATH . '/modules');
> }
>
> // called!
> public function _initRequest()
> {
> // runs _initFrontController() if not already run:
> $this->bootstrapFrontController();
>
> $this->request = new Zend_Controller_Request_Http;
> $this->front->setRequest($this->request);
> }
>
> public function run()
> {
> $this->front->dispatch();
> }
>
> // had to add this????
> public function unregisterPluginResource($resource){}
> }
>
> My setup:
>
> $paths = array(
> get_include_path(),
> '../library',
> '../library/Incu',
> '../library/Zapp'
> );
> set_include_path(join(PATH_SEPARATOR, array_reverse($paths)));
>
> defined('APPLICATION_PATH')
> or define('APPLICATION_PATH', realpath(dirname(__FILE__) .
> '/../application'));
> defined('APPLICATION_ENV')
> or define('APPLICATION_ENV', 'development');
>
> require_once 'Zend/Application.php';
>
> /**
> * Now there are multiple ways to set up the application. Firstly, the way via
> * options or Zend_Config:
> */
> $application = new Zend_Application(APPLICATION_ENV, array(
> 'bootstrap' => APPLICATION_PATH . '/bootstrap/Bootstrap.php',
> 'autoloadernamespaces' => array('Zend', 'SF')
> )
> );
>
> $application->bootstrap();
>
> var_dump($application);
--
Matthew Weier O'Phinney
Software Architect | [email protected]
Zend Framework | http://framework.zend.com/