/** * {@inheritDoc} */ public function boot() { $app = $this->app; // We told a little lie in the configuration. Extensions are actually // auto-registered upon booting of the Extensions Service Provider as // we had no access to configuration if ($app['config']->get('cartalyst.extensions.auto_register')) { Extension::setConnectionResolver($app['db']); Extension::setEventDispatcher($app['events']); Extension::setMigrator($app['migrator']); $app['extensions']->findAndRegisterExtensions(); $app['extensions']->sortExtensions(); // Now we will check if the extensions should be auto-booted. if ($app['config']->get('cartalyst.extensions.auto_boot')) { foreach ($app['extensions'] as $extension) { $extension->setupDatabase(); } foreach ($app['extensions']->allEnabled() as $extension) { $extension->boot(); } } } }
/** * Sets up the extensions environment for Platform. * * @return void */ public function setupExtensions() { Extension::setMigrator($this->app['migrator']); Extension::setConnectionResolver($this->app['db']); Extension::setEventDispatcher($this->app['events']); $this->extensionBag->findAndRegisterExtensions(); $this->extensionBag->sortExtensions(); }
/** * Installs all the available extensions. * * @return void */ protected function installExtensions() { // Alright, database connection established. Let's now grab all // core extensions $extensionBag = $this->laravel['platform']->getExtensionBag(); // Register all local extension $extensionBag->findAndRegisterExtensions(); // Sort the extensions by their dependencies $extensionBag->sortExtensions(); // Set the connection resolver on our extensions Extension::setConnectionResolver($this->laravel['db']); // Set the laravel migrator on our extensions Extension::setMigrator($this->laravel['migrator']); // Flush the Cache $this->laravel['cache']->flush(); // Loop through extensions foreach ($extensionBag->all() as $extension) { $extension->install(); $extension->enable(); } }
public function testUninstalling() { $extension = m::mock('Cartalyst\\Extensions\\Extension[isUninstalled,databaseDelete]'); $extension->__construct($bag = m::mock('Cartalyst\\Extensions\\ExtensionBag'), 'foo/bar', 'path/to/extension', array('migrations_path' => 'migrations')); Extension::setMigrator($migrator = m::mock('Illuminate\\Database\\Migrations\\Migrator')); $extension->shouldReceive('isUninstalled')->once(); $migrator->shouldReceive('getMigrationFiles')->with('path/to/extension/migrations')->once()->andReturn($files = array('migration_foo', 'migration_bar')); $migrator->shouldReceive('getRepository')->once()->andReturn($repository = m::mock('Illuminate\\Database\\Migrations\\MigrationRepositoryInterface')); $repository->shouldReceive('getRan')->once()->andReturn($ran = array('migration_foo', 'migration_bar', 'migration_baz')); // Test we are resolving in reverse order $migrator->shouldReceive('resolve')->with('migration_bar')->once()->ordered()->andReturn($migration2 = m::mock('stdClass')); $migration2->shouldReceive('down')->once()->ordered(); $migrator->shouldReceive('resolve')->with('migration_foo')->once()->ordered()->andReturn($migration1 = m::mock('stdClass')); $migration1->shouldReceive('down')->once()->ordered(); $repository->shouldReceive('delete')->with(m::type('stdClass'))->twice(); $extension->shouldReceive('databaseDelete')->once(); Extension::setEventDispatcher($events = new Dispatcher()); $events->listen('extension.uninstalling', function (Extension $extension) { $_SERVER['__extension.uninstalling'] = true; }); $events->listen('extension.uninstalled', function (Extension $extension) { $_SERVER['__extension.uninstalled'] = true; }); $extension->uninstall(); $this->assertTrue($_SERVER['__extension.uninstalling']); unset($_SERVER['__extension.uninstalling']); $this->assertTrue($_SERVER['__extension.uninstalled']); unset($_SERVER['__extension.uninstalled']); }