[FLOW3-general] Package handling / autoloading

Adrian Föder adrian at foeder.de
Mon Jun 4 17:09:10 CEST 2012


...so for the autoloading of external libraries, I currently came up 
with the following; assuming this folder structure:

   * [Acme.Northwind]
     * [Classes]
       * Package.php
     * [Resources]
       * [Php]
         * [Libraries]
           * [FancyThing]
             * [src]
               * [FancyThing]
                 * FirstClass.php
                 * SecondClass.php
             * [test]
             * readme.md
             * .gitignore
             * license.txt

a few word about this:
"Php", I chose the freedom to rename it to Php like in Mvc, Aop etc.
"Libraries", this level maybe could be omitted

so, "FancyThing" already is a concrete git submodule pointing to any 
PSR-0-compatible project. In this case, the classes begin in the "src" 
folder and the class's namespace base again is "FancyThing".

This leads to the following implementation:

Package.php (see https://gist.github.com/2868929):
---------------
	public function boot(\TYPO3\FLOW3\Core\Bootstrap $bootstrap) {
		spl_autoload_register(function($className){
			if (substr($className, 0, strlen('FancyThing_')) === 'FanyThing_') {
				$classesSubPath = str_replace('_', '/', $className);
				$classesFullPath = 
\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->getResourcesPath(), 
'Php/Libraries/FancyThing/src/', $classesSubPath));

					// note: require_once is not used intentionally to discover 
accidental multiple use of
					// different instances of Elastica through the system
				require $classesFullPath . '.php';
			}
		});
	}


This *works*, although it works around the proxy and everything. The 
question is, if we not even might want to have this, because these third 
party libraries might be/stay unproxied and "unmagic'd" however.

Please, again, tell me your thoughts.


More information about the FLOW3-general mailing list