public function instantiateAnnotation(Customweb_Annotation_Cache_Annotation $cacheInstance, $targetReflection = false) { $class = Customweb_Annotation_Util::resolveClassName($cacheInstance->getName()); $parameters = $this->instanciateNestedAnnotations($cacheInstance->getParameters()); if (Customweb_Core_Util_Class::isClassLoaded($class) && !Customweb_Annotation_Util::ignores($class)) { $annotationReflection = new ReflectionClass($class); $instance = $annotationReflection->newInstance(); if (method_exists($instance, 'setData')) { $instance->setData($parameters); } else { set_error_handler(array($this, 'handleInstanciationErrors')); try { foreach ($parameters as $propertyName => $propertyValue) { $methodName = 'set' . $propertyName; if (method_exists($instance, $methodName)) { $instance->{$methodName}($propertyValue); } elseif (property_exists($instance, $propertyName)) { $instance->{$propertyName} = $propertyValue; } else { throw new Exception(Customweb_Core_String::_("Property @property could not be set on annotation class @class")->format(array('@class' => $class, '@property' => $propertyName))); } } } catch (Exception $e) { restore_error_handler(); throw $e; } restore_error_handler(); } if (method_exists($instance, 'checkConstraints')) { $instance->checkConstraints($targetReflection); } return $instance; } return false; }
/** * @param string $serializedString * @throws Customweb_Core_Exception_ClassNotFoundException */ private static function preloadClasses($serializedString) { $matches = array(); preg_match_all('/O:[0-9]+:\\"(.+?)\\":/', $serializedString, $matches); if (isset($matches[1])) { foreach ($matches[1] as $match) { $className = $match; if (!Customweb_Core_Util_Class::isClassLoaded($className)) { try { Customweb_Core_Util_Class::loadLibraryClassByName($className); } catch (Customweb_Core_Exception_ClassNotFoundException $e) { if (!class_exists($className)) { throw $e; } } } } } }