本文整理匯總了PHP中Illuminate\Database\Capsule\Manager::getContainer方法的典型用法代碼示例。如果您正苦於以下問題:PHP Manager::getContainer方法的具體用法?PHP Manager::getContainer怎麽用?PHP Manager::getContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Database\Capsule\Manager
的用法示例。
在下文中一共展示了Manager::getContainer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
public function __construct(array $connections)
{
$useEloquent = true;
$fetchMode = null;
$defaultConnName = null;
$capsule = new Capsule();
foreach ($connections as $name => $conn) {
if (!$useEloquent && isset($conn['eloquent'])) {
$useEloquent = true;
}
if ($fetchMode === null && isset($conn['fetch_mode']) && !empty($conn['fetch_mode'])) {
$fetchMode = $conn['fetch_mode'];
}
if ($defaultConnName === null && isset($conn['default']) && $conn['default'] === true) {
$defaultConnName = $name;
}
$capsule->addConnection($this->normaliseConfigKeys($conn), $name);
}
// Set the Capsule configuration options
$config = $capsule->getContainer()->make('config');
$config['database.fetch'] = $fetchMode ?: PDO::FETCH_ASSOC;
$config['database.default'] = $defaultConnName ?: 'default';
$capsule->getContainer()->instance('config', $config);
// If the users are using eloquent, lets boot it
if ($useEloquent) {
$capsule->bootEloquent();
}
$capsule->setAsGlobal();
$this->capsule = $capsule;
}
示例2: getContainer
/**
* Get the IoC container instance.
*
* @return \Illuminate\Container\Container
*/
public function getContainer()
{
return $this->capsule->getContainer();
}
示例3: 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']);
示例4: function
$app->get('/', function () use($cache_dir) {
// Filesystem cache
$capsule = new Capsule();
$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();