/** * @param Attribute $attribute * @param object $object * @return mixed */ private function retrieveClassicAttribute(Attribute $attribute, $object) { $propertyPath = explode('.', $attribute->getProperty()); $propertyValue = $object; foreach ($propertyPath as $property) { $getter = 'get' . ucfirst($property); if (!method_exists($propertyValue, $getter)) { throw new \InvalidArgumentException('There is no getter for the "' . $attribute->getProperty() . '" attribute for object "' . get_class($propertyValue) . '"'); } if (($propertyValue = $propertyValue->{$getter}()) === null) { return null; } } return $propertyValue; }
/** * @param Attribute $attribute * @param object $object * @return mixed */ private function retrieveClassicAttribute(Attribute $attribute, $object, $getter_params = []) { $propertyPath = explode('.', $attribute->getProperty()); $propertyValue = $object; foreach ($propertyPath as $property) { $getter = $this->getter_prefix . call_user_func($this->getter_name_transformation_function, $property); // Use is_callable, instead of method_exists, to deal with __call magic method if (!is_callable([$propertyValue, $getter])) { throw new \InvalidArgumentException('There is no getter for the "' . $attribute->getProperty() . '" attribute for object "' . get_class($propertyValue) . '" with getter "' . $getter . '"'); } if (($propertyValue = call_user_func_array([$propertyValue, $getter], isset($getter_params[$property]) ? $getter_params[$property] : [])) === null) { return null; } } return $propertyValue; }