当前位置: 首页>>代码示例>>PHP>>正文


PHP Manager::getDatabaseManager方法代码示例

本文整理汇总了PHP中Illuminate\Database\Capsule\Manager::getDatabaseManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::getDatabaseManager方法的具体用法?PHP Manager::getDatabaseManager怎么用?PHP Manager::getDatabaseManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Capsule\Manager的用法示例。


在下文中一共展示了Manager::getDatabaseManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setValidator

 protected function setValidator()
 {
     $filesystem = new FileLoader(new Filesystem(), CONFIG_DIR . DIRECTORY_SEPARATOR . 'langs');
     $translator = new Translator($filesystem, Main::$app->web->get('locale', false) ?: 'en');
     $this->validator = new ValidatorFactory($translator);
     $verifier = new DatabasePresenceVerifier($this->capsule->getDatabaseManager());
     $this->validator->setPresenceVerifier($verifier);
 }
开发者ID:xandros15,项目名称:aigisu,代码行数:8,代码来源:Connection.php

示例2: initialize

 /**
  * Initializes the Eloquent ORM.
  */
 public function initialize()
 {
     $this->capsule->bootEloquent();
     if ('default' !== $this->defaultConnection) {
         $this->capsule->getDatabaseManager()->setDefaultConnection($this->defaultConnection);
     }
 }
开发者ID:wouterj,项目名称:eloquent-bundle,代码行数:10,代码来源:EloquentInitializer.php

示例3: 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();
     });
 }
开发者ID:singularity321,项目名称:Arty,代码行数:25,代码来源:DatabaseServiceProvider.php

示例4: getConnectionResolver

 /**
  * @param $config
  * @return \Illuminate\Database\ConnectionResolverInterface
  */
 protected function getConnectionResolver($config)
 {
     $name = $config['database.default'];
     $conn = $config['database.connections'][$name];
     $db = new Manager();
     $db->addConnection($conn);
     return $db->getDatabaseManager();
 }
开发者ID:yusukezzz,项目名称:migrator,代码行数:12,代码来源:MigrationProvider.php

示例5: setUp

 public function setUp()
 {
     $this->fileSystem = new Filesystem();
     $this->cache = new Repository(new FileStore($this->fileSystem, './cache'));
     $this->fileSystem->copy('./stubs.sqlite', './stubs-real.sqlite');
     $capsule = new Capsule();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => './stubs-real.sqlite', 'prefix' => '']);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     $this->connection = $capsule->getDatabaseManager()->connection('default');
 }
开发者ID:wandu,项目名称:laravel-repository,代码行数:11,代码来源:RepositoryTestCase.php

示例6: initDb

 protected function initDb()
 {
     $capsule = new Manager();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', 'fetch' => PDO::FETCH_CLASS]);
     $capsule->getConnection()->setFetchMode(PDO::FETCH_CLASS);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     $this->db = $capsule->getDatabaseManager();
     $this->createTables();
     $this->initMuffing();
     return $this->db;
 }
开发者ID:pnagaraju25,项目名称:tbmsg,代码行数:12,代码来源:TestCaseDb.php

示例7: connect

 /**
  * Start up eloquent
  *
  * @param array|null $credentials
  *
  * @return \Illuminate\Database\Connection|null
  */
 public function connect(array $credentials = null)
 {
     if ($credentials = $credentials ?? $this->getDsn()) {
         $this->capsule->getDatabaseManager()->purge($this->capsule->getDatabaseManager()->getDefaultConnection());
         $this->capsule->addConnection(array_merge(['driver' => 'mysql', 'host' => 'localhost', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => ''], $credentials));
         $this->capsule->setEventDispatcher($this->dispatcher);
         $this->capsule->setAsGlobal();
         $this->capsule->bootEloquent();
         $this->connection = $this->capsule->getConnection();
         $this->connection->enableQueryLog();
         return $this->connection;
     }
     return null;
 }
开发者ID:minutephp,项目名称:framework,代码行数:21,代码来源:Database.php

示例8: setUpBeforeClass

 /**
  * Set up the tests
  */
 public static function setUpBeforeClass()
 {
     $capsule = new Manager();
     $capsule->addConnection(array('driver' => 'sqlite', 'database' => ':memory:'));
     // Bind to Eloquent
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     // Set facades
     DB::setFacadeApplication(new Container());
     DB::swap($capsule->getDatabaseManager());
     // Reguard attributes
     Model::reguard();
     self::createTables($capsule);
 }
开发者ID:anahkiasen,项目名称:fakable,代码行数:17,代码来源:FakableTestCase.php

