public function testFindWithValidDocument()
 {
     $image = new GridFSFile();
     $image->setBytes('01010101');
     $this->repo->expects($this->atLeastOnce())->method('find')->with($this->isInstanceOf('\\MongoId'))->will($this->returnValue(array('file' => $image)));
     $this->assertEquals('01010101', $this->loader->find('0123456789abcdef01234567'));
 }
Exemplo n.º 2
0
 public function hydrate($value, $data = Null, $object = Null)
 {
     $organizationImageEntity = $value;
     // @TODO: has the Object already an Image, than take this
     //
     if (is_string($value)) {
         $client = new HttpClient($value, array('sslverifypeer' => false));
         $response = $client->send();
         $file = new GridFSFile();
         $file->setBytes($response->getBody());
         $organizationImageEntity = $this->repository->create();
         $organizationImageEntity->setType($response->getHeaders()->get('Content-Type')->getFieldValue());
         $organizationImageEntity->setFile($file);
     }
     return $organizationImageEntity;
 }
Exemplo n.º 3
0
 /**
  * Wrapper method for MongoGridFS::storeFile().
  *
  * This method returns the GridFSFile object, unlike the base MongoGridFS
  * method, which returns the "_id" field of the saved document. The "_id"
  * will be set on the $document parameter, which is passed by reference.
  *
  * @see http://php.net/manual/en/mongogridfs.storefile.php
  * @param string|GridFSFile $file     String filename or a GridFSFile object
  * @param array             $document
  * @param array             $options
  * @return GridFSFile
  */
 public function storeFile($file, array &$document, array $options = [])
 {
     if (!$file instanceof GridFSFile) {
         $file = new GridFSFile($file);
     }
     $options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
     if ($file->hasUnpersistedFile()) {
         $id = $this->mongoCollection->storeFile($file->getFilename(), $document, $options);
     } else {
         $id = $this->mongoCollection->storeBytes($file->getBytes(), $document, $options);
     }
     $document = array_merge(['_id' => $id], $document);
     $gridFsFile = $this->mongoCollection->get($id);
     // TODO: Consider throwing exception if file cannot be fetched
     $file->setMongoGridFSFile($this->mongoCollection->get($id));
     return $file;
 }
Exemplo n.º 4
0
 public function testGetSizeWithEmptyState()
 {
     $file = new GridFSFile();
     $this->assertEquals(0, $file->getSize());
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  *
  *
  * @see \Zend\Authentication\Adapter\AdapterInterface::authenticate()
  */
 public function authenticate()
 {
     $hybridAuth = $this->getHybridAuth();
     /* @var $adapter \Hybrid_Provider_Model */
     $adapter = $hybridAuth->authenticate($this->_provider);
     $userProfile = $adapter->getUserProfile();
     $email = isset($userProfile->emailVerified) && !empty($userProfile->emailVerified) ? $userProfile->emailVerified : $userProfile->email;
     $forceSave = false;
     $user = $this->getRepository()->findByProfileIdentifier($userProfile->identifier);
     if (!$user) {
         $forceSave = true;
         $user = $this->getRepository()->create();
     }
     $currentInfo = $user->getProfile();
     $newInfo = (array) $userProfile;
     if ($forceSave || $currentInfo != $newInfo) {
         /*  */
         $dm = $this->getRepository()->getDocumentManager();
         if ('' == $user->getInfo()->email) {
             $user->getInfo()->email = $email;
         }
         $user->getInfo()->firstName = $userProfile->firstName;
         $user->getInfo()->lastName = $userProfile->lastName;
         $user->getInfo()->birthDay = $userProfile->birthDay;
         $user->getInfo()->birthMonth = $userProfile->birthMonth;
         $user->getInfo()->birthYear = $userProfile->birthYear;
         $user->getInfo()->postalcode = $userProfile->zip;
         $user->getInfo()->city = $userProfile->city;
         $user->getInfo()->street = $userProfile->address;
         $user->getInfo()->phone = $userProfile->phone;
         $user->getInfo()->gender = $userProfile->gender;
         $user->setLogin($email);
         $user->setProfile($newInfo);
         $dm->persist($user);
         // make sure all ids are generated and user exists in database.
         $dm->flush();
         /*
          * This must be after flush because a newly created user has no id!
          */
         if ($forceSave || !$user->getInfo()->image && $userProfile->photoURL) {
             // get user image
             if ('' != $userProfile->photoURL) {
                 $client = new \Zend\Http\Client($userProfile->photoURL, array('sslverifypeer' => false));
                 $response = $client->send();
                 $file = new GridFSFile();
                 $file->setBytes($response->getBody());
                 $userImage = new UserImage();
                 $userImage->setName($userProfile->lastName . $userProfile->firstName);
                 $userImage->setType($response->getHeaders()->get('Content-Type')->getFieldValue());
                 $userImage->setUser($user);
                 $userImage->setFile($file);
                 $user->getInfo()->setImage($userImage);
                 $dm->persist($userImage);
                 //$this->getRepository()->store($user->info);
             }
             // We have to flush again
             $dm->flush();
         }
     }
     return new Result(Result::SUCCESS, $user->getId(), array('firstLogin' => $forceSave, 'user' => $user));
 }