示例#1
0
 /**
  * Build a Filter with the given query parts
  *
  * @param array    $queryParts
  * @param Database $collection
  * @return FilterResult
  */
 public function buildFilterFromQueryParts($queryParts, $collection)
 {
     $comparisons = array();
     foreach ($queryParts as $propertyKey => $testValue) {
         //			$comparisons[] = new PropertyComparison($propertyKey, PropertyComparisonInterface::TYPE_EQUAL_TO, $testValue);
         $comparisons[] = new PropertyComparison($propertyKey, PropertyComparisonInterface::TYPE_LIKE, $testValue);
     }
     $filter = new Filter($comparisons);
     return $filter->filterCollection($collection);
 }
示例#2
0
 /**
  * A test that should validate the behavior of data object references in a database
  *
  * @test
  */
 public function objectLiveCycleTest()
 {
     /** @var \Cundd\PersistentObjectStore\DataAccess\Coordinator $coordinator */
     $coordinator = $this->getDiContainer()->get('\\Cundd\\PersistentObjectStore\\DataAccess\\Coordinator');
     $newFilter = new Filter();
     //		$database = $coordinator->getDataByDatabase('contacts');
     //		$this->filter->addComparison(new Comparison('email', ComparisonInterface::TYPE_CONTAINS, '@cundd.net'));
     $database = $coordinator->getDatabase('people');
     $newFilter->addComparison(new PropertyComparison('eyeColor', ComparisonInterface::TYPE_EQUAL_TO, 'green'));
     $newFilterResult = $newFilter->filterCollection($database);
     /** @var DocumentInterface $memberFromNewFilter */
     $memberFromNewFilter = $newFilterResult->current();
     /** @var DocumentInterface $memberFromFixture */
     $memberFromFixture = $this->fixture->current();
     $this->assertEquals($memberFromNewFilter, $memberFromFixture);
     $movie = 'Star Wars';
     $key = 'favorite_movie';
     $memberFromNewFilter->setValueForKey($movie, $key);
     $this->assertEquals($memberFromNewFilter, $memberFromFixture);
     $this->assertEquals(spl_object_hash($memberFromNewFilter), spl_object_hash($memberFromFixture));
     $this->assertEquals($movie, $memberFromNewFilter->valueForKey($key));
     $this->assertEquals($movie, $memberFromFixture->valueForKey($key));
 }
示例#3
0
 /**
  * Filters the database using the given comparisons
  *
  * @param array|ComparisonInterface $comparisons
  * @return \Cundd\PersistentObjectStore\Filter\FilterResultInterface
  */
 public function filter($comparisons)
 {
     if (!is_array($comparisons)) {
         $comparisons = func_get_args();
     }
     $filter = new Filter($comparisons);
     return $filter->filterCollection($this);
 }