/**
  * Set a document attribute
  *
  * The key (attribute name) must be a string.
  *
  * This will validate the value of the attribute and might throw an
  * exception if the value is invalid.
  *
  * @throws ClientException
  *
  * @param string $key   - attribute name
  * @param mixed  $value - value for attribute
  *
  * @return void
  */
 public function set($key, $value)
 {
     if ($this->_doValidate) {
         // validate the value passed
         ValueValidator::validate($value);
     }
     if ($key[0] === '_') {
         if ($key === self::ENTRY_ID) {
             $this->setInternalId($value);
             return;
         }
         if ($key === self::ENTRY_KEY) {
             $this->setInternalKey($value);
             return;
         }
         if ($key === self::ENTRY_REV) {
             $this->setRevision($value);
             return;
         }
         if ($key === self::ENTRY_FROM) {
             $this->setFrom($value);
             return;
         }
         if ($key === self::ENTRY_TO) {
             $this->setTo($value);
             return;
         }
     }
     if (!$this->_changed) {
         if (!isset($this->_values[$key]) || $this->_values[$key] !== $value) {
             // set changed flag
             $this->_changed = true;
         }
     }
     // and store the value
     $this->_values[$key] = $value;
 }
 /**
  * Runs the value through the provided ValueValidator and registers the errors.
  * Options of $this can be mapped to those of the passed ValueValidator using
  * the $optionMap parameter in which keys are source names and values are target
  * names.
  *
  * @since 0.1
  *
  * @param mixed $value
  * @param ValueValidator $validator
  * @param string|null $property
  * @param array $optionMap
  */
 protected function runSubValidator($value, ValueValidator $validator, $property = null, array $optionMap = array())
 {
     if ($optionMap !== array()) {
         $options = array();
         foreach ($optionMap as $source => $target) {
             if (array_key_exists($source, $this->options)) {
                 $options[$target] = $this->options[$source];
             }
         }
         $validator->setOptions($options);
     }
     /**
      * @var Error $error
      */
     foreach ($validator->validate($value)->getErrors() as $error) {
         $this->addError(Error::newError($error->getText(), $property));
     }
 }
 /**
  * Set the value of a single bind variable or set all bind variables at once
  *
  * This will also validate the bind values.
  *
  * Allowed value types for bind parameters are string, int,
  * double, bool and array. Arrays must not contain any other
  * than these types.
  *
  * @throws ClientException
  *
  * @param mixed  $name  - name of bind variable OR an array with all bind variables
  * @param string $value - value for bind variable
  *
  * @return void
  */
 public function set($name, $value = null)
 {
     if (is_array($name)) {
         foreach ($name as $value) {
             ValueValidator::validate($value);
         }
         $this->_values = $name;
     } else {
         if (is_int($name) || is_string($name)) {
             $this->_values[(string) $name] = $value;
             ValueValidator::validate($value);
         } else {
             throw new ClientException('Bind variable name should be string or int');
         }
     }
 }
 /**
  * ValidationResult constructor.
  * @param AccessTable $access
  * @param array $data the data to validate (and save)
  */
 public function __construct(AccessTable $access, $data)
 {
     parent::__construct();
     $this->access = $access;
     $this->data = $data;
 }
 /**
  * Set a graph attribute
  *
  * The key (attribute name) must be a string.
  * This will validate the value of the attribute and might throw an
  * exception if the value is invalid.
  *
  * @throws ClientException
  *
  * @param string $key    - attribute name
  * @param mixed  $value  - value for attribute
  *
  * @return void
  */
 public function set($key, $value)
 {
     if ($key === self::ENTRY_EDGE_DEFINITIONS) {
         if ($this->_doValidate) {
             ValueValidator::validate($value);
         }
         foreach ($value as $ed) {
             $edgeDefinition = new EdgeDefinition();
             foreach ($ed[self::ENTRY_FROM] as $from) {
                 $edgeDefinition->addFromCollection($from);
             }
             foreach ($ed[self::ENTRY_TO] as $to) {
                 $edgeDefinition->addToCollection($to);
             }
             $edgeDefinition->setRelation($ed[self::ENTRY_COLLECTION]);
             $this->addEdgeDefinition($edgeDefinition);
         }
     } else {
         if ($key === self::ENTRY_ORPHAN_COLLECTIONS) {
             if ($this->_doValidate) {
                 ValueValidator::validate($value);
             }
             foreach ($value as $o) {
                 $this->addOrphanCollection($o);
             }
         } else {
             parent::set($key, $value);
         }
     }
 }