本文整理汇总了PHP中Illuminate\Database\Capsule\Manager类的典型用法代码示例。如果您正苦于以下问题:PHP Manager类的具体用法?PHP Manager怎么用?PHP Manager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Application $app)
{
$app['illuminate.db.default_options'] = array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '');
$app['illuminate.db'] = $app->share(function ($app) {
return $app['illuminate.capsule']->getConnection($app['illuminate.db.default_connection']);
});
$app['illuminate.db.options.initializer'] = $app->protect(function () use($app) {
if (!isset($app['illuminate.db.options'])) {
$app['illuminate.db.options'] = array('default' => array());
}
$tmp = $app['illuminate.db.options'];
foreach ($tmp as $name => &$options) {
$options = array_replace($app['illuminate.db.default_options'], $options);
if (!isset($app['illuminate.db.default_connection'])) {
$app['illuminate.db.default_connection'] = $name;
}
}
$app['illuminate.db.options'] = $tmp;
});
$app['illuminate.capsule'] = $app->share(function ($app) {
$app['illuminate.db.options.initializer']();
$capsule = new Manager();
foreach ($app['illuminate.db.options'] as $name => $options) {
$capsule->addConnection($options, $name);
}
return $capsule;
});
}
示例2: onBootstrap
/**
* @param MvcEvent $event
*/
public function onBootstrap(MvcEvent $event)
{
$eventManager = $event->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$app = $event->getApplication();
$serviceManager = $app->getServiceManager();
// Set the Query Profiler
$profiler = new DoplioFirePhpProfiler();
$capsule = new Capsule();
$config = $serviceManager->get('config')['database'];
foreach ($config as $connName => $dbConfig) {
$capsule->addConnection($dbConfig, $connName);
if (isset($dbConfig['profiler']) && $dbConfig['profiler'] === TRUE) {
$profiler->enable();
}
}
// $capsule->setCacheManager();
$capsule->bootEloquent();
$serviceManager->setService('Doplio', $capsule);
$serviceManager->setService('DoplioFirePhpProfiler', $profiler);
$eventManager->attach(MvcEvent::EVENT_FINISH, function () use($capsule, $config, $profiler) {
if ($profiler->isDisabled()) {
return;
}
foreach ($config as $connectionName => $notUsed) {
$connection = $capsule->getConnection($connectionName);
foreach ($connection->getQueryLog() as $query) {
$profiler->addQuery($query, $connectionName);
}
}
$profiler->showTables();
});
}
示例3: initialize
/**
* Initializes the Eloquent ORM.
*/
public function initialize()
{
$this->capsule->bootEloquent();
if ('default' !== $this->defaultConnection) {
$this->capsule->getDatabaseManager()->setDefaultConnection($this->defaultConnection);
}
}
示例4: register
public function register(Application $app)
{
$app['illuminate.db.default_options'] = (require $app['base_dir'] . '/backend/config/database.php');
$app['illuminate.db'] = $app->share(function ($app) {
return $app['illuminate.capsule']->getConnection($app['illuminate.db.default_connection']);
});
$app['illuminate.db.options.initializer'] = $app->protect(function () use($app) {
if (!isset($app['illuminate.db.options'])) {
$app['illuminate.db.options'] = array('default' => array());
}
$tmp = $app['illuminate.db.options'];
foreach ($tmp as $name => &$options) {
$options = array_replace($app['illuminate.db.default_options'], $options);
if (!isset($app['illuminate.db.default_connection'])) {
$app['illuminate.db.default_connection'] = $name;
}
}
$app['illuminate.db.options'] = $tmp;
});
$app['illuminate.capsule'] = $app->share(function ($app) {
$app['illuminate.db.options.initializer']();
$capsule = new Manager();
foreach ($app['illuminate.db.options'] as $name => $options) {
$capsule->addConnection($options, $name);
}
return $capsule;
});
}
示例5: _makeEloquent
/**
* Setup eloquent database
* @param \Illuminate\Database\Capsule\Manager $capsule
* @throws \Lassi\App\Exception\NotFoundException
* @return \Lassi\App\Database
*/
private function _makeEloquent(Capsule $capsule)
{
// Throw exception if minimum requirements not met
if (!getenv('db_driver') || !getenv('db_name')) {
throw new NotFoundException('App configurations not found.');
}
// Get capsule instance
$this->capsule = $capsule;
// Cache db driver
$db_driver = getenv('db_driver');
// Setup connection defaults
$configs = array('driver' => $db_driver, 'database' => getenv('db_name'), 'prefix' => getenv('db_prefix'), 'charset' => getenv('db_charset'), 'collation' => getenv('db_collation'));
// Add extras depending on type of driver/connection
if ($db_driver !== 'sqlite') {
if (getenv('db_host')) {
$configs['host'] = getenv('db_host');
}
if (getenv('db_username')) {
$configs['username'] = getenv('db_username');
}
if (getenv('db_password')) {
$configs['password'] = getenv('db_password');
}
}
// Setup connection
$this->capsule->addConnection($configs);
// Set as global
$this->capsule->setAsGlobal();
// Boot eloquent
$this->capsule->bootEloquent();
return $this;
}
示例6: register
public function register()
{
$this->app->singleton('laravel.db', function ($app) {
$config = $app['config'];
// Get the default database from the configuration
$default = $config['database.default'];
// Create an capsule instance
$capsule = new CapsuleManager($app);
// Override the default value with the user's config value
$config['database.default'] = $default;
if (!isset($config['database.connections']) || empty($config['database.connections'])) {
throw new ConfigurationException("Invalid database configuration");
}
$connections = $config['database.connections'];
foreach ($connections as $name => $connectionConfig) {
$capsule->addConnection($connectionConfig, $name);
}
$capsule->setAsGlobal();
// Setup the Eloquent ORM...
if ($config['eloquent.boot'] === true) {
$capsule->bootEloquent();
}
return $capsule->getDatabaseManager();
});
}
示例7: configureDatabase
protected function configureDatabase()
{
$db = new DB();
$db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
$db->bootEloquent();
$db->setAsGlobal();
}
示例8: setUpDatabase
/**
* @return DB
*/
public function setUpDatabase()
{
$db = new DB();
$db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
$db->setAsGlobal();
$db->bootEloquent();
}
示例9: configureDatabaseConnection
/**
* Set up the database connection.
*
* @before
* @return void
*/
protected function configureDatabaseConnection()
{
$database = new DB();
$database->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
$database->bootEloquent();
$database->setAsGlobal();
}
示例10: init
public function init()
{
$this->capsule = new Capsule();
$this->capsule->addConnection(['driver' => 'mysql', 'host' => DB_HOST, 'port' => DB_PORT, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => DB_CHARSET, 'collation' => DB_COLLATION]);
$this->capsule->bootEloquent();
$this->capsule->setAsGlobal();
}
示例11: __construct
public function __construct()
{
$capsule = new Capsule();
$capsule->addConnection(["driver" => "mysql", "host" => "localhost", "database" => "development", "username" => "developer", "password" => "developer", "charset" => "utf8", "collation" => "utf8_general_ci", "prefix" => ""]);
$capsule->setEventDispatcher(new Dispatcher(new Container()));
$capsule->bootEloquent();
}
示例12: start
/**
* Initialize the Eloquent ORM.
*
*/
public static function start()
{
$capsule = new Capsule();
$capsule->addConnection(['driver' => 'mysql', 'host' => DB_HOST, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASS, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
示例13: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['application.speakers'] = $app->share(function ($app) {
$userMapper = $app['spot']->mapper(\OpenCFP\Domain\Entity\User::class);
$talkMapper = $app['spot']->mapper(\OpenCFP\Domain\Entity\Talk::class);
$speakerRepository = new SpotSpeakerRepository($userMapper);
return new Speakers(new CallForProposal(new \DateTime($app->config('application.enddate'))), new SentryIdentityProvider($app['sentry'], $speakerRepository), $speakerRepository, new SpotTalkRepository($talkMapper), new EventDispatcher());
});
$app[AirportInformationDatabase::class] = $app->share(function ($app) {
$capsule = new Capsule();
$capsule->addConnection(['driver' => 'mysql', 'host' => $app->config('database.host'), 'database' => $app->config('database.database'), 'username' => $app->config('database.user'), 'password' => $app->config('database.password'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
$capsule->setAsGlobal();
return new IlluminateAirportInformationDatabase($capsule);
});
$app['security.random'] = $app->share(function ($app) {
return new PseudoRandomStringGenerator(new Factory());
});
$app['oauth.resource'] = $app->share(function ($app) {
$sessionStorage = new SessionStorage();
$accessTokenStorage = new AccessTokenStorage();
$clientStorage = new ClientStorage();
$scopeStorage = new ScopeStorage();
$server = new ResourceServer($sessionStorage, $accessTokenStorage, $clientStorage, $scopeStorage);
return $server;
});
$app['application.speakers.api'] = $app->share(function ($app) {
$userMapper = $app['spot']->mapper(\OpenCFP\Domain\Entity\User::class);
$talkMapper = $app['spot']->mapper(\OpenCFP\Domain\Entity\Talk::class);
$speakerRepository = new SpotSpeakerRepository($userMapper);
return new Speakers(new CallForProposal(new \DateTime($app->config('application.enddate'))), new OAuthIdentityProvider($app['oauth.resource'], $speakerRepository), $speakerRepository, new SpotTalkRepository($talkMapper), new EventDispatcher());
});
}
示例14: boot
public static function boot()
{
require BASE_PATH . '/vendor/autoload.php';
$capsule = new Capsule();
$capsule->addConnection(Config::get('database.connections.' . Config::get('database.default')));
$capsule->bootEloquent();
}
示例15: setUpDatabases
private function setUpDatabases()
{
$database = new DB();
$database->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
$database->bootEloquent();
$database->setAsGlobal();
}