/** * Execute the console command. * * @return mixed */ public function handle(Filesystem $filesystem, AddonEnvironment $env) { $this->filesystem = $filesystem; $addon_name = $this->argument('addon'); $this->addon = $env->addon($addon_name); // check addon if ($this->addon === null) { throw new UnexpectedValueException("Addon '{$addon_name}' is not found."); } $this->currentNamespace = trim($this->addon->phpNamespace(), '\\'); $this->newNamespace = str_replace('/', '\\', $this->argument('namespace')); // check namespace if (!$this->validPhpNamespace($this->newNamespace)) { throw new UnexpectedValueException("PHP namespace '{$this->newNamespace}' is invalid."); } // confirm $this->line('Addon name: ' . $addon_name); $this->line('Addon path: ' . $this->addon->relativePath($this->laravel)); $this->line('PHP namespace: ' . $this->newNamespace); if (!$this->option('force')) { if (!$this->confirm('Are you sure? [y/N]', false)) { $this->comment('canceled'); return; } } $this->setAddonNamespaces(); $this->setComposerNamespace(); $this->setClassNamespace(); $this->setConfigNamespaces(); $this->info('Addon namespace set!'); }
/** * setup & boot addons. */ protected function bootAddons() { foreach ($this->addonEnvironment->addons() as $name => $addon) { // boot addon $addon->boot($this->app); } }
/** * Execute the console command. * * @param \Jumilla\Addomnipot\Laravel\Addons\AddonGenerator $generator * * @return mixed */ public function handle(Filesystem $filesystem, AddonEnvironment $env, AddonGenerator $generator) { $addon_name = preg_replace('#(/+)#', '-', $this->argument('name')); // Check addon-directory if ($env->exists($addon_name)) { throw new UnexpectedValueException("addon directory '{$addon_name}' is already exists."); } $output_path = $env->spacePath($this->option('space'), $addon_name); // Adjust addon_name $addon_name = preg_replace('/[^\\w_\\-]/', '', $addon_name); $addon_class = preg_replace(['/[^\\w_]/', '/^(\\d)/'], ['', '_$1'], studly_case($addon_name)); // namespace if ($this->option('no-namespace')) { $namespace = ''; } else { if ($this->option('namespace')) { $namespace = str_replace('/', '\\', $this->option('namespace')); } else { $namespace = 'App\\' . $addon_class; } if (!$this->validPhpNamespace($namespace)) { throw new UnexpectedValueException("PHP namespace '{$namespace}' is invalid."); } } // languages $languages = $this->option('language') ? explode($this->option('language')) : []; // Show select prompt if not specified $skeleton = $this->chooseSkeleton($this->argument('skeleton')); $properties = ['addon_name' => $addon_name, 'addon_class' => $addon_class, 'namespace' => $namespace, 'languages' => array_unique(array_merge(['en', $this->laravel['config']->get('app.locale')], $languages))]; // confirm $this->line('Addon name: ' . $properties['addon_name']); $this->line('PHP namespace: ' . $properties['namespace']); $this->line('Skeleton: ' . $skeleton); $this->line('Languages: ' . implode(', ', $properties['languages'])); if (!$this->option('yes') && !$this->confirm('generate ready? [Y/n]', true)) { $this->comment('canceled'); return; } try { $generator->generateAddon($output_path, str_replace(':', '-', $skeleton), $properties); $this->info('Addon Generated.'); } catch (Exception $ex) { $filesystem->deleteDirectory($output_path); throw $ex; } }
/** * Execute the console command. * * @return mixed */ public function handle(Filesystem $filesystem, AddonEnvironment $env) { // make addons/ $addonsDirectory = $env->path(); if (!$filesystem->exists($addonsDirectory)) { $filesystem->makeDirectory($addonsDirectory); } // copy app/config/addon.php $addonConfigSourceFile = __DIR__ . '/../../config/addon.php'; $addonConfigFile = $this->laravel['path.config'] . '/addon.php'; if (!$filesystem->exists($addonConfigFile)) { $filesystem->copy($addonConfigSourceFile, $addonConfigFile); $this->info('make config: ' . $addonConfigFile); } // show lists $addons = $env->addons(); foreach ($addons as $addon) { $this->dump($addon); } }
/** * Execute the console command. * * @return mixed */ public function handle(Filesystem $filesystem, AddonEnvironment $env) { $addon_name = $this->argument('addon'); $addon = $env->addon($addon_name); // check addon if ($addon === null) { throw new UnexpectedValueException(sprintf('Addon "%s" is not found.', $addon_name)); } // confirm $this->line('Addon name: ' . $addon_name); $this->line('Addon path: ' . $addon->relativePath($this->laravel)); if (!$this->option('force')) { if (!$this->confirm('Are you sure? [y/N]', false)) { $this->comment('canceled'); return; } } // process $filesystem->deleteDirectory($addon->path()); $this->info(sprintf('Addon "%s" removed.', $addon_name)); }
/** * Execute the console command. * * @return mixed */ public function handle(Filesystem $filesystem, AddonEnvironment $env) { // make addons/ $addons_directory = $env->path(); if (!$filesystem->exists($addons_directory)) { $filesystem->makeDirectory($addons_directory); } $addon_name = $this->argument('addon'); if (!$addon_name) { $addons = $env->addons(); $this->line('--------'); foreach ($addons as $addon) { $this->dump($addon); $this->line('--------'); } } else { $addon = $env->addon($addon_name); // check addon if ($addon === null) { throw new UnexpectedValueException(sprintf('Addon "%s" is not found.', $addon_name)); } $this->dump($addon); } }
public function boot() { foreach ($this->addonEnvironment->addons() as $addon) { $addon->boot($this->app); } }