コード例 #1
0
ファイル: CollectionType.php プロジェクト: cosmow/riak-odm
 public function convertToDatabaseValue($value)
 {
     if ($value !== null && !is_array($value)) {
         throw RiakException::invalidValueForType('Collection', array('array', 'null'), $value);
     }
     return $value !== null ? array_values($value) : null;
 }
コード例 #2
0
ファイル: HashType.php プロジェクト: cosmow/riak-odm
 public function convertToDatabaseValue($value)
 {
     if ($value !== null && !is_array($value)) {
         throw RiakException::invalidValueForType('Hash', array('array', 'null'), $value);
     }
     return $value !== null ? (object) $value : null;
 }
コード例 #3
0
ファイル: DocumentManager.php プロジェクト: cosmow/riak-odm
 /**
  * Throws an exception if the DocumentManager is closed or currently not active.
  *
  * @throws RiakException If the DocumentManager is closed.
  */
 private function errorIfClosed()
 {
     if ($this->closed) {
         throw RiakException::documentManagerClosed();
     }
 }
コード例 #4
0
 /**
  * Adds support for magic finders.
  *
  * @param string $method
  * @param array $arguments
  * @throws RiakException
  * @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 (substr($method, 0, 6) == 'findBy') {
         $by = substr($method, 6, strlen($method));
         $method = 'findBy';
     } elseif (substr($method, 0, 9) == 'findOneBy') {
         $by = substr($method, 9, strlen($method));
         $method = 'findOneBy';
     } else {
         throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
     }
     if (!isset($arguments[0])) {
         throw RiakException::findByRequiresParameter($method . $by);
     }
     $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
     if ($this->class->hasField($fieldName)) {
         return $this->{$method}(array($fieldName => $arguments[0]));
     } else {
         throw RiakException::invalidFindByCall($this->documentName, $fieldName, $method . $by);
     }
 }
コード例 #5
0
ファイル: UnitOfWork.php プロジェクト: cosmow/riak-odm
 /**
  * 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 RiakException
  */
 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 RiakException::detachedDocumentCannotBeRemoved();
         default:
             throw RiakException::invalidDocumentState($documentState);
     }
 }
コード例 #6
0
ファイル: Configuration.php プロジェクト: cosmow/riak-odm
 /**
  * Sets default repository class.
  *
  * @param string $className
  *
  * @return void
  *
  * @throws RiakException If not is a ObjectRepository
  */
 public function setDefaultRepositoryClassName($className)
 {
     $reflectionClass = new \ReflectionClass($className);
     if (!$reflectionClass->implementsInterface('Doctrine\\Common\\Persistence\\ObjectRepository')) {
         throw RiakException::invalidDocumentRepository($className);
     }
     $this->attributes['defaultRepositoryClassName'] = $className;
 }
コード例 #7
0
ファイル: Query.php プロジェクト: cosmow/riak-odm
 /**
  * Execute the query and returns the results.
  *
  * @throws \CosmoW\ODM\Riak\RiakException
  * @return mixed
  */
 public function execute()
 {
     if ($this->isIndexRequired() && !$this->isIndexed()) {
         throw RiakException::queryNotIndexed($this->class->name, $this->getUnindexedFields());
     }
     $results = parent::execute();
     if (!$this->hydrate) {
         return $results;
     }
     $uow = $this->dm->getUnitOfWork();
     /* A geoNear command returns an ArrayIterator, where each result is an
      * object with "dis" (computed distance) and "obj" (original document)
      * properties. If hydration is enabled, eagerly hydrate these results.
      *
      * Other commands results are not handled, since their results may not
      * resemble documents in the collection.
      */
     if ($this->query['type'] === self::TYPE_GEO_NEAR) {
         foreach ($results as $key => $result) {
             $document = $result['obj'];
             if ($this->class->distance !== null) {
                 $document[$this->class->distance] = $result['dis'];
             }
             $results[$key] = $uow->getOrCreateDocument($this->class->name, $document, $this->unitOfWorkHints);
         }
         $results->reset();
     }
     /* If a single document is returned from a findAndModify command and it
      * includes the identifier field, attempt hydration.
      */
     if (($this->query['type'] === self::TYPE_FIND_AND_UPDATE || $this->query['type'] === self::TYPE_FIND_AND_REMOVE) && is_array($results) && isset($results['_id'])) {
         $results = $uow->getOrCreateDocument($this->class->name, $results, $this->unitOfWorkHints);
         if (!empty($this->primers)) {
             $referencePrimer = new ReferencePrimer($this->dm, $uow);
             foreach ($this->primers as $fieldName => $primer) {
                 $primer = is_callable($primer) ? $primer : null;
                 $referencePrimer->primeReferences($this->class, array($results), $fieldName, $this->unitOfWorkHints, $primer);
             }
         }
     }
     return $results;
 }