コード例 #1
0
 /**
  * @param \Notadd\Foundation\Extension\ExtensionManager $manager
  */
 public function boot(ExtensionManager $manager)
 {
     if ($this->app->isInstalled()) {
         $manager->getExtensions()->each(function (Extension $extension) use($manager) {
             $registrar = $extension->getRegistrar();
             static::$complies = static::$complies->merge($registrar->compiles());
             $this->commands($registrar->loadCommands());
             (new Collection($registrar->loadLocalizationsFrom()))->each(function ($path, $namespace) {
                 $this->loadTranslationsFrom($path, $namespace);
             });
             (new Collection($registrar->loadMigrationsFrom()))->each(function ($paths) {
                 $this->loadMigrationsFrom($paths);
             });
             (new Collection($registrar->loadPublishesFrom()))->each(function ($to, $from) {
                 $this->publishes([$from => $to], 'public');
             });
             (new Collection($registrar->loadViewsFrom()))->each(function ($path, $namespace) {
                 $this->loadViewsFrom($path, $namespace);
             });
             $extension->enable();
             $this->app->make(Dispatcher::class)->fire(new ExtensionEnabled($this->app, $manager, $extension));
             $manager->boot($registrar);
         });
     }
     $this->commands([InstallCommand::class, ListCommand::class, UninstallCommand::class, UpdateCommand::class]);
 }
コード例 #2
0
ファイル: UpdateCommand.php プロジェクト: notadd/framework
 /**
  * @param \Notadd\Foundation\Extension\ExtensionManager           $manager
  * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings
  *
  * @return bool
  */
 public function fire(ExtensionManager $manager, SettingsRepository $settings)
 {
     $name = $this->input->getArgument('name');
     $extensions = $manager->getExtensionPaths();
     if (!$extensions->offsetExists($name)) {
         $this->error("Extension {$name} do not exist!");
         return false;
     }
     if (!$this->container->make(SettingsRepository::class)->get('extension.' . $name . '.installed')) {
         $this->error("Extension {$name} does not installed!");
         return false;
     }
     $extension = $extensions->get($name);
     $path = $extension;
     if (Str::contains($path, $manager->getVendorPath())) {
         $this->error("Please update extension {$name} from composer command!");
         return false;
     }
     $extensionFile = new JsonFile($path . DIRECTORY_SEPARATOR . 'composer.json');
     $extension = collect($extensionFile->read());
     if ($extension->has('autoload')) {
         $autoload = collect($extension->get('autoload'));
         $autoload->has('classmap') && collect($autoload->get('classmap'))->each(function ($value) use($path) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($path . DIRECTORY_SEPARATOR . $value)) . '/';
             if (!in_array($path, $this->backup['autoload']['classmap'])) {
                 $this->backup['autoload']['classmap'][] = $path;
             }
         });
         $autoload->has('files') && collect($autoload->get('files'))->each(function ($value) use($path) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($path . DIRECTORY_SEPARATOR . $value));
             if (!in_array($path, $this->backup['autoload']['files'])) {
                 $this->backup['autoload']['files'][] = $path;
             }
         });
         $autoload->has('psr-0') && collect($autoload->get('psr-0'))->each(function ($value, $key) use($path) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($path . DIRECTORY_SEPARATOR . $value)) . '/';
             $this->backup['autoload']['psr-0'][$key] = $path;
         });
         $autoload->has('psr-4') && collect($autoload->get('psr-4'))->each(function ($value, $key) use($path) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($path . DIRECTORY_SEPARATOR . $value)) . '/';
             $this->backup['autoload']['psr-4'][$key] = $path;
         });
         $this->json->addProperty('autoload', $this->backup['autoload']);
         $settings->set('extension.' . $name . '.autoload', json_encode($autoload->toArray()));
     }
     if ($extension->has('require')) {
         $require = collect($extension->get('require'));
         $require->each(function ($version, $name) {
             $this->backup['require'][$name] = $version;
         });
         $this->json->addProperty('require', $this->backup['require']);
         $settings->set('extension.' . $name . '.require', json_encode($require->toArray()));
     }
     $this->updateComposer(true);
     $this->info("Extension {$name} is updated!");
     return true;
 }
コード例 #3
0
ファイル: ListCommand.php プロジェクト: notadd/framework
 /**
  * @param \Notadd\Foundation\Extension\ExtensionManager $manager
  */
 public function fire(ExtensionManager $manager)
 {
     $paths = $manager->getExtensionPaths();
     $list = new Collection();
     $settings = $this->container->make(SettingsRepository::class);
     $this->info('Extensions list:');
     $paths->each(function ($path, $key) use($list, $settings) {
         $list->push([$key, $path, $settings->get('extension.' . $key . '.installed') ? 'Yes' : 'No']);
     });
     $this->table($this->headers, $list->toArray());
 }
