Permalink
Browse files

Added example for injection after instantiation only.

  • Loading branch information...
1 parent 7f70660 commit ff4bcebe16b2d979412291ec655543b583fb6a9f Ralph Schindler committed Apr 18, 2012
Showing with 40 additions and 0 deletions.
  1. +40 −0 example-21.php
View
@@ -0,0 +1,40 @@
+<?php
+
+namespace MovieApp {
+
+ class Lister implements FinderAwareInterface {
+ public $finder;
+ public function setFinder(Finder $finder){
+ $this->finder = $finder;
+ }
+ }
+
+ class Finder {
+ public function findAllByName($name) {}
+ }
+
+ interface FinderAwareInterface {
+ public function setFinder(Finder $finder);
+ }
+}
+
+namespace {
+ // bootstrap
+ include 'zf2bootstrap' . ((stream_resolve_include_path('zf2bootstrap.php')) ? '.php' : '.dist.php');
+
+ $di = new Zend\Di\Di;
+ $lister = new MovieApp\Lister;
+
+var_dump($lister);
+
+ $di->injectDependencies($lister);
+
+var_dump($lister);
+
+ // expression to test
+ $works = ($lister->finder instanceof MovieApp\Finder);
+
+ // display result
+ echo (($works) ? 'It works!' : 'It DOES NOT work!') . PHP_EOL;
+
+}

0 comments on commit ff4bceb

Please sign in to comment.