本文整理汇总了PHP中Doctrine\ODM\MongoDB\Types\Type类的典型用法代码示例。如果您正苦于以下问题:PHP Type类的具体用法?PHP Type怎么用?PHP Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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');
}
}
示例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');
}
}
示例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));
}
示例4: installTypes
public function installTypes()
{
foreach ($this->types as $type => $class) {
if (!MongoDBType::hasType($type)) {
MongoDBType::addType($type, $class);
}
}
}
示例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));
}
示例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'));
}
示例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);
}
示例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);
}
示例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;
}
}
}
示例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;
}
示例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;
}
}
}
示例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);
}
示例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'));
}
示例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;
}
}
}
}
示例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;
}