示例#1
0
 /**
  * Create new AVACL from existing permissions.
  *
  * @param array $data represents permissions.
  *
  * @return AVACL
  * @throws \Exception
  * @ignore
  */
 public static function _createACLFromJSON($data)
 {
     $acl = new AVACL();
     foreach ($data as $id => $permissions) {
         if (!is_string($id)) {
             throw new \Exception('Tried to create an ACL with an invalid userId.');
         }
         foreach ($permissions as $accessType => $value) {
             if ($accessType !== 'read' && $accessType !== 'write') {
                 throw new \Exception('Tried to create an ACL with an invalid permission type.');
             }
             if (!is_bool($value)) {
                 throw new \Exception('Tried to create an ACL with an invalid permission value.');
             }
             $acl->setAccess($accessType, $id, $value);
         }
     }
     return $acl;
 }
示例#2
0
 /**
  * Handle merging of special fields for the object.
  *
  * @param array &$data Data received from server.
  *
  * @return null
  */
 private function mergeMagicFields(&$data)
 {
     if (isset($data['objectId'])) {
         $this->objectId = $data['objectId'];
         unset($data['objectId']);
     }
     if (isset($data['createdAt'])) {
         $this->createdAt = new \DateTime($data['createdAt']);
         unset($data['createdAt']);
     }
     if (isset($data['updatedAt'])) {
         $this->updatedAt = new \DateTime($data['updatedAt']);
         unset($data['updatedAt']);
     }
     if (isset($data['ACL'])) {
         $acl = AVACL::_createACLFromJSON($data['ACL']);
         $this->serverData['ACL'] = $acl;
         unset($data['ACL']);
     }
 }