本文整理汇总了PHP中Doctrine\ODM\MongoDB\Types\Type::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::getType方法的具体用法?PHP Type::getType怎么用?PHP Type::getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Types\Type
的用法示例。
在下文中一共展示了Type::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: 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'));
}
示例3: 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);
}
示例4: checkEnumType
/**
* @param ClassMetadata $classMetadata
*
* @throws MappingException
*/
protected function checkEnumType(ClassMetadata $classMetadata)
{
foreach ($classMetadata->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['cubiche:enum'])) {
$enumMapping = $mapping['cubiche:enum'];
$type = str_replace('\\', '.', $enumMapping['type']);
if (!Type::hasType($type)) {
Type::registerType($type, DynamicEnumType::class);
Type::getType($type)->setTargetClass($enumMapping['type']);
}
$classMetadata->fieldMappings[$fieldName]['type'] = $type;
}
}
}
示例5: 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;
}
示例6: 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);
}
示例7: 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'));
}
示例8: computeOrRecomputeChangeSet
/**
* Used to do the common work of computeChangeSet and recomputeSingleDocumentChangeSet
*
* @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class
* @param object $document
* @param boolean $recompute
*/
private function computeOrRecomputeChangeSet(ClassMetadata $class, $document, $recompute = false)
{
$oid = spl_object_hash($document);
$actualData = $this->getDocumentActualData($document);
$isNewDocument = !isset($this->originalDocumentData[$oid]);
if ($isNewDocument) {
// Document is either NEW or MANAGED but not yet fully persisted (only has an id).
// These result in an INSERT.
$this->originalDocumentData[$oid] = $actualData;
$changeSet = array();
foreach ($actualData as $propName => $actualValue) {
$changeSet[$propName] = array(null, $actualValue);
}
$this->documentChangeSets[$oid] = $changeSet;
} else {
// Document is "fully" MANAGED: it was already fully persisted before
// and we have a copy of the original data
$originalData = $this->originalDocumentData[$oid];
$isChangeTrackingNotify = $class->isChangeTrackingNotify();
if ($isChangeTrackingNotify && !$recompute) {
$changeSet = $this->documentChangeSets[$oid];
} else {
$changeSet = array();
}
foreach ($actualData as $propName => $actualValue) {
// skip not saved fields
if (isset($class->fieldMappings[$propName]['notSaved']) && $class->fieldMappings[$propName]['notSaved'] === true) {
continue;
}
$orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null;
// skip if value has not changed
if ($orgValue === $actualValue) {
// but consider dirty GridFSFile instances as changed
if (!(isset($class->fieldMappings[$propName]['file']) && $actualValue->isDirty())) {
continue;
}
}
// if relationship is a embed-one, schedule orphan removal to trigger cascade remove operations
if (isset($class->fieldMappings[$propName]['embedded']) && $class->fieldMappings[$propName]['type'] === 'one') {
if ($orgValue !== null) {
$this->scheduleOrphanRemoval($orgValue);
}
$changeSet[$propName] = array($orgValue, $actualValue);
continue;
}
// if owning side of reference-one relationship
if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['type'] === 'one' && $class->fieldMappings[$propName]['isOwningSide']) {
if ($orgValue !== null && $class->fieldMappings[$propName]['orphanRemoval']) {
$this->scheduleOrphanRemoval($orgValue);
}
$changeSet[$propName] = array($orgValue, $actualValue);
continue;
}
if ($isChangeTrackingNotify) {
continue;
}
// ignore inverse side of reference-many relationship
if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['type'] === 'many' && $class->fieldMappings[$propName]['isInverseSide']) {
continue;
}
// Persistent collection was exchanged with the "originally"
// created one. This can only mean it was cloned and replaced
// on another document.
if ($actualValue instanceof PersistentCollection) {
$owner = $actualValue->getOwner();
if ($owner === null) {
// cloned
$actualValue->setOwner($document, $class->fieldMappings[$propName]);
} elseif ($owner !== $document) {
// no clone, we have to fix
if (!$actualValue->isInitialized()) {
$actualValue->initialize();
// we have to do this otherwise the cols share state
}
$newValue = clone $actualValue;
$newValue->setOwner($document, $class->fieldMappings[$propName]);
$class->reflFields[$propName]->setValue($document, $newValue);
}
}
// if embed-many or reference-many relationship
if (isset($class->fieldMappings[$propName]['type']) && $class->fieldMappings[$propName]['type'] === 'many') {
$changeSet[$propName] = array($orgValue, $actualValue);
if ($orgValue instanceof PersistentCollection) {
$this->scheduleCollectionDeletion($orgValue);
}
continue;
}
// skip equivalent date values
if (isset($class->fieldMappings[$propName]['type']) && $class->fieldMappings[$propName]['type'] === 'date') {
$dateType = Type::getType('date');
$dbOrgValue = $dateType->convertToDatabaseValue($orgValue);
$dbActualValue = $dateType->convertToDatabaseValue($actualValue);
if ($dbOrgValue instanceof \MongoDate && $dbActualValue instanceof \MongoDate && $dbOrgValue == $dbActualValue) {
//.........这里部分代码省略.........
示例9: testHashDoesntAcceptScalar
/**
* @expectedException \Doctrine\ODM\MongoDB\MongoDBException
* @expectedExceptionMessage Hash type requires value of type array or null, scalar given
*/
public function testHashDoesntAcceptScalar()
{
$t = Type::getType('hash');
$t->convertToDatabaseValue(true);
}
示例10: getType
private function getType($type)
{
// due to change in ODM beta 9
return class_exists('Doctrine\\ODM\\MongoDB\\Types\\Type') ? \Doctrine\ODM\MongoDB\Types\Type::getType($type) : \Doctrine\ODM\MongoDB\Mapping\Types\Type::getType($type);
}
示例11: closureToPHP
public function closureToPHP()
{
return '$process = $value;foreach ($process as $key => $value) { if ($value) { ' . Type::getType('dough_currency_money')->closureToPHP() . '$process[$key] = $return; } } $return = $process;';
}
示例12: setUp
/**
* setup type we want to test
*
* @return void
*/
public function setUp()
{
Type::registerType('hasharray', HashArrayType::class);
$this->type = Type::getType('hasharray');
}
示例13: testClosureToPHP
public function testClosureToPHP()
{
$type = Type::getType('dough_money');
$this->assertSame('$return = new \\Dough\\Money\\Money($value);', $type->closureToPHP());
}
示例14: testConvertToDatabaseValueShouldGenerateMongoIds
/**
* @dataProvider provideInvalidMongoIdConstructorArguments
*/
public function testConvertToDatabaseValueShouldGenerateMongoIds($value)
{
$type = Type::getType('id');
$this->assertInstanceOf('MongoId', $type->convertToDatabaseValue($value));
}
示例15: getDatabaseIdentifierValue
/**
* Casts the identifier to its database type.
*
* @param mixed $id
* @return mixed $id
*/
public function getDatabaseIdentifierValue($id)
{
$idType = $this->fieldMappings[$this->identifier]['type'];
return Type::getType($idType)->convertToDatabaseValue($id);
}