Skip to content

Instantly share code, notes, and snippets.

@bramstroker
Created February 20, 2013 15:27
Show Gist options
  • Save bramstroker/4996327 to your computer and use it in GitHub Desktop.
Save bramstroker/4996327 to your computer and use it in GitHub Desktop.
<?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