Commit 9281f04c authored by Taylor Otwell's avatar Taylor Otwell

minor refactorings.

parent 41ca8169
<?php namespace Laravel\Cache\Drivers;
use Laravel\Config;
class Factory {
/**
* Create a new cache driver instance.
*
* @param string $driver
* @return Driver
*/
public static function make($driver)
{
switch ($driver)
{
case 'apc':
return new APC(Config::get('cache.key'));
case 'file':
return new File(CACHE_PATH);
case 'memcached':
return new Memcached(\Laravel\Memcached::instance(), Config::get('cache.key'));
case 'redis':
return new Redis(\Laravel\Redis::db());
default:
throw new \Exception("Cache driver {$driver} is not supported.");
}
}
}
\ No newline at end of file
......@@ -36,17 +36,39 @@ class Manager {
if ( ! array_key_exists($driver, static::$drivers))
{
if ( ! IoC::registered("laravel.cache.{$driver}"))
{
throw new \Exception("Cache driver [$driver] is not supported.");
}
return static::$drivers[$driver] = Drivers\Factory::make($driver);
return static::$drivers[$driver] = static::factory($driver);
}
return static::$drivers[$driver];
}
/**
* Create a new cache driver instance.
*
* @param string $driver
* @return Driver
*/
protected static function factory($driver)
{
switch ($driver)
{
case 'apc':
return new Drivers\APC(Config::get('cache.key'));
case 'file':
return new Drivers\File(CACHE_PATH);
case 'memcached':
return new Drivers\Memcached(Memcached::instance(), Config::get('cache.key'));
case 'redis':
return new Drivers\Redis(Redis::db());
default:
throw new \Exception("Cache driver {$driver} is not supported.");
}
}
/**
* Pass all other methods to the default cache driver.
*
......
<?php namespace Laravel\Database\Connectors;
class Factory {
/**
* Create a new database connector instance.
*
* @param string $driver
* @return Connector
*/
public static function make($driver)
{
switch ($driver)
{
case 'sqlite':
return new SQLite(DATABASE_PATH);
case 'mysql':
return new MySQL;
case 'pgsql':
return new Postgres;
default:
throw new \Exception("Database driver [$driver] is not supported.");
}
}
}
\ No newline at end of file
......@@ -65,7 +65,31 @@ class Manager {
return call_user_func($config['connector'], $config);
}
return Connectors\Factory::make($config['driver'])->connect($config);
return static::connector($config['driver'])->connect($config);
}
/**
* Create a new database connector instance.
*
* @param string $driver
* @return Connector
*/
protected static function connector($driver)
{
switch ($driver)
{
case 'sqlite':
return new Connectors\SQLite(DATABASE_PATH);
case 'mysql':
return new Connectors\MySQL;
case 'pgsql':
return new Connectors\Postgres;
default:
throw new \Exception("Database driver [$driver] is not supported.");
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment