/** * Process class method parameters * * @param array $def * @param Zend\Code\Reflection\ClassReflection $rClass * @param Zend\Code\Reflection\MethodReflection $rMethod */ protected function processParams(&$def, Reflection\ClassReflection $rClass, Reflection\MethodReflection $rMethod) { if (count($rMethod->getParameters()) === 0) { return; } parent::processParams($def, $rClass, $rMethod); $methodName = $rMethod->getName(); /** @var $p \ReflectionParameter */ foreach ($rMethod->getParameters() as $p) { $fqName = $rClass->getName() . '::' . $rMethod->getName() . ':' . $p->getPosition(); $def['parameters'][$methodName][$fqName][] = $p->isOptional() && $p->isDefaultValueAvailable() ? $p->getDefaultValue() : null; } }
<?php include 'zf2bootstrap.php'; // must register autoloader $autoloader->registerNamespace('Foo\\Bar', __DIR__ . '/12'); $compiler = new Zend\Di\Definition\CompilerDefinition(); $compiler->addDirectory(__DIR__ . '/12/'); $compiler->compile(); $definitions = new Zend\Di\DefinitionList($compiler); $di = new Zend\Di\Di($definitions); $baz = $di->get('Foo\\Bar\\Baz'); // expression to test $works = $baz->bam instanceof Foo\Bar\Bam; // display result echo $works ? 'It works!' : 'It DOES NOT work!';
<?php // bootstrap include 'zf2bootstrap' . (stream_resolve_include_path('zf2bootstrap.php') ? '.php' : '.dist.php'); // must register autoloader spl_autoload_register(function ($class) { if (strpos($class, 'Foo\\Bar') !== 0) { return; } include_once __DIR__ . '/11/' . str_replace('\\', '/', substr($class, 7)) . '.php'; }); // compile phase $compiler = new Zend\Di\Definition\CompilerDefinition(); $compiler->addDirectory(__DIR__ . '/11/'); $compiler->compile(); $arrayDef = $compiler->toArrayDefinition(); $definitions = new Zend\Di\DefinitionList($arrayDef); $di = new Zend\Di\Di($definitions); $baz = $di->get('Foo\\Bar\\Baz'); // expression to test $works = $baz->bam instanceof Foo\Bar\Bam; // display result echo ($works ? 'It works!' : 'It DOES NOT work!') . PHP_EOL;
<?php require_once 'library/Zend/Loader/StandardAutoloader.php'; $loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true)); $loader->registerNamespace('SON', 'library/SON'); $loader->register(); $components = array('SON'); foreach ($components as $component) { $diCompiler = new Zend\Di\Definition\CompilerDefinition(); $diCompiler->addDirectory('library/' . $component); $diCompiler->compile(); file_put_contents('data/di/' . $component . '-definition.php', '<?php return ' . var_export($diCompiler->toArrayDefinition()->toArray(), true) . ';'); }
<?php // bootstrap include 'zf2bootstrap' . (stream_resolve_include_path('zf2bootstrap.php') ? '.php' : '.dist.php'); // must register autoloader spl_autoload_register(function ($class) { if (strpos($class, 'Foo\\Bar') !== 0) { return; } include_once __DIR__ . '/12/' . str_replace('\\', '/', substr($class, 7)) . '.php'; }); // compile phase $compiler = new Zend\Di\Definition\CompilerDefinition(); $compiler->getIntrospectionStrategy()->setUseAnnotations(true); // TURN ANNOTATIONS ON $compiler->addDirectory(__DIR__ . '/12/'); $compiler->compile(); $arrayDef = $compiler->toArrayDefinition(); $definitions = new Zend\Di\DefinitionList($arrayDef); $di = new Zend\Di\Di($definitions); $baz = $di->get('Foo\\Bar\\Baz'); // expression to test $works = $baz->bam instanceof Foo\Bar\Bam; // display result echo $works ? 'It works!' : 'It DOES NOT work!';
/** * @param string $class */ protected function processClass($class) { $this->_classGenerator->generateForConstructor($class); parent::processClass($class); }