Skip to content

Instantly share code, notes, and snippets.

@matteosister
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteosister/9536983 to your computer and use it in GitHub Desktop.
Save matteosister/9536983 to your computer and use it in GitHub Desktop.
A trait to use the PhpOption in the EntityRepository
<?php
namespace Vendor\Repository;
use PhpOption\Option;
use Doctrine\DBAL\LockMode;
trait OptionRepositoryTrait
{
public function find($id, $lockMode = LockMode::NONE, $lockVersion = null)
{
return Option::fromValue(parent::find($id, $lockMode, $lockVersion));
}
public function findAll()
{
return Option::fromValue(parent::findAll());
}
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
return Option::fromValue(parent::findBy($criteria, $orderBy, $limit, $offset));
}
public function findOneBy(array $criteria, array $orderBy = null)
{
return Option::fromValue(parent::findOneBy($criteria, $orderBy));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment