本文整理汇总了PHP中Illuminate\Database\Capsule\Manager::setCacheManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::setCacheManager方法的具体用法?PHP Manager::setCacheManager怎么用?PHP Manager::setCacheManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Capsule\Manager
的用法示例。
在下文中一共展示了Manager::setCacheManager方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Register the Illuminate Database service
*
* @param Silex\Application
*/
public function register(Application $app)
{
$app['db.connection_defaults'] = array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'test', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null);
$app['db.boot'] = true;
$app['db.global'] = true;
$app['db.container'] = $app->share(function () {
return new Container();
});
$app['db.dispatcher'] = $app->share(function () use($app) {
return new Dispatcher($app['db.container']);
});
if (class_exists('\\Illuminate\\Cache\\CacheManager')) {
$app['db.cache_manager'] = $app->share(function () use($app) {
return new \Illuminate\Cache\CacheManager($app['db.container']);
});
}
$app['db.cache'] = array('driver' => 'apc', 'prefix' => 'laravel');
$app['db'] = $app->share(function () use($app) {
$db = new Capsule($app['db.container']);
$db->setEventDispatcher($app['db.dispatcher']);
if (isset($app['db.cache_manager']) && isset($app['db.cache'])) {
$db->setCacheManager($app['db.cache_manager']);
foreach ($app['db.cache'] as $key => $value) {
$app['db.container']->offsetGet('config')->offsetSet('cache.' . $key, $value);
}
}
if ($app['db.global']) {
$db->setAsGlobal();
}
if ($app['db.boot']) {
$db->bootEloquent();
}
if (!isset($app['db.connections'])) {
$connection = array();
if (isset($app['db.connection'])) {
$connection = $app['db.connection'];
}
$app['db.connections'] = array('default' => $connection);
}
foreach ($app['db.connections'] as $connection => $options) {
$db->addConnection(array_replace($app['db.connection_defaults'], $options), $connection);
}
if (!$app['debug']) {
$db->connection()->disableQueryLog();
}
return $db;
});
}
开发者ID:mattkirwan,项目名称:illuminate-database-silex-service-provider,代码行数:53,代码来源:IlluminateDatabaseServiceProvider.php
示例2: register
/**
* Register the Capsule service.
*
* @param Application $app
**/
public function register(Application $app)
{
$app['capsule.connection_defaults'] = array('driver' => 'mysql', 'host' => 'localhost', 'database' => null, 'username' => 'root', 'password' => null, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null, 'logging' => false);
$app['capsule.global'] = true;
$app['capsule.eloquent'] = true;
$app['capsule.container'] = $app->share(function () {
return new Container();
});
$app['capsule.dispatcher'] = $app->share(function () use($app) {
return new Dispatcher($app['capsule.container']);
});
if (class_exists('Illuminate\\Cache\\CacheManager')) {
$app['capsule.cache_manager'] = $app->share(function () use($app) {
return new CacheManager($app['capsule.container']);
});
}
$app['capsule'] = $app->share(function ($name) use($app) {
$capsule = new Capsule($app['capsule.container']);
$capsule->setEventDispatcher($app['capsule.dispatcher']);
if (isset($app['capsule.cache_manager']) && isset($app['capsule.cache'])) {
$capsule->setCacheManager($app['capsule.cache_manager']);
foreach ($app['capsule.cache'] as $key => $value) {
$app['capsule.container']->offsetGet('config')->offsetSet('cache.' . $key, $value);
}
}
if ($app['capsule.global']) {
$capsule->setAsGlobal();
}
if ($app['capsule.eloquent']) {
$capsule->bootEloquent();
}
if (!isset($app['capsule.connections'])) {
$app['capsule.connections'] = array('default' => isset($app['capsule.connection']) ? $app['capsule.connection'] : array());
}
foreach ($app['capsule.connections'] as $connection => $options) {
$options = array_replace($app['capsule.connection_defaults'], $options);
$logging = $options['logging'];
unset($options['logging']);
$capsule->addConnection($options, $connection);
if ($logging) {
$capsule->connection($connection)->enableQueryLog();
} else {
$capsule->connection($connection)->disableQueryLog();
}
}
return $capsule;
});
}
示例3: setCacheManager
/**
* Set the cache manager to be used by connections.
*
* @param \Illuminate\Cache\CacheManager $cache
* @return void
*/
public function setCacheManager(CacheManager $cache)
{
$this->capsule->setCacheManager($cache);
}
示例4: dirname
<?php
namespace App;
include dirname(__FILE__) . "/../config/config.php";
use Illuminate\Container\Container;
// Only needed for DB
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Cache\CacheManager;
$dbc = new DB();
$dbc->addConnection(['driver' => 'mysql', 'host' => $config['host'], 'database' => $config['database'], 'username' => $config['username'], 'password' => $config['password'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false]);
// $dbc->setFetchMode(PDO::FETCH_CLASS);
$container = $dbc->getContainer();
$container['config']['cache.driver'] = $config['cache_driver'];
$container['config']['cache.path'] = $config['cache_path'];
$container['config']['cache.prefix'] = "rr20";
$container['files'] = new Filesystem();
$container['config']['cache.memcached'] = ['host' => $config['cache_servers'], 'port' => $config['cache_port'], 'weight' => 100];
$container->offsetGet('config')->offsetSet('cache.driver', 'array');
$cacheManager = new CacheManager($container);
$dbc->setEventDispatcher(new Dispatcher(new Container()));
$dbc->setCacheManager($cacheManager);
$dbc->setAsGlobal();
$dbc->bootEloquent();
global $dbc;
// $cache = new \Blablacar\Memcached\Client();
// $cache->addServer($config['cache_servers'], $config['cache_port']);
示例5: Filesystem
$container = $capsule->getContainer();
$container['config']['cache.driver'] = 'file';
$container['config']['cache.path'] = $cache_dir;
$container['files'] = new Filesystem();
$capsule->setCacheManager(new CacheManager($container));
$cache = $container->make('cache');
$cache->put('cache-test', 'Howdy. I am teh cache.', 500);
echo $cache->get('cache-test');
});
$app->get('/cacheDatabase', function () use($cache_dir) {
// Filesystem cache, merged with basic database connection for 'remember'
$capsule = new Capsule();
$container = $capsule->getContainer();
$container['config']['cache.driver'] = 'file';
$container['config']['cache.path'] = $cache_dir;
$container['files'] = new Filesystem();
$capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'illuminate_non_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container()));
// Set the cache manager instance used by connections... (optional)
$capsule->setCacheManager(new CacheManager($container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
// Use it
echo '<pre>';
$user = Capsule::table('users')->where('id', 1)->remember(10)->get();
var_dump($user);
});
$app->run();