Пример #1
0
 public static function configure(array $config = null)
 {
     if (empty($config) or empty($config["store"])) {
         $store = "null";
     } else {
         $store = $config["store"];
     }
     // if we've passed custom Store instance
     if (!is_string($store)) {
         $storeInterface = $store;
     } else {
         $storeConfig = isset($config[$store]) ? $config[$store] : array();
         if ($store == "memcached") {
             $storeInterface = MemcachedStore::factory($storeConfig);
         } elseif ($store == "memcache") {
             $storeInterface = MemcacheStore::factory($storeConfig);
         } elseif ($store == "apc") {
             $storeInterface = new ApcStore($storeConfig);
         } elseif ($store == "file") {
             $storeInterface = new FileStore($storeConfig["path"]);
         } elseif ($store == "null") {
             $storeInterface = new NullStore();
         } else {
             $storeInterface = DI::reflect($store, $storeConfig);
         }
     }
     // creating new SugiPHP\Cache instance
     $instance = new SugiPhpCache($storeInterface);
     // check we want keys prefix
     if (!empty($config["prefix"])) {
         $instance->setPrefix($config["prefix"]);
     }
     // save it
     static::$instance = $instance;
 }
Пример #2
0
 public static function factory($params)
 {
     if (empty($params["type"])) {
         throw new DBException("Required database type parameter is missing", "internal_error");
     }
     $type = $params["type"];
     unset($params["type"]);
     if (isset($params[$type]) and is_array($params[$type])) {
         $params = $params[$type];
     }
     // if we've passed custom Store instance
     if (!is_string($type)) {
         $driver = $type;
     } else {
         $type = strtolower($type);
         if ($type == "mysql" or $type == "mysqli") {
             $driver = new mysql($params);
         } elseif ($type == "pgsql") {
             $driver = new pgsql($params);
         } elseif ($type == "sqlite" or $type == "sqlite3") {
             $driver = new sqlite($params);
         } else {
             $driver = DI::reflect($type, $params);
         }
     }
     return new DB($driver);
 }
Пример #3
0
Файл: di.php Проект: rezon/sugi
    }
}
class B
{
    protected function __construct(A $a, $p1, $p2 = "1", $p3 = "!")
    {
        echo "<p>Constructor B({$a}, {$p1} {$p2}{$p3})</p>";
    }
    public static function factory(A $a)
    {
        echo "<p>B::factory({$a})</p>";
        return new self($a, "I am number");
    }
    public function __toString()
    {
        return "B";
    }
}
class C
{
    public function __construct(A $a, B $b, $p1, $p2)
    {
        echo "<p>Constructor C({$a}, {$b}, {$p1} {$p2})</p>";
    }
    public function __toString()
    {
        return "C";
    }
}
$c = \Sugi\DI::reflect("C", array("p1" => "Formula", "p2" => "One"));