Beispiel #1
0
 public function testAddGetCustomDatetimeFunction()
 {
     $this->configuration->addCustomDatetimeFunction('FunctionName', __CLASS__);
     $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('FunctionName'));
     $this->assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction'));
     $this->configuration->setCustomDatetimeFunctions(array('OtherFunctionName' => __CLASS__));
     $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('OtherFunctionName'));
     $this->setExpectedException('Doctrine\\ORM\\ORMException');
     $this->configuration->addCustomDatetimeFunction('date_add', __CLASS__);
 }
 /**
  * @param string $type
  * @param string $functionName
  * @param string $functionClass
  * @param Configuration $configuration
  */
 protected function registerDqlFunction($type, $functionName, $functionClass, Configuration $configuration)
 {
     switch ($type) {
         case 'datetime':
             $configuration->addCustomDatetimeFunction($functionName, $functionClass);
             break;
         case 'numeric':
             $configuration->addCustomNumericFunction($functionName, $functionClass);
             break;
         case 'string':
         default:
             $configuration->addCustomStringFunction($functionName, $functionClass);
     }
 }
 /**
  * @param Configuration $configuration
  * @param string        $database
  */
 public static function load(Configuration $configuration, $database)
 {
     $parser = new Parser();
     // Load the corresponding config file.
     $config = $parser->parse(file_get_contents(realpath(__DIR__ . '/../../config/' . $database . '.yml')));
     $parsed = $config['doctrine']['orm']['dql'];
     // Load the existing function classes.
     if (array_key_exists('datetime_functions', $parsed)) {
         foreach ($parsed['datetime_functions'] as $key => $value) {
             $configuration->addCustomDatetimeFunction(strtoupper($key), $value);
         }
     }
     if (array_key_exists('numeric_functions', $parsed)) {
         foreach ($parsed['numeric_functions'] as $key => $value) {
             $configuration->addCustomNumericFunction(strtoupper($key), $value);
         }
     }
     if (array_key_exists('string_functions', $parsed)) {
         foreach ($parsed['string_functions'] as $key => $value) {
             $configuration->addCustomStringFunction(strtoupper($key), $value);
         }
     }
 }
 /**
  * Adds userdefined functions.
  *
  * @param  Configuration $config
  * @param  array         $options
  * @return Configuration
  */
 private static function addCustomFunctions(Configuration $config, array $options = array())
 {
     if (null !== ($strFcts = Collection::get($options, 'orm:entity_managers:default:dql:string_functions'))) {
         foreach ($strFcts as $name => $class) {
             if (class_exists($class)) {
                 $config->addCustomStringFunction($name, $class);
             }
         }
     }
     if (null !== ($numFcts = Collection::get($options, 'orm:entity_managers:default:dql:numeric_functions'))) {
         foreach ($numFcts as $name => $class) {
             if (class_exists($class)) {
                 $config->addCustomNumericFunction($name, $class);
             }
         }
     }
     if (null !== ($datetimeFcts = Collection::get($options, 'orm:entity_managers:default:dql:datetime_functions'))) {
         foreach ($datetimeFcts as $name => $class) {
             if (class_exists($class)) {
                 $config->addCustomDatetimeFunction($name, $class);
             }
         }
     }
     return $config;
 }
 protected function setupCustomFunctions(Configuration $config, $spec)
 {
     foreach ($spec['custom_hydration_modes'] as $name => $classname) {
         $config->addCustomHydrationMode($name, $classname);
     }
     foreach ($spec['custom_datetime_functions'] as $name => $classname) {
         $config->addCustomDatetimeFunction($name, $classname);
     }
     foreach ($spec['custom_numeric_functions'] as $name => $classname) {
         $config->addCustomNumericFunction($name, $classname);
     }
     foreach ($spec['custom_string_functions'] as $name => $classname) {
         $config->addCustomStringFunction($name, $classname);
     }
     foreach ($spec['filters'] as $name => $classname) {
         $config->addFilter($name, $classname);
     }
 }