Beispiel #1
0
 /**
  * Parse\Client::initialize, must be called before using Parse features.
  *
  * @param string $app_id     Parse Application ID
  * @param string $rest_key   Parse REST API Key
  * @param string $master_key Parse Master Key
  *
  * @return null
  */
 public static function initialize($app_id, $rest_key, $master_key)
 {
     ParseUser::registerSubclass();
     ParseRole::registerSubclass();
     ParseInstallation::registerSubclass();
     self::$applicationId = $app_id;
     self::$restKey = $rest_key;
     self::$masterKey = $master_key;
     if (!static::$storage) {
         if (session_status() === PHP_SESSION_ACTIVE) {
             self::setStorage(new ParseSessionStorage());
         } else {
             self::setStorage(new ParseMemoryStorage());
         }
     }
 }
Beispiel #2
0
 /**
  * Parse\Client::initialize, must be called before using Parse features.
  *
  * @param string  $app_id               Parse Application ID
  * @param string  $rest_key             Parse REST API Key
  * @param string  $master_key           Parse Master Key
  * @param boolean $enableCurlExceptions Enable or disable Parse curl exceptions
  *
  * @return null
  */
 public static function initialize($app_id, $rest_key, $master_key, $enableCurlExceptions = true)
 {
     if (!ParseObject::hasRegisteredSubclass('_User')) {
         ParseUser::registerSubclass();
     }
     if (!ParseObject::hasRegisteredSubclass('_Role')) {
         ParseRole::registerSubclass();
     }
     ParseInstallation::registerSubclass();
     ParseSession::registerSubclass();
     self::$applicationId = $app_id;
     self::$restKey = $rest_key;
     self::$masterKey = $master_key;
     self::$enableCurlExceptions = $enableCurlExceptions;
     if (!static::$storage) {
         if (session_status() === PHP_SESSION_ACTIVE) {
             self::setStorage(new ParseSessionStorage());
         } else {
             self::setStorage(new ParseMemoryStorage());
         }
     }
 }
Beispiel #3
0
 public function createEden()
 {
     $eden = [];
     $eden['adam'] = $this->createUser('adam');
     $eden['eve'] = $this->createUser('eve');
     $eden['snake'] = $this->createUser('snake');
     $eden['adam']->signUp();
     $eden['eve']->signUp();
     $eden['snake']->signUp();
     $eden['humans'] = ParseRole::createRole('humans', $this->aclPublic());
     $eden['humans']->getUsers()->add($eden['adam']);
     $eden['humans']->getUsers()->add($eden['eve']);
     $eden['creatures'] = ParseRole::createRole('creatures', $this->aclPublic());
     $eden['creatures']->getUsers()->add($eden['snake']);
     ParseObject::saveAll([$eden['humans'], $eden['creatures']]);
     $eden['edenkin'] = ParseRole::createRole('edenkin', $this->aclPublic());
     $eden['edenkin']->getRoles()->add($eden['humans']);
     $eden['edenkin']->getRoles()->add($eden['creatures']);
     $eden['edenkin']->save();
     $eden['apple'] = ParseObject::create('Things');
     $eden['apple']->set('name', 'apple');
     $eden['apple']->set('ACL', $this->aclPrivateTo($eden['humans']));
     $eden['garden'] = ParseObject::create('Things');
     $eden['garden']->set('name', 'garden');
     $eden['garden']->set('ACL', $this->aclPrivateTo($eden['edenkin']));
     ParseObject::saveAll([$eden['apple'], $eden['garden']]);
     return $eden;
 }
Beispiel #4
0
 public function createEden()
 {
     $eden = [];
     $eden['adam'] = $this->createUser('adam');
     $eden['eve'] = $this->createUser('eve');
     $eden['snake'] = $this->createUser('snake');
     $eden['adam']->signUp();
     $eden['eve']->signUp();
     $eden['snake']->signUp();
     $eden['humans'] = ParseRole::createRole("humans", $this->aclPublic());
     $eden['humans']->getUsers()->add($eden['adam']);
     $eden['humans']->getUsers()->add($eden['eve']);
     $eden['creatures'] = ParseRole::createRole("creatures", $this->aclPublic());
     $eden['creatures']->getUsers()->add($eden['snake']);
     ParseObject::saveAll([$eden['humans'], $eden['creatures']]);
     $eden['edenkin'] = ParseRole::createRole("edenkin", $this->aclPublic());
     $eden['edenkin']->getRoles()->add($eden['humans']);
     $eden['edenkin']->getRoles()->add($eden['creatures']);
     $eden['edenkin']->save();
     $eden['apple'] = ParseObject::create("Things");
     $eden['apple']->set("name", "apple");
     $eden['apple']->set("ACL", $this->aclPrivateTo($eden['humans']));
     $eden['garden'] = ParseObject::create("Things");
     $eden['garden']->set("name", "garden");
     $eden['garden']->set("ACL", $this->aclPrivateTo($eden['edenkin']));
     ParseObject::saveAll([$eden['apple'], $eden['garden']]);
     return $eden;
 }
Beispiel #5
0
 /**
  * Check whether the role is valid or not.
  *
  * @param ParseRole $role
  *
  * @throws \Exception
  */
 private static function validateRoleState($role)
 {
     if (!$role->getObjectId()) {
         throw new Exception('Roles must be saved to the server before they can be used in an ACL.');
     }
 }
Beispiel #6
0
     $role = $query->first();
     if ($role != NULL) {
         if ($roleGenerateType != 'new') {
             $role->getUsers()->add($user);
             $role->save();
         }
         $saveRole = true;
     }
 }
 if ($roleGenerateType != 'exist' && $saveRole != true) {
     // 新しくロールを追加
     if (empty($roleName) != true) {
         $roleACL = new ParseACL();
         $roleACL->setPublicWriteAccess(true);
         $roleACL->setPublicReadAccess(true);
         $role = ParseRole::createRole($roleName, $roleACL);
         $role->getUsers()->add($user);
         $role->save();
         $saveRole = true;
     }
 }
 if ($saveRole == true) {
     $hasChangeAcceptRole = false;
     foreach ($acceptRoleNames as $acceptRoleName) {
         $query = new ParseQuery("_Role");
         $query->equalTo('name', $acceptRoleName);
         $acceptRole = $query->first();
         if ($acceptRole != NULL) {
             $role->getRoles()->add($acceptRole);
             $hasChangeAcceptRole = true;
         }