Skip to content

Commit

Permalink
Added example of preference to Zend\Di Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Schindler committed Mar 19, 2012
1 parent 2f43a88 commit 7f70660
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions example-20.php
@@ -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.