TrackManiaControl/libs/curl-easy/cURL/Collection.php

79 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2014-02-18 18:15:12 +01:00
<?php
namespace cURL;
class Collection
{
/**
* @var array Collection
*/
protected $data = array();
/**
* Converts current object to array
2015-01-19 11:15:52 +01:00
*
2014-02-18 18:15:12 +01:00
* @return array
*/
public function toArray()
{
return $this->data;
}
/**
* Sets value
2015-01-19 11:15:52 +01:00
*
2014-02-18 18:15:12 +01:00
* @param mixed $key Key
* @param mixed $value Value
* @return self
*/
public function set($key, $value = null)
{
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->data[$k] = $v;
}
} else {
$this->data[$key] = $value;
}
return $this;
}
/**
* Checks if key does exist
2015-01-19 11:15:52 +01:00
*
2014-02-18 18:15:12 +01:00
* @param mixed $key Key
* @return bool TRUE if exists, FALSE otherwise
*/
public function has($key)
{
return isset($this->data[$key]);
}
/**
2015-01-19 11:15:52 +01:00
* Returns value of $key
*
2014-02-18 18:15:12 +01:00
* @param mixed $key Key
2015-01-19 11:15:52 +01:00
* @throws Exception Key does not exist
2014-02-18 18:15:12 +01:00
* @return mixed Value of key
*/
public function get($key)
{
if ($this->has($key)) {
return $this->data[$key];
} else {
throw new Exception('Key does not exist.');
}
}
/**
* Removes key
2015-01-19 11:15:52 +01:00
*
2014-02-18 18:15:12 +01:00
* @param mixed $key Key to remove
* @return self
*/
public function remove($key)
{
unset($this->data[$key]);
return $this;
}
}