Created
July 28, 2014 22:37
-
-
Save l3l0/ed7a69d5b2c72ebdbc57 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 | |
namespace L3l0\Bundle\SomethingBundle\Repository; | |
use L3l0\Something\Model\Some; | |
use L3l0\Something\Repository\SomeRepository; | |
use Doctrine\Common\Persistence\ObjectManager; | |
class DoctrineSomeRepository implements SomeRepository | |
{ | |
private $manager; | |
public function __construct(ObjectManager $manager) | |
{ | |
$this->manager = $manager; | |
} | |
public function save(Some $some) | |
{ | |
$this->manager->persist($some); | |
$this->manager->flush($some); | |
} | |
} |
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 | |
namespace L3l0\InMemorySomething\Repository; | |
use L3l0\Something\Model\Some; | |
use L3l0\Something\Repository\SomeRepository; | |
class InMemorySomeRepository implements SomeRepository | |
{ | |
private $someCollection = []; | |
public function save(Some $some) | |
{ | |
$this->someCollection[spl_object_hash($some)] = $some; | |
} | |
} |
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 SomeController | |
{ | |
private $repository; | |
public function __construct(SomeRepository $repository) | |
{ | |
$this->repository = $repository; | |
} | |
public function doSomethingAction() | |
{ | |
//do something | |
//.. | |
$this->repository->save($some); | |
} | |
} |
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 | |
namespace L3l0\Something\Repository; | |
use L3l0\Something\Model\Some | |
interface SomeRepository | |
{ | |
public function save(Some $some); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment