Cachearium\CacheAbstract::factory PHP Method

factory() public static method

Returns a cache
public static factory ( string $backend ) : CacheAbstract
$backend string
return CacheAbstract
    public static function factory($backend)
    {
        $classname = '\\Cachearium\\Backend\\Cache' . $backend;
        if (!class_exists($classname)) {
            throw new Exceptions\CacheInvalidBackendException("Class does not exist");
        }
        return $classname::singleton();
    }

Usage Example

 public function testFactory()
 {
     try {
         CacheAbstract::factory("invalidbackend");
         $this->assertTrue(false);
     } catch (Cachearium\Exceptions\CacheInvalidBackendException $e) {
         $this->assertTrue(true);
     }
 }
All Usage Examples Of Cachearium\CacheAbstract::factory