Created
February 20, 2013 15:27
-
-
Save bramstroker/4996327 to your computer and use it in GitHub Desktop.
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
<?php | |
class MyService | |
{ | |
private $repo; | |
public function __construct(ObjectRepository $repo) | |
{ | |
$this->repo = $repo; | |
} | |
public function doSomethingConsumingMyRepo() | |
{ | |
$objects = $repo->findAll(); | |
} | |
} | |
//My custom implementation of an ObjectRepository | |
class SomeRepository implements ObjectRepository | |
{ | |
public function findAll() | |
{ | |
//My implementation | |
} | |
} | |
$repo = new SomeRepository(); | |
new MyService($repo); | |
//EnityRepository also implements ObjectRepository | |
$repo = $entityManager->getRepository('MyEntity'); | |
new MyService($repo); | |
//Both will work because my service depends on the ObjectRepository | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment