Vilma_Driver::factory PHP Method

factory() public static method

Attempts to return a concrete Vilma_Driver instance based on $driver.
public static factory ( string $driver = null, array $params = null ) : Vilma_Driver
$driver string The type of concrete Vilma_Driver subclass to return.
$params array A hash containing any additional configuration or connection parameters a subclass might need.
return Vilma_Driver The newly created concrete Vilma_Driver instance.
    public static function factory($driver = null, $params = null)
    {
        if (is_null($driver)) {
            $driver = $GLOBALS['conf']['storage']['driver'];
        }
        $driver = Horde_String::ucfirst(basename($driver));
        if (is_null($params)) {
            $params = Horde::getDriverConfig('storage', $driver);
        }
        $class = 'Vilma_Driver_' . $driver;
        if (class_exists($class)) {
            return new $class($params);
        }
        throw new Vilma_Exception(sprintf(_("No such backend \"%s\" found"), $driver));
    }

Usage Example

Esempio n. 1
0
 protected function _init()
 {
     $this->driver = Vilma_Driver::factory();
     // Get the currently active domain, possibly storing a change into the
     // session.
     // Domain is passed in by ID, which may or may not be the
     // the same as the actual DNS domain name.
     $domain_id = Horde_Util::getFormData('domain_id');
     if (strlen($domain_id)) {
         $domain = $this->driver->getDomain($domain_id);
         if (!empty($domain['domain_name'])) {
             $this->curdomain = $domain;
             Vilma::setCurDomain($domain);
         }
     } elseif ($domain = $GLOBALS['session']->get('vilma', 'domain')) {
         $this->curdomain = $domain;
     }
 }