當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Model::setConnectionResolver方法代碼示例

本文整理匯總了PHP中Illuminate\Database\Eloquent\Model::setConnectionResolver方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::setConnectionResolver方法的具體用法?PHP Model::setConnectionResolver怎麽用?PHP Model::setConnectionResolver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::setConnectionResolver方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: initialize

 /**
  * Initialize the Laravel framework.
  * @param SymfonyRequest $request
  */
 private function initialize($request = null)
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $oldDb = $this->app['db'];
     }
     // The module can login a user with the $I->amLoggedAs() method,
     // but this is not persisted between requests. Store a reference
     // to the logged in user to simulate this.
     $loggedInUser = null;
     if ($this->app['auth'] && $this->app['auth']->check()) {
         $loggedInUser = $this->app['auth']->user();
     }
     // Load the application object
     $this->app = $this->kernel = $this->loadApplication();
     // Set the request instance for the application
     if (is_null($request)) {
         $appConfig = (require $this->module->config['project_dir'] . 'config/app.php');
         $request = SymfonyRequest::create($appConfig['url']);
     }
     $this->app->instance('request', Request::createFromBase($request));
     $this->app->instance('middleware.disable', $this->module->config['disable_middleware']);
     // Bootstrap the application
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Restore the old database object if available
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     // If there was a user logged in restore this user.
     // Also reload the user object from the user provider to prevent stale user data.
     if ($loggedInUser) {
         $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier());
         $this->app['auth']->setUser($refreshed ?: $loggedInUser);
     }
     $this->module->setApplication($this->app);
 }
開發者ID:Dossar,項目名稱:boltbse,代碼行數:43,代碼來源:Laravel5.php

示例2: initialize

 /**
  * Initialize the Laravel framework.
  */
 private function initialize()
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $oldDb = $this->app['db'];
     }
     // The module can login a user with the $I->amLoggedAs() method,
     // but this is not persisted between requests. Store a reference
     // to the logged in user to simulate this.
     $loggedInUser = null;
     if ($this->app['auth'] && $this->app['auth']->check()) {
         $loggedInUser = $this->app['auth']->user();
     }
     $this->app = $this->kernel = $this->loadApplication();
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Set the base url for the Request object
     $url = $this->app['config']->get('app.url', 'http://localhost');
     $this->app->instance('request', Request::createFromBase(SymfonyRequest::create($url)));
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     // If there was a user logged in restore this user.
     // Also reload the user object from the user provider to prevent stale user data.
     if ($loggedInUser) {
         $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier());
         $this->app['auth']->setUser($refreshed ?: $loggedInUser);
     }
     $this->module->setApplication($this->app);
 }
開發者ID:corcre,項目名稱:elabftw,代碼行數:35,代碼來源:Laravel5.php

示例3: setDatabase

 private function setDatabase($dbConfig)
 {
     $capsule = new Capsule();
     $capsule->addConnection($dbConfig, $this->connName);
     $this->set('db', $capsule->getConnection($this->connName));
     //set model conn for all models
     $resolver = new \Illuminate\Database\ConnectionResolver();
     $resolver->addConnection($this->connName, $capsule->getConnection($this->connName));
     $resolver->setDefaultConnection($this->connName);
     \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
 }
開發者ID:hosannahighertech,項目名稱:upendo,代碼行數:11,代碼來源:App.php

示例4: __construct

 protected function __construct()
 {
     $this->app = new Container();
     // Register mock instances with IoC container
     $config = $this->getConfig();
     $this->app->singleton('config', function () use($config) {
         return $config;
     });
     list($connector, $manager) = $this->getDatabase();
     $this->app->singleton('db.factory', function () use($connector) {
         return $connector;
     });
     $this->app->singleton('db', function () use($manager) {
         return $manager;
     });
     $auth = $this->getAuth();
     $this->app->singleton('auth', function () use($auth) {
         return $auth;
     });
     $dispatcher = new Dispatcher($this->app);
     $this->app->singleton('events', function () use($dispatcher) {
         return $dispatcher;
     });
     Model::setConnectionResolver($this->app['db']);
     Model::setEventDispatcher($this->app['events']);
 }
開發者ID:nstapelbroek,項目名稱:culpa-laravel-5,代碼行數:26,代碼來源:AppFactory.php

示例5: initialize

 /**
  * Initialize the Laravel Framework.
  *
  * @throws ModuleConfig
  */
 private function initialize()
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $oldDb = $this->app['db'];
     }
     // Store the current value for the router filters
     // so it can be reset after reloading the application
     $oldFiltersEnabled = null;
     if ($router = $this->app['router']) {
         $property = new \ReflectionProperty(get_class($router), 'filtering');
         $property->setAccessible(true);
         $oldFiltersEnabled = $property->getValue($router);
     }
     $this->app = $this->loadApplication();
     $this->kernel = $this->getStackedClient();
     $this->app->boot();
     // Reset the booted flag of the Application object
     // so the app will be booted again if it receives a new Request
     $property = new \ReflectionProperty(get_class($this->app), 'booted');
     $property->setAccessible(true);
     $property->setValue($this->app, false);
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     if (!is_null($oldFiltersEnabled)) {
         $oldFiltersEnabled ? $this->app['router']->enableFilters() : $this->app['router']->disableFilters();
     }
     $this->module->setApplication($this->app);
 }
開發者ID:hitechdk,項目名稱:Codeception,代碼行數:38,代碼來源:Laravel4.php

示例6: createSentry

 /**
  * Creates a new instance of Sentry.
  *
  * @return \Cartalyst\Sentry\Sentry
  * @throws \RuntimeException
  */
 public static function createSentry()
 {
     // Get some resources
     $ci =& get_instance();
     $ci->load->driver('session');
     // If Eloquent doesn't exist, then we must assume they are using their own providers.
     if (class_exists('Illuminate\\Database\\Eloquent\\Model')) {
         $ci->load->database();
         // Let's connect and get the PDO instance
         $method = $ci->db->pconnect ? 'db_pconnect' : 'db_connect';
         $pdo = $ci->db->{$method}();
         // Validate PDO
         if (!$pdo instanceof PDO) {
             throw new \RuntimeException("Sentry will only work with PDO database connections.");
         }
         // Setup PDO
         foreach (static::$pdoOptions as $key => $value) {
             $pdo->setAttribute($key, $value);
         }
         $driverName = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
         $tablePrefix = substr($ci->db->dbprefix('.'), 0, -1);
         Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
     }
     return new BaseSentry($userProvider = new UserProvider(new NativeHasher()), new GroupProvider(), new ThrottleProvider($userProvider), new CISession($ci->session), new CICookie($ci->input), $ci->input->ip_address());
 }
開發者ID:shomimn,項目名稱:builder,代碼行數:31,代碼來源:Sentry.php

示例7: bootModels

 /**
  * @param $resolver
  */
 protected function bootModels($resolver)
 {
     Model::clearBootedModels();
     Model::setEventDispatcher($this->app['illuminate.events']);
     Model::setConnectionResolver($resolver);
     $this->app['dispatcher']->dispatch(NineEvents::MODELS_BOOTED, new EloquentEvent($this->container->get('db')));
 }
開發者ID:formula9,項目名稱:framework,代碼行數:10,代碼來源:EloquentServiceProvider.php

示例8: register

 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('flarum.db', function () {
         $factory = new ConnectionFactory($this->app);
         $connection = $factory->make($this->app->make('flarum.config')['database']);
         $connection->setEventDispatcher($this->app->make('Illuminate\\Contracts\\Events\\Dispatcher'));
         $connection->setFetchMode(PDO::FETCH_CLASS);
         return $connection;
     });
     $this->app->alias('flarum.db', 'Illuminate\\Database\\ConnectionInterface');
     $this->app->singleton('Illuminate\\Database\\ConnectionResolverInterface', function () {
         $resolver = new ConnectionResolver(['flarum' => $this->app->make('flarum.db')]);
         $resolver->setDefaultConnection('flarum');
         return $resolver;
     });
     $this->app->alias('Illuminate\\Database\\ConnectionResolverInterface', 'db');
     if (Core::isInstalled()) {
         $this->app->booting(function () {
             $resolver = $this->app->make('Illuminate\\Database\\ConnectionResolverInterface');
             Model::setConnectionResolver($resolver);
             Model::setEventDispatcher($this->app->make('events'));
         });
     }
     $this->app->singleton('Flarum\\Migrations\\MigrationRepositoryInterface', function ($app) {
         return new DatabaseMigrationRepository($app['db'], 'migrations');
     });
 }
開發者ID:redstarxz,項目名稱:flarumone,代碼行數:32,代碼來源:DatabaseServiceProvider.php

示例9: addMockConnection

 /**
  * Set mock connection.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  */
 protected function addMockConnection(Model $model)
 {
     $resolver = m::mock('\\Illuminate\\Database\\ConnectionResolverInterface');
     $model->setConnectionResolver($resolver);
     $resolver->shouldReceive('connection')->andReturn(m::mock('\\Illuminate\\Database\\Connection'));
     $model->getConnection()->shouldReceive('getQueryGrammar')->andReturn(m::mock('\\Illuminate\\Database\\Query\\Grammars\\Grammar'));
     $model->getConnection()->shouldReceive('getPostProcessor')->andReturn(m::mock('\\Illuminate\\Database\\Query\\Processors\\Processor'));
 }
