Last active
December 24, 2015 21:19
-
-
Save mnapoli/6864216 to your computer and use it in GitHub Desktop.
Doctrine Expression API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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