本文整理汇总了PHP中Doctrine\ORM\Configuration::setCustomNumericFunctions方法的典型用法代码示例。如果您正苦于以下问题:PHP Configuration::setCustomNumericFunctions方法的具体用法?PHP Configuration::setCustomNumericFunctions怎么用?PHP Configuration::setCustomNumericFunctions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Configuration
的用法示例。
在下文中一共展示了Configuration::setCustomNumericFunctions方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** @var $options \DoctrineORMModule\Options\Configuration */
$options = $this->getOptions($serviceLocator);
$config = new Configuration();
$config->setAutoGenerateProxyClasses($options->getGenerateProxies());
$config->setProxyDir($options->getProxyDir());
$config->setProxyNamespace($options->getProxyNamespace());
$config->setEntityNamespaces($options->getEntityNamespaces());
$config->setCustomDatetimeFunctions($options->getDatetimeFunctions());
$config->setCustomStringFunctions($options->getStringFunctions());
$config->setCustomNumericFunctions($options->getNumericFunctions());
$config->setClassMetadataFactoryName($options->getClassMetadataFactoryName());
foreach ($options->getNamedQueries() as $name => $query) {
$config->addNamedQuery($name, $query);
}
foreach ($options->getNamedNativeQueries() as $name => $query) {
$config->addNamedNativeQuery($name, $query['sql'], new $query['rsm']());
}
foreach ($options->getCustomHydrationModes() as $modeName => $hydrator) {
$config->addCustomHydrationMode($modeName, $hydrator);
}
foreach ($options->getFilters() as $name => $class) {
$config->addFilter($name, $class);
}
$config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache()));
$config->setQueryCacheImpl($serviceLocator->get($options->getQueryCache()));
$config->setResultCacheImpl($serviceLocator->get($options->getResultCache()));
$config->setHydrationCacheImpl($serviceLocator->get($options->getHydrationCache()));
$config->setMetadataDriverImpl($serviceLocator->get($options->getDriver()));
if ($namingStrategy = $options->getNamingStrategy()) {
if (is_string($namingStrategy)) {
if (!$serviceLocator->has($namingStrategy)) {
throw new InvalidArgumentException(sprintf('Naming strategy "%s" not found', $namingStrategy));
}
$config->setNamingStrategy($serviceLocator->get($namingStrategy));
} else {
$config->setNamingStrategy($namingStrategy);
}
}
if ($repositoryFactory = $options->getRepositoryFactory()) {
if (is_string($repositoryFactory)) {
if (!$serviceLocator->has($repositoryFactory)) {
throw new InvalidArgumentException(sprintf('Repository factory "%s" not found', $repositoryFactory));
}
$config->setRepositoryFactory($serviceLocator->get($repositoryFactory));
} else {
$config->setRepositoryFactory($repositoryFactory);
}
}
if ($entityListenerResolver = $options->getEntityListenerResolver()) {
if ($entityListenerResolver instanceof EntityListenerResolver) {
$config->setEntityListenerResolver($entityListenerResolver);
} else {
$config->setEntityListenerResolver($serviceLocator->get($entityListenerResolver));
}
}
$this->setupDBALConfiguration($serviceLocator, $config);
return $config;
}
示例2: testAddGetCustomNumericFunction
public function testAddGetCustomNumericFunction()
{
$this->configuration->addCustomNumericFunction('FunctionName', __CLASS__);
$this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('FunctionName'));
$this->assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction'));
$this->configuration->setCustomNumericFunctions(array('OtherFunctionName' => __CLASS__));
$this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('OtherFunctionName'));
$this->setExpectedException('Doctrine\\ORM\\ORMException');
$this->configuration->addCustomNumericFunction('abs', __CLASS__);
}
示例3: applyDqlSettingsToConfiguration
/**
* Apply configured settings regarding DQL to the Doctrine Configuration.
* At the moment, these are custom DQL functions.
*
* @param array $configuredSettings
* @param Configuration $doctrineConfiguration
* @return void
*/
protected function applyDqlSettingsToConfiguration(array $configuredSettings, Configuration $doctrineConfiguration)
{
if (isset($configuredSettings['customStringFunctions'])) {
$doctrineConfiguration->setCustomStringFunctions($configuredSettings['customStringFunctions']);
}
if (isset($configuredSettings['customNumericFunctions'])) {
$doctrineConfiguration->setCustomNumericFunctions($configuredSettings['customNumericFunctions']);
}
if (isset($configuredSettings['customDatetimeFunctions'])) {
$doctrineConfiguration->setCustomDatetimeFunctions($configuredSettings['customDatetimeFunctions']);
}
}
示例4: setCustomFunctions
/**
* @param Configuration $configuration
*/
protected function setCustomFunctions(Configuration $configuration)
{
$configuration->setCustomDatetimeFunctions($this->config->get('doctrine.custom_datetime_functions'));
$configuration->setCustomNumericFunctions($this->config->get('doctrine.custom_numeric_functions'));
$configuration->setCustomStringFunctions($this->config->get('doctrine.custom_string_functions'));
}
示例5: __invoke
/**
* {@inheritDoc}
*
* @return Configuration
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/** @var $options \DoctrineORMModule\Options\Configuration */
$options = $this->getOptions($container);
$config = new Configuration();
$config->setAutoGenerateProxyClasses($options->getGenerateProxies());
$config->setProxyDir($options->getProxyDir());
$config->setProxyNamespace($options->getProxyNamespace());
$config->setEntityNamespaces($options->getEntityNamespaces());
$config->setCustomDatetimeFunctions($options->getDatetimeFunctions());
$config->setCustomStringFunctions($options->getStringFunctions());
$config->setCustomNumericFunctions($options->getNumericFunctions());
$config->setClassMetadataFactoryName($options->getClassMetadataFactoryName());
foreach ($options->getNamedQueries() as $name => $query) {
$config->addNamedQuery($name, $query);
}
foreach ($options->getNamedNativeQueries() as $name => $query) {
$config->addNamedNativeQuery($name, $query['sql'], new $query['rsm']());
}
foreach ($options->getCustomHydrationModes() as $modeName => $hydrator) {
$config->addCustomHydrationMode($modeName, $hydrator);
}
foreach ($options->getFilters() as $name => $class) {
$config->addFilter($name, $class);
}
$config->setMetadataCacheImpl($container->get($options->getMetadataCache()));
$config->setQueryCacheImpl($container->get($options->getQueryCache()));
$config->setResultCacheImpl($container->get($options->getResultCache()));
$config->setHydrationCacheImpl($container->get($options->getHydrationCache()));
$config->setMetadataDriverImpl($container->get($options->getDriver()));
if ($namingStrategy = $options->getNamingStrategy()) {
if (is_string($namingStrategy)) {
if (!$container->has($namingStrategy)) {
throw new InvalidArgumentException(sprintf('Naming strategy "%s" not found', $namingStrategy));
}
$config->setNamingStrategy($container->get($namingStrategy));
} else {
$config->setNamingStrategy($namingStrategy);
}
}
if ($quoteStrategy = $options->getQuoteStrategy()) {
if (is_string($quoteStrategy)) {
if (!$container->has($quoteStrategy)) {
throw new InvalidArgumentException(sprintf('Quote strategy "%s" not found', $quoteStrategy));
}
$config->setQuoteStrategy($container->get($quoteStrategy));
} else {
$config->setQuoteStrategy($quoteStrategy);
}
}
if ($repositoryFactory = $options->getRepositoryFactory()) {
if (is_string($repositoryFactory)) {
if (!$container->has($repositoryFactory)) {
throw new InvalidArgumentException(sprintf('Repository factory "%s" not found', $repositoryFactory));
}
$config->setRepositoryFactory($container->get($repositoryFactory));
} else {
$config->setRepositoryFactory($repositoryFactory);
}
}
if ($entityListenerResolver = $options->getEntityListenerResolver()) {
if ($entityListenerResolver instanceof EntityListenerResolver) {
$config->setEntityListenerResolver($entityListenerResolver);
} else {
$config->setEntityListenerResolver($container->get($entityListenerResolver));
}
}
$secondLevelCache = $options->getSecondLevelCache();
if ($secondLevelCache->isEnabled()) {
$regionsConfig = new RegionsConfiguration($secondLevelCache->getDefaultLifetime(), $secondLevelCache->getDefaultLockLifetime());
foreach ($secondLevelCache->getRegions() as $regionName => $regionConfig) {
if (isset($regionConfig['lifetime'])) {
$regionsConfig->setLifetime($regionName, $regionConfig['lifetime']);
}
if (isset($regionConfig['lock_lifetime'])) {
$regionsConfig->setLockLifetime($regionName, $regionConfig['lock_lifetime']);
}
}
// As Second Level Cache caches queries results, we reuse the result cache impl
$cacheFactory = new DefaultCacheFactory($regionsConfig, $config->getResultCacheImpl());
$cacheFactory->setFileLockRegionDirectory($secondLevelCache->getFileLockRegionDirectory());
$cacheConfiguration = new CacheConfiguration();
$cacheConfiguration->setCacheFactory($cacheFactory);
$cacheConfiguration->setRegionsConfiguration($regionsConfig);
$config->setSecondLevelCacheEnabled();
$config->setSecondLevelCacheConfiguration($cacheConfiguration);
}
if ($className = $options->getDefaultRepositoryClassName()) {
$config->setDefaultRepositoryClassName($className);
}
$this->setupDBALConfiguration($container, $config);
return $config;
}
示例6: createWithConfig
/**
* {@inheritdoc}
*/
protected function createWithConfig(ContainerInterface $container, $configKey)
{
$config = $this->retrieveConfig($container, $configKey, 'configuration');
$configuration = new Configuration();
$configuration->setProxyDir($config['proxy_dir']);
$configuration->setProxyNamespace($config['proxy_namespace']);
$configuration->setAutoGenerateProxyClasses($config['auto_generate_proxy_classes']);
$configuration->setEntityNamespaces($config['entity_namespaces']);
$configuration->setCustomDatetimeFunctions($config['datetime_functions']);
$configuration->setCustomStringFunctions($config['string_functions']);
$configuration->setCustomNumericFunctions($config['numeric_functions']);
$configuration->setCustomHydrationModes($config['custom_hydration_modes']);
$configuration->setClassMetadataFactoryName($config['class_metadata_factory_name']);
foreach ($config['named_queries'] as $name => $dql) {
$configuration->addNamedQuery($name, $dql);
}
foreach ($config['named_native_queries'] as $name => $query) {
$configuration->addNamedNativeQuery($name, $query['sql'], $query['rsm']);
}
foreach ($config['filters'] as $name => $className) {
$configuration->addFilter($name, $className);
}
$configuration->setMetadataCacheImpl($this->retrieveDependency($container, $config['metadata_cache'], 'cache', CacheFactory::class));
$configuration->setQueryCacheImpl($this->retrieveDependency($container, $config['query_cache'], 'cache', CacheFactory::class));
$configuration->setResultCacheImpl($this->retrieveDependency($container, $config['result_cache'], 'cache', CacheFactory::class));
$configuration->setHydrationCacheImpl($this->retrieveDependency($container, $config['hydration_cache'], 'cache', CacheFactory::class));
$configuration->setMetadataDriverImpl($this->retrieveDependency($container, $config['driver'], 'driver', DriverFactory::class));
if (is_string($config['naming_strategy'])) {
$configuration->setNamingStrategy($container->get($config['naming_strategy']));
} elseif (null !== $config['naming_strategy']) {
$configuration->setNamingStrategy($config['naming_strategy']);
}
if (is_string($config['repository_factory'])) {
$configuration->setRepositoryFactory($container->get($config['repository_factory']));
} elseif (null !== $config['repository_factory']) {
$configuration->setRepositoryFactory($config['repository_factory']);
}
if (is_string($config['entity_listener_resolver'])) {
$configuration->setEntityListenerResolver($container->get($config['entity_listener_resolver']));
} elseif (null !== $config['entity_listener_resolver']) {
$configuration->setEntityListenerResolver($config['entity_listener_resolver']);
}
if (null !== $config['default_repository_class_name']) {
$configuration->setDefaultRepositoryClassName($config['default_repository_class_name']);
}
if ($config['second_level_cache']['enabled']) {
$regionsConfig = new RegionsConfiguration($config['second_level_cache']['default_lifetime'], $config['second_level_cache']['default_lock_lifetime']);
foreach ($config['second_level_cache']['regions'] as $regionName => $regionConfig) {
if (array_key_exists('lifetime', $regionConfig)) {
$regionsConfig->setLifetime($regionName, $regionConfig['lifetime']);
}
if (array_key_exists('lock_lifetime', $regionConfig)) {
$regionsConfig->setLockLifetime($regionName, $regionConfig['lock_lifetime']);
}
}
$cacheFactory = new DefaultCacheFactory($regionsConfig, $configuration->getResultCacheImpl());
$cacheFactory->setFileLockRegionDirectory($config['second_level_cache']['file_lock_region_directory']);
$cacheConfiguration = new CacheConfiguration();
$cacheConfiguration->setCacheFactory($cacheFactory);
$cacheConfiguration->setRegionsConfiguration($regionsConfig);
$configuration->setSecondLevelCacheEnabled(true);
$configuration->setSecondLevelCacheConfiguration($cacheConfiguration);
}
if (is_string($config['sql_logger'])) {
$configuration->setSQLLogger($container->get($config['sql_logger']));
} elseif (null !== $config['sql_logger']) {
$configuration->setSQLLogger($config['sql_logger']);
}
return $configuration;
}
示例7: register
public function register(Container $app)
{
if (!isset($app['dbs'])) {
throw new \LogicException('You must register the DoctrineServiceProvider to use the DoctrineOrmServiceProvider.');
}
if (!isset($app['caches'])) {
throw new \LogicException('You must register the DoctrineCacheServiceProvider to use the DoctrineOrmServiceProvider.');
}
$app['ems.options.initializer'] = $app->protect(function () use($app) {
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
if (!isset($app['ems.options'])) {
$app['ems.options'] = ['default' => isset($app['orm.options']) ? $app['orm.options'] : []];
}
$app['ems.options'] = array_map(function ($options) use($app) {
return array_replace($app['orm.default_options'], $options);
}, $app['ems.options']);
if (!isset($app['ems.default'])) {
$app['ems.default'] = array_keys(array_slice($app['ems.options'], 0, 1))[0];
}
});
$app['ems'] = function (Container $app) {
$app['ems.options.initializer']();
$container = new Container();
foreach ($app['ems.options'] as $name => $options) {
if ($app['ems.default'] === $name) {
$config = $app['orm.config'];
} else {
$config = $app['ems.config'][$name];
}
$connection = $app['dbs'][$options['connection']];
$manager = $app['dbs.event_manager'][$options['connection']];
$container[$name] = function () use($connection, $config, $manager) {
return EntityManager::create($connection, $config, $manager);
};
}
return $container;
};
$app['ems.config'] = function (Container $app) {
$app['ems.options.initializer']();
$container = new Container();
foreach ($app['ems.options'] as $name => $options) {
$config = new Configuration();
$config->setProxyDir($app['orm.proxy_dir']);
$config->setProxyNamespace($app['orm.proxy_namespace']);
$config->setAutoGenerateProxyClasses($app['orm.auto_generate_proxy_classes']);
$config->setCustomStringFunctions($app['orm.custom_functions_string']);
$config->setCustomNumericFunctions($app['orm.custom_functions_numeric']);
$config->setCustomDatetimeFunctions($app['orm.custom_functions_datetime']);
$config->setMetadataCacheImpl($app['orm.cache.factory']('metadata', $options));
$config->setQueryCacheImpl($app['orm.cache.factory']('query', $options));
$config->setResultCacheImpl($app['orm.cache.factory']('result', $options));
$config->setMetadataDriverImpl($app['orm.mapping.chain']($config, $options['mappings']));
$container[$name] = $config;
}
return $container;
};
$app['orm.cache.factory'] = $app->protect(function ($type, $options) use($app) {
$type = $type . '_cache_driver';
if (!isset($options[$type])) {
$options[$type] = 'array';
}
if (!is_array($options[$type])) {
$options[$type] = ['driver' => $options[$type]];
}
$driver = $options[$type]['driver'];
$namespace = isset($options[$type]['namespace']) ? $options[$type]['namespace'] : null;
$cache = $app['cache.factory']($driver, $options);
$cache->setNamespace($namespace);
return $cache;
});
$app['orm.mapping.chain'] = $app->protect(function (Configuration $config, array $mappings) {
$chain = new MappingDriverChain();
foreach ($mappings as $mapping) {
if (!is_array($mapping)) {
throw new \InvalidArgumentException();
}
switch ($mapping['type']) {
case 'annotation':
$useSimpleAnnotationReader = isset($mapping['use_simple_annotation_reader']) ? $mapping['use_simple_annotation_reader'] : true;
$driver = $config->newDefaultAnnotationDriver($mapping['path'], $useSimpleAnnotationReader);
break;
case 'yml':
$driver = new YamlDriver($mapping['path']);
break;
default:
throw new \InvalidArgumentException();
break;
}
$chain->addDriver($driver, $mapping['namespace']);
}
return $chain;
});
$app['orm.proxy_dir'] = null;
$app['orm.proxy_namespace'] = 'Proxy';
$app['orm.auto_generate_proxy_classes'] = true;
$app['orm.custom_functions_string'] = [];
//.........这里部分代码省略.........
示例8: loadInstance
/**
* {@inheritDoc}
*/
protected function loadInstance()
{
$opts = $this->opts;
$config = new DoctrineConfiguration();
// proxies
$config->setAutoGenerateProxyClasses($opts['auto_generate_proxies']);
$config->setProxyDir($opts['proxy_dir']);
$config->setProxyNamespace($opts['proxy_namespace']);
// entity namespaces
$config->setEntityNamespaces($opts['entity_namespaces']);
// add custom functions
$config->setCustomDatetimeFunctions($opts['custom_datetime_functions']);
$config->setCustomStringFunctions($opts['custom_string_functions']);
$config->setCustomNumericFunctions($opts['custom_numeric_functions']);
// custom queries
foreach ($opts['named_queries'] as $query) {
$config->addNamedQuery($query['name'], $query['dql']);
}
foreach ($opts['named_native_queries'] as $query) {
$config->addNamedNativeQuery($query['name'], $query['sql'], new $query['rsm']());
}
// caching
$config->setQueryCacheImpl($this->queryCache);
$config->setMetadataCacheImpl($this->metadataCache);
$config->setResultCacheImpl($this->metadataCache);
// logger
$config->setSQLLogger($this->logger);
// finally, the driver
$config->setMetadataDriverImpl($this->metadataDriver);
$this->instance = $config;
}
示例9: register
public function register(Container $c)
{
parent::register($c);
$c['orm.options'] = array();
$c['orm.types'] = array();
$c['orm.proxies_dir'] = sys_get_temp_dir();
$c['orm.proxies_namespace'] = 'DoctrineProxy';
$c['orm.auto_generate_proxies'] = $c->factory(function ($c) {
return $c['debug'];
});
$c['orm.custom.functions.string'] = array();
$c['orm.custom.functions.numeric'] = array();
$c['orm.custom.functions.datetime'] = array();
$c['orm.custom.hydration_modes'] = array();
$c['orm.class_metadata_factory_name'] = 'Doctrine\\ORM\\Mapping\\ClassMetadataFactory';
$c['orm.default_repository_class'] = 'Doctrine\\ORM\\EntityRepository';
$c['orm.initialize'] = $c->protect(function () use($c) {
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
if (!isset($c['orm.options'])) {
$c['orm.options'] = array('default' => array());
} elseif (!is_array(reset($c['orm.options']))) {
// Se o primeiro elemento do array de opções não for um array,
// muito provavelmente o usuário está colocando as options de
// uma única conexão, então usar como default
$c['orm.options'] = array('default' => $c['orm.options']);
}
$tmp = $c['orm.options'];
foreach ($tmp as $name => &$options) {
if (!isset($options['connection'])) {
throw new \LogicException("Missing 'connection' param in Doctrine ORM in {$name}.");
}
if (is_string($options['connection'])) {
$options['connection'] = $c['dbal.options'][$options['connection']];
} elseif (!is_array($options['connection']) && !$options['connection'] instanceof Connection) {
throw new \LogicException("Param 'connection' in {$name} must be a string, array or a Connection instance.");
}
}
$c['orm.options'] = $tmp;
$c['orm.defaultName'] = key($c['orm.options']);
});
$c['orm.ems'] = function ($c) {
$c['orm.initialize']();
$ems = new Container();
foreach ($c['orm.options'] as $name => $options) {
$config = $c['orm.configs'][$name];
$connection = $options['connection'];
$ems[$name] = function ($ems) use($connection, $config) {
return EntityManager::create($connection, $config);
};
}
return $ems;
};
$c['orm.configs'] = function ($c) {
$c['orm.initialize']();
$configs = new Container();
foreach ($c['orm.options'] as $name => $options) {
$configs[$name] = $config = new Configuration();
$config->setProxyDir($c['orm.proxies_dir']);
$config->setProxyNamespace($c['orm.proxies_namespace']);
$config->setAutoGenerateProxyClasses($c['orm.auto_generate_proxies']);
$config->setCustomStringFunctions($c['orm.custom.functions.string']);
$config->setCustomNumericFunctions($c['orm.custom.functions.numeric']);
$config->setCustomDatetimeFunctions($c['orm.custom.functions.datetime']);
$config->setCustomHydrationModes($c['orm.custom.hydration_modes']);
$config->setClassMetadataFactoryName($c['orm.class_metadata_factory_name']);
$config->setDefaultRepositoryClassName($c['orm.default_repository_class']);
$config->setEntityListenerResolver($c['orm.entity_listener_resolver']);
$config->setRepositoryFactory($c['orm.repository_factory']);
$config->setNamingStrategy($c['orm.strategy.naming']);
$config->setQuoteStrategy($c['orm.strategy.quote']);
$chain = new MappingDriverChain();
$config->setMetadataDriverImpl($chain);
foreach ((array) $options['mappings'] as $entity) {
if (!is_array($entity)) {
throw new \InvalidArgumentException("The 'orm.options' option 'mappings' should be an array of arrays.");
}
if (isset($entity['alias'])) {
$config->addEntityNamespace($entity['alias'], $entity['namespace']);
}
switch ($entity['type']) {
case 'annotation':
if (isset($c['annotation.reader'])) {
$driver = new AnnotationDriver($c['annotation.reader'], (array) $entity['path']);
} else {
$simple = isset($entity['use_simple_annotation_reader']) ? $entity['use_simple_annotation_reader'] : true;
$driver = $config->newDefaultAnnotationDriver((array) $entity['path'], $simple);
}
break;
case 'yml':
$driver = new YamlDriver($entity['path']);
break;
case 'simple_yml':
$driver = new SimplifiedYamlDriver(array($entity['path'] => $entity['namespace']));
break;
case 'xml':
$driver = new XmlDriver($entity['path']);
//.........这里部分代码省略.........
示例10: setupCustomDQLFunctions
/**
* Setup custom DQL functions.
*
* @param \Doctrine\ORM\Configuration $config
* @param array $options
*/
protected static function setupCustomDQLFunctions(Configuration &$config, array $options)
{
$config->setCustomStringFunctions($options['string_functions']);
$config->setCustomNumericFunctions($options['numeric_functions']);
$config->setCustomDatetimeFunctions($options['datetime_functions']);
}