diff --git a/config.dist.php b/config.dist.php index 1f9bee4..a6c5779 100644 --- a/config.dist.php +++ b/config.dist.php @@ -1,5 +1,4 @@ getInstanceManager()->setProperty('My\A', 'username', 'foo'); - $di->getInstanceManager()->setProperty('My\A', 'password', 'bar'); + $di = new Zend\Di\Di(); + $di->instanceManager()->setParameters('My\A', array('username' => 'foo', 'password' => 'bar')); + $di->instanceManager()->setParameters('My\A', array('password' => 'bar')); $c = $di->get('My\C'); echo $c; $d = $di->get('My\C'); diff --git a/examples/di/02/_main_.php b/examples/di/02/_main_.php index 99bb9b9..a90409a 100644 --- a/examples/di/02/_main_.php +++ b/examples/di/02/_main_.php @@ -5,21 +5,23 @@ function _main_() { if (!file_exists(__DIR__ . '/di-definition.php')) { echo 'COMPILING DEFINITION (run again to delete di-definition.php)' . PHP_EOL; - $compiler = new Zend\Di\Definition\Compiler(); - $compiler->addCodeScannerDirectory(new Zend\Code\Scanner\DirectoryScanner(__DIR__ . '/My/')); - $definition = $compiler->compile(); - file_put_contents(__DIR__ . '/di-definition.php', 'toArray(), true) . ';'); + $compiler = new Zend\Di\Definition\CompilerDefinition(); + $compiler->addDirectory(__DIR__ . '/My/'); + $compiler->compile(); + $definition = $compiler->toArrayDefinition()->toArray(); + file_put_contents(__DIR__ . '/di-definition.php', 'setDefinition($definition); - $di->getInstanceManager()->setProperty('My\DbAdapter', 'username', 'foo'); - $di->getInstanceManager()->setProperty('My\DbAdapter', 'password', 'bar'); - $c = $di->get('My\RepositoryA'); - echo $c . PHP_EOL; + $arrayDefinition = new Zend\Di\Definition\ArrayDefinition($definition); + $definitionList = new Zend\Di\DefinitionList($arrayDefinition); + $di = new Zend\Di\Di($definitionList); + $di->instanceManager()->setParameters('My\DbAdapter', array('username' => 'foo')); + $di->instanceManager()->setParameters('My\DbAdapter', array('password' => 'bar')); + $a = $di->get('My\RepositoryA'); + echo $a . PHP_EOL; } diff --git a/examples/di/03/My/.DS_Store b/examples/di/03/My/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/examples/di/03/My/.DS_Store differ diff --git a/examples/di/03/_main_.php b/examples/di/03/_main_.php index e1cebd4..07402d0 100644 --- a/examples/di/03/_main_.php +++ b/examples/di/03/_main_.php @@ -5,34 +5,30 @@ function _main_() { if (!class_exists('My\DiDefinition', true)) { echo 'COMPILING DEFINITION (and writing to disk at My\DiDefinition.php)' . PHP_EOL; - $compiler = new Zend\Di\Definition\Compiler(); - $compiler->addCodeScannerDirectory(new Zend\Code\Scanner\DirectoryScanner(__DIR__ . '/My/')); - $definition = $compiler->compile(); - $codeGenerator = new Zend\CodeGenerator\Php\PhpFile(); - $codeGenerator->setClass(($class = new Zend\CodeGenerator\Php\PhpClass())); + $compiler = new Zend\Di\Definition\CompilerDefinition(); + $compiler->addDirectory(__DIR__ . '/My/'); + $compiler->compile(); + $codeGenerator = new Zend\Code\Generator\FileGenerator(); + $codeGenerator->setClass(($class = new Zend\Code\Generator\ClassGenerator())); + $method = new Zend\Code\Generator\MethodGenerator('__construct'); + $method->setBody('parent::__construct(' . var_export($compiler->toArrayDefinition()->toArray(), true) . ');'); $class->setNamespaceName('My'); $class->setName('DiDefinition'); $class->setExtendedClass('\Zend\Di\Definition\ArrayDefinition'); - $class->setMethod(array( - 'name' => '__construct', - 'body' => 'parent::__construct(' . var_export($definition->toArray(), true) . ');' - )); + $class->setMethod($method); file_put_contents(__DIR__ . '/My/DiDefinition.php', $codeGenerator->generate()); - unset($compiler, $definition, $codeGenerator, $class); } else { echo 'USING DEFINITION' . PHP_EOL; } $definition = new My\DiDefinition(); - - - $di = new Zend\Di\DependencyInjector; - $di->setDefinition($definition); - $di->getInstanceManager()->setProperty('My\DbAdapter', 'username', 'foo'); - $di->getInstanceManager()->setProperty('My\DbAdapter', 'password', 'bar'); - $c = $di->get('My\RepositoryA'); - echo $c . PHP_EOL; + $definitionList = new Zend\Di\DefinitionList(array($definition)); + $di = new Zend\Di\Di($definitionList); + $di->instanceManager()->setParameters('My\DbAdapter', array('username' => 'foo')); + $di->instanceManager()->setParameters('My\DbAdapter', array('password' => 'bar')); + $a = $di->get('My\RepositoryA'); + echo $a . PHP_EOL; } diff --git a/examples/di/04/_main_.php b/examples/di/04/_main_.php index f23f62a..7886d7d 100644 --- a/examples/di/04/_main_.php +++ b/examples/di/04/_main_.php @@ -4,16 +4,18 @@ function _main_() { simple_autoloader_register('My', __DIR__); - $compiler = new Zend\Di\Definition\Compiler(); - $compiler->addCodeScannerDirectory(new Zend\Code\Scanner\DirectoryScanner(__DIR__ . '/My/')); - $definition = $compiler->compile(); - - $di = new Zend\Di\DependencyInjector(); - $di->setDefinition($definition); + $compiler = new Zend\Di\Definition\CompilerDefinition(); + $compiler->addDirectory(__DIR__ . '/My/'); + $compiler->compile(); + $definition = $compiler->toArrayDefinition()->toArray(); + + $arrayDefinition = new Zend\Di\Definition\ArrayDefinition($definition); + $definitionList = new Zend\Di\DefinitionList($arrayDefinition); + $di = new Zend\Di\Di($definitionList); $dbAdapter = new My\DbAdapter('foo', 'bar'); //$di->getInstanceManager()->setProperty('My\Mapper', 'dbAdapter', $dbAdapter); - $c = $di->get('My\RepositoryA', array('dbAdapter' => $dbAdapter)); - echo $c . PHP_EOL; + $a = $di->get('My\RepositoryA', array('dbAdapter' => $dbAdapter)); + echo $a . PHP_EOL; echo 'Hash for dbAdapter injected: ' . spl_object_hash($dbAdapter) . PHP_EOL; } diff --git a/examples/di/05/_main_.php b/examples/di/05/_main_.php index acc8344..8c1ae1d 100644 --- a/examples/di/05/_main_.php +++ b/examples/di/05/_main_.php @@ -3,17 +3,17 @@ function _main_() { simple_autoloader_register('My', __DIR__); - $di = new Zend\Di\DependencyInjector(); - $im = $di->getInstanceManager(); + $di = new Zend\Di\Di(); + $im = $di->instanceManager(); $im->addAlias('my-repository', 'My\RepositoryA'); $im->addAlias('my-mapper', 'My\Mapper'); $im->addAlias('my-dbAdapter', 'My\DbAdapter'); - $im->setProperties('My\DbAdapter', array('username' => 'readonlyuser', 'password' => 'bar')); + $im->setParameters('My\DbAdapter', array('username' => 'readonlyuser', 'password' => 'bar')); - $im->addPreferredInstance('my-repository', 'my-mapper'); - $im->addPreferredInstance('my-mapper', 'my-dbAdapter'); + $im->addTypePreference('my-repository', 'my-mapper'); + $im->addTypePreference('my-mapper', 'my-dbAdapter'); // another alias $im->addAlias('my-rwDbAdapter', 'My\DbAdapter', array('username' => 'readwriteuser')); diff --git a/examples/di/06/_main_.php b/examples/di/06/_main_.php index 22076db..a440462 100644 --- a/examples/di/06/_main_.php +++ b/examples/di/06/_main_.php @@ -5,11 +5,8 @@ function _main_() { $configValues = new Zend\Config\Ini(__DIR__ . '/di-config.ini', 'production'); $diConfig = new Zend\Di\Configuration($configValues->di); - - - $di = new Zend\Di\DependencyInjector($diConfig); - - $im = $di->getInstanceManager(); + $di = new Zend\Di\Di(null, null, $diConfig); + $im = $di->instanceManager(); $c = $di->get('my-repository', array('dbAdapter' => 'my-dbAdapter')); @@ -25,7 +22,6 @@ function _main_() { echo $f . PHP_EOL . PHP_EOL; - echo 'Is it the same object (c && d): '; var_dump(($c === $d)); echo PHP_EOL; diff --git a/examples/di/06/di-config.ini b/examples/di/06/di-config.ini index be55d18..0cda7fe 100644 --- a/examples/di/06/di-config.ini +++ b/examples/di/06/di-config.ini @@ -8,18 +8,7 @@ di.instance.alias.my-dbAdapter = 'My\DbAdapter' di.instance.preferences.my-repository[] = 'my-mapper' di.instance.preferences.my-mapper[] = 'my-dbAdapter' -di.instance.properties.My\DbAdapter.username = 'readonly' -di.instance.properties.My\DbAdapter.password = 'mypassword' - -di.instance.properties.my-dbAdapter.username = 'readwrite'; - - - - - - - - - - +di.instance.My\DbAdapter.parameters.username = 'readonly' +di.instance.My\DbAdapter.parameters.password = 'mypassword' +di.instance.parameters.my-dbAdapter.username = 'readwrite'; \ No newline at end of file diff --git a/examples/event-manager/01/.DS_Store b/examples/event-manager/01/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/examples/event-manager/01/.DS_Store differ diff --git a/examples/event-manager/01/Dispatcher.php b/examples/event-manager/01/Example/Dispatcher.php similarity index 100% rename from examples/event-manager/01/Dispatcher.php rename to examples/event-manager/01/Example/Dispatcher.php diff --git a/examples/event-manager/01/MyPlugin.php b/examples/event-manager/01/Example/MyPlugin.php similarity index 100% rename from examples/event-manager/01/MyPlugin.php rename to examples/event-manager/01/Example/MyPlugin.php diff --git a/examples/event-manager/01/PluginHandler.php b/examples/event-manager/01/Example/PluginHandler.php similarity index 71% rename from examples/event-manager/01/PluginHandler.php rename to examples/event-manager/01/Example/PluginHandler.php index 279e5e1..db3c2a1 100644 --- a/examples/event-manager/01/PluginHandler.php +++ b/examples/event-manager/01/Example/PluginHandler.php @@ -17,13 +17,13 @@ public function __construct() public function register($plugin) { if (method_exists($plugin, 'onInit')) { - $this->eventManager->attach('init', $plugin, 'onInit'); + $this->eventManager->attach('init', array($plugin, 'onInit')); } if (method_exists($plugin, 'onPreDispatch')) { - $this->eventManager->attach('preDispatch', $plugin, 'onPreDispatch'); + $this->eventManager->attach('preDispatch', array($plugin, 'onPreDispatch')); } if (method_exists($plugin, 'onPostDispatch')) { - $this->eventManager->attach('postDispatch', $plugin, 'onPostDispatch'); + $this->eventManager->attach('postDispatch', array($plugin, 'onPostDispatch')); } } diff --git a/examples/event-manager/01/_main_.php b/examples/event-manager/01/_main_.php index d2106b6..4d93ffc 100644 --- a/examples/event-manager/01/_main_.php +++ b/examples/event-manager/01/_main_.php @@ -1,15 +1,11 @@ registerNamespace('Example', __DIR__); + simple_autoloader_register('Example', __DIR__); $ph = new Example\PluginHandler(); $ph->register(new Example\MyPlugin()); $sd = new Example\Dispatcher($ph); $sd->dispatch(); - -} - - +} \ No newline at end of file diff --git a/examples/event-manager/02/.DS_Store b/examples/event-manager/02/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/examples/event-manager/02/.DS_Store differ diff --git a/examples/event-manager/02/Dispatcher.php b/examples/event-manager/02/Example/Dispatcher.php similarity index 100% rename from examples/event-manager/02/Dispatcher.php rename to examples/event-manager/02/Example/Dispatcher.php diff --git a/examples/event-manager/02/MyPlugin.php b/examples/event-manager/02/Example/MyPlugin.php similarity index 100% rename from examples/event-manager/02/MyPlugin.php rename to examples/event-manager/02/Example/MyPlugin.php diff --git a/examples/event-manager/02/PluginHandler.php b/examples/event-manager/02/Example/PluginHandler.php similarity index 73% rename from examples/event-manager/02/PluginHandler.php rename to examples/event-manager/02/Example/PluginHandler.php index 89c18bc..52452d4 100644 --- a/examples/event-manager/02/PluginHandler.php +++ b/examples/event-manager/02/Example/PluginHandler.php @@ -17,13 +17,13 @@ public function __construct() public function register(PluginHandler\PluginHandlerInterface $plugin) { if ($plugin instanceof PluginHandler\OnInitInterface) { - $this->eventManager->attach('init', $plugin, 'onInit'); + $this->eventManager->attach('init', array($plugin, 'onInit')); } if ($plugin instanceof PluginHandler\OnPreDispatchInterface) { - $this->eventManager->attach('preDispatch', $plugin, 'onPreDispatch'); + $this->eventManager->attach('preDispatch', array($plugin, 'onPreDispatch')); } if ($plugin instanceof PluginHandler\OnPostDispatchInterface) { - $this->eventManager->attach('postDispatch', $plugin, 'onPostDispatch'); + $this->eventManager->attach('postDispatch', array($plugin, 'onPostDispatch')); } } diff --git a/examples/event-manager/02/PluginHandler/OnInitInterface.php b/examples/event-manager/02/Example/PluginHandler/OnInitInterface.php similarity index 100% rename from examples/event-manager/02/PluginHandler/OnInitInterface.php rename to examples/event-manager/02/Example/PluginHandler/OnInitInterface.php diff --git a/examples/event-manager/02/PluginHandler/OnPostDispatchInterface.php b/examples/event-manager/02/Example/PluginHandler/OnPostDispatchInterface.php similarity index 100% rename from examples/event-manager/02/PluginHandler/OnPostDispatchInterface.php rename to examples/event-manager/02/Example/PluginHandler/OnPostDispatchInterface.php diff --git a/examples/event-manager/02/PluginHandler/OnPreDispatchInterface.php b/examples/event-manager/02/Example/PluginHandler/OnPreDispatchInterface.php similarity index 100% rename from examples/event-manager/02/PluginHandler/OnPreDispatchInterface.php rename to examples/event-manager/02/Example/PluginHandler/OnPreDispatchInterface.php diff --git a/examples/event-manager/02/PluginHandler/PluginHandlerInterface.php b/examples/event-manager/02/Example/PluginHandler/PluginHandlerInterface.php similarity index 100% rename from examples/event-manager/02/PluginHandler/PluginHandlerInterface.php rename to examples/event-manager/02/Example/PluginHandler/PluginHandlerInterface.php diff --git a/examples/event-manager/02/_main_.php b/examples/event-manager/02/_main_.php index 26e9b8a..70c3dde 100644 --- a/examples/event-manager/02/_main_.php +++ b/examples/event-manager/02/_main_.php @@ -1,15 +1,11 @@ register(new MyPlugin()); + simple_autoloader_register('Example', __DIR__); + + $ph = new Example\PluginHandler(); + $ph->register(new Example\MyPlugin()); - $sd = new Dispatcher($ph); + $sd = new Example\Dispatcher($ph); $sd->dispatch(); - -} - -_main_(); \ No newline at end of file +} \ No newline at end of file