Permalink
Browse files

Added example of preference to Zend\Di Examples

  • Loading branch information...
Ralph Schindler
Ralph Schindler committed Mar 19, 2012
1 parent 2f43a88 commit 7f70660b16447e65de2c7b88df7d43de84887492
Showing with 37 additions and 0 deletions.
  1. +37 −0 example-20.php
View
@@ -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;
}

0 comments on commit 7f70660

Please sign in to comment.