-- coreyward <[email protected]> wrote
(on Monday, 04 May 2009, 07:22 PM -0700):
> I'm just getting my feet wet with ZF, so excuse the ignorance here....
>
> The Zend Reference guide for the Zend_Loader_Autoloader_Resource adds a
> resource without specifying the namespace parameter, ie:
>
> $resourceLoader->addResourceType('model', 'models/',);
>
> According to the docs, that's fine, as the namespace parameter is optional.
> According to the source code, though, and a bare-bones app that is throwing
> an exception over it, the namespace can't be left off unless that resource
> type has already been added to the Autoloader_Resource:
I evidently need to update the docs.
Components in a resource *must* have a component namespace -- it's
intended to ensure class matching can occur cleanly. The $namespace
parameter is optional, as you say, only when the resource has already
been added to the loader -- and in such a case, it will use the
previously registered namespace.
> public function addResourceType($type, $path, $namespace = null)
> {
> $type = strtolower($type);
> if (!isset($this->_resourceTypes[$type])) {
> if (null === $namespace) {
> require_once 'Zend/Loader/Exception.php';
> throw new Zend_Loader_Exception('Initial definition of a
> resource type must include a namespace');
> }
> $namespaceTopLevel = $this->getNamespace();
> $namespace = ucfirst(trim($namespace, '_'));
> $this->_resourceTypes[$type] = array(
> 'namespace' => empty($namespaceTopLevel) ? $namespace :
> $namespaceTopLevel . '_' . $namespace,
> );
> }
> // [...]
> }
>
> What's going on here? I'm guessing it has something to do with the module
> autoloader that automatically interprets the 'model' resource type, but I
> don't know what it would be.
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/