-
-
Save Ocramius/2996921 to your computer and use it in GitHub Desktop.
ZF2 Di definition compiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// in ZF2 project, place this in ./bin directory | |
chdir(dirname(__DIR__)); | |
$zf2Path = (getenv('ZF2_PATH') ?: 'vendor/ZendFramework/library'); | |
require_once $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; | |
require_once $zf2Path . '/Zend/Loader/StandardAutoloader.php'; | |
use Zend\Loader\AutoloaderFactory; | |
use Zend\Loader\StandardAutoloader; | |
AutoloaderFactory::factory(array('Zend\Loader\StandardAutoloader' => array( | |
StandardAutoloader::AUTOREGISTER_ZF => true, | |
StandardAutoloader::ACT_AS_FALLBACK => false, | |
))); | |
// list of components to be compiled | |
$components = array( | |
'Zend_Authentication', | |
'Zend_Cache', | |
'Zend_Config', | |
'Zend_EventManager', | |
'Zend_Http', | |
'Zend_Loader', | |
'Zend_Mvc', | |
'Zend_Stdlib', | |
'Zend_View', | |
); | |
foreach ($components as $component) { | |
$diCompiler = new Zend\Di\Definition\CompilerDefinition; | |
$diCompiler->addDirectory(__DIR__ . '/../vendor/ZendFramework/library/' . str_replace('_', '/', $component)); | |
$diCompiler->compile(); | |
file_put_contents( | |
__DIR__ . '/../data/di/' . $component . '-definition.php', | |
'<?php return ' . var_export($diCompiler->toArrayDefinition()->toArray(), true) . ';' | |
); | |
} | |
// list modules in order of dependency | |
$modules = array( | |
'Predis', | |
'ZfcBase', | |
'ZfcUser', | |
'Ign' => 'IgnCommon', | |
'Application', | |
'IgnVideo', | |
'IgnWidget', | |
'DocsWidgetsIgnCom', | |
'WwwIgnCom', | |
); | |
foreach ($modules as $namespace => $module) { | |
if (is_numeric($namespace)) { | |
$namespace = $module; | |
} | |
$moduleSrc = __DIR__ . '/../module/' . $module . '/src/' . $namespace; | |
if (!is_dir($moduleSrc)) { | |
$moduleSrc = __DIR__ . '/../site/' . $module . '/src/' . $namespace; | |
} | |
if (!is_dir($moduleSrc)) { | |
$moduleSrc = __DIR__ . '/../vendor/' . $module . '/src/' . $namespace; | |
} | |
if (!is_dir($moduleSrc)) { | |
$moduleSrc = __DIR__ . '/../vendor/' . $module . '/lib/' . $namespace; | |
} | |
\Zend\Loader\AutoloaderFactory::factory(array( | |
'Zend\Loader\StandardAutoloader' => array( | |
'namespaces' => array( | |
$namespace => $moduleSrc, | |
), | |
), | |
)); | |
$diCompiler = new Zend\Di\Definition\CompilerDefinition; | |
$diCompiler->getIntrospectionStrategy()->setUseAnnotations(true); | |
$diCompiler->addDirectory($moduleSrc); | |
$diCompiler->compile(); | |
file_put_contents( | |
__DIR__ . '/../data/di/' . $module . '-definition.php', | |
'<?php return ' . var_export($diCompiler->toArrayDefinition()->toArray(), true) . ';' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment