Skip to content

Commit

Permalink
More docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
boenrobot committed Jan 20, 2012
1 parent 7b3aca1 commit a7dea44
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
49 changes: 44 additions & 5 deletions src/PEAR2/Cache/SHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,39 @@
*/
namespace PEAR2\Cache;

/**
* Main class for this package.
*
* Automatically chooses an adapter based on the available extensions.
*
* @category Cache
* @package PEAR2_Cache_SHM
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear2.php.net/PEAR2_Cache_SHM
*/
class SHM
{
protected $adapter;
public function __construct($persistendId)

/**
* Creates a new shared memory storage.
*
* Estabilishes a separate persistent storage.
*
* @param string|SHM\Adapter $persistentId The ID for the storage or an
* already instanciated storage adapter. If an ID is specified, an adapter
* will automatically be chosen based on the available extensions.
*/
public function __construct($persistentId)
{
if ($persistendId instanceof SHM\Adapter) {
$this->adapter = $persistendId;
if ($persistentId instanceof SHM\Adapter) {
$this->adapter = $persistentId;
} else {
if (version_compare(phpversion('apc'), '3.0.13', '>=')) {
$this->adapter = new SHM\Adapter\APC($persistendId);
$this->adapter = new SHM\Adapter\APC($persistentId);
} elseif (version_compare(phpversion('wincache'), '1.1.0', '>=')) {
$this->adapter = new SHM\Adapter\Wincache($persistendId);
$this->adapter = new SHM\Adapter\Wincache($persistentId);
} else {
throw new SHM\InvalidArgumentException(
'No appropriate adapter available', 1
Expand All @@ -40,11 +61,29 @@ public function __construct($persistendId)
}
}

/**
* Get the currently set SHM adapter.
*
* @return SHM\Adapter The currently set adapter
*/
public function getAdapter()
{
return $this->adapter;
}

/**
* Calls a method from the adapter.
*
* This is a magic method, thanks to which any method you call will be
* redirected to the adapter. Every adapter implements at minimum the
* {@link SHM\Adapter} interface, so check it out for what you can expect as
* common functionality.
*
* @param string $method The adapter method to call/
* @param array $args The arguments to the method.
*
* @return mixed Whatever the adapter method returns.
*/
public function __call($method, $args)
{
return call_user_func_array(
Expand Down
9 changes: 9 additions & 0 deletions src/PEAR2/Cache/SHM/Adapter/APC.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
*/
use PEAR2\Cache\SHM;

/**
* Shared memory adapter for the APC extension.
*
* @category Cache
* @package PEAR2_Cache_SHM
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear2.php.net/PEAR2_Cache_SHM
*/
class APC implements Adapter
{
/**
Expand Down
9 changes: 9 additions & 0 deletions src/PEAR2/Cache/SHM/Adapter/Wincache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
*/
use PEAR2\Cache\SHM;

/**
* Shared memory adapter for the WinCache extension.
*
* @category Cache
* @package PEAR2_Cache_SHM
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear2.php.net/PEAR2_Cache_SHM
*/
class Wincache implements Adapter
{
/**
Expand Down

0 comments on commit a7dea44

Please sign in to comment.