[DDC-1637] Collection Filtering API #117

Merged
merged 9 commits into from May 26, 2012

Conversation

Projects
None yet
4 participants
+ foreach ($expressions as $expr) {
+ if ($expr instanceof Value) {
+ throw new \RuntimeException("Values are not supported expressions as children of and/or expressions.");
+ } else if (!($expr instanceof Expression)) {
@stof

stof Mar 15, 2012

Member

should be simply if, and the braces are useless around instanceof

@beberlei

beberlei Mar 16, 2012

Owner

i never know the operator precedence of instanceof, so its save to brace it.

+ {
+ if ($expr instanceof Comparison) {
+ return $this->walkComparison($expr);
+ } else if ($expr instanceof Value) {
@stof

stof Mar 15, 2012

Member

should be if

+
+ abstract public function walkCompositeExpression(CompositeExpression $expr);
+
+ public function dispatch(Expression $expr)
@stof

stof Mar 15, 2012

Member

missing phpdoc for all methods

+ *
+ * @return ExpressionBuilder
+ */
+ public function expr();
@stof

stof Mar 15, 2012

Member

should the ArrayCollection implement the interface ?

@beberlei

beberlei Mar 16, 2012

Owner

its WIP ;-) Step by step

+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ * @since 2.3
+ */
+interface Selectable
@stof

stof Mar 15, 2012

Member

should this interface extend Collection to allow typehinting on it and still exxpecting the Collection interface ?

@@ -0,0 +1,66 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYvalue HOLDERS AND CONTRIBUTORS
@schmittjoh

schmittjoh Mar 15, 2012

Member

search/replace detected :)

@stof

stof Mar 15, 2012

Member

oh, nice one :)

@beberlei

beberlei Mar 16, 2012

Owner

good catch :-)

+ $accessor = "get" . $field;
+ if (method_exists($object, $accessor)) {
+ return $object->$accessor();
+ } else if ($object instanceof \ArrayAccess) {
@stof

stof Mar 16, 2012

Member

simply if :)

+ switch ($comparison->getOperator()) {
+ case Comparison::EQ:
+ case Comparison::IS:
+ return function ($object) use($field, $value) {
@stof

stof Mar 16, 2012

Member

IIRC, Sf2 uses a space after use for closures. Not sure about Doctrine.

@guilhermeblanco

guilhermeblanco Mar 17, 2012

Owner

Doctrine also uses space after use.

+ static public function getObjectFieldValue($object, $field)
+ {
+ $accessor = "get" . $field;
+ if (method_exists($object, $accessor)) {
@stof

stof Mar 16, 2012

Member

what about isFoo ?

+ };
+ case Comparison::IN:
+ return function ($object) use($field, $value) {
+ return in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
@stof

stof Mar 16, 2012

Member

this will break if the field value is a collection instead of an array

@stof

stof Mar 16, 2012

Member

ok, I just saw that the value can only be an array

+ const GTE = '>=';
+ const IS = 'IS';
+ const IN = 'IN';
+ const NIN = 'NIN';
@stof

stof Mar 16, 2012

Member

what about CONTAINS to check that the field contains a given value (for fields holding an array of a collection obviously)

Member

stof commented Apr 15, 2012

@beberlei any progress here ?

Member

stof commented May 5, 2012

@beberlei what is the status here ?

Owner

beberlei commented May 26, 2012

@stof continueing now :)

Member

stof commented May 26, 2012

@beberlei great news

beberlei added a commit that referenced this pull request May 26, 2012

Merge pull request #117 from doctrine/DDC-1637
[DDC-1637] Collection Filtering API

@beberlei beberlei merged commit 4ac23ae into master May 26, 2012

@doctrinebot doctrinebot referenced this pull request in doctrine/doctrine2 Dec 6, 2015

Closed

DDC-1637: Linq-like Filter API for collections #2278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment