php Illuminate-Database-Capsule-Manager类(方法)实例源码

下面列出了php Illuminate-Database-Capsule-Manager 类(方法)源码代码实例,从而了解它的用法。

作者:gigabla    项目:silex-d   
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;
     });
 }

作者:middleou    项目:doplio-zf   
/**
  * @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();
     });
 }

作者:wouter    项目:eloquent-bundl   
/**
  * Initializes the Eloquent ORM.
  */
 public function initialize()
 {
     $this->capsule->bootEloquent();
     if ('default' !== $this->defaultConnection) {
         $this->capsule->getDatabaseManager()->setDefaultConnection($this->defaultConnection);
     }
 }

作者:shomim    项目:builde   
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;
     });
 }

作者:leandrocanabarr    项目:lass   
/**
  * 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;
 }

作者:singularity32    项目:Art   
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();
     });
 }

作者:adamwatha    项目:faktor   
protected function configureDatabase()
 {
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $db->bootEloquent();
     $db->setAsGlobal();
 }

作者:sabahtalate    项目:laracas   
/**
  * @return DB
  */
 public function setUpDatabase()
 {
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $db->setAsGlobal();
     $db->bootEloquent();
 }

作者:thirtee    项目:testbenc   
/**
  * 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();
 }

作者:joppuy    项目:Dullaha   
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();
 }

作者:raynaldm    项目:php-educatio   
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();
 }

作者:justincdotm    项目:bookm   
/**
  * 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();
 }

作者:intfr    项目:opencf   
/**
  * {@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());
     });
 }

作者:paulboc    项目:vorhysu   
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();
 }

作者:steveaz    项目:rudoll   
private function setUpDatabases()
 {
     $database = new DB();
     $database->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $database->bootEloquent();
     $database->setAsGlobal();
 }

作者:rained2    项目:laravel-billin   
public function setUp()
 {
     parent::setUp();
     Eloquent::unguard();
     $this->faker = Faker\Factory::create();
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $db->bootEloquent();
     $db->setAsGlobal();
     $this->schema()->create('users', function ($table) {
         $table->increments('id');
         $table->string('email');
         $table->string('name');
         $table->string('billing_id')->nullable();
         $table->text('billing_cards')->nullable();
         $table->text('billing_discounts')->nullable();
         $table->tinyInteger('billing_active')->default(0);
         $table->string('billing_subscription')->nullable();
         $table->tinyInteger('billing_free')->default(0);
         $table->string('billing_plan', 25)->nullable();
         $table->integer('billing_amount')->default(0);
         $table->string('billing_interval')->nullable();
         $table->integer('billing_quantity')->default(0);
         $table->string('billing_card')->nullable();
         $table->timestamp('billing_trial_ends_at')->nullable();
         $table->timestamp('billing_subscription_ends_at')->nullable();
         $table->text('billing_subscription_discounts')->nullable();
         $table->timestamps();
     });
 }

作者:ozca    项目:framewor   
public function bootDb()
 {
     // Init Eloquent ORM Connection
     $capsule = new Capsule();
     $capsule->addConnection(Config::getDbConfig());
     $capsule->bootEloquent();
 }

作者:marcelgrube    项目:cashie   
public function setUp()
 {
     Eloquent::unguard();
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $db->bootEloquent();
     $db->setAsGlobal();
     $this->schema()->create('users', function ($table) {
         $table->increments('id');
         $table->string('email');
         $table->string('name');
         $table->string('stripe_id')->nullable();
         $table->string('card_brand')->nullable();
         $table->string('card_last_four')->nullable();
         $table->timestamps();
     });
     $this->schema()->create('subscriptions', function ($table) {
         $table->increments('id');
         $table->integer('user_id');
         $table->string('name');
         $table->string('stripe_id');
         $table->string('stripe_plan');
         $table->integer('quantity');
         $table->timestamp('trial_ends_at')->nullable();
         $table->timestamp('ends_at')->nullable();
         $table->timestamps();
     });
 }

作者:chrs    项目:corce   
/**
  * Connect to the Wordpress database
  * 
  * @param array $params
  */
 public static function connect(array $params)
 {
     $capsule = new Capsule();
     $params = array_merge(static::$baseParams, $params);
     $capsule->addConnection($params);
     $capsule->bootEloquent();
 }

作者:nlambli    项目:limag   
public static function init()
 {
     $db = new DB();
     $db->addConnection(parse_ini_file('db.ini'));
     $db->setAsGlobal();
     $db->bootEloquent();
 }


问题


面经


文章

微信
公众号

扫码关注公众号