Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function extract($object)
 {
     $objectClass = get_class($object);
     if (isset($this->objectMethodsCache[$objectClass])) {
         $methods = $this->objectMethodsCache[$objectClass];
     } else {
         $methods = $this->objectMethodsCache[$objectClass] = get_class_methods($object);
     }
     $result = [];
     $context = clone $this->extractionContext;
     // Performance trick, do not try to instantiate
     $context->object = $object;
     // Pass 1: finding out which properties can be extracted, with which methods (populate hydration cache)
     if (!isset($this->extractionMethodsCache[$objectClass])) {
         $this->extractionMethodsCache[$objectClass] = [];
         foreach ($methods as $method) {
             if (!$this->filterChain->accept($method, $context)) {
                 continue;
             }
             $property = preg_replace('/get/', '', $method);
             // Allow to strip "get" for getters
             $property = $this->namingStrategy->getNameForExtraction($property, $context);
             $this->extractionMethodsCache[$objectClass][$method] = $property;
         }
     }
     // Pass 2: actually extract data
     foreach ($this->extractionMethodsCache[$objectClass] as $method => $property) {
         $result[$property] = $this->extractValue($property, $object->{$method}(), $context);
     }
     return $result;
 }
 /**
  * @iterations 1000
  */
 public function traverseCompositeFilter()
 {
     $context = new ExtractionContext();
     $context->object = $this->object;
     $this->filter->accept('getOne', $context);
     $this->filter->accept('getTwo', $context);
     $this->filter->accept('isThree', $context);
 }
Esempio n. 3
0
 public function testOrFilter()
 {
     $filterContainer = new FilterChain();
     $filterContainer->orFilter(new ExcludeMethodsFilter(['getBar', 'getBaz', 'hasFoo']));
     $filterContainer->orFilter(new GetFilter());
     $this->assertTrue($filterContainer->accept('getBar'), 'Accepted because of the GetFilter');
     $this->assertTrue($filterContainer->accept('isFoo'), 'Accepted because not in the GetFilter');
     $this->assertFalse($filterContainer->accept('hasFoo'), 'Rejected because is in Exclude and not a Get');
 }