示例9: register

 /**
  * Register database services
  * 
  * @param  PimpleContainer $di Container
  */
 public function register(PimpleContainer $di)
 {
     $params = $this->databaseParams;
     $di['dbConnection'] = function () use($params, $di) {
         $capsule = $di['db'];
         return $capsule->getConnection();
     };
     $di['dbConnectionResolver'] = function () use($params, $di) {
         $connection = $di['dbConnection'];
         $resolver = new ConnectionResolver(['default' => $connection]);
         $resolver->setDefaultConnection('default');
         return $resolver;
     };
     $di['dbMigrationRepository'] = function () use($params, $di) {
         $resolver = $di['dbConnectionResolver'];
         $repository = new DatabaseMigrationRepository($resolver, 'migrations');
         return $repository;
     };
     $di['dbMigrator'] = function () use($params, $di) {
         class_alias(Schema::class, 'Schema');
         Schema::setContainer($di);
         $resolver = $di['dbConnectionResolver'];
         $repository = $di['dbMigrationRepository'];
         $filesystem = new Filesystem();
         $migrator = new Migrator($repository, $resolver, $filesystem);
         return $migrator;
     };
     $di['db'] = function () use($params, $di) {
         class_alias(DB::class, 'DB');
         DB::setContainer($di);
         $capsule = new Capsule();
         $capsule->setEventDispatcher(new Dispatcher(new Container()));
         $capsule->setAsGlobal();
         $capsule->bootEloquent();
         $capsule->addConnection($params);
         if (class_exists(MongoDbConnection::class)) {
             $capsule->getDatabaseManager()->extend('mongodb', function ($config) {
                 return new MongoDbConnection($config);
             });
         }
         return $capsule;
     };
     $di['dbManager'] = function () use($params, $di) {
         $dbCapsule = $di['db'];
         return $dbCapsule->getDatabaseManager();
     };
     $di['db'];
 }
开发者ID:canis-io,项目名称:slim-laravel-helpers,代码行数:53,代码来源:DatabaseProvider.php

示例10: register

 /**
  * Register Illuminate with the application
  *
  * @param array $config
  * @param Application $app
  * @return void
  */
 public function register(Application $app)
 {
     // Set some sane defaults
     $defaults = array('boot' => true, 'eloquent' => true, 'fetch' => PDO::FETCH_CLASS, 'global' => true, 'default' => 'default', 'connections' => array('default' => array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'silex', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null)));
     // Merge in any passed configuration
     $this->config = array_merge($defaults, $app['db.config']);
     // Make sure all connections have all required fields
     if (isset($this->config['connections'])) {
         foreach ($this->config['connections'] as $index => $connection) {
             $this->config['connections'][$index] = array_merge($defaults['connections']['default'], $connection);
         }
     }
     // Create a container for the database pool
     $app['db.container'] = $app->share(function () {
         return new Container();
     });
     // Create the connections to the datbase
     $app['db'] = $app->share(function () use($app) {
         $db = new Capsule($app['db.container']);
         // Set PDO fetch mode as per configuration
         $db->setFetchMode($this->config['fetch']);
         // Set as global, use eloquent as per configuration
         if ($this->config['eloquent']) {
             $db->bootEloquent();
         }
         if ($this->config['global']) {
             $db->setAsGlobal();
         }
         // Set up the event dispatcher if we have it available
         if (class_exists('Illuminate\\Events\\Dispatcher')) {
             $db->setEventDispatcher(new Dispatcher($app['db.container']));
         }
         // Initialise each connection
         foreach ($this->config['connections'] as $connection => $options) {
             $db->addConnection(array_replace($this->config['connections'][$this->config['default']], $options), $connection);
             // If we're in debug mode we're going to want to use the query log, otherwise leave it disabled
             // to speed up queries and reduce memory usage
             if ($app['debug']) {
                 $db->getConnection($connection)->enableQueryLog();
             }
         }
         // Finally set default connection
         $db->getDatabaseManager()->setDefaultConnection($this->config['default']);
         return $db;
     });
 }
开发者ID:sjdaws,项目名称:silluminate,代码行数:53,代码来源:DatabaseServiceProvider.php

示例11: __construct

 /**
  * Create a new Validator factory instance.
  *
  * @param  \Illuminate\Database\Capsule\Manager $db
  * @return \Illuminate\Validation\Factory
  */
 public function __construct($db)
 {
     if (!$this->factory) {
         /**
          * illuminate/translation (Translator) package need for correct work of Validator
          */
         $translator = new Translator('en');
         $this->factory = new Factory($translator);
         /**
          * To set database presence verifier we need database connection instance,
          * which is implements ConnectionResolverInterface. For this purpose 
          * Illuminate\Database\Capsule\Manager class, which we get from $db arg,
          * have getDatabaseManager() function.
          * With defined DatabasePresenceVerifier we can use rules such as: 
          *      unique:table,column,except,idColumn
          *      exists:table,column
          */
         $dbManager = $db->getDatabaseManager();
         $this->factory->setPresenceVerifier(new DatabasePresenceVerifier($dbManager));
     }
     return $this->factory;
 }
