Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Bring fun(ctional APIs) into Doctrine by integrating PhpOption with Doctrine
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/Doctrine
tests/Doctrine/Fun/Tests
.gitignore
.travis.yml
README.md
composer.json
phpunit.xml.dist

README.md

Doctrine Fun: Bring fun(ctional APIs) into Doctrine by integrating PhpOption with Doctrine Build Status

Extends Doctrine to integrate PhpOption. Comes with a custom repository class that returns PhpOption\LazyOption instead of null or entity.

Use functional repository

<?php
$repository = $em->getRepository('MyEntity');

// EntityRepository::find() returns instance of \PhpOption\Option instead of plain entity
$entity = $repository->find(12)->getOrElse(new Entity());

// EntityRepository::findOneBy(...) returns Option as well
$entity = $repository->findOneBy(array('property' => 'value'))->get();

Set functional repository as a default repository class

<?php
$config = new Doctrine\ORM\Configuration();
$config->setDefaultRepositoryClassName('Doctrine\Fun\EntityRepository');

$em = EntityManager::create(..., $config);

Decorating EntityManager so that EntityManager::createQuery() returns a Query object that has a getOptionResult() method

<?php
$em = new Doctrine\Fun\EntityManagerDecorator(EntityManager::create(..., $config));

// $query is an instance of Doctrine\Fun\Query
$option = $em->createQuery('SELECT MyEntity e FROM MyEntity')->getOptionResult();

$entity = $option->getOrElse(new MyEntity());
Something went wrong with that request. Please try again.