/** * Initializes the object according to its class specification and given arguments. * * @param array $properties The values to give to the properties. */ protected function initializeProperties($properties = null) { $this->getPropertiesInfo(); // Initialize the properties that were defined using the Initialize / InitializeObject annotations $initializeValueValidationEnabled = Configuration::isInitializeValuesValidationEnabled(); foreach ($this->_initialPropertiesValues as $propertyName => $initialization) { $value = null; switch ($initialization['type']) { case 'initialize': $value = $initialization['value']; break; default: $className = $initialization['value']; $value = new $className(); break; } if ($initializeValueValidationEnabled) { $this->assertPropertyValue($propertyName, $value); } $this->{$propertyName} = $value; $this->updateInitializedPropertyValue($propertyName, $value); } // Initialize the propeties using given arguments if ($this->_initializationNeededArguments !== null && $properties !== null) { $numberOfNeededArguments = count($this->_initializationNeededArguments); MethodCallManager::assertArgsNumber($numberOfNeededArguments, $properties); for ($i = 0; $i < $numberOfNeededArguments; $i++) { $propertyName = $this->_initializationNeededArguments[$i]; $argument = $properties[$i]; $this->assertPropertyValue($propertyName, $argument); $this->{$propertyName} = $argument; $this->updateInitializedPropertyValue($propertyName, $argument); } } }
public function process(ContainerBuilder $container) { $enableCache = $container->getParameter('antares_accessible.cache.enable'); // Annotation reader $annotationsReader = $container->get('antares_accessible.annotations.reader'); if ($annotationsReader instanceof NullService) { if ($enableCache) { $debug = $container->getParameter('kernel.debug'); $annotationCacheDriver = $container->get('antares_accessible.annotations.cache_driver'); $annotationsCache = new ChainCache([new ArrayCache(), $annotationCacheDriver]); Configuration::setAnnotationReader(new CachedReader(new AnnotationReader(), $annotationsCache, $debug)); } } else { Configuration::setAnnotationReader($annotationsReader); } // Constraints validator $constraintsValidator = $container->get('antares_accessible.constraints_validation.validator'); if (!$constraintsValidator instanceof NullService) { Configuration::setConstraintsValidator($constraintsValidator); } // Cache driver if ($enableCache) { $cacheDriver = $container->get('antares_accessible.cache.driver'); Configuration::setCacheDriver($cacheDriver); } // Enable the constraints validation of Initialize annotations values $constraintsValidationEnabled = $container->getParameter('antares_accessible.constraints_validation.enable'); Configuration::setConstraintsValidationEnabled($constraintsValidationEnabled); // Enable the constraints validation of Initialize annotations values $validateInitializeValues = $container->getParameter('antares_accessible.constraints_validation.validate_initialize_values'); Configuration::setInitializeValuesValidationEnabled($validateInitializeValues); }
public function testArrayCacheDriverCanBeModified() { $arrayCache = Configuration::getArrayCache(); $newCacheDriver = new ArrayCache(); Configuration::setArrayCache($newCacheDriver); $this->assertEquals($newCacheDriver, Configuration::getArrayCache()); Configuration::setArrayCache($arrayCache); }
/** * Validates the given value compared to given property constraints. * If the value is valid, a call to `count` to the object returned * by this method should give 0. * * @param object $object The object to compare. * @param string $property The name of the reference property. * @param mixed $value The value to check. * * @return Symfony\Component\Validator\ConstraintViolationList * The list of constraints violations the check returns. */ public static function validatePropertyValue($object, $property, $value) { return Configuration::getConstraintsValidator()->validatePropertyValue($object, $property, $value); }
/** * Save a value to the cache. * * @param string $id * @param mixed $value */ public static function saveToCache($id, $value) { $arrayCache = Configuration::getArrayCache(); $cacheDriver = Configuration::getCacheDriver(); $arrayCache->save($id, $value); if ($cacheDriver !== null) { $cacheDriver->save($id, $value); } }