setEventDispatcher() публичный статический Метод

Set the event dispatcher instance.
public static setEventDispatcher ( Illuminate\Contracts\Events\Dispatcher $dispatcher ) : void
$dispatcher Illuminate\Contracts\Events\Dispatcher
Результат void
Пример #1
0
 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']);
 }
 /**
  * @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')));
 }
 /**
  * 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');
     });
 }
Пример #4
0
 /**
  * Setup the test environment.
  *
  * @return void
  */
 protected function setUp()
 {
     if (!$this->app) {
         $this->refreshApplication();
     }
     $this->setUpTraits();
     foreach ($this->afterApplicationCreatedCallbacks as $callback) {
         call_user_func($callback);
     }
     Facade::clearResolvedInstances();
     Model::setEventDispatcher($this->app['events']);
     $this->setUpHasRun = true;
 }
Пример #5
0
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     Model::setConnectionResolver($this->app['db']);
     Model::setEventDispatcher($this->app['events']);
 }
Пример #6
0
 /**
  * Bootstrap Eloquent so it is ready for usage.
  *
  * @return void
  */
 public function bootEloquent()
 {
     Eloquent::setConnectionResolver($this->manager);
     // If we have an event dispatcher instance, we will go ahead and register it
     // with the Eloquent ORM, allowing for model callbacks while creating and
     // updating "model" instances; however, if it not necessary to operate.
     if ($dispatcher = $this->getEventDispatcher()) {
         Eloquent::setEventDispatcher($dispatcher);
     }
 }
 /**
  * Mock the model event dispatcher so all Eloquent events are silenced.
  *
  * @return $this
  */
 protected function withoutModelEvents()
 {
     $mock = Mockery::mock('Illuminate\\Contracts\\Events\\Dispatcher');
     $mock->shouldReceive('fire')->andReturnUsing(function ($called) {
         $this->firedModelEvents[] = $called;
     });
     $mock->shouldReceive('until')->andReturnUsing(function ($called) {
         $this->firedModelEvents[] = $called;
         return true;
     });
     $mock->shouldReceive('listen')->andReturnUsing(function ($event, $listener, $priority) {
         //
     });
     Model::setEventDispatcher($mock);
     return $this;
 }
 /**
  * Configure the dispatcher.
  *
  * @return void
  */
 private function configureEventDispatcher()
 {
     $dispatcher = new Dispatcher(app());
     Model::setEventDispatcher($dispatcher);
     app()->instance(DispatcherContract::class, $dispatcher);
 }
Пример #9
0
 /**
  * Prepare the Eloquent ORM for use.
  *
  * @return void
  */
 public function bootEloquent()
 {
     Eloquent\Model::setConnectionResolver($this->manager);
     Eloquent\Model::setEventDispatcher($this->config['events']);
 }
Пример #10
0
 /**
  * Bootstrap Eloquent.
  *
  * @return void
  */
 public static function setUpBeforeClass()
 {
     Eloquent::setConnectionResolver(new DatabaseIntegrationTestConnectionResolver());
     Eloquent::setEventDispatcher(new Illuminate\Events\Dispatcher());
 }
 /**
  * Bootstrap Eloquent.
  *
  * @return void
  */
 public static function setUpBeforeClass()
 {
     Eloquent::setConnectionResolver(new ConnectionResolver());
     Eloquent::setEventDispatcher(new Dispatcher());
 }