开发者ID:mrcoco,项目名称:tinyshop-v2,代码行数:28,代码来源:validator.php

示例12: register

 public function register(Container $pimple)
 {
     $pimple['db'] = function ($pimple) {
         $db = new Manager();
         $db->addConnection(['driver' => 'mysql', 'host' => $pimple['config']['db.host'], 'database' => $pimple['config']['db.database'], 'username' => $pimple['config']['db.username'], 'password' => $pimple['config']['db.password'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => $pimple['config']['db.prefix']]);
         $db->setEventDispatcher($pimple['events']);
         // Make this Capsule instance available globally via static methods... (optional)
         $db->setAsGlobal();
         // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
         $db->bootEloquent();
         if ($pimple['config']['log.sql']) {
             // 记录查询过的日志
             $manager = $db->getDatabaseManager();
             try {
                 $manager->listen(function ($query, $bindings = null, $time = null, $connectionName = null) use($manager, $pimple) {
                     // Laravel 5.2 changed the way some core events worked. We must account for
                     // the first argument being an "event object", where arguments are passed
                     // via object properties, instead of individual arguments.
                     if ($query instanceof \Illuminate\Database\Events\QueryExecuted) {
                         $bindings = $query->bindings;
                         $time = $query->time;
                         $connection = $query->connection;
                         $query = $query->sql;
                     } else {
                         $connection = $manager->connection($connectionName);
                     }
                     $pimple['log']->debug($query, $bindings);
                     $pimple['sql_log']->set($query, $bindings);
                 });
             } catch (\Exception $e) {
                 $pimple['log']->debug($e->getMessage());
             }
         }
         return $db;
     };
 }
开发者ID:skyguest,项目名称:ecadapter,代码行数:36,代码来源:DBServiceProvider.php

示例13: __construct

 /**
  * Initialise a new collector
  *
  * @param Capsule $database
  * @return void
  */
 public function __construct(Capsule $database)
 {
     $this->connections = $database->getDatabaseManager()->getConnections();
 }
开发者ID:sjdaws,项目名称:silluminate,代码行数:10,代码来源:DatabaseDataCollector.php

示例14: function

    $validator = $validation->make($data, $rules);
    if ($validator->fails()) {
        $errors = $validator->errors();
    }
    return $app->render('form.php', ['posted' => true, 'errors' => $errors, 'email' => $_POST['email']]);
});
// For a thorough example, we establish a database connection
// to drive the database presence verifier used by the validator.
// If you do not need to validate against values in the database,
// the database presence verifier and related code can be removed.
$app->get('/database', function () use($app) {
    return $app->render('form.php', ['posted' => false, 'errors' => null, 'email' => '']);
});
$app->post('/database', function () use($app) {
    $capsule = new Capsule();
    $capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'illuminate_non_laravel', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
    $loader = new FileLoader(new Filesystem(), 'lang');
    $translator = new Translator($loader, 'en');
    $presence = new DatabasePresenceVerifier($capsule->getDatabaseManager());
    $validation = new Factory($translator, new Container());
    $validation->setPresenceVerifier($presence);
    $data = ['email' => $_POST['email']];
    $rules = ['email' => 'required|email|unique:users'];
    $errors = null;
    $validator = $validation->make($data, $rules);
    if ($validator->fails()) {
        $errors = $validator->errors();
    }
    return $app->render('form.php', ['posted' => true, 'errors' => $errors, 'email' => $_POST['email']]);
});
$app->run();
开发者ID:hskrasek,项目名称:IlluminateNonLaravel,代码行数:31,代码来源:index.php

示例15: initDb

 private function initDb()
 {
     $capsule = new Capsule();
     $capsule->addConnection(['driver' => 'sqlite', 'host' => 'localhost', 'database' => ':memory:', 'prefix' => '']);
     $capsule->setEventDispatcher(new Dispatcher(new Container()));
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     Capsule::schema()->create('settings', function ($table) {
         $table->increments('id');
         $table->string('key')->index()->unique();
         $table->string('value')->longText();
     });
     return $capsule->getDatabaseManager();
 }
开发者ID:tuvaergun,项目名称:l5-options,代码行数:14,代码来源:OptionsTest.php


注:本文中的Illuminate\Database\Capsule\Manager::getDatabaseManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。