hello
Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : chryzalihi ( 621211) PHP Version : 8.3.31 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl Directory : /home/c/h/r/chryzalihi/www/wp-content/languages/themes/the/ |
home/chryzalihi/www/wp-contentOLD/plugins/backwpup/vendor/Guzzle/Common/Collection.php 0000604 00000026416 15244541610 0025240 0 ustar 00 <?php
namespace Guzzle\Common;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;
/**
* Key value pair collection object
*/
class Collection implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInterface
{
/** @var array Data associated with the object. */
protected $data;
/**
* @param array $data Associative array of data to set
*/
public function __construct(array $data = array())
{
$this->data = $data;
}
/**
* Create a new collection from an array, validate the keys, and add default values where missing
*
* @param array $config Configuration values to apply.
* @param array $defaults Default parameters
* @param array $required Required parameter names
*
* @return self
* @throws InvalidArgumentException if a parameter is missing
*/
public static function fromConfig(array $config = array(), array $defaults = array(), array $required = array())
{
$data = $config + $defaults;
if ($missing = array_diff($required, array_keys($data))) {
throw new InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing));
}
return new self($data);
}
public function count()
{
return count($this->data);
}
public function getIterator()
{
return new \ArrayIterator($this->data);
}
public function toArray()
{
return $this->data;
}
/**
* Removes all key value pairs
*
* @return Collection
*/
public function clear()
{
$this->data = array();
return $this;
}
/**
* Get all or a subset of matching key value pairs
*
* @param array $keys Pass an array of keys to retrieve only a subset of key value pairs
*
* @return array Returns an array of all matching key value pairs
*/
public function getAll(array $keys = null)
{
return $keys ? array_intersect_key($this->data, array_flip($keys)) : $this->data;
}
/**
* Get a specific key value.
*
* @param string $key Key to retrieve.
*
* @return mixed|null Value of the key or NULL
*/
public function get($key)
{
return isset($this->data[$key]) ? $this->data[$key] : null;
}
/**
* Set a key value pair
*
* @param string $key Key to set
* @param mixed $value Value to set
*
* @return Collection Returns a reference to the object
*/
public function set($key, $value)
{
$this->data[$key] = $value;
return $this;
}
/**
* Add a value to a key. If a key of the same name has already been added, the key value will be converted into an
* array and the new value will be pushed to the end of the array.
*
* @param string $key Key to add
* @param mixed $value Value to add to the key
*
* @return Collection Returns a reference to the object.
*/
public function add($key, $value)
{
if (!array_key_exists($key, $this->data)) {
$this->data[$key] = $value;
} elseif (is_array($this->data[$key])) {
$this->data[$key][] = $value;
} else {
$this->data[$key] = array($this->data[$key], $value);
}
return $this;
}
/**
* Remove a specific key value pair
*
* @param string $key A key to remove
*
* @return Collection
*/
public function remove($key)
{
unset($this->data[$key]);
return $this;
}
/**
* Get all keys in the collection
*
* @return array
*/
public function getKeys()
{
return array_keys($this->data);
}
/**
* Returns whether or not the specified key is present.
*
* @param string $key The key for which to check the existence.
*
* @return bool
*/
public function hasKey($key)
{
return array_key_exists($key, $this->data);
}
/**
* Case insensitive search the keys in the collection
*
* @param string $key Key to search for
*
* @return bool|string Returns false if not found, otherwise returns the key
*/
public function keySearch($key)
{
foreach (array_keys($this->data) as $k) {
if (!strcasecmp($k, $key)) {
return $k;
}
}
return false;
}
/**
* Checks if any keys contains a certain value
*
* @param string $value Value to search for
*
* @return mixed Returns the key if the value was found FALSE if the value was not found.
*/
public function hasValue($value)
{
return array_search($value, $this->data);
}
/**
* Replace the data of the object with the value of an array
*
* @param array $data Associative array of data
*
* @return Collection Returns a reference to the object
*/
public function replace(array $data)
{
$this->data = $data;
return $this;
}
/**
* Add and merge in a Collection or array of key value pair data.
*
* @param Collection|array $data Associative array of key value pair data
*
* @return Collection Returns a reference to the object.
*/
public function merge($data)
{
foreach ($data as $key => $value) {
$this->add($key, $value);
}
return $this;
}
/**
* Over write key value pairs in this collection with all of the data from an array or collection.
*
* @param array|\Traversable $data Values to override over this config
*
* @return self
*/
public function overwriteWith($data)
{
if (is_array($data)) {
$this->data = $data + $this->data;
} elseif ($data instanceof Collection) {
$this->data = $data->toArray() + $this->data;
} else {
foreach ($data as $key => $value) {
$this->data[$key] = $value;
}
}
return $this;
}
/**
* Returns a Collection containing all the elements of the collection after applying the callback function to each
* one. The Closure should accept three parameters: (string) $key, (string) $value, (array) $context and return a
* modified value
*
* @param \Closure $closure Closure to apply
* @param array $context Context to pass to the closure
* @param bool $static Set to TRUE to use the same class as the return rather than returning a Collection
*
* @return Collection
*/
public function map(\Closure $closure, array $context = array(), $static = true)
{
$collection = $static ? new static() : new self();
foreach ($this as $key => $value) {
$collection->add($key, $closure($key, $value, $context));
}
return $collection;
}
/**
* Iterates over each key value pair in the collection passing them to the Closure. If the Closure function returns
* true, the current value from input is returned into the result Collection. The Closure must accept three
* parameters: (string) $key, (string) $value and return Boolean TRUE or FALSE for each value.
*
* @param \Closure $closure Closure evaluation function
* @param bool $static Set to TRUE to use the same class as the return rather than returning a Collection
*
* @return Collection
*/
public function filter(\Closure $closure, $static = true)
{
$collection = ($static) ? new static() : new self();
foreach ($this->data as $key => $value) {
if ($closure($key, $value)) {
$collection->add($key, $value);
}
}
return $collection;
}
public function offsetExists($offset)
{
return isset($this->data[$offset]);
}
public function offsetGet($offset)
{
return isset($this->data[$offset]) ? $this->data[$offset] : null;
}
public function offsetSet($offset, $value)
{
$this->data[$offset] = $value;
}
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
/**
* Set a value into a nested array key. Keys will be created as needed to set the value.
*
* @param string $path Path to set
* @param mixed $value Value to set at the key
*
* @return self
* @throws RuntimeException when trying to setPath using a nested path that travels through a scalar value
*/
public function setPath($path, $value)
{
$current =& $this->data;
$queue = explode('/', $path);
while (null !== ($key = array_shift($queue))) {
if (!is_array($current)) {
throw new RuntimeException("Trying to setPath {$path}, but {$key} is set and is not an array");
} elseif (!$queue) {
$current[$key] = $value;
} elseif (isset($current[$key])) {
$current =& $current[$key];
} else {
$current[$key] = array();
$current =& $current[$key];
}
}
return $this;
}
/**
* Gets a value from the collection using an array path (e.g. foo/baz/bar would retrieve bar from two nested arrays)
* Allows for wildcard searches which recursively combine matches up to the level at which the wildcard occurs. This
* can be useful for accepting any key of a sub-array and combining matching keys from each diverging path.
*
* @param string $path Path to traverse and retrieve a value from
* @param string $separator Character used to add depth to the search
* @param mixed $data Optional data to descend into (used when wildcards are encountered)
*
* @return mixed|null
*/
public function getPath($path, $separator = '/', $data = null)
{
if ($data === null) {
$data =& $this->data;
}
$path = is_array($path) ? $path : explode($separator, $path);
while (null !== ($part = array_shift($path))) {
if (!is_array($data)) {
return null;
} elseif (isset($data[$part])) {
$data =& $data[$part];
} elseif ($part != '*') {
return null;
} else {
// Perform a wildcard search by diverging and merging paths
$result = array();
foreach ($data as $value) {
if (!$path) {
$result = array_merge_recursive($result, (array) $value);
} elseif (null !== ($test = $this->getPath($path, $separator, $value))) {
$result = array_merge_recursive($result, (array) $test);
}
}
return $result;
}
}
return $data;
}
/**
* Inject configuration settings into an input string
*
* @param string $input Input to inject
*
* @return string
* @deprecated
*/
public function inject($input)
{
Version::warn(__METHOD__ . ' is deprecated');
$replace = array();
foreach ($this->data as $key => $val) {
$replace['{' . $key . '}'] = $val;
}
return strtr($input, $replace);
}
}
home/chryzalihi/www/wp-contentOLD/plugins/backwpup/vendor/OpenCloud/Common/Collection.php 0000604 00000026254 15245100644 0025647 0 ustar 00 <?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace OpenCloud\Common;
use OpenCloud\Common\Log\Logger;
/**
* @deprecated
* @codeCoverageIgnore
*/
class Collection extends Base
{
private $service;
private $itemClass;
private $itemList = array();
private $pointer = 0;
private $sortKey;
private $nextPageClass;
private $nextPageCallback;
private $nextPageUrl;
/**
* A Collection is an array of objects
*
* Some assumptions:
* * The `Collection` class assumes that there exists on its service
* a factory method with the same name of the class. For example, if
* you create a Collection of class `Foobar`, it will attempt to call
* the method `parent::Foobar()` to create instances of that class.
* * It assumes that the factory method can take an array of values, and
* it passes that to the method.
*
* @param Service $service - the service associated with the collection
* @param string $itemclass - the Class of each item in the collection
* (assumed to be the name of the factory method)
* @param array $arr - the input array
*/
public function __construct($service, $class, array $array = array())
{
$service->getLogger()->warning(Logger::deprecated(__METHOD__, 'OpenCloud\Common\Collection\CollectionBuilder'));
$this->setService($service);
$this->setNextPageClass($class);
// If they've supplied a FQCN, only get the last part
$class = (false !== ($classNamePos = strrpos($class, '\\')))
? substr($class, $classNamePos + 1)
: $class;
$this->setItemClass($class);
// Set data
$this->setItemList($array);
}
/**
* Set the entire data array.
*
* @param array $array
*/
private function setItemList(array $array)
{
$this->itemList = $array;
return $this;
}
/**
* Retrieve the entire data array.
*
* @return array
*/
public function getItemList()
{
return $this->itemList;
}
/**
* Set the service.
*
* @param Service|PersistentObject $service
*/
public function setService($service)
{
$this->service = $service;
return $this;
}
/**
* Retrieves the service associated with the Collection
*
* @return Service
*/
public function getService()
{
return $this->service;
}
/**
* Set the resource class name.
*/
private function setItemClass($itemClass)
{
$this->itemClass = $itemClass;
return $this;
}
/**
* Get item class.
*/
private function getItemClass()
{
return $this->itemClass;
}
/**
* Set the key that will be used for sorting.
*/
private function setSortKey($sortKey)
{
$this->sortKey = $sortKey;
return $this;
}
/**
* Get the key that will be used for sorting.
*/
private function getSortKey()
{
return $this->sortKey;
}
/**
* Set next page class.
*/
private function setNextPageClass($nextPageClass)
{
$this->nextPageClass = $nextPageClass;
return $this;
}
/**
* Get next page class.
*/
private function getNextPageClass()
{
return $this->nextPageClass;
}
/**
* for paginated collection, sets the callback function and URL for
* the next page
*
* The callback function should have the signature:
*
* function Whatever($class, $url, $parent)
*
* and the `$url` should be the URL of the next page of results
*
* @param callable $callback the name of the function (or array of
* object, function name)
* @param string $url the URL of the next page of results
* @return void
*/
public function setNextPageCallback($callback, $url)
{
$this->nextPageCallback = $callback;
$this->nextPageUrl = $url;
return $this;
}
/**
* Get next page callback.
*/
private function getNextPageCallback()
{
return $this->nextPageCallback;
}
/**
* Get next page URL.
*/
private function getNextPageUrl()
{
return $this->nextPageUrl;
}
/**
* Returns the number of items in the collection
*
* For most services, this is the total number of items. If the Collection
* is paginated, however, this only returns the count of items in the
* current page of data.
*
* @return int
*/
public function count()
{
return count($this->getItemList());
}
/**
* Pseudonym for count()
*
* @codeCoverageIgnore
*/
public function size()
{
return $this->count();
}
/**
* Resets the pointer to the beginning, but does NOT return the first item
*
* @api
* @return void
*/
public function reset()
{
$this->pointer = 0;
}
/**
* Resets the collection pointer back to the first item in the page
* and returns it
*
* This is useful if you're only interested in the first item in the page.
*
* @api
* @return Base the first item in the set
*/
public function first()
{
$this->reset();
return $this->next();
}
/**
* Return the item at a particular point of the array.
*
* @param mixed $offset
* @return mixed
*/
public function getItem($pointer)
{
return (isset($this->itemList[$pointer])) ? $this->itemList[$pointer] : false;
}
/**
* Add an item to this collection
*
* @param mixed $item
*/
public function addItem($item)
{
$this->itemList[] = $item;
}
/**
* Returns the next item in the page
*
* @api
* @return Base the next item or FALSE if at the end of the page
*/
public function next()
{
if ($this->pointer >= $this->count()) {
return false;
}
$data = $this->getItem($this->pointer++);
$class = $this->getItemClass();
// Are there specific methods in the parent/service that can be used to
// instantiate the resource? Currently supported: getResource(), resource()
foreach (array($class, 'get' . ucfirst($class)) as $method) {
if (method_exists($this->service, $method)) {
return call_user_func(array($this->service, $method), $data);
}
}
// Backup method
if (method_exists($this->service, 'resource')) {
return $this->service->resource($class, $data);
}
return false;
}
/**
* sorts the collection on a specified key
*
* Note: only top-level keys can be used as the sort key. Note that this
* only sorts the data in the current page of the Collection (for
* multi-page data).
*
* @api
* @param string $keyname the name of the field to use as the sort key
* @return void
*/
public function sort($keyname = 'id')
{
$this->setSortKey($keyname);
usort($this->itemList, array($this, 'sortCompare'));
}
/**
* selects only specified items from the Collection
*
* This provides a simple form of filtering on Collections. For each item
* in the collection, it calls the callback function, passing it the item.
* If the callback returns `TRUE`, then the item is retained; if it returns
* `FALSE`, then the item is deleted from the collection.
*
* Note that this should not supersede server-side filtering; the
* `Collection::Select()` method requires that *all* of the data for the
* Collection be retrieved from the server before the filtering is
* performed; this can be very inefficient, especially for large data
* sets. This method is mostly useful on smaller-sized sets.
*
* Example:
* <code>
* $services = $connection->ServiceList();
* $services->Select(function ($item) { return $item->region=='ORD';});
* // now the $services Collection only has items from the ORD region
* </code>
*
* `Select()` is *destructive*; that is, it actually removes entries from
* the collection. For example, if you use `Select()` to find items with
* the ID > 10, then use it again to find items that are <= 10, it will
* return an empty list.
*
* @api
* @param callable $testfunc a callback function that is passed each item
* in turn. Note that `Select()` performs an explicit test for
* `FALSE`, so functions like `strpos()` need to be cast into a
* boolean value (and not just return the integer).
* @returns void
* @throws DomainError if callback doesn't return a boolean value
*/
public function select($testfunc)
{
foreach ($this->getItemList() as $index => $item) {
$test = call_user_func($testfunc, $item);
if (!is_bool($test)) {
throw new Exceptions\DomainError(
Lang::translate('Callback function for Collection::Select() did not return boolean')
);
}
if ($test === false) {
unset($this->itemList[$index]);
}
}
}
/**
* returns the Collection object for the next page of results, or
* FALSE if there are no more pages
*
* Generally, the structure for a multi-page collection will look like
* this:
*
* $coll = $obj->Collection();
* do {
* while ($item = $coll->Next()) {
* // do something with the item
* }
* } while ($coll = $coll->NextPage());
*
* @api
* @return Collection if there are more pages of results, otherwise FALSE
*/
public function nextPage()
{
return ($this->getNextPageUrl() !== null)
? call_user_func($this->getNextPageCallback(), $this->getNextPageClass(), $this->getNextPageUrl())
: false;
}
/**
* Compares two values of sort keys
*/
private function sortCompare($a, $b)
{
$key = $this->getSortKey();
// Handle strings
if (is_string($a->$key)) {
return strcmp($a->$key, $b->$key);
}
// Handle others with logical comparisons
if ($a->$key == $b->$key) {
return 0;
} elseif ($a->$key < $b->$key) {
return -1;
} else {
return 1;
}
}
}