Agh ...sorry wrong list!

Too distracted by the Australia v's Italy game that is about to start!

Sorry everyone,

Nick

Does it niggle anyone else that there is an inconsistency with naming Zend_View helper classes?

When subclassing controllers there is the following recommendation in the manual...

-----------------
2.3.2.1. Prefix
Classes included with the Zend Framework follow a convention where every class is prefixed by "Zend_". This is the prefix. We recommend that you name all of your classes in the same way, e.g. if your company name is Widget, Inc., the prefix might be "Widget_".

-----------------

...while the View Helper section says...

-----------------
15.4.3. Writing Custom Helpers
Writing custom helpers is easy; just follow these rules:

The class name must be Zend_View_Helper_*, where * is the helper name itself. E.g., if you were writing a helper called "specialPurpose", the class name would be "Zend_View_Helper_SpecialPurpose" (note the capitalization).
------------------

I could therefore have the following...

library/
    Zend/
        View/
            Helper/
    MyProject/
        View/
            Helper/
               MyHelper.php
        Controller/
            Router.php

...and the Class names would be:

MyProject_Controller_Router

Zend_View_Helper_MyHelper

Personally I'd like a general convention whereby any project/domain specific subclass, replacement for Zend files, helper class, filter class use the prefix_ convention. I can foresee this being more crucial in larger projects or simply ones that use a combination of directories like:

library/
    Zend/
        View/
            Helper/
    MyCMS/
        View/
            Helper/
               MyHelper.php
    MyProject/
        View/
            Helper/
               MyHelper.php

For teamwork it would surely be simpler to be able to say to all files developed for MyProject be prefixed MyProject_ and kept in the MyProject directory?

Some very hacky play around code suggests this is at least possible:

private function _loadClass($type, $name)
{
        $file = ucfirst($name) . '.php';
        foreach ($this->_path[$type] as $dir) {
$class = rtrim($dir, '\\/' . DIRECTORY_SEPARATOR) . '_' . ucfirst ($name);

                if (class_exists($class, false)) {
                return $class;
                }

                $path = str_replace('_', DIRECTORY_SEPARATOR, $dir );
                // PATCH: to allow include_path files
                if (include $path . DIRECTORY_SEPARATOR . $file) {              
                        if (! class_exists($class, false)) {
                                $msg = "$type '$name' loaded but class '$class' not 
found within";
                                throw new Zend_View_Exception($msg);
                        }
                
                        return $class;
                }
        }

        throw new Zend_View_Exception("$type '$name' not found in path.");
}

called by $view->addHelperPath('UW_View_Helper');

We all know the teasing PHP gets for it's lack of consistent naming conventions and namespaces so what are everyone's thoughts on the above?

Nick








Reply via email to