Mercurial > hg > isophonics-drupal-site
comparison vendor/instaclick/php-webdriver/lib/WebDriver/Storage.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | |
2 /** | |
3 * Copyright 2011-2017 Anthon Pang. All Rights Reserved. | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 * | |
17 * @package WebDriver | |
18 * | |
19 * @author Anthon Pang <apang@softwaredevelopment.ca> | |
20 */ | |
21 | |
22 namespace WebDriver; | |
23 | |
24 use WebDriver\Exception as WebDriverException; | |
25 | |
26 /** | |
27 * WebDriver\Storage class | |
28 * | |
29 * @package WebDriver | |
30 * | |
31 * @method mixed getKey($key) Get key/value pair. | |
32 * @method void deleteKey($key) Delete a specific key. | |
33 * @method integer size() Get the number of items in the storage. | |
34 */ | |
35 abstract class Storage extends AbstractWebDriver | |
36 { | |
37 /** | |
38 * {@inheritdoc} | |
39 */ | |
40 protected function methods() | |
41 { | |
42 return array( | |
43 'key' => array('GET', 'DELETE'), | |
44 'size' => array('GET'), | |
45 ); | |
46 } | |
47 | |
48 /** | |
49 * Get all keys from storage or a specific key/value pair | |
50 * | |
51 * @return mixed | |
52 */ | |
53 public function get() | |
54 { | |
55 // get all keys | |
56 if (func_num_args() === 0) { | |
57 $result = $this->curl('GET', ''); | |
58 | |
59 return $result['value']; | |
60 } | |
61 | |
62 // get key/value pair | |
63 if (func_num_args() === 1) { | |
64 return $this->getKey(func_get_arg(0)); | |
65 } | |
66 | |
67 throw WebDriverException::factory(WebDriverException::UNEXPECTED_PARAMETERS); | |
68 } | |
69 | |
70 /** | |
71 * Set specific key/value pair | |
72 * | |
73 * @return \WebDriver\Storage | |
74 * | |
75 * @throw \WebDriver\Exception\UnexpectedParameters if unexpected parameters | |
76 */ | |
77 public function set() | |
78 { | |
79 if (func_num_args() === 1 | |
80 && is_array($arg = func_get_arg(0)) | |
81 ) { | |
82 $this->curl('POST', '', $arg); | |
83 | |
84 return $this; | |
85 } | |
86 | |
87 if (func_num_args() === 2) { | |
88 $arg = array( | |
89 'key' => func_get_arg(0), | |
90 'value' => func_get_arg(1), | |
91 ); | |
92 $this->curl('POST', '', $arg); | |
93 | |
94 return $this; | |
95 } | |
96 | |
97 throw WebDriverException::factory(WebDriverException::UNEXPECTED_PARAMETERS); | |
98 } | |
99 | |
100 /** | |
101 * Delete storage or a specific key | |
102 * | |
103 * @return \WebDriver\Storage | |
104 * | |
105 * @throw \WebDriver\Exception\UnexpectedParameters if unexpected parameters | |
106 */ | |
107 public function delete() | |
108 { | |
109 // delete storage | |
110 if (func_num_args() === 0) { | |
111 $this->curl('DELETE', ''); | |
112 | |
113 return $this; | |
114 } | |
115 | |
116 // delete key from storage | |
117 if (func_num_args() === 1) { | |
118 return $this->deleteKey(func_get_arg(0)); | |
119 } | |
120 | |
121 throw WebDriverException::factory(WebDriverException::UNEXPECTED_PARAMETERS); | |
122 } | |
123 | |
124 /** | |
125 * Factory method to create Storage objects | |
126 * | |
127 * @param string $type 'local' or 'session' storage | |
128 * @param string $url URL | |
129 * | |
130 * @return \WebDriver\Storage | |
131 */ | |
132 public static function factory($type, $url) | |
133 { | |
134 // dynamically define custom storage classes | |
135 $className = ucfirst(strtolower($type)); | |
136 $namespacedClassName = __CLASS__ . '\\' . $className; | |
137 | |
138 if (!class_exists($namespacedClassName, false)) { | |
139 eval( | |
140 'namespace ' . __CLASS__ . '; final class ' . $className . ' extends \\' . __CLASS__ . '{}' | |
141 ); | |
142 } | |
143 | |
144 return new $namespacedClassName($url); | |
145 } | |
146 } |