/** * Remove a filter from the composition. * To not extract "has" methods, you simply need to unregister it * * <code> * $filterComposite->removeFilter('has'); * </code> * * @param $name * @return Filter\FilterComposite */ public function removeFilter($name) { return $this->filterComposite->removeFilter($name); }
/** * Extract values from an object with class methods * * Extracts the getter/setter of the given $object. * * @param object $object * @return array * @throws Exception\BadMethodCallException for a non-object $object */ public function extract($object) { if (!is_object($object)) { throw new Exception\BadMethodCallException(sprintf('%s expects the provided $object to be a PHP object)', __METHOD__)); } $objectClass = get_class($object); // reset the hydrator's hydrator's cache for this object, as the filter may be per-instance if ($object instanceof Filter\FilterProviderInterface) { $this->extractionMethodsCache[$objectClass] = null; } // pass 1 - finding out which properties can be extracted, with which methods (populate hydration cache) if (!isset($this->extractionMethodsCache[$objectClass])) { $this->extractionMethodsCache[$objectClass] = []; $filter = $this->filterComposite; $methods = get_class_methods($object); if ($object instanceof Filter\FilterProviderInterface) { $filter = new Filter\FilterComposite([$object->getFilter()], [new Filter\MethodMatchFilter('getFilter')]); } foreach ($methods as $method) { $methodFqn = $objectClass . '::' . $method; if (!($filter->filter($methodFqn) && $this->callableMethodFilter->filter($methodFqn))) { continue; } $attribute = $method; if (strpos($method, 'get') === 0) { $attribute = substr($method, 3); if (!property_exists($object, $attribute)) { $attribute = lcfirst($attribute); } } $this->extractionMethodsCache[$objectClass][$method] = $attribute; } } $values = []; // pass 2 - actually extract data foreach ($this->extractionMethodsCache[$objectClass] as $methodName => $attributeName) { $realAttributeName = $this->extractName($attributeName, $object); $values[$realAttributeName] = $this->extractValue($realAttributeName, $object->{$methodName}(), $object); } return $values; }