CacheEngine::Factory PHP Метод

Factory() публичный статический Метод

Loads the engine specified by the given name.
public static Factory ( $p_engineName, $p_path = null ) : boolean
$p_engineName
Результат boolean
    public static function Factory($p_engineName, $p_path = null)
    {
        if (is_null($p_path)) {
            $path = dirname(__FILE__);
        } else {
            $path = $p_path;
        }
        $filePath = "{$path}/CacheEngine_{$p_engineName}.php";
        if (!file_exists($filePath)) {
            throw new InvalidCacheEngine($p_engineName);
        }
        require_once $filePath;
        $className = "CacheEngine_{$p_engineName}";
        if (!class_exists($className)) {
            throw new InvalidCacheEngine($p_engineName);
        }
        $cacheObj = new $className();
        if ($cacheObj->isSupported()) {
            return $cacheObj;
        }
        return null;
    }

Usage Example

Пример #1
0
 /**
  * Returns true if the given cache engine was supported
  *
  * @param $p_cacheEngine
  * @return boolean
  *                 TRUE on success, FALSE on failure
  */
 public static function IsSupported($p_cacheEngine = null)
 {
     if (empty($p_cacheEngine)) {
         return false;
     }
     try {
         if ($cacheEngine = CacheEngine::Factory($p_cacheEngine)) {
             return true;
         } else {
             return false;
         }
     } catch (InvalidCacheEngine $ex) {
         return false;
     }
 }