開發者ID:DavidIWilson,項目名稱:site1,代碼行數:13,代碼來源:EloquentConnectionTrait.php

示例10: __construct

 public function __construct()
 {
     $settings = array('driver' => 'pgsql', 'host' => 'localhost', 'database' => 'yesbike', 'username' => 'postgres', 'password' => 'macedo', 'charset' => 'UTF8', 'prefix' => '');
     $connFactory = new \Illuminate\Database\Connectors\ConnectionFactory(new \Illuminate\Container\Container());
     $conn = $connFactory->make($settings);
     $resolver = new \Illuminate\Database\ConnectionResolver();
     $resolver->addConnection('default', $conn);
     $resolver->setDefaultConnection('default');
     \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
 }
開發者ID:gjrmacedo,項目名稱:testeArquiteturaPHP,代碼行數:10,代碼來源:UserRepository.php

示例11: setupDatabaseResolver

 /**
  * Sets up the Eloquent Connection Resolver with the given PDO connection.
  *
  * @param  PDO    $pdo
  * @param  string $driverName
  * @param  string $tablePrefix
  * @return void
  */
 public static function setupDatabaseResolver(PDO $pdo, $driverName = null, $tablePrefix = '')
 {
     // If Eloquent doesn't exist, then we must assume they are using their own providers.
     if (class_exists('Illuminate\\Database\\Eloquent\\Model')) {
         if (is_null($driverName)) {
             $driverName = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
         }
         Eloquent::setConnectionResolver(new ConnectionResolver($pdo, $driverName, $tablePrefix));
     }
 }
開發者ID:trangunghoa,項目名稱:l4cms,代碼行數:18,代碼來源:Sentry.php

示例12: setConnectionResolver

 private function setConnectionResolver()
 {
     if ($this->checkTablesExists() && is_null(Model::getConnectionResolver())) {
         $res = new ConnectionResolver();
         DB::pretend(function ($db) use($res) {
             $res->addConnection(config('database.default'), $db);
             $res->setDefaultConnection(config('database.default'));
         });
         Model::setConnectionResolver($res);
     }
 }
開發者ID:jooorooo,項目名稱:multi-language,代碼行數:11,代碼來源:Manager.php

示例13: call

 public function call()
 {
     $container = new Illuminate\Container\Container();
     $connFactory = new \Illuminate\Database\Connectors\ConnectionFactory($container);
     $conn = $connFactory->make(array('driver' => 'mysql', 'host' => '127.0.0.1', 'database' => 'flysmuthe', 'username' => \config\SecureConfig::$dbUsername, 'password' => \config\SecureConfig::$dbPassword, 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => ''));
     $resolver = new \Illuminate\Database\ConnectionResolver();
     $resolver->addConnection('default', $conn);
     $resolver->setDefaultConnection('default');
     \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
     //Call next middleware
     $this->next->call();
 }
開發者ID:sovereignshare,項目名稱:fly-smuthe-web,代碼行數:12,代碼來源:index.php

示例14: __construct

 public function __construct()
 {
     $this->ci =& get_instance();
     $config = $this->ci->db;
     // Get the DB object
     $pdo = new PDO('mysql:host=' . $config->hostname . ';dbname=' . $config->database, $config->username, $config->password);
     $drivers = array('mysql' => '\\Illuminate\\Database\\MySqlConnection', 'pgsql' => '\\Illuminate\\Database\\PostgresConnection', 'sqlite' => '\\Illuminate\\Database\\SQLiteConnection');
     $conn = new $drivers['mysql']($pdo, $config->database, $config->dbprefix);
     $resolver = new Illuminate\Database\ConnectionResolver();
     $resolver->addConnection('default', $conn);
     $resolver->setDefaultConnection('default');
     \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
 }
開發者ID:nscreed,項目名稱:hub-app,代碼行數:13,代碼來源:RoyalEloquent.php

示例15: load

 public function load()
 {
     // Database information : should be inject with DI
     $settings = array('driver' => 'sqlite', 'database' => 'vdm_posts_db.sqlite', 'prefix' => '');
     // Bootstrap Eloquent ORM
     $container = new Container();
     $connFactory = new \Illuminate\Database\Connectors\ConnectionFactory($container);
     $conn = $connFactory->make($settings);
     $resolver = new \Illuminate\Database\ConnectionResolver();
     $resolver->addConnection('default', $conn);
     $resolver->setDefaultConnection('default');
     \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
 }
開發者ID:ahocquard,項目名稱:vdm,代碼行數:13,代碼來源:SqliteConnexion.php


注:本文中的Illuminate\Database\Eloquent\Model::setConnectionResolver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。