/**
  * Validates data.
  * @param [String => Mixed] $data Properties to be changed on the model.
  * @throws \Exception
  */
 protected function validateData(array $data)
 {
     if (isset($data['title'])) {
         XAPIHelpers::checkType('title', 'string', $data['title']);
     }
     if (isset($data['description'])) {
         XAPIHelpers::checkType('description', 'string', $data['description']);
     }
     if (isset($data['owner_id'])) {
         XAPIHelpers::checkType('owner_id', 'MongoId', $data['owner_id']);
     }
     // Validate users.
     if (isset($data['users'])) {
         XAPIHelpers::checkType('users', 'array', $data['users']);
         foreach ($data['users'] as $key => $field) {
             XAPIHelpers::checkType("fields.{$key}", 'array', $field);
             if (isset($field['_id'])) {
                 XAPIHelpers::checkType("fields.{$key}._id", 'MongoId', $field['_id']);
             }
             if (isset($field['email'])) {
                 XAPIHelpers::checkType("fields.{$key}.email", 'string', $field['email']);
             }
             if (isset($field['name'])) {
                 XAPIHelpers::checkType("fields.{$key}.name", 'string', $field['name']);
             }
             if (isset($field['role'])) {
                 XAPIHelpers::checkType("fields.{$key}.role", 'string', $field['role']);
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Constructs a new Error with a $errors.
  * @param string $message
  */
 public function __construct($errors)
 {
     \Locker\XApi\Helpers::checkType('errors', 'array', $errors);
     $this->errors = $errors;
     $errors = array_map(function ($error) {
         return (string) $error;
     }, $errors);
     parent::__construct(json_encode($errors), 400);
 }
Beispiel #3
0
 public function setValue($new_value)
 {
     Helpers::checkType('new_value', 'array', $new_value);
     $member_type = $this->member_type;
     $this->value = array_map(function ($element) use($member_type) {
         return new $member_type($element);
     }, $new_value);
     return $this;
 }
 /**
  * Validates data.
  * @param [String => Mixed] $data Properties to be changed on the model.
  * @throws \Exception
  */
 protected function validateData(array $data)
 {
     if (isset($data['name'])) {
         XAPIHelpers::checkType('name', 'string', $data['name']);
     }
     if (isset($data['description'])) {
         XAPIHelpers::checkType('description', 'string', $data['description']);
     }
     if (isset($data['query'])) {
         XAPIHelpers::checkType('query', 'array', $data['query']);
     }
     if (isset($data['since'])) {
         XAPIHelpers::checkType('since', 'string', $data['since']);
     }
     if (isset($data['until'])) {
         XAPIHelpers::checkType('until', 'string', $data['until']);
     }
 }
 /**
  * Validates data.
  * @param [String => Mixed] $data Properties to be changed on the model.
  * @throws \Exception
  */
 protected function validateData(array $data)
 {
     if (isset($data['name'])) {
         XAPIHelpers::checkType('name', 'string', $data['name']);
     }
     if (isset($data['description'])) {
         XAPIHelpers::checkType('description', 'string', $data['description']);
     }
     if (isset($data['report'])) {
         XAPIHelpers::checkType('report', 'string', $data['report']);
     }
     // Validates fields.
     if (isset($data['fields'])) {
         XAPIHelpers::checkType('fields', 'array', $data['fields']);
         foreach ($data['fields'] as $key => $field) {
             XAPIHelpers::checkType("fields.{$key}", 'array', $field);
         }
     }
 }
Beispiel #6
0
 /**
  * Adds a $trace.
  * @param string $trace
  */
 public final function addTrace($trace)
 {
     Helpers::checkType('trace', 'string', $trace);
     array_splice($this->trace, 0, 0, [$trace]);
     return $this;
 }
Beispiel #7
0
 public function unsetProp($prop_key)
 {
     if (gettype($this->value) !== 'object') {
         return $this;
     }
     Helpers::checkType('prop_key', 'string', $prop_key);
     unset($this->value->{$prop_key});
     return $this;
 }