Skip to content
Browse files

Streamlining the memcache client constructor and configuration, to ma…

…ke way for easier unit testing
  • Loading branch information...
1 parent 00dac13 commit 62488baad3eb39a84d01ea58f3b7171558277577 Kevin Boyd committed Nov 19, 2011
Showing with 7 additions and 24 deletions.
  1. +3 −23 Client/MemcacheClient.php
  2. +4 −1 Resources/config/services.yml
View
26 Client/MemcacheClient.php
@@ -15,41 +15,21 @@
*/
class MemcacheClient implements CacheClientInterface
{
- public $dic = null;
-
protected $safe = false;
protected $mem = null;
protected $servers = array();
protected $sockttl = 0.2;
protected $compression = false;
/**
- * Checks for the existence of the Memcache extension, and instantiates an internal Memcache instance
- * if it exists (throws an exception if the extension is not found).
- *
- * @access public
- * @return void
- */
- public function __construct()
- {
- if ( !class_exists( 'Memcache' ) )
- {
- throw new \Exception( 'Memcache Is Not Installed' );
- }
-
- $this->mem = new \Memcache();
- }
-
- /**
- * Inject a dependency injection container
+ * Constructs the cache client using an injected Memcache instance
*
- * @param mixed $dic
* @access public
* @return void
*/
- public function setContainer( $dic )
+ public function __construct( \Memcache $memcache )
{
- $this->dic = $dic;
+ $this->mem = $memcache;
}
/**
View
5 Resources/config/services.yml
@@ -1,13 +1,16 @@
parameters:
beryllium_cache.class: Beryllium\CacheBundle\Cache
beryllium_cache.client.class: Beryllium\CacheBundle\Client\MemcacheClient
+ beryllium_cache.client.memcache.class: Memcache
beryllium_cache.client.servers: { 127.0.0.1 : 11211 }
services:
+ beryllium_cache.client.memcache:
+ class: %beryllium_cache.client.memcache.class%
beryllium_cache.client:
class: %beryllium_cache.client.class%
+ arguments: [@beryllium_cache.client.memcache]
calls:
- - [ setContainer, [ @service_container ] ]
- [ addServers, [ %beryllium_cache.client.servers% ] ]
beryllium_cache:
class: %beryllium_cache.class%

0 comments on commit 62488ba

Please sign in to comment.
Something went wrong with that request. Please try again.