├── IdentifierInterface.php ├── composer.json └── README.md /IdentifierInterface.php: -------------------------------------------------------------------------------- 1 | =5" 16 | }, 17 | "autoload": { 18 | "psr-0": { 19 | "HappyR": "" 20 | } 21 | }, 22 | "target-dir": "HappyR" 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HappyR Identifier Interface 2 | 3 | This "library" is not much. It is just one interface. The interface makes sure you have a public function called 4 | *getId()*. 5 | 6 | Say that you are writing AcmeMessageBundle with a Message entity. Each Message should have a relation to a User. You 7 | could write something like this: 8 | 9 | ````php 10 | 11 | class Message 12 | { 13 | private $user; 14 | 15 | /* ... */ 16 | 17 | public function setUser(IdentifierInterface $user) 18 | { 19 | $this->user = $user; 20 | } 21 | 22 | /* ... */ 23 | } 24 | 25 | class MessageSenderService 26 | { 27 | /* ... */ 28 | public function send(Message $message, IdentifierInterface $recipient) 29 | { 30 | if ($message->getUser()->getId() == $recipient->getId()) { 31 | throw new \Exception("You can not send a message to yourself."); 32 | } 33 | 34 | /* ... */ 35 | } 36 | } 37 | 38 | ```` 39 | 40 | You could of course ship your own IdentifierInterface with your AcmeMessageBundle but after a while you will notice that 41 | your User entity implements too many interfaces... 42 | 43 | ````php 44 | class User implements SymfonyUserInterface, AcmeMessageBundleIdInterface, OtherBundleInterface, AcmeDemoBundleUserInterface, CompanyBundleIdentifierInterface, MyIndentifierInterface 45 | { 46 | /* ... */ 47 | } 48 | ```` 49 | 50 | When we create **Symfony2** bundles we will always use the HappyR Identifier Interface for both public and interal work. 51 | --------------------------------------------------------------------------------