minor refactorings.

This commit is contained in:
Taylor Otwell 2011-11-11 23:15:17 -06:00
parent 41ca816951
commit 9281f04cdd
4 changed files with 53 additions and 70 deletions

View File

@ -1,34 +0,0 @@
<?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.");
}
}
}

View File

@ -36,17 +36,39 @@ public static function driver($driver = null)
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.
*

View File

@ -1,29 +0,0 @@
<?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.");
}
}
}

View File

@ -65,7 +65,31 @@ protected static function connect($config)
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.");
}
}
/**