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'));
 }
示例#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;
 }
示例#3
0
 public function testGetSizeWithSetBytes()
 {
     $file = new GridFSFile();
     $file->setBytes('bytes');
     $this->assertEquals(5, $file->getSize());
 }
示例#4
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));
 }