mirror of
https://github.com/predis/predis.git
synced 2026-10-14 16:02:50 +00:00
[phpdoc] Add API documentation.
This is a starting point to add a documentation of the whole set of APIs and classes of Predis. The next step will be to actually improve and extend it.
This commit is contained in:
@@ -17,6 +17,11 @@ use Predis\Options\ClientProfile;
|
||||
use Predis\Options\ClientCluster;
|
||||
use Predis\Options\ClientConnectionFactory;
|
||||
|
||||
/**
|
||||
* Class that manages validation and conversion of client options.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ClientOptions
|
||||
{
|
||||
private static $_sharedOptions;
|
||||
@@ -26,12 +31,20 @@ class ClientOptions
|
||||
|
||||
private $_options = array();
|
||||
|
||||
/**
|
||||
* @param array $options Array of client options.
|
||||
*/
|
||||
public function __construct(Array $options = array())
|
||||
{
|
||||
$this->_handlers = $this->initialize($options);
|
||||
$this->_defined = array_keys($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the default options are initialized.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getSharedOptions()
|
||||
{
|
||||
if (isset(self::$_sharedOptions)) {
|
||||
@@ -48,18 +61,35 @@ class ClientOptions
|
||||
return self::$_sharedOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines an option handler or overrides an existing one.
|
||||
*
|
||||
* @param string $option Name of the option.
|
||||
* @param IOption $handler Handler for the option.
|
||||
*/
|
||||
public static function define($option, IOption $handler)
|
||||
{
|
||||
self::getSharedOptions();
|
||||
self::$_sharedOptions[$option] = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undefines the handler for the specified option.
|
||||
*
|
||||
* @param string $option Name of the option.
|
||||
*/
|
||||
public static function undefine($option)
|
||||
{
|
||||
self::getSharedOptions();
|
||||
unset(self::$_sharedOptions[$option]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes client options handlers.
|
||||
*
|
||||
* @param array $options List of client options values.
|
||||
* @return array
|
||||
*/
|
||||
private function initialize($options)
|
||||
{
|
||||
$handlers = self::getSharedOptions();
|
||||
@@ -76,11 +106,23 @@ class ClientOptions
|
||||
return $handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified option is set.
|
||||
*
|
||||
* @param string $option Name of the option.
|
||||
* @return Boolean
|
||||
*/
|
||||
public function __isset($option)
|
||||
{
|
||||
return in_array($option, $this->_defined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the specified option.
|
||||
*
|
||||
* @param string $option Name of the option.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($option)
|
||||
{
|
||||
if (isset($this->_options[$option])) {
|
||||
|
||||
Reference in New Issue
Block a user