コード例 #4
0
ファイル: UpdateCommand.php プロジェクト: notadd/framework
 /**
  * Command Handler.
  *
  * @param \Notadd\Foundation\Extension\ExtensionManager           $manager
  * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings
  *
  * @return bool
  * @throws \Exception
  */
 public function fire(ExtensionManager $manager, SettingsRepository $settings)
 {
     $name = $this->input->getArgument('name');
     $extensions = $manager->getExtensionPaths();
     if (!$extensions->offsetExists($name)) {
         $this->error("Extension {$name} do not exist!");
         return false;
     }
     if (!$this->container->make(SettingsRepository::class)->get('extension.' . $name . '.installed')) {
         $this->error("Extension {$name} does not installed!");
         return false;
     }
     $extension = $extensions->get($name);
     $path = $extension;
     if (Str::contains($path, $manager->getVendorPath())) {
         $this->error("Please update extension {$name} from composer command!");
         return false;
     }
     $this->info("Extension {$name} is updated!");
     return true;
 }
コード例 #5
0
ファイル: UninstallCommand.php プロジェクト: notadd/framework
 /**
  * Command Handler.
  *
  * @param \Notadd\Foundation\Extension\ExtensionManager           $manager
  * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings
  *
  * @return true
  * @throws \Exception
  */
 public function fire(ExtensionManager $manager, SettingsRepository $settings)
 {
     $name = $this->input->getArgument('name');
     $extensions = $manager->getExtensionPaths();
     if (!$extensions->offsetExists($name)) {
         $this->error("Extension {$name} do not exist!");
         return false;
     }
     if (!$settings->get('extension.' . $name . '.installed')) {
         $this->error("Extension {$name} does not installed!");
         return false;
     }
     $path = $extensions->get($name);
     if (Str::contains($path, $manager->getVendorPath())) {
         $this->error("Please remove extension {$name} from composer.json!");
         return false;
     }
     $this->composer->dumpAutoloads();
     $settings->set('extension.' . $name . '.installed', false);
     $this->info("Extension {$name} is uninstalled!");
     return true;
 }
コード例 #6
0
ファイル: InstallCommand.php プロジェクト: notadd/framework
 /**
  * @param \Notadd\Foundation\Extension\ExtensionManager           $manager
  * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings
  *
  * @return bool
  */
 public function fire(ExtensionManager $manager, SettingsRepository $settings)
 {
     $this->name = $this->input->getArgument('name');
     $extensions = $manager->getExtensionPaths();
     if (!$extensions->offsetExists($this->name)) {
         $this->error("Extension {$this->name} do not exist!");
         return false;
     }
     if ($settings->get("extension.{$this->name}.installed")) {
         $this->error("Extension {$this->name} is installed!");
         return false;
     }
     $this->path = $extensions->get($this->name);
     if (Str::contains($this->path, $manager->getVendorPath())) {
         $this->error("Extension {$this->name} is installed!");
         return false;
     }
     if ($this->files->exists($bootstrap = $this->path . DIRECTORY_SEPARATOR . 'bootstrap.php')) {
         $class = $this->files->getRequire($bootstrap);
     } else {
         $this->error('Extension files do not exists!');
         return false;
     }
     $bootstrap = $this->container->make($class);
     $this->info = $bootstrap->getExtensionInfo();
     $extensionFile = new JsonFile($this->path . DIRECTORY_SEPARATOR . 'composer.json');
     $this->extension = collect($extensionFile->read());
     $this->preInstall();
     if ($bootstrap->install() === true) {
         $this->postInstall($settings);
         $this->updateComposer(true);
         $settings->set("extension.{$this->name}.installed", true);
     } else {
         $this->error('Extension install fail!');
         return false;
     }
     $this->info("Extension {$this->name} is installed!");
     return true;
 }
コード例 #7
0
ファイル: InstallCommand.php プロジェクト: notadd/framework
 /**
  * Command handler.
  *
  * @param \Notadd\Foundation\Extension\ExtensionManager           $manager
  * @param \Notadd\Foundation\Setting\Contracts\SettingsRepository $settings
  *
  * @return bool
  * @throws \Exception
  */
 public function fire(ExtensionManager $manager, SettingsRepository $settings)
 {
     $this->name = $this->input->getArgument('name');
     $extensions = $manager->getExtensionPaths();
     if (!$extensions->offsetExists($this->name)) {
         $this->error("Extension {$this->name} do not exist!");
         return false;
     }
     if ($settings->get("extension.{$this->name}.installed")) {
         $this->error("Extension {$this->name} is installed!");
         return false;
     }
     $this->path = $extensions->get($this->name);
     if (Str::contains($this->path, $manager->getVendorPath())) {
         $this->error("Extension {$this->name} is installed!");
         return false;
     }
     $this->postInstall($settings);
     $this->composer->dumpAutoloads();
     $this->resetOpcache();
     $settings->set("extension.{$this->name}.installed", true);
     $this->info("Extension {$this->name} is installed!");
     return true;
 }