happyr/identifier-interface

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.
This package is abandoned and no longer maintained. No replacement package was suggested.

Write down your routing mapping at one place

1.0.0 2014-01-01 14:30 UTC

This package is auto-updated.

Last update: 2019-02-20 21:16:05 UTC


README

This "library" is not much. It is just one interface. The interface makes sure you have a public function called getId().

Say that you are writing AcmeMessageBundle with a Message entity. Each Message should have a relation to a User. You could write something like this:


class Message
{
  private $user;

  /* ... */

  public function setUser(IdentifierInterface $user)
  {
    $this->user = $user;
  }

  /* ... */
}

class MessageSenderService
{
  /* ... */
  public function send(Message $message, IdentifierInterface $recipient)
  {
     if ($message->getUser()->getId() == $recipient->getId()) {
        throw new \Exception("You can not send a message to yourself.");
     }

     /* ... */
  }
}

You could of course ship your own IdentifierInterface with your AcmeMessageBundle but after a while you will notice that your User entity implements too many interfaces...

class User implements SymfonyUserInterface, AcmeMessageBundleIdInterface, OtherBundleInterface, AcmeDemoBundleUserInterface, CompanyBundleIdentifierInterface, MyIndentifierInterface
{
  /* ... */
}

When we create Symfony2 bundles we will always use the HappyR Identifier Interface for both public and interal work.