WeUniversalClassLoaderPlugin is a project mainly written in PHP, based on the MIT license.
bringing the Sf2 UniversalClassLoader to symfony 1
This plugin brings the Symfony2 PSR-0 UniversalClassLoader to your symfony 1 project. The namespaces can be configured in namespaces.yml config files.
/plugins/weUniversalClassLoaderPlugin
using GIT, SVN or whatever you like/config/ProjectConfiguration.class.php
<?php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
...
$this->enablePlugins('weUniversalClassLoaderPlugin');
...
}
}
Let's assume you gut a plugin called /plugins/mySuperAwesomePlugin and want to use this namespaced PHP file:
<?php
namespace Acme\AwesomeClasses;
class SuperAwesome
{
}
/plugins/mySuperAwesomePlugin/config/namespaces.yml
all:
register:
namespaces:
# all src paths are relative to sf_root_dir
'Acme\AwesomeClasses': '/plugins/mySuperAwesomePlugin/src'
/plugins/mySuperAwesomePlugin/src/Acme/AwesomeClasses/SuperAwesome.php
That's it! The file won't be detected by the symfony 1 autoloader since it's outside the plugin's lib/ folder. If you now access \Acme\AwesomeClasses\SuperAwesome
it will be loaded automatically.
Because the namespaces config handler is initiated after context.load_factories
has fired, you cannot use your namespaced classes beforehand. To be precise, you should wait for the we.namespaces_classloader_available
event.
Last but not least there are 2 events which will be fired by this plugin:
config.namespaces_configuration_loaded
as soon as the namespaces.yml config files have been loadedwe.namespaces_classloader_available
as soon as the ClassLoader is available