ArangoDB-PHP-Core API Documentation
  • Namespace
  • Class
  • Deprecated

Namespaces

  • frankmayer
    • ArangoDbPhpCore
      • Api
        • Rest
      • Config
      • Connectors
      • Plugins
      • Protocols
        • Http
      • TraitRepository

Classes

  • frankmayer\ArangoDbPhpCore\Api\Rest\Api
  • frankmayer\ArangoDbPhpCore\Api\Rest\Async
  • frankmayer\ArangoDbPhpCore\Api\Rest\Batch
  • frankmayer\ArangoDbPhpCore\Api\Rest\Collection
  • frankmayer\ArangoDbPhpCore\Api\Rest\Database
  • frankmayer\ArangoDbPhpCore\Api\Rest\Document
  • frankmayer\ArangoDbPhpCore\Api\Rest\DocumentBase
  • frankmayer\ArangoDbPhpCore\Api\Rest\Edge
  • frankmayer\ArangoDbPhpCore\Autoloader
  • frankmayer\ArangoDbPhpCore\Client
  • frankmayer\ArangoDbPhpCore\ClientOptions
  • frankmayer\ArangoDbPhpCore\Config\ConnectionOptions
  • frankmayer\ArangoDbPhpCore\Config\DefaultValues
  • frankmayer\ArangoDbPhpCore\Config\Endpoint
  • frankmayer\ArangoDbPhpCore\Config\UpdatePolicy
  • frankmayer\ArangoDbPhpCore\Connectors\AbstractHttpConnector
  • frankmayer\ArangoDbPhpCore\Plugins\Plugin
  • frankmayer\ArangoDbPhpCore\Plugins\PluginManager
  • frankmayer\ArangoDbPhpCore\Plugins\TestPlugin
  • frankmayer\ArangoDbPhpCore\Plugins\TracerPlugin
  • frankmayer\ArangoDbPhpCore\Protocols\Http\AbstractHttpRequest
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpRequest
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpResponse

Interfaces

  • frankmayer\ArangoDbPhpCore\Api\ApiInterface
  • frankmayer\ArangoDbPhpCore\Api\RestApiInterface
  • frankmayer\ArangoDbPhpCore\ClientInterface
  • frankmayer\ArangoDbPhpCore\ConnectorInterface
  • frankmayer\ArangoDbPhpCore\Plugins\PluginInterface
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpConnectorInterface
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpRequestInterface
  • frankmayer\ArangoDbPhpCore\Protocols\Http\HttpResponseInterface
  • frankmayer\ArangoDbPhpCore\Protocols\RequestInterface
  • frankmayer\ArangoDbPhpCore\Protocols\ResponseInterface

Traits

  • frankmayer\ArangoDbPhpCore\Api\Rest\DocumentTrait
  • frankmayer\ArangoDbPhpCore\Api\Rest\EdgeTrait
  • frankmayer\ArangoDbPhpCore\TraitRepository\ClientLogger

