本文整理汇总了PHP中Doctrine\ODM\MongoDB\MongoDBException类的典型用法代码示例。如果您正苦于以下问题:PHP MongoDBException类的具体用法?PHP MongoDBException怎么用?PHP MongoDBException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MongoDBException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertToDatabaseValue
public function convertToDatabaseValue($value)
{
if ($value !== null && !is_array($value)) {
throw MongoDBException::invalidValueForType('Hash', array('array', 'null'), $value);
}
return $value !== null ? (object) $value : null;
}
示例2: convertToDatabaseValue
public function convertToDatabaseValue($value)
{
if ($value !== null && !is_array($value)) {
throw MongoDBException::invalidValueForType('Collection', array('array', 'null'), $value);
}
return $value !== null ? array_values($value) : null;
}
示例3: getDocumentNamespace
/**
* Resolves a registered namespace alias to the full namespace.
*
* @param string $documentNamespaceAlias
* @return string
* @throws MongoDBException
*/
public function getDocumentNamespace($documentNamespaceAlias)
{
if (!isset($this->attributes['documentNamespaces'][$documentNamespaceAlias])) {
throw MongoDBException::unknownDocumentNamespace($documentNamespaceAlias);
}
return trim($this->attributes['documentNamespaces'][$documentNamespaceAlias], '\\');
}
示例4: getAliasNamespace
/**
* Resolves a registered namespace alias to the full namespace.
*
* @param string $alias
* @return string
* @throws MongoDBException
*/
public function getAliasNamespace($alias)
{
foreach (array_keys($this->getManagers()) as $name) {
try {
return $this->getManager($name)->getConfiguration()->getDocumentNamespace($alias);
} catch (MongoDBException $e) {
}
}
throw MongoDBException::unknownDocumentNamespace($alias);
}
示例5: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadataInfo $class)
{
foreach ($this->drivers as $namespace => $driver) {
if (strpos($className, $namespace) === 0) {
$driver->loadMetadataForClass($className, $class);
return;
}
}
throw MongoDBException::classIsNotAValidDocument($className);
}
示例6: __load
public function __load()
{
if (!$this->__isInitialized__ && $this->__documentPersister__) {
$this->__isInitialized__ = true;
if ($this->__documentPersister__->load($this->__identifier__, $this) === null) {
throw \Doctrine\ODM\MongoDB\MongoDBException::documentNotFound(get_class($this), $this->__identifier__);
}
unset($this->__documentPersister__, $this->__identifier__);
}
}
示例7: __clone
public function __clone()
{
if (!$this->__isInitialized__ && $this->__documentPersister__) {
$this->__isInitialized__ = true;
$class = $this->__documentPersister__->getClassMetadata();
$original = $this->__documentPersister__->load($this->__identifier__);
if ($original === null) {
throw \Doctrine\ODM\MongoDB\MongoDBException::documentNotFound(get_class($this), $this->__identifier__);
}
foreach ($class->reflFields as $field => $reflProperty) {
$reflProperty->setValue($this, $reflProperty->getValue($original));
}
unset($this->__documentPersister__, $this->__identifier__);
}
}
开发者ID:superdweebie,项目名称:identity-module,代码行数:15,代码来源:__CG__SdsIdentityModuleDataModelForgotCredentialToken.php
示例8: doRemove
/**
* Deletes an document as part of the current unit of work.
*
* This method is internally called during delete() cascades as it tracks
* the already visited documents to prevent infinite recursions.
*
* @param object $document The document to delete.
* @param array $visited The map of the already visited documents.
* @throws InvalidArgumentException If the instance is a detached document.
*/
private function doRemove($document, array &$visited)
{
$oid = spl_object_hash($document);
if (isset($visited[$oid])) {
return;
// Prevent infinite recursion
}
$visited[$oid] = $document;
// mark visited
$class = $this->dm->getClassMetadata(get_class($document));
$documentState = $this->getDocumentState($document);
switch ($documentState) {
case self::STATE_NEW:
case self::STATE_REMOVED:
// nothing to do
break;
case self::STATE_MANAGED:
if (isset($class->lifecycleCallbacks[Events::preRemove])) {
$class->invokeLifecycleCallbacks(Events::preRemove, $document);
}
if ($this->evm->hasListeners(Events::preRemove)) {
$this->evm->dispatchEvent(Events::preRemove, new LifecycleEventArgs($document, $this->dm));
}
$this->scheduleForDelete($document);
$this->cascadePreRemove($class, $document);
break;
case self::STATE_DETACHED:
throw MongoDBException::detachedDocumentCannotBeRemoved();
default:
throw MongoDBException::invalidDocumentState($documentState);
}
$this->cascadeRemove($document, $visited);
}
示例9: __call
/**
* Adds support for magic finders.
*
* @param string $method
* @param array $arguments
* @throws MongoDBException
* @throws \BadMethodCallException If the method called is an invalid find* method
* or no find* method at all and therefore an invalid
* method call.
* @return array|object The found document/documents.
*/
public function __call($method, $arguments)
{
if (strpos($method, 'findBy') === 0) {
$by = substr($method, 6, strlen($method));
$method = 'findBy';
} elseif (strpos($method, 'findOneBy') === 0) {
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
} else {
throw new \BadMethodCallException("Undefined method: '{$method}'. The method name must start with 'findBy' or 'findOneBy'!");
}
if (!isset($arguments[0])) {
throw MongoDBException::findByRequiresParameter($method . $by);
}
$fieldName = Inflector::camelize($by);
if ($this->class->hasField($fieldName)) {
return $this->{$method}(array($fieldName => $arguments[0]));
} else {
throw MongoDBException::invalidFindByCall($this->documentName, $fieldName, $method . $by);
}
}
示例10: enableShardingForDbByDocumentName
/**
* Enable sharding for database which contains documents with given name.
*
* @param string $documentName
*
* @throws MongoDBException
*/
public function enableShardingForDbByDocumentName($documentName)
{
$dbName = $this->dm->getDocumentDatabase($documentName)->getName();
$adminDb = $this->dm->getConnection()->selectDatabase('admin');
$result = $adminDb->command(array('enableSharding' => $dbName));
// Error code is only available with MongoDB 3.2. MongoDB 3.0 only returns a message
// Thus, check code if it exists and fall back on error message
if ($result['ok'] == 1 || isset($result['code']) && $result['code'] == 23 || $result['errmsg'] == 'already enabled') {
return;
}
throw MongoDBException::failedToEnableSharding($dbName, $result['errmsg']);
}
示例11: enableShardingForDbByDocumentName
/**
* Enable sharding for database which contains documents with given name.
*
* @param string $documentName
*
* @throws MongoDBException
*/
public function enableShardingForDbByDocumentName($documentName)
{
$dbName = $this->dm->getDocumentDatabase($documentName)->getName();
$adminDb = $this->dm->getConnection()->selectDatabase('admin');
$result = $adminDb->command(array('enableSharding' => $dbName));
if ($result['ok'] != 1 && $result['errmsg'] !== 'already enabled') {
throw MongoDBException::failedToEnableSharding($dbName, $result['errmsg']);
}
}
示例12: findMappingFile
protected function findMappingFile($className)
{
$defaultFileName = str_replace('\\', '.', $className) . $this->fileExtension;
foreach ($this->paths as $path) {
if (!isset($this->prefixes[$path])) {
if (file_exists($path . DIRECTORY_SEPARATOR . $defaultFileName)) {
return $path . DIRECTORY_SEPARATOR . $defaultFileName;
}
continue;
}
$prefix = $this->prefixes[$path];
if (0 !== strpos($className, $prefix . '\\')) {
continue;
}
$filename = $path . '/' . strtr(substr($className, strlen($prefix) + 1), '\\', '.') . $this->fileExtension;
if (file_exists($filename)) {
return $filename;
}
throw MongoDBException::mappingNotFound($className, $filename);
}
throw MongoDBException::mappingNotFound($className, substr($className, strrpos($className, '\\') + 1) . $this->fileExtension);
}
示例13: doRemove
/**
* Deletes a document as part of the current unit of work.
*
* This method is internally called during delete() cascades as it tracks
* the already visited documents to prevent infinite recursions.
*
* @param object $document The document to delete.
* @param array $visited The map of the already visited documents.
* @throws MongoDBException
*/
private function doRemove($document, array &$visited)
{
$oid = spl_object_hash($document);
if (isset($visited[$oid])) {
return;
// Prevent infinite recursion
}
$visited[$oid] = $document;
// mark visited
/* Cascade first, because scheduleForDelete() removes the entity from
* the identity map, which can cause problems when a lazy Proxy has to
* be initialized for the cascade operation.
*/
$this->cascadeRemove($document, $visited);
$class = $this->dm->getClassMetadata(get_class($document));
$documentState = $this->getDocumentState($document);
switch ($documentState) {
case self::STATE_NEW:
case self::STATE_REMOVED:
// nothing to do
break;
case self::STATE_MANAGED:
if (!empty($class->lifecycleCallbacks[Events::preRemove])) {
$class->invokeLifecycleCallbacks(Events::preRemove, $document);
}
if ($this->evm->hasListeners(Events::preRemove)) {
$this->evm->dispatchEvent(Events::preRemove, new LifecycleEventArgs($document, $this->dm));
}
$this->scheduleForDelete($document);
break;
case self::STATE_DETACHED:
throw MongoDBException::detachedDocumentCannotBeRemoved();
default:
throw MongoDBException::invalidDocumentState($documentState);
}
}
示例14: loadMetadata
/**
* Loads the metadata of the class in question and all it's ancestors whose metadata
* is still not loaded.
*
* @param string $name The name of the class for which the metadata should get loaded.
* @param array $tables The metadata collection to which the loaded metadata is added.
*/
private function loadMetadata($className)
{
if (!$this->initialized) {
$this->initialize();
}
$loaded = array();
$parentClasses = $this->getParentClasses($className);
$parentClasses[] = $className;
// Move down the hierarchy of parent classes, starting from the topmost class
$parent = null;
$visited = array();
foreach ($parentClasses as $className) {
if (isset($this->loadedMetadata[$className])) {
$parent = $this->loadedMetadata[$className];
if (!$parent->isMappedSuperclass && !$parent->isEmbeddedDocument) {
array_unshift($visited, $className);
}
continue;
}
$class = $this->newClassMetadataInstance($className);
if ($parent) {
if (!$parent->isMappedSuperclass) {
$class->setInheritanceType($parent->inheritanceType);
$class->setDiscriminatorField($parent->discriminatorField);
$class->setDiscriminatorMap($parent->discriminatorMap);
}
$class->setIdGeneratorType($parent->generatorType);
$this->addInheritedFields($class, $parent);
$this->addInheritedIndexes($class, $parent);
$class->setIdentifier($parent->identifier);
$class->setVersioned($parent->isVersioned);
$class->setVersionField($parent->versionField);
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
$class->setFile($parent->getFile());
}
// Invoke driver
try {
$this->driver->loadMetadataForClass($className, $class);
} catch (ReflectionException $e) {
throw MongoDBException::reflectionFailure($className, $e);
}
if (!$class->identifier && !$class->isMappedSuperclass && !$class->isEmbeddedDocument) {
throw MongoDBException::identifierRequired($className);
}
if ($parent && !$parent->isMappedSuperclass && !$class->isEmbeddedDocument) {
if ($parent->generatorType) {
$class->setIdGeneratorType($parent->generatorType);
}
if ($parent->generatorOptions) {
$class->setIdGeneratorOptions($parent->generatorOptions);
}
if ($parent->idGenerator) {
$class->setIdGenerator($parent->idGenerator);
}
} else {
$this->completeIdGeneratorMapping($class);
}
if ($parent && $parent->isInheritanceTypeSingleCollection()) {
$class->setDatabase($parent->getDatabase());
$class->setCollection($parent->getCollection());
}
$db = $class->getDatabase() ?: $this->config->getDefaultDB();
$class->setDatabase($this->dm->formatDBName($db));
$class->setParentClasses($visited);
if ($this->evm->hasListeners(Events::loadClassMetadata)) {
$eventArgs = new \Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs($class, $this->dm);
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
}
$this->loadedMetadata[$className] = $class;
$parent = $class;
if (!$class->isMappedSuperclass && !$class->isEmbeddedDocument) {
array_unshift($visited, $className);
}
$loaded[] = $className;
}
return $loaded;
}
示例15: execute
/**
* Execute the query and returns the results.
*
* @return mixed
*/
public function execute()
{
$uow = $this->dm->getUnitOfWork();
if ($this->isIndexRequired() && !$this->isIndexed()) {
throw MongoDBException::queryNotIndexed($this->class->name, $this->getUnindexedFields());
}
$results = parent::execute();
$hints = array();
if ($this->refresh) {
$hints[self::HINT_REFRESH] = true;
}
if ($this->query['slaveOkay'] === true) {
$hints[self::HINT_SLAVE_OKAY] = true;
}
// Unwrap the BaseEagerCursor
if ($results instanceof BaseEagerCursor) {
$results = $results->getCursor();
}
// Convert the regular mongodb cursor to the odm cursor
if ($results instanceof BaseCursor) {
$results = $this->wrapCursor($results, $hints);
}
// Wrap odm cursor with EagerCursor if true
if ($this->query['eagerCursor'] === true) {
$results = new EagerCursor($results, $this->dm->getUnitOfWork(), $this->class);
}
// GeoLocationFindQuery just returns an instance of ArrayIterator so we have to
// iterator over it and hydrate each object.
if ($this->query['type'] === self::TYPE_GEO_LOCATION && $this->hydrate) {
foreach ($results as $key => $result) {
$document = $result['obj'];
if ($this->class->distance) {
$document[$this->class->distance] = $result['dis'];
}
$results[$key] = $uow->getOrCreateDocument($this->class->name, $document, $hints);
}
$results->reset();
}
if ($this->primers) {
$documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
foreach ($this->primers as $fieldName => $primer) {
if ($primer) {
$documentPersister->primeCollection($results, $fieldName, $primer, $hints);
}
}
}
if ($this->hydrate && is_array($results) && isset($results['_id'])) {
// Convert a single document array to a document object
$results = $uow->getOrCreateDocument($this->class->name, $results, $hints);
}
return $results;
}