/** * Get the information on a class from its instance. * * @param object $object * * @return array */ public static function getClassInformation($object) { $reflectionObject = new \ReflectionObject($object); $cacheId = md5("classInformation:" . $reflectionObject->getName()); $classInfo = self::getFromCache($cacheId); if ($classInfo !== null) { return $classInfo; } $objectClasses = self::getClassesToRead($reflectionObject); $objectProperties = self::getProperties($objectClasses); $annotationReader = Configuration::getAnnotationReader(); $classInfo = array('accessProperties' => AccessReader::getAccessProperties($objectProperties, $annotationReader), 'collectionsItemNames' => CollectionsReader::getCollectionsItemNames($objectProperties, $annotationReader), 'associationsList' => AssociationReader::getAssociations($objectProperties, $annotationReader), 'constraintsValidationEnabled' => ConstraintsReader::isConstraintsValidationEnabled($objectClasses, $annotationReader), 'initialPropertiesValues' => AutoConstructReader::getPropertiesToInitialize($objectProperties, $annotationReader), 'initializationNeededArguments' => AutoConstructReader::getConstructArguments($objectClasses, $annotationReader)); self::saveToCache($cacheId, $classInfo); return $classInfo; }
/** * Validates the given value compared to given property constraints. * If the value is not valid, an InvalidArgumentException will be thrown. * * @param string $property The name of the reference property. * @param mixed $value The value to check. * * @throws \InvalidArgumentException If the value is not valid. */ protected function assertPropertyValue($property, $value) { $this->getPropertiesInfo(); if ($this->_constraintsValidationEnabled) { $constraintsViolations = ConstraintsReader::validatePropertyValue($this, $property, $value); if ($constraintsViolations->count()) { $errorMessage = "Argument given is invalid; its constraints validation failed for property {$property} with the following messages: \""; $errorMessageList = array(); foreach ($constraintsViolations as $violation) { $errorMessageList[] = $violation->getMessage(); } $errorMessage .= implode("\", \n\"", $errorMessageList) . "\"."; throw new \InvalidArgumentException($errorMessage); } } }