Exceptions

  • frankmayer\ArangoDbPhpCore\ClientException
  • frankmayer\ArangoDbPhpCore\ConnectionException
  • frankmayer\ArangoDbPhpCore\Exception
  • frankmayer\ArangoDbPhpCore\ServerException
  1 <?php
  2 
  3 /**
  4  * ArangoDB-PHP-Core client: default values
  5  *
  6  * Taken from the original ArangoDB-Client, in order to maintain easy migration. Thanks Jan ;)
  7  *
  8  * @author    Frank Mayer
  9  * @copyright Copyright 2013-2015, FRANKMAYER.NET, Athens, Greece
 10  */
 11 
 12 namespace frankmayer\ArangoDbPhpCore\Config;
 13 
 14 use frankmayer\ArangoDbPhpCore\ClientException;
 15 use frankmayer\ArangoDbPhpCore\Exception;
 16 
 17 /**
 18  * Simple container class for the client options.
 19  * This class also provides the default values for the client
 20  * options and will perform a simple validation of them.
 21  * It provides array access to its members.
 22  *
 23  * @package   frankmayer\ArangoDbPhpCore\Config
 24  */
 25 class ConnectionOptions implements
 26     \ArrayAccess
 27 {
 28     /**
 29      * The current options
 30      *
 31      * @var array
 32      */
 33     private $_values = [];
 34 
 35     /**
 36      * The client endpoint object
 37      *
 38      * @var Endpoint
 39      */
 40     private $_endpoint = null;
 41 
 42     /**
 43      * Endpoint string index constant
 44      */
 45     const OPTION_ENDPOINT = 'endpoint';
 46 
 47     /**
 48      * Host name string index constant (deprecated, use endpoint instead)
 49      */
 50     const OPTION_HOST = 'host';
 51 
 52     /**
 53      * Port number index constant (deprecated, use endpoint instead)
 54      */
 55     const OPTION_PORT = 'port';
 56 
 57     /**
 58      * Timeout value index constant
 59      */
 60     const OPTION_TIMEOUT = 'timeout';
 61 
 62     /**
 63      * Trace function index constant
 64      */
 65     const OPTION_TRACE = 'trace';
 66 
 67     /**
 68      * Enhanced trace
 69      */
 70     const OPTION_ENHANCED_TRACE = 'enhancedTrace';
 71 
 72     /**
 73      * "Create collections if they don't exist" index constant
 74      */
 75     const OPTION_CREATE = 'createCollection';
 76 
 77     /**
 78      * Update revision constant
 79      */
 80     const OPTION_REVISION = 'rev';
 81 
 82     /**
 83      * Update policy index constant
 84      */
 85     const OPTION_UPDATE_POLICY = 'policy';
 86 
 87     /**
 88      * Update keepNull constant
 89      */
 90     const OPTION_UPDATE_KEEPNULL = 'keepNull';
 91 
 92     /**
 93      * Replace policy index constant
 94      */
 95     const OPTION_REPLACE_POLICY = 'policy';
 96 
 97     /**
 98      * Delete policy index constant
 99      */
100     const OPTION_DELETE_POLICY = 'policy';
101 
102     /**
103      * Wait for sync index constant
104      */
105     const OPTION_WAIT_SYNC = 'waitForSync';
106 
107     /**
108      * Limit index constant
109      */
110     const OPTION_LIMIT = 'limit';
111 
112     /**
113      * Skip index constant
114      */
115     const OPTION_SKIP = 'skip';
116 
117     /**
118      * Batch size index constant
119      */
120     const OPTION_BATCHSIZE = 'batchSize';
121 
122     /**
123      * Wait for sync index constant
124      */
125     const OPTION_JOURNAL_SIZE = 'journalSize';
126 
127     /**
128      * Wait for sync index constant
129      */
130     const OPTION_IS_SYSTEM = 'isSystem';
131 
132     /**
133      * Wait for sync index constant
134      */
135     const OPTION_IS_VOLATILE = 'isVolatile';
136 
137     /**
138      * Authentication user name
139      */
140     const OPTION_AUTH_USER = 'AuthUser';
141 
142     /**
143      * Authentication password
144      */
145     const OPTION_AUTH_PASSWD = 'AuthPasswd';
146 
147     /**
148      * Authentication type
149      */
150     const OPTION_AUTH_TYPE = 'AuthType';
151 
152     /**
153      * Client
154      */
155     const OPTION_CLIENT = 'Client';
156 
157     /**
158      * Reconnect flag
159      */
160     const OPTION_RECONNECT = 'Reconnect';
161 
162     /**
163      * Batch flag
164      */
165     const OPTION_BATCH = 'Batch';
166 
167     /**
168      * Batchpart flag
169      */
170     const OPTION_BATCHPART = 'BatchPart';
171 
172     /**
173      * UTF-8 CHeck Flag
174      */
175     const OPTION_CHECK_UTF8_CONFORM = 'CheckUtf8Conform';
176 
177     /**
178      * Set defaults, use options provided by client and validate them
179      *
180      *
181      * @param array $options - initial options
182      *
183      * @throws ClientException
184      */
185     public function __construct(array $options)
186     {
187         $this->_values = array_merge(self::getDefaults(), $options);
188         $this->validate();
189     }
190 
191     /**
192      * Get all options
193      *
194      * @return array - all options as an array
195      */
196     public function getAll()
197     {
198         return $this->_values;
199     }
200 
201     /**
202      * Set and validate a specific option, necessary for ArrayAccess
203      *
204      * @throws Exception
205      *
206      * @param string $offset - name of option
207      * @param mixed  $value  - value for option
208      *
209      * @return void
210      */
211     public function offsetSet($offset, $value)
212     {
213         $this->_values[$offset] = $value;
214         $this->validate();
215     }
216 
217     /**
218      * Check whether an option exists, necessary for ArrayAccess
219      *
220      * @param string $offset -name of option
221      *
222      * @return bool - true if option exists, false otherwise
223      */
224     public function offsetExists($offset)
225     {
226         return isset($this->_values[$offset]);
227     }
228 
229     /**
230      * Remove an option and validate, necessary for ArrayAccess
231      *
232      * @throws Exception
233      *
234      * @param string $offset - name of option
235      *
236      * @return void
237      */
238     public function offsetUnset($offset)
239     {
240         unset($this->_values[$offset]);
241         $this->validate();
242     }
243 
244     /**
245      * Get a specific option, necessary for ArrayAccess
246      *
247      * @throws ClientException
248      *
249      * @param string $offset - name of option
250      *
251      * @return mixed - value of option, will throw if option is not set
252      */
253     public function offsetGet($offset)
254     {
255         if (!array_key_exists($offset, $this->_values)) {
256             throw new ClientException('Invalid option ' . $offset);
257         }
258 
259         return $this->_values[$offset];
260     }
261 
262     /**
263      * Get the endpoint object for the client
264      *
265      * @throws ClientException
266      * @return Endpoint - endpoint object
267      */
268     public function getEndpoint()
269     {
270         if ($this->_endpoint === null) {
271             // will also validate the endpoint
272             $this->_endpoint = new Endpoint($this->_values[self::OPTION_ENDPOINT]);
273         }
274 
275         return $this->_endpoint;
276     }
277 
278     /**
279      * Get the default values for the options
280      *
281      * @return array - array of default client options
282      */
283     private static function getDefaults()
284     {
285         return [
286             self::OPTION_ENDPOINT           => null,
287             self::OPTION_HOST               => null,
288             self::OPTION_PORT               => DefaultValues::DEFAULT_PORT,
289             self::OPTION_TIMEOUT            => DefaultValues::DEFAULT_TIMEOUT,
290             self::OPTION_CREATE             => DefaultValues::DEFAULT_CREATE,
291             self::OPTION_UPDATE_POLICY      => DefaultValues::DEFAULT_UPDATE_POLICY,
292             self::OPTION_REPLACE_POLICY     => DefaultValues::DEFAULT_REPLACE_POLICY,
293             self::OPTION_DELETE_POLICY      => DefaultValues::DEFAULT_DELETE_POLICY,
294             self::OPTION_REVISION           => null,
295             self::OPTION_WAIT_SYNC          => DefaultValues::DEFAULT_WAIT_SYNC,
296             self::OPTION_BATCHSIZE          => null,
297             self::OPTION_JOURNAL_SIZE       => DefaultValues::DEFAULT_JOURNAL_SIZE,
298             self::OPTION_IS_SYSTEM          => false,
299             self::OPTION_IS_VOLATILE        => DefaultValues::DEFAULT_IS_VOLATILE,
300             self::OPTION_CLIENT             => DefaultValues::DEFAULT_CLIENT,
301             self::OPTION_TRACE              => null,
302             self::OPTION_ENHANCED_TRACE     => false,
303             self::OPTION_AUTH_USER          => null,
304             self::OPTION_AUTH_PASSWD        => null,
305             self::OPTION_AUTH_TYPE          => null,
306             self::OPTION_RECONNECT          => false,
307             self::OPTION_BATCH              => false,
308             self::OPTION_BATCHPART          => false,
309             self::OPTION_CHECK_UTF8_CONFORM => DefaultValues::DEFAULT_CHECK_UTF8_CONFORM,
310         ];
311     }
312 
313     /**
314      * Return the supported authorization types
315      *
316      * @return array - array with supported authorization types
317      */
318     private static function getSupportedAuthTypes()
319     {
320         return ['Basic'];
321     }
322 
323     /**
324      * Return the supported client types
325      *
326      * @return array - array with supported client types
327      */
328     private static function getSupportedClientTypes()
329     {
330         return ['Close', 'Keep-Alive'];
331     }
332 
333     /**
334      * Validate the options
335      *
336      * @throws ClientException
337      * @return void - will throw if an invalid option value is found
338      */
339     private function validate()
340     {
341         if (isset($this->_values[self::OPTION_HOST]) && !is_string($this->_values[self::OPTION_HOST])) {
342             throw new ClientException('host should be a string');
343         }
344 
345         if (isset($this->_values[self::OPTION_PORT]) && !is_int($this->_values[self::OPTION_PORT])) {
346             throw new ClientException('port should be an integer');
347         }
348 
349         // can use either endpoint or host/port
350         if (isset($this->_values[self::OPTION_HOST]) && isset($this->_values[self::OPTION_ENDPOINT])) {
351             throw new ClientException('must not specify both host and endpoint');
352         } else {
353             if (isset($this->_values[self::OPTION_HOST]) && !isset($this->_values[self::OPTION_ENDPOINT])) {
354                 // upgrade host/port to an endpoint
355                 $this->_values[self::OPTION_ENDPOINT] = 'tcp://' . $this->_values[self::OPTION_HOST] . ':' . $this->_values[self::OPTION_PORT];
356             }
357         }
358 
359         assert(isset($this->_values[self::OPTION_ENDPOINT]));
360         // set up a new endpoint, this will also validate it
361         $this->getEndpoint();
362         if (Endpoint::getType($this->_values[self::OPTION_ENDPOINT]) === Endpoint::TYPE_UNIX) {
363             // must set port to 0 for UNIX sockets
364             $this->_values[self::OPTION_PORT] = 0;
365         }
366 
367         if (isset($this->_values[self::OPTION_AUTH_TYPE]) && !in_array(
368                 $this->_values[self::OPTION_AUTH_TYPE],
369                 self::getSupportedAuthTypes()
370             )
371         ) {
372             throw new ClientException('unsupported authorization method');
373         }
374 
375         if (isset($this->_values[self::OPTION_CLIENT]) && !in_array(
376                 $this->_values[self::OPTION_CLIENT],
377                 self::getSupportedClientTypes()
378             )
379         ) {
380             throw new ClientException(sprintf(
381                 "unsupported client value '%s'",
382                 $this->_values[self::OPTION_CLIENT]
383             ));
384         }
385 
386         UpdatePolicy::validate($this->_values[self::OPTION_UPDATE_POLICY]);
387         UpdatePolicy::validate($this->_values[self::OPTION_REPLACE_POLICY]);
388         UpdatePolicy::validate($this->_values[self::OPTION_DELETE_POLICY]);
389     }
390 }
391 
ArangoDB-PHP-Core API Documentation API documentation generated by ApiGen