Zend Framework

Make Zend_Loader_PluginLoader to prefix agnostic (namespaces)

Details

  • Type: New Feature New Feature
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.8.4
  • Fix Version/s: 1.10.2
  • Component/s: Zend_Loader
  • Labels:
    None

Description

Zend_Loader_PluginLoader appends '_' to the prefixes added to it, preventing the use of namespaces classes as plugins.
Making it prefix-agnostic allows it to load namespaced classes, by specification of a "My\View\Helper\" prefix.

  1. zf-7350.patch
    22/Jul/09 6:34 AM
    0.5 kB
    Giorgio Sironi
  2. zf-7350-2.patch
    23/Feb/10 7:55 AM
    0.5 kB
    Giorgio Sironi
  3. zf-7350-3.patch
    23/Feb/10 11:21 AM
    2 kB
    Giorgio Sironi

Issue Links

Activity

Hide
Giorgio Sironi added a comment -

Quick and dirty fix to allow the use of namespaced view helpers.
This works only because since view helpers cannot be in subfolders and the basename is directly appended to the path. For other classes path calculation could be wrong.

Show
Giorgio Sironi added a comment - Quick and dirty fix to allow the use of namespaced view helpers. This works only because since view helpers cannot be in subfolders and the basename is directly appended to the path. For other classes path calculation could be wrong.
Hide
Steven Rosato added a comment -

The provided fix works well and does not seem to break the tests though that one must always append the
at the end of the namespace prefix for exemple in resource loading in an ini file:

pluginPaths["My\Application\Resource\\"] = "My/Application/Resource"

To optionnally provide the ending backslash strstr($prefix, '
') could be used but then again non subnamespaces would fail at that using

$pluginLoader->addPrefixPath('My', 'Path/To/My'); //My is a namespace

still the only quick solution remain but an end backslash must be provided.

$pluginLoader->addPrefixPath('My
', 'Path/To/My'); //My is a namespace

Don't know your thoughts on that maybe Giorgio's solution may prove the only one not breaking anything.

Show
Steven Rosato added a comment - The provided fix works well and does not seem to break the tests though that one must always append the
at the end of the namespace prefix for exemple in resource loading in an ini file: pluginPaths["My\Application\Resource\\"] = "My/Application/Resource" To optionnally provide the ending backslash strstr($prefix, '
') could be used but then again non subnamespaces would fail at that using $pluginLoader->addPrefixPath('My', 'Path/To/My'); //My is a namespace still the only quick solution remain but an end backslash must be provided. $pluginLoader->addPrefixPath('My
', 'Path/To/My'); //My is a namespace Don't know your thoughts on that maybe Giorgio's solution may prove the only one not breaking anything.
Hide
Steven Rosato added a comment -

Edit (correction): though that one must always append the "\ \"

[second code snippet]:

and $pluginLoader->addPrefixPath('My\ \', 'Path/To/My'); //My is a namespace

[with no space between the backslashes --my double backslashes were escaped]

Show
Steven Rosato added a comment - Edit (correction): though that one must always append the "\ \" [second code snippet]: and $pluginLoader->addPrefixPath('My\ \', 'Path/To/My'); //My is a namespace [with no space between the backslashes --my double backslashes were escaped]
Hide
Andy Thompson added a comment -

I also came across this issue as I'm starting to write my applications using proper namespaces. I tackled the issue using the same method. I can't see it having any problems considering
has never been used as a class name character, and looking at the end character seems the most logical way to do this.

Since Zend_Loader has been modified to support PHP 5.3 namespaces in 1.10, I was hoping this could be implemented as a minor release?

Show
Andy Thompson added a comment - I also came across this issue as I'm starting to write my applications using proper namespaces. I tackled the issue using the same method. I can't see it having any problems considering
has never been used as a class name character, and looking at the end character seems the most logical way to do this. Since Zend_Loader has been modified to support PHP 5.3 namespaces in 1.10, I was hoping this could be implemented as a minor release?
Hide
Steven Rosato added a comment -

I'm still watching and hoping for this as it is my only patch that I need to apply each time Zend upgrades. It does not break unit tests and I, too, think it should be implemented in a minor release.

Show
Steven Rosato added a comment - I'm still watching and hoping for this as it is my only patch that I need to apply each time Zend upgrades. It does not break unit tests and I, too, think it should be implemented in a minor release.
Hide
Giorgio Sironi added a comment -

Updated patch for Zend Framework 1.10.1; hope this will be integrated soon.

Show
Giorgio Sironi added a comment - Updated patch for Zend Framework 1.10.1; hope this will be integrated soon.
Hide
Matthew Weier O'Phinney added a comment -

Giorgio – any chance I can get a unit test from you as well?

Show
Matthew Weier O'Phinney added a comment - Giorgio – any chance I can get a unit test from you as well?
Hide
Giorgio Sironi added a comment - - edited

zf-7350-3: patch to use against /trunk with unit test added to PluginLoaderTest and necessary changes to Zend_Loader_PluginLoader. It incorporates the previous ones.

Show
Giorgio Sironi added a comment - - edited zf-7350-3: patch to use against /trunk with unit test added to PluginLoaderTest and necessary changes to Zend_Loader_PluginLoader. It incorporates the previous ones.
Hide
Matthew Weier O'Phinney added a comment -

Patch applied to trunk and 1.10 release branch. Modified slightly to add a conditional to skip the test when PHP version is < 5.3.0.

Show
Matthew Weier O'Phinney added a comment - Patch applied to trunk and 1.10 release branch. Modified slightly to add a conditional to skip the test when PHP version is < 5.3.0.

People

Vote (5)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: