Skip to content

Instantly share code, notes, and snippets.

@mnapoli
Last active December 24, 2015 21:19
Show Gist options
  • Save mnapoli/6864216 to your computer and use it in GitHub Desktop.
Save mnapoli/6864216 to your computer and use it in GitHub Desktop.
Doctrine Expression API
<?php
interface Updatable
{
public function apply(Expression $e);
}
// Solution 1
// More powerful, but needs to parse and evaluate the string
class Expression
{
public $criteria;
public function set($field, $value);
}
$expression->set('position', 'position + 1');
// Solution 2
// Easier to implement, more limited
class Expression
{
public $criteria;
public function setValue($field, $value);
public function setValueFromField($targetField, $sourceField);
public function add($field, $number);
public function multiply($field, $number);
public function divide($field, $number);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment