aboutsummaryrefslogtreecommitdiff
path: root/includes/vendor/rmccue/requests/library/Requests/Utility
diff options
context:
space:
mode:
authors1n <[email protected]>2020-03-28 10:36:41 -0700
committers1n <[email protected]>2020-03-28 10:36:41 -0700
commit25b7d2aab61ae6421398d3abae5da6ffe590333d (patch)
tree611985ec78bb2d94099c9fd5dd687f5c9cee6f3e /includes/vendor/rmccue/requests/library/Requests/Utility
parentInitial commit (diff)
downloadcrack.cf-backup-master.tar.xz
crack.cf-backup-master.zip
3/28/2020, 10:36HEADmaster
Diffstat (limited to 'includes/vendor/rmccue/requests/library/Requests/Utility')
-rw-r--r--includes/vendor/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php103
-rw-r--r--includes/vendor/rmccue/requests/library/Requests/Utility/FilteredIterator.php45
2 files changed, 148 insertions, 0 deletions
diff --git a/includes/vendor/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php b/includes/vendor/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php
new file mode 100644
index 0000000..2c97893
--- /dev/null
+++ b/includes/vendor/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * Case-insensitive dictionary, suitable for HTTP headers
+ *
+ * @package Requests
+ * @subpackage Utilities
+ */
+
+/**
+ * Case-insensitive dictionary, suitable for HTTP headers
+ *
+ * @package Requests
+ * @subpackage Utilities
+ */
+class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {
+ /**
+ * Actual item data
+ *
+ * @var array
+ */
+ protected $data = array();
+
+ /**
+ * Creates a case insensitive dictionary.
+ *
+ * @param array $data Dictionary/map to convert to case-insensitive
+ */
+ public function __construct(array $data = array()) {
+ foreach ($data as $key => $value) {
+ $this->offsetSet($key, $value);
+ }
+ }
+
+ /**
+ * Check if the given item exists
+ *
+ * @param string $key Item key
+ * @return boolean Does the item exist?
+ */
+ public function offsetExists($key) {
+ $key = strtolower($key);
+ return isset($this->data[$key]);
+ }
+
+ /**
+ * Get the value for the item
+ *
+ * @param string $key Item key
+ * @return string Item value
+ */
+ public function offsetGet($key) {
+ $key = strtolower($key);
+ if (!isset($this->data[$key])) {
+ return null;
+ }
+
+ return $this->data[$key];
+ }
+
+ /**
+ * Set the given item
+ *
+ * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
+ *
+ * @param string $key Item name
+ * @param string $value Item value
+ */
+ public function offsetSet($key, $value) {
+ if ($key === null) {
+ throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
+ }
+
+ $key = strtolower($key);
+ $this->data[$key] = $value;
+ }
+
+ /**
+ * Unset the given header
+ *
+ * @param string $key
+ */
+ public function offsetUnset($key) {
+ unset($this->data[strtolower($key)]);
+ }
+
+ /**
+ * Get an iterator for the data
+ *
+ * @return ArrayIterator
+ */
+ public function getIterator() {
+ return new ArrayIterator($this->data);
+ }
+
+ /**
+ * Get the headers as an array
+ *
+ * @return array Header data
+ */
+ public function getAll() {
+ return $this->data;
+ }
+}
diff --git a/includes/vendor/rmccue/requests/library/Requests/Utility/FilteredIterator.php b/includes/vendor/rmccue/requests/library/Requests/Utility/FilteredIterator.php
new file mode 100644
index 0000000..76a29e7
--- /dev/null
+++ b/includes/vendor/rmccue/requests/library/Requests/Utility/FilteredIterator.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Iterator for arrays requiring filtered values
+ *
+ * @package Requests
+ * @subpackage Utilities
+ */
+
+/**
+ * Iterator for arrays requiring filtered values
+ *
+ * @package Requests
+ * @subpackage Utilities
+ */
+class Requests_Utility_FilteredIterator extends ArrayIterator {
+ /**
+ * Callback to run as a filter
+ *
+ * @var callable
+ */
+ protected $callback;
+
+ /**
+ * Create a new iterator
+ *
+ * @param array $data
+ * @param callable $callback Callback to be called on each value
+ */
+ public function __construct($data, $callback) {
+ parent::__construct($data);
+
+ $this->callback = $callback;
+ }
+
+ /**
+ * Get the current item's value after filtering
+ *
+ * @return string
+ */
+ public function current() {
+ $value = parent::current();
+ $value = call_user_func($this->callback, $value);
+ return $value;
+ }
+}