├── .gitignore
├── .travis.yml
├── README.md
├── app
├── code
│ └── community
│ │ └── Hackathon
│ │ └── PSR0Autoloader
│ │ ├── Model
│ │ ├── Observer.php
│ │ └── SplAutoloader.php
│ │ └── etc
│ │ └── config.xml
└── etc
│ └── modules
│ └── Hackathon_PSR0Autoloader.xml
├── composer.json
├── modman
├── phpunit.xml.dist
├── shell
└── autoloader_initializer.php
└── tests
├── Basic
└── CaseTest.php
└── bootstrap.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | vendor/
3 | test-root/
4 |
5 | composer.lock
6 |
7 | mage-ci.local.json
8 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 | php:
3 | - 5.3
4 | - 5.5
5 | env:
6 | - MAGENTO=1.8.1.0
7 | - MAGENTO=1.9.1.0
8 | before_install:
9 | - mkdir test-root/
10 | install:
11 | - composer install --dev
12 | before_script:
13 | - CURR_DIR=$(pwd)
14 | - vendor/bin/mage-ci install test-root $MAGENTO magento_test -c -t -r http://mage-ci.ecomdev.org
15 | script:
16 | - vendor/bin/phpunit
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Magento-PSR-0-Autoloader
2 | ========================
3 |
4 | This Extension adds a PSR-0 Autoloader before the Magento Autoloader
5 |
6 | To initialize a new namespace, insert following code in the ``-node of local.xml:
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ## Magento Composer Autoloader
16 |
17 | You can also use this Extension to add the composer Autoloader.
18 |
19 | You need to configure the Path to your Vendor directory in your ``-node of local.xml:
20 |
21 |
22 |
23 |
24 |
25 | ## disable the default magento autoloader
26 |
27 | To disable the default magento autoloader, insert following code in the ``-node of local.xml:
28 |
29 |
30 | 1
31 |
--------------------------------------------------------------------------------
/app/code/community/Hackathon/PSR0Autoloader/Model/Observer.php:
--------------------------------------------------------------------------------
1 | getNode(self::CONFIG_PATH_PSR0NAMESPACES);
14 | if ($node && is_array($node->asArray())){
15 | $namespaces = array_keys($node->asArray());
16 | }
17 | return $namespaces;
18 | }
19 |
20 | /**
21 | * return false, if no composer Vendor Path is set in local.xml
22 | */
23 | protected function getComposerVendorPath(){
24 | $node = Mage::getConfig()->getNode(self::CONFIG_PATH_COMPOSER_VENDOR_PATH);
25 | $path = str_replace( '{{root_dir}}', Mage::getBaseDir(), $node);
26 | return $path;
27 | }
28 |
29 | protected function shouldDisableBaseAutoloader() {
30 | $config = Mage::getConfig()->getNode(self::CONFIG_PATH_BASE_AUTOLOADER_DISABLE);
31 | if($config && $config != "0" && $config != "false"){
32 | return true;
33 | }else{
34 | return false;
35 | }
36 | }
37 |
38 | public function addAutoloader() {
39 | if(!self::$shouldAdd){
40 | return;
41 | }
42 | foreach ($this->getNamespacesToRegister() as $namespace){
43 | if (is_dir(Mage::getBaseDir('lib') . DS . $namespace)){
44 | $args = array($namespace, Mage::getBaseDir('lib') . DS . $namespace);
45 | $autoloader = Mage::getModel("psr0autoloader/splAutoloader", $args);
46 | $autoloader->register();
47 | }
48 | }
49 | if($composerVendorPath = $this->getComposerVendorPath()){
50 | require_once $composerVendorPath . '/autoload.php';
51 | }
52 | if ($this->shouldDisableBaseAutoloader()) {
53 | spl_autoload_unregister(array(Varien_Autoload::instance(), 'autoload'));
54 | }
55 | self::$shouldAdd = false;
56 | }
57 |
58 | }
--------------------------------------------------------------------------------
/app/code/community/Hackathon/PSR0Autoloader/Model/SplAutoloader.php:
--------------------------------------------------------------------------------
1 | .
18 | */
19 |
20 | /**
21 | * SplClassLoader implementation that implements the technical interoperability
22 | * standards for PHP 5.3 namespaces and class names.
23 | *
24 | * http://groups.google.com/group/php-standards/web/final-proposal
25 | *
26 | * // Example which loads classes for the Doctrine Common package in the
27 | * // Doctrine\Common namespace.
28 | * $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
29 | * $classLoader->register();
30 | *
31 | * @license http://www.opensource.org/licenses/mit-license.html MIT License
32 | * @author Jonathan H. Wage
33 | * @author Roman S. Borschel
34 | * @author Matthew Weier O'Phinney
35 | * @author Kris Wallsmith
36 | * @author Fabien Potencier
37 | */
38 | class Hackathon_PSR0Autoloader_Model_SplAutoloader extends Mage_Core_Model_Abstract
39 | {
40 |
41 | private $_fileExtension = '.php';
42 | private $_namespace;
43 | private $_includePath;
44 | private $_namespaceSeparator = '\\';
45 |
46 | /**
47 | * Creates a new SplClassLoader that loads classes of the
48 | * specified namespace.
49 | *
50 | * @param string $ns The namespace to use.
51 | */
52 | public function __construct($ns = null, $includePath = null)
53 | {
54 | $this->_namespace = $ns;
55 | $this->_includePath = $includePath;
56 | }
57 |
58 | /**
59 | * Sets the namespace separator used by classes in the namespace of this class loader.
60 | *
61 | * @param string $sep The separator to use.
62 | */
63 | public function setNamespaceSeparator($sep)
64 | {
65 | $this->_namespaceSeparator = $sep;
66 | }
67 |
68 | /**
69 | * Gets the namespace seperator used by classes in the namespace of this class loader.
70 | *
71 | * @return string
72 | */
73 | public function getNamespaceSeparator()
74 | {
75 | return $this->_namespaceSeparator;
76 | }
77 |
78 | /**
79 | * Sets the base include path for all class files in the namespace of this class loader.
80 | *
81 | * @param string $includePath
82 | */
83 | public function setIncludePath($includePath)
84 | {
85 | $this->_includePath = $includePath;
86 | }
87 |
88 | /**
89 | * Gets the base include path for all class files in the namespace of this class loader.
90 | *
91 | * @return string $includePath
92 | */
93 | public function getIncludePath()
94 | {
95 | return $this->_includePath;
96 | }
97 |
98 | /**
99 | * Sets the file extension of class files in the namespace of this class loader.
100 | *
101 | * @param string $fileExtension
102 | */
103 | public function setFileExtension($fileExtension)
104 | {
105 | $this->_fileExtension = $fileExtension;
106 | }
107 |
108 | /**
109 | * Gets the file extension of class files in the namespace of this class loader.
110 | *
111 | * @return string $fileExtension
112 | */
113 | public function getFileExtension()
114 | {
115 | return $this->_fileExtension;
116 | }
117 |
118 | /**
119 | * Installs this class loader on the SPL autoload stack.
120 | */
121 | public function register()
122 | {
123 | spl_autoload_register(array($this, 'loadClass'), true, true);
124 | }
125 |
126 | /**
127 | * Uninstalls this class loader from the SPL autoloader stack.
128 | */
129 | public function unregister()
130 | {
131 | spl_autoload_unregister(array($this, 'loadClass'));
132 | }
133 |
134 | /**
135 | * Loads the given class or interface.
136 | *
137 | * @param string $className The name of the class to load.
138 | * @return void
139 | */
140 | public function loadClass($className)
141 | {
142 | $className = ltrim($className, '\\');
143 | $fileName = '';
144 | if ($lastNsPos = strripos($className, '\\')) {
145 | $namespace = substr($className, 0, $lastNsPos);
146 | $className = substr($className, $lastNsPos + 1);
147 | $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
148 | }
149 | $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
150 | $fileName = stream_resolve_include_path($fileName);
151 | if (false !== $fileName) {
152 | include_once $fileName;
153 | }
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/app/code/community/Hackathon/PSR0Autoloader/etc/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 0.0.1
6 |
7 |
8 |
9 |
10 |
11 | Hackathon_PSR0Autoloader_Model
12 |
13 |
14 |
15 |
16 |
17 |
18 | Hackathon_PSR0Autoloader_Model_Observer
19 | addAutoloader
20 |
21 |
22 |
23 |
24 |
25 |
26 | Hackathon_PSR0Autoloader_Model_Observer
27 | addAutoloader
28 |
29 |
30 |
31 |
32 |
33 |
34 | Hackathon_PSR0Autoloader_Model_Observer
35 | addAutoloader
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/etc/modules/Hackathon_PSR0Autoloader.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | true
6 | community
7 |
8 |
9 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "firegento/psr0autoloader",
3 | "licenses": ["MIT", "GPL-3.0"],
4 | "type": "magento-module",
5 | "description": "This extension adds a PSR-0 autoloader before the Varien autoloader",
6 | "authors": [
7 | {
8 | "name":"Michael Ryvlin"
9 | },
10 | {
11 | "name":"Damian Luszczymak"
12 | }
13 | ],
14 | "require-dev": {
15 | "firegento/mage-ci": "master-dev",
16 | "phpunit/phpunit": "~4.4"
17 | },
18 | "repositories": [
19 | {
20 | "type": "composer",
21 | "url": "http://packages.firegento.com"
22 | }
23 | ],
24 | "extra": {
25 | "magento-root-dir": "test-root"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/modman:
--------------------------------------------------------------------------------
1 | app/code/community/Hackathon/PSR0Autoloader/ app/code/community/Hackathon/PSR0Autoloader/
2 | app/etc/modules/Hackathon_PSR0Autoloader.xml app/etc/modules/Hackathon_PSR0Autoloader.xml
3 | shell/autoloader_initializer.php shell/autoloader_initializer.php
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
14 |
15 |
16 | ./tests/Basic/
17 |
18 |
19 | ./tests/phpunit/web
20 |
21 |
22 |
23 |
24 |
25 | slow
26 |
27 |
28 |
29 |
30 |
31 | ./src/
32 | ./vendor/wizards-fugue/
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/shell/autoloader_initializer.php:
--------------------------------------------------------------------------------
1 | init()->loadEventObservers('global');
13 | Mage::app()->addEventArea('global');
14 | Mage::dispatchEvent('add_spl_autoloader');
15 | return $this;
16 | }
17 | }
--------------------------------------------------------------------------------
/tests/Basic/CaseTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(!!$model);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | cleanCache();
23 |
24 | //spl_autoload_unregister(array(Varien_Autoload::instance(),'autoload'));
25 |
26 |
--------------------------------------------------------------------------------