-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example of preference to Zend\Di Examples
- Loading branch information
Ralph Schindler
committed
Mar 19, 2012
1 parent
2f43a88
commit 7f70660
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace MovieApp { | ||
class Lister { | ||
public $finder; | ||
public function setFinder(FinderInterface $finder){ | ||
$this->finder = $finder; | ||
} | ||
} | ||
|
||
class DbFinder implements FinderInterface{ | ||
} | ||
|
||
interface FinderInterface { | ||
} | ||
} | ||
|
||
namespace { | ||
// bootstrap | ||
include 'zf2bootstrap' . ((stream_resolve_include_path('zf2bootstrap.php')) ? '.php' : '.dist.php'); | ||
|
||
$di = new Zend\Di\Di; | ||
$di->configure(new Zend\Di\Configuration(array( | ||
'instance' => array( | ||
'preferences' => array( | ||
'MovieApp\FinderInterface' => 'MovieApp\DbFinder' | ||
) | ||
) | ||
))); | ||
$lister = $di->get('MovieApp\Lister'); | ||
|
||
// expression to test | ||
$works = ($lister->finder instanceof MovieApp\DbFinder); | ||
|
||
// display result | ||
echo (($works) ? 'It works!' : 'It DOES NOT work!') . PHP_EOL; | ||
} |