annotate vendor/instaclick/php-webdriver/lib/WebDriver/Storage.php @ 5:12f9dff5fda9 tip

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