本文整理汇总了PHP中Doctrine\ODM\MongoDB\Types\Type类的典型用法代码示例。如果您正苦于以下问题:PHP Type类的具体用法?PHP Type怎么用?PHP Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Register custom doctrine types
*/
public function __construct()
{
if (class_exists('\\Doctrine\\ODM\\MongoDB\\Types\\Type')) {
\Doctrine\ODM\MongoDB\Types\Type::registerType(self::ODM_ENTITIES_TYPE, 'Akeneo\\Bundle\\StorageUtilsBundle\\Doctrine\\MongoDBODM\\Types\\Entities');
\Doctrine\ODM\MongoDB\Types\Type::registerType(self::ODM_ENTITY_TYPE, 'Akeneo\\Bundle\\StorageUtilsBundle\\Doctrine\\MongoDBODM\\Types\\Entity');
}
}
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:10,代码来源:AkeneoStorageUtilsBundle.php
示例2: __construct
/**
* Register cuctom doctrine types
*/
public function __construct()
{
if (class_exists('\\Doctrine\\ODM\\MongoDB\\Types\\Type')) {
\Doctrine\ODM\MongoDB\Types\Type::registerType(self::ODM_ENTITIES_TYPE, 'Pim\\Bundle\\CatalogBundle\\MongoDB\\Type\\Entities');
\Doctrine\ODM\MongoDB\Types\Type::registerType(self::ODM_ENTITY_TYPE, 'Pim\\Bundle\\CatalogBundle\\MongoDB\\Type\\Entity');
}
}
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:10,代码来源:PimCatalogBundle.php
示例3: testConvertToPHPValue
/**
* @dataProvider convertToPHPValueProvider
*
* @param array $ref reference as from mongo
* @param string $routeId name of route that should get loaded
* @param string $url url we expect to result from the conversion
*
* @return void
*/
public function testConvertToPHPValue($ref, $routeId, $url)
{
$this->doubles['router']->expects($this->once())->method('generate')->with($this->equalTo($routeId), $this->equalTo(array('id' => $ref['$id'])))->will($this->returnValue($url));
$sut = Type::getType('extref');
$sut->setRouter($this->doubles['router']);
$this->assertEquals($url, $sut->convertToPHPValue($ref));
}
开发者ID:smoskalenko,项目名称:graviton,代码行数:16,代码来源:ExtReferenceTest.php
示例4: installTypes
public function installTypes()
{
foreach ($this->types as $type => $class) {
if (!MongoDBType::hasType($type)) {
MongoDBType::addType($type, $class);
}
}
}
开发者ID:rhapsody-project,项目名称:crypto-bundle,代码行数:8,代码来源:TypeInstaller.php
示例5: ensureArray
/**
* @param mixed|self $expression
* @return mixed
*/
protected function ensureArray($expression)
{
// Convert field names in expressions
if (is_string($expression) && substr($expression, 0, 1) === '$') {
return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
}
// Convert PHP types to MongoDB types for everything else
return Type::convertPHPToDatabaseValue(parent::ensureArray($expression));
}
开发者ID:doctrine,项目名称:mongodb-odm,代码行数:13,代码来源:Expr.php
示例6: boot
/**
* inject services into custom type
*
* @return void
*/
public function boot()
{
/* @var $router Router */
$router = $this->container->get('router');
/* @var $type \Graviton\DocumentBundle\Types\ExtReference */
$type = Type::getType('extref');
$type->setRouter($router);
$type->setMapping($this->container->getParameter('graviton.document.type.extref.mapping'));
}
开发者ID:smoskalenko,项目名称:graviton,代码行数:14,代码来源:GravitonDocumentBundle.php
示例7: testClosureToPHP
/**
* @dataProvider provideDatabaseToPHPValues
*/
public function testClosureToPHP($input, $output)
{
$type = Type::getType(Type::DATE);
$return = null;
call_user_func(function ($value) use($type, &$return) {
eval($type->closureToPHP());
}, $input);
$this->assertInstanceOf('DateTime', $return);
$this->assertTimestampEquals($output, $return);
}
开发者ID:im286er,项目名称:ent,代码行数:13,代码来源:DateTypeTest.php
示例8: onBootstrap
/**
* Sets up services on the bootstrap event.
*
* @internal
* Creates the translation service and a ModuleRouteListener
*
* @param MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
// Register the TimezoneAwareDate type with DoctrineMongoODM
// Use it in Annotions ( @Field(type="tz_date") )
if (!DoctrineType::hasType('tz_date')) {
DoctrineType::addType('tz_date', '\\Core\\Repository\\DoctrineMongoODM\\Types\\TimezoneAwareDate');
}
$sm = $e->getApplication()->getServiceManager();
$translator = $sm->get('translator');
// initialise translator!
\Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
$eventManager = $e->getApplication()->getEventManager();
$sharedManager = $eventManager->getSharedManager();
# $LogListener = new LogListener();
# $LogListener->attach($eventManager);
if (!\Zend\Console\Console::isConsole()) {
$redirectCallback = function () use($e) {
$routeMatch = $e->getRouteMatch();
$lang = $routeMatch ? $routeMatch->getParam('lang', 'en') : 'en';
$uri = $e->getRouter()->getBaseUrl() . '/' . $lang . '/error';
header('Location: ' . $uri);
};
$errorHandlerListener = new ErrorHandlerListener($sm->get('ErrorLogger'), $redirectCallback);
$errorHandlerListener->attach($eventManager);
$languageRouteListener = new LanguageRouteListener();
$languageRouteListener->attach($eventManager);
$ajaxRenderListener = new AjaxRenderListener();
$ajaxRenderListener->attach($eventManager);
$enforceJsonResponseListener = new EnforceJsonResponseListener();
$enforceJsonResponseListener->attach($eventManager);
$stringListener = new StringListener();
$stringListener->attach($eventManager);
//
$notificationlistener = $sm->get('Core/Listener/Notification');
$notificationlistener->attachShared($sharedManager);
$notificationAjaxHandler = new NotificationAjaxHandler();
$eventManager->attach(MvcEvent::EVENT_DISPATCH, array($notificationAjaxHandler, 'injectView'), -20);
$notificationlistener->attach(NotificationEvent::EVENT_NOTIFICATION_HTML, array($notificationAjaxHandler, 'render'), -20);
}
$persistenceListener = new PersistenceListener();
$persistenceListener->attach($eventManager);
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($event) {
$application = $event->getApplication();
if ($application::ERROR_EXCEPTION == $event->getError()) {
$ex = $event->getParam('exception');
if (404 == $ex->getCode()) {
$event->setError($application::ERROR_CONTROLLER_NOT_FOUND);
}
}
}, 500);
$eventManager->attach(MvcEvent::EVENT_DISPATCH, function ($event) use($eventManager) {
$eventManager->trigger('postDispatch', $event);
}, -150);
}
开发者ID:vfulco,项目名称:YAWIK,代码行数:62,代码来源:Module.php
示例9: checkCoordinateType
/**
* @param ClassMetadata $classMetadata
*/
protected function checkCoordinateType(ClassMetadata $classMetadata)
{
foreach ($classMetadata->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['cubiche:coordinate'])) {
$type = 'Coordinate';
if (!Type::hasType($type)) {
Type::registerType($type, CoordinateType::class);
}
$classMetadata->fieldMappings[$fieldName]['type'] = $type;
}
}
}
开发者ID:cubiche,项目名称:cubiche,代码行数:15,代码来源:EventListener.php
示例10: convertToPHPValue
public function convertToPHPValue($value)
{
if ($value === null) {
return null;
}
if (!is_array($value)) {
throw new CustomTypeException('Array expected.');
}
$converter = Type::getType('date');
$value = array_map(function ($date) use($converter) {
return $converter->convertToPHPValue($date);
}, array_values($value));
return $value;
}
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:14,代码来源:CustomTypeTest.php
示例11: checkIdType
/**
* @param ClassMetadata $classMetadata
*
* @throws MappingException
*/
protected function checkIdType(ClassMetadata $classMetadata)
{
foreach ($classMetadata->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['cubiche:id'])) {
$idMapping = $mapping['cubiche:id'];
$type = str_replace('\\', '.', $idMapping['type']);
if (!Type::hasType($type)) {
Type::registerType($type, DynamicIdType::class);
Type::getType($type)->setTargetClass($idMapping['type']);
}
$classMetadata->fieldMappings[$fieldName]['type'] = $type;
}
}
}
开发者ID:cubiche,项目名称:cubiche,代码行数:19,代码来源:EventListener.php
示例12: convertToPHPValue
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value)
{
if ($value === null) {
return new ArrayList();
}
if (is_array($value) || $value instanceof \Traversable) {
$items = array();
$type = Type::getType($this->innerType);
foreach ($value as $item) {
$items[] = $type->convertToPHPValue($item);
}
return new ArrayList($items);
}
return parent::convertToPHPValue($value);
}
开发者ID:cubiche,项目名称:cubiche,代码行数:18,代码来源:ArrayListType.php
示例13: testCreation
public function testCreation()
{
$logger = $this->getMockForAbstractClass('DoctrineMongoODMModule\\Logging\\Logger');
$metadataCache = $this->getMockForAbstractClass('Doctrine\\Common\\Cache\\Cache');
$mappingDriver = $this->getMockForAbstractClass('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
$serviceLocator = $this->getMockForAbstractClass('Zend\\ServiceManager\\ServiceLocatorInterface');
$serviceLocator->expects($this->exactly(4))->method('get')->withConsecutive(array('Configuration'), array('stubbed_logger'), array('doctrine.cache.stubbed_metadatacache'), array('doctrine.driver.stubbed_driver'))->willReturnOnConsecutiveCalls(array('doctrine' => array('configuration' => array('odm_test' => array('logger' => 'stubbed_logger', 'metadata_cache' => 'stubbed_metadatacache', 'driver' => 'stubbed_driver', 'generate_proxies' => true, 'proxy_dir' => 'data/DoctrineMongoODMModule/Proxy', 'proxy_namespace' => 'DoctrineMongoODMModule\\Proxy', 'generate_hydrators' => true, 'hydrator_dir' => 'data/DoctrineMongoODMModule/Hydrator', 'hydrator_namespace' => 'DoctrineMongoODMModule\\Hydrator', 'default_db' => 'default_db', 'filters' => array(), 'types' => array('CustomType' => 'DoctrineMongoODMModuleTest\\Assets\\CustomType'), 'classMetadataFactoryName' => 'stdClass')))), $logger, $metadataCache, $mappingDriver);
$factory = new ConfigurationFactory('odm_test');
$config = $factory->createService($serviceLocator);
$this->assertInstanceOf('Doctrine\\ODM\\MongoDB\\Configuration', $config);
$this->assertNotNull($config->getLoggerCallable());
$this->assertSame($metadataCache, $config->getMetadataCacheImpl());
$this->assertSame($mappingDriver, $config->getMetadataDriverImpl());
$this->assertInstanceOf('DoctrineMongoODMModuleTest\\Assets\\CustomType', \Doctrine\ODM\MongoDB\Types\Type::getType('CustomType'));
}
开发者ID:RageZBla,项目名称:DoctrineMongoODMModule,代码行数:15,代码来源:ConfigurationFactoryTest.php
示例14: checkTypes
/**
* @param ClassMetadata $classMetadata
*/
protected function checkTypes(ClassMetadata $classMetadata)
{
$types = array_keys($this->typeMapping);
foreach ($classMetadata->fieldMappings as $fieldName => $mapping) {
foreach ($types as $type) {
if (isset($mapping['cubiche:' . $type])) {
$typeName = substr($this->typeMapping[$type], strrpos($this->typeMapping[$type], '\\') + 1);
if (!Type::hasType($typeName)) {
Type::registerType($typeName, $this->typeMapping[$type]);
}
$classMetadata->fieldMappings[$fieldName]['type'] = $typeName;
break;
}
}
}
}
开发者ID:cubiche,项目名称:cubiche,代码行数:19,代码来源:EventListener.php
示例15: dm
/**
* @return \Doctrine\ODM\MongoDB\DocumentManager
*/
public function dm()
{
if ($this->dm === null) {
$this->dm = $this->createTestDocumentManager();
$this->uow = $this->dm->getUnitOfWork();
Type::addType('Phonenumber', PhonenumberType::class);
Type::addType('Role', RoleType::class);
$this->dm->getEventManager()->addEventSubscriber(new MetadataEventSubscriber());
$this->dm->getEventManager()->addEventSubscriber(new CollectionsEventSubscriber());
$this->dm->getEventManager()->addEventSubscriber(new ModelEventSubscriber());
$this->dm->getEventManager()->addEventSubscriber(new IdentityEventSubscriber());
$this->dm->getEventManager()->addEventSubscriber(new GeolocationEventSubscriber());
$this->dm->getEventManager()->addEventSubscriber(new SystemEventSubscriber());
}
return $this->dm;
}
开发者ID:cubiche,项目名称:cubiche,代码行数:19,代码来源:DocumentManagerTestCaseTrait.php
示例16: setUp
public function setUp()
{
Type::hasType('object') ? Type::overrideType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType') : Type::addType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType');
$config = new Configuration();
$config->setProxyDir(\sys_get_temp_dir());
$config->setProxyNamespace('PayumTestsProxies');
$config->setHydratorDir(\sys_get_temp_dir());
$config->setHydratorNamespace('PayumTestsHydrators');
$config->setMetadataDriverImpl($this->getMetadataDriverImpl($config));
$config->setMetadataCacheImpl(new ArrayCache());
$config->setDefaultDB('payum_tests');
$connection = new Connection(null, array(), $config);
$this->dm = DocumentManager::create($connection, $config);
foreach ($this->dm->getConnection()->selectDatabase('payum_tests')->listCollections() as $collection) {
$collection->drop();
}
}
开发者ID:stan5621,项目名称:eduwind,代码行数:17,代码来源:BaseMongoTest.php
示例17: createService
/**
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
* @return \Doctrine\ODM\MongoDB\Configuration
* @throws \Exception
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** @var $options \DoctrineMongoODMModule\Options\Configuration */
$options = $this->getOptions($serviceLocator, 'configuration');
$config = new Configuration();
// logger
if ($options->getLogger()) {
$logger = $serviceLocator->get($options->getLogger());
$config->setLoggerCallable(array($logger, 'log'));
}
// proxies
$config->setAutoGenerateProxyClasses($options->getGenerateProxies());
$config->setProxyDir($options->getProxyDir());
$config->setProxyNamespace($options->getProxyNamespace());
// hydrators
$config->setAutoGenerateHydratorClasses($options->getGenerateHydrators());
$config->setHydratorDir($options->getHydratorDir());
$config->setHydratorNamespace($options->getHydratorNamespace());
// default db
$config->setDefaultDB($options->getDefaultDb());
// caching
$config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache()));
// retries
$config->setRetryConnect($options->getRetryConnect());
$config->setRetryQuery($options->getRetryQuery());
// Register filters
foreach ($options->getFilters() as $alias => $class) {
$config->addFilter($alias, $class);
}
// the driver
$config->setMetadataDriverImpl($serviceLocator->get($options->getDriver()));
// metadataFactory, if set
if ($factoryName = $options->getClassMetadataFactoryName()) {
$config->setClassMetadataFactoryName($factoryName);
}
// custom types
foreach ($options->getTypes() as $name => $class) {
if (Type::hasType($name)) {
Type::overrideType($name, $class);
} else {
Type::addType($name, $class);
}
}
return $config;
}
开发者ID:RageZBla,项目名称:DoctrineMongoODMModule,代码行数:50,代码来源:ConfigurationFactory.php
示例18: setUp
public function setUp()
{
$this->skipTestsIfPhp7();
if (false == (class_exists(\MongoId::class) && class_exists(Connection::class))) {
$this->markTestSkipped('Either mongo extension or\\and doctrine\\mongo-odm are not installed.');
}
Type::hasType('object') ? Type::overrideType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType') : Type::addType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType');
$config = new Configuration();
$config->setProxyDir(\sys_get_temp_dir());
$config->setProxyNamespace('PayumTestsProxies');
$config->setHydratorDir(\sys_get_temp_dir());
$config->setHydratorNamespace('PayumTestsHydrators');
$config->setMetadataDriverImpl($this->getMetadataDriverImpl($config));
$config->setMetadataCacheImpl(new ArrayCache());
$config->setDefaultDB('payum_tests');
$connection = new Connection(null, array(), $config);
$this->dm = DocumentManager::create($connection, $config);
foreach ($this->dm->getConnection()->selectDatabase('payum_tests')->listCollections() as $collection) {
$collection->drop();
}
}
开发者ID:piotrantosik,项目名称:Payum,代码行数:21,代码来源:BaseMongoTest.php
示例19: bootstrapDoctrine
public function bootstrapDoctrine(MvcEvent $event)
{
$serviceManager = $event->getApplication()->getServiceManager();
/** @var Options\ModuleOptions $moduleOptions */
$moduleOptions = $serviceManager->get(__NAMESPACE__ . '\\Options\\ModuleOptions');
if ($moduleOptions->getDoctrine()->registerUuidType()) {
if (!class_exists('Rhumsaa\\Uuid\\Uuid')) {
throw new Exception\RuntimeException('Failed to register "uuid" Doctrine mapping type: ' . 'Missing required class Rhumsaa\\Uuid\\Uuid');
}
if (class_exists(DoctrineOrmTypes\Type::CLASS)) {
DoctrineOrmTypes\Type::addType(DoctrineUuidType::NAME, DoctrineUuidType::CLASS);
}
if (class_exists(DoctrineOdmTypes\Type::CLASS)) {
DoctrineOdmTypes\Type::registerType(DoctrineOdmUuidType::NAME, DoctrineOdmUuidType::CLASS);
}
}
if ($moduleOptions->getDoctrine()->registerDatetimeImmutableType()) {
if (class_exists(DoctrineOdmTypes\Type::CLASS)) {
DoctrineOdmTypes\Type::registerType(DoctrineOdmDateTimeImmutType::NAME, DoctrineOdmDateTimeImmutType::CLASS);
}
}
if ($moduleOptions->getDoctrine()->registerDatetimeNoTzType()) {
if (class_exists(DoctrineOdmTypes\Type::CLASS)) {
DoctrineOdmTypes\Type::registerType(DoctrineOdmDateTimeNoTzType::NAME, DoctrineOdmDateTimeNoTzType::CLASS);
}
}
if ($moduleOptions->getDoctrine()->registerDatetimeImmutableNoTzType()) {
if (class_exists(DoctrineOdmTypes\Type::CLASS)) {
DoctrineOdmTypes\Type::registerType(DoctrineOdmDateTimeImmutNoTzType::NAME, DoctrineOdmDateTimeImmutNoTzType::CLASS);
}
}
// /** @var \Zend\ServiceManager\ServiceManager $serviceManager */
// $serviceManager = $event->getApplication()->getServiceManager();
//
// /** @var \Doctrine\ORM\EntityManager $entityManager */
// $entityManager = $serviceManager->get('Doctrine\ORM\EntityManager');
// $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('db_mytype', 'mytype');
}
开发者ID:detailnet,项目名称:dfw-persistence-module,代码行数:38,代码来源:Module.php
示例20: createStorage
/**
* {@inheritDoc}
*/
public function createStorage($modelClass, $idProperty, array $options)
{
if (false == Type::hasType('object')) {
Type::addType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType');
}
$driver = new MappingDriverChain();
// payum's basic models
$coreRootDir = dirname((new \ReflectionClass(GatewayInterface::class))->getFileName());
$driver->addDriver(new XmlDriver(new SymfonyFileLocator(array($coreRootDir . '/Bridge/Doctrine/Resources/mapping' => 'Payum\\Core\\Model'), '.mongodb.xml'), '.mongodb.xml'), 'Payum\\Core\\Model');
// your models
$sererRootDir = dirname((new \ReflectionClass(Application::class))->getFileName());
AnnotationDriver::registerAnnotationClasses();
$driver->addDriver(new AnnotationDriver(new AnnotationReader(), array($sererRootDir . '/Model')), 'Payum\\Server\\Model');
$config = new Configuration();
$config->setProxyDir(\sys_get_temp_dir() . '/PayumServer');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(\sys_get_temp_dir() . '/PayumServer');
$config->setHydratorNamespace('Hydrators');
$config->setMetadataDriverImpl($driver);
$config->setMetadataCacheImpl(new ArrayCache());
$config->setDefaultDB($options['databaseName']);
$connection = new Connection($options['host'], array(), $config);
return new DoctrineStorage(DocumentManager::create($connection, $config), $modelClass);
}
开发者ID:Headd2k,项目名称:PayumServer,代码行数:27,代码来源:DoctrineMongoDbFactory.php
注:本文中的Doctrine\ODM\MongoDB\Types\Type类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论