2009年2月28日星期六

Re: [fw-mvc] Proper use of Zend_Loader_Autoloader_Resource

-- keith Pope <mute.pop3@googlemail.com> wrote
(on Saturday, 28 February 2009, 03:08 PM +0000):
> Ah this is why it didnt work for me :)
>
> Should the methods be private or public in the bootstrap file?

The various initializer resources need only be prefixed with '_' -- they
*should* be protected or private, to ensure that they may only be called
via bootstrap() or __call(). The rationale behind this is twofold:

* Consistency of interface. While you can define _init*() methods in
your class, we're also allowing use of resource plugins (you can see
some of these in the Zend/Application/Resource/ tree). To have a
consistent interface for both resource plugins and internal
initializers, we have defined the bootstrap() and __call() methods.

* Dependency tracking. One of the "rules" for Zend_Application is that
any given resource/initializer may be run only once. However,
certain resources/initializers may depend on others. The bootstrap()
method keeps track of which ones have been run, and returns early
when a requested resource/initializer has been run previously.


> 2009/2/28 Matthew Weier O'Phinney <matthew@zend.com>:
> > -- Cristian Bichis <contact@zftutorials.com> wrote
> > (on Saturday, 28 February 2009, 11:49 AM +0200):
> >> Ok, i put up a sample based on http://framework.zend.com/wiki/display/ZFPROP/
> >> Zend_Application+-+Ben+Scholzen
> >>
> >> I don't get the error i encountered before, but i get a new one.
> >>
> >> //index.php
> >> <?php
> >>     if( !defined('APPLICATION_ENVIRONMENT'))
> >>         define('APPLICATION_ENVIRONMENT', 'production');
> >>
> >>     define('PUBLIC_PATH', realpath(dirname(__FILE__)));
> >>     define('BASE_PATH', realpath(dirname(dirname(__FILE__))));
> >>     define('APPLICATION_PATH', BASE_PATH . '/application');
> >>     define('MODULE_PATH', APPLICATION_PATH . '/modules');
> >>
> >>     set_include_path(
> >>         BASE_PATH . '/library/dasprid' . PATH_SEPARATOR
> >>         .BASE_PATH . '/library/incubator' . PATH_SEPARATOR
> >>         .BASE_PATH . '/library' . PATH_SEPARATOR
> >>         . get_include_path()
> >>     );
> >>
> >>     require 'Zend/Application.php';
> >>
> >>     $application = new Zend_Application(APPLICATION_ENVIRONMENT, array(
> >>         'autoloaderNamespaces' => array(
> >>             'Imagis',
> >>         ),
> >>         'bootstrap' => APPLICATION_PATH . '/Bootstrap.php'
> >>     ));
> >>
> >>     $application->bootstrap();
> >>
> >>     Zend_Controller_Front::getInstance()->dispatch();
> >> ?>
> >>
> >> //Bootstrap.php based on http://framework.zend.com/wiki/display/ZFPROP/
> >> Zend_Application+-+Ben+Scholzen
> >> <?php
> >>
> >> require_once 'Zend/Application/Bootstrap/Base.php';
> >>
> >> class Bootstrap extends Zend_Application_Bootstrap_Base
> >> {
> >>     public $front;
> >>
> >>     public function init()
> >>     {
> >>         $this->front = Zend_Controller_Front::getInstance();
> >>     }
> >>
> >>     public function run()
> >>     {
> >>         $this->front->dispatch();
> >>     }
> >>
> >>     protected function _initControllers()
> >>     {
> >>         //$this->front->setControllerDirectory(APPLICATION_PATH . '/
> >> controllers', 'default');
> >>         $this->front->addModuleDirectory(MODULE_PATH . '/modules');
> >>         return $this;
> >>     }
> >>
> >>     protected function _initRequest()
> >>     {
> >>         $this->request = new Zend_Controller_Request_Http;
> >>         $this->front->setRequest($this->request);
> >>         return $this;
> >>     }
> >> }
> >>
> >>
> >> And the error is: Fatal error: Call to a member function addModuleDirectory()
> >> on a non-object in D:\_Work\site\application\Bootstrap.php on line 22
> >>
> >>
> >> Might be something i configured incorrectly.
> >
> > No -- but it does reflect that the proposal needs to be updated. :)
> > There is a better example in the example.php file inside DASPRiD's user
> > branch.
> >
> > Basically, your index.php looks good -- it's your Bootstrap class that
> > isn't working correctly here, and it's due to some conventions that have
> > changed as part of the proposal evaluation.
> >
> > First off, there is no init() method. This is offset by the fact that,
> > instead, you can now do dependency checking in your initializers. As
> > an example, try the following Bootstrap:
> >
> >    class Bootstrap extends Zend_Application_Bootstrap_Base
> >    {
> >        public function _initFrontController()
> >        {
> >            $this->front = Zend_Controller_Front::getInstance();
> >        }
> >
> >
> >        protected function _initControllers()
> >        {
> >            // runs _initFrontController() if not already run:
> >            $this->bootstrapFrontController();
> >
> >            $this->front->addModuleDirectory(MODULE_PATH . '/modules');
> >        }
> >
> >        protected 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();
> >        }
> >     }
> >
> > Note the calls to "bootstrapFrontController()" -- those proxy to
> > _initFrontController() -- but will only call that method if not
> > previously run. An equivalent is to call bootstrap('FrontController').
> >
> > Basically, this allows you to ensure certain resources are present prior
> > to executing a particular initializer -- such as, in your case, the
> > front controller.
> >
> >> Cristian
> >>
> >>
> >>
> >> Matthew Weier O'Phinney wrote:
> >>
> >>     -- Cristian Bichis <contact@zftutorials.com> wrote
> >>     (on Friday, 27 February 2009, 11:11 PM +0200):
> >>
> >>
> >>         Matthew Weier O'Phinney wrote:
> >>
> >>             However, I've just gone through and cleaned up all the resources to
> >>             ensure that the require_once calls are removed and that they are
> >>             appropriately declaring their dependencies, so next time you try, you
> >>             should not have these issues.
> >>
> >>
> >>
> >>             Hmmm... based on your error, I think you had an outdated checkout.
> >>
> >>         Actually require_once was from my code not Zend code.
> >>
> >>         The required classes are not developed yet as far as i know. I just checked on
> >>         SVN and no, there are not in yet. Also the #zftalk log is confirming what i
> >>         said...
> >>
> >>
> >>     Unfortunately, I'm not logged in to IRC at this time. I'm modifying the
> >>     QuickStart to use Zend_Application right now, and having no issues. Can
> >>     you, or someone else, give an example of how you're using
> >>     Zend_Application, and what errors you're running into?
> >>
> >>
> >>
> >>
> >>
> >> --
> >> Best regards,
> >> Cristian Bichis
> >> www.zftutorials.com | www.zfforums.com | www.zftalk.com | www.zflinks.com
> >>
> >
> > --
> > Matthew Weier O'Phinney
> > Software Architect       | matthew@zend.com
> > Zend Framework           | http://framework.zend.com/
> >
> >
>
>
>
> --
> ----------------------------------------------------------------------
> [MuTe]
> ----------------------------------------------------------------------
>

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: