コード例 #1
0
 /**
  * Helper function that validates and includes an old single method parameter setting into the parameters array given.
  * This is only for keeping backwards-compatibility where methods had for example a parameter which was called 'policy' and
  * which was later changed to being an array of options, so more than one options can be passed easily.
  * This is only for options that are to be sent to the ArangoDB server.
  *
  * @param array $options   - The options array that may hold the policy to include in the parameters. If it's not an array, then the value is the policy value.
  * @param array $params    - The parameters into which the options will be included.
  * @param mixed $parameter - the old single parameter key to use.
  *
  * @return array $params - array of parameters for use in a url
  */
 protected function validateAndIncludeOldSingleParameterInParams($options, $params, $parameter)
 {
     $value = null;
     if (!is_array($options)) {
         $value = $options;
     } else {
         $value = array_key_exists($parameter, $options) ? $options[$parameter] : $value;
     }
     if ($value === null) {
         $value = $this->getConnection()->getOption($parameter);
     }
     if ($parameter === ConnectionOptions::OPTION_UPDATE_POLICY) {
         UpdatePolicy::validate($value);
     }
     if (is_bool($value)) {
         $value = UrlHelper::getBoolString($value);
     }
     $params[$parameter] = $value;
     return $params;
 }
コード例 #2
0
 /**
  * Validate the options
  *
  * @throws ClientException
  * @return void - will throw if an invalid option value is found
  */
 private function validate()
 {
     if (isset($this->_values[self::OPTION_HOST]) && !is_string($this->_values[self::OPTION_HOST])) {
         throw new ClientException('host should be a string');
     }
     if (isset($this->_values[self::OPTION_PORT]) && !is_int($this->_values[self::OPTION_PORT])) {
         throw new ClientException('port should be an integer');
     }
     // can use either endpoint or host/port
     if (isset($this->_values[self::OPTION_HOST]) && isset($this->_values[self::OPTION_ENDPOINT])) {
         throw new ClientException('must not specify both host and endpoint');
     } else {
         if (isset($this->_values[self::OPTION_HOST]) && !isset($this->_values[self::OPTION_ENDPOINT])) {
             // upgrade host/port to an endpoint
             $this->_values[self::OPTION_ENDPOINT] = 'tcp://' . $this->_values[self::OPTION_HOST] . ':' . $this->_values[self::OPTION_PORT];
         }
     }
     assert(isset($this->_values[self::OPTION_ENDPOINT]));
     // set up a new endpoint, this will also validate it
     $this->getEndpoint();
     if (Endpoint::getType($this->_values[self::OPTION_ENDPOINT]) === Endpoint::TYPE_UNIX) {
         // must set port to 0 for UNIX sockets
         $this->_values[self::OPTION_PORT] = 0;
     }
     if (isset($this->_values[self::OPTION_AUTH_TYPE]) && !in_array($this->_values[self::OPTION_AUTH_TYPE], self::getSupportedAuthTypes())) {
         throw new ClientException('unsupported authorization method');
     }
     if (isset($this->_values[self::OPTION_CONNECTION]) && !in_array($this->_values[self::OPTION_CONNECTION], self::getSupportedConnectionTypes())) {
         throw new ClientException(sprintf("unsupported connection value '%s'", $this->_values[self::OPTION_CONNECTION]));
     }
     UpdatePolicy::validate($this->_values[self::OPTION_UPDATE_POLICY]);
     UpdatePolicy::validate($this->_values[self::OPTION_REPLACE_POLICY]);
     UpdatePolicy::validate($this->_values[self::OPTION_DELETE_POLICY]);
 }