/** * Handle the command. * * @param Seed $command */ public function handle(Seed $command) { $this->seeder->setContainer(app()); $this->seeder->setCommand($command->getCommand()); Model::unguard(); $class = $command->getClass(); $addon = $this->addons->get($command->getAddon()); /** * Depending on when this is called, and * how seeding uses the view layer the addon's * could be decorated, so un-decorate them real * quick before proceeding. */ if ($addon && $addon instanceof Presenter) { $addon = $addon->getObject(); } /** * If the addon was passed then * get it and seed it. */ if ($addon) { $this->call($this->getSeederClass($addon)); } /** * If a seeder class was passed then * call it from the seeder utility. */ if (!$addon && $class) { $this->call($class); } }
/** * Return the located addon instance. * * @param $object * @return \Anomaly\Streams\Platform\Addon\Addon|mixed|null */ public function resolve($object) { if (!($namespace = $this->locate($object))) { return null; } return $this->addons->get($namespace); }
/** * Handle the command. * * @param GetAddonFromMigration $command * @return Addon|null */ public function handle(GetAddonFromMigration $command) { $matcher = "/(^[a-zA-Z0-9._]+?)(?=__)/"; $reflection = new \ReflectionClass($command->getMigration()); $fileName = implode('_', array_slice(explode('_', basename($reflection->getFileName())), 4)); preg_match($matcher, $fileName, $matches); return $this->addons->get(isset($matches[1]) ? $matches[1] : null); }
/** * Restore the value. * * @param $value * @return null|Addon */ public function restore($value) { if ($value instanceof Addon) { return $value; } if ($value && ($addon = $this->addons->get($value))) { return $addon; } return null; }
/** * Handle the command. * * @param CreateAddonMigrationFolder $command * @return string|null */ public function handle(CreateAddonMigrationFolder $command) { $path = null; if ($addon = $this->addons->get($command->getAddon())) { $path = $addon->getPath('migrations'); if (!$this->files->isDirectory($path)) { $this->files->makeDirectory($path); } } return $path; }
/** * Export all entries. * * @param $addon * @param $namespace * @param $stream * @return \Illuminate\Http\RedirectResponse */ public function export($addon, $namespace, $stream) { $addon = $this->addons->get($addon); /* @var StreamInterface $stream */ $stream = $this->streams->findBySlugAndNamespace($stream, $namespace); /* * Resolve the model and set * it on the repository. */ $this->repository->setModel($this->container->make($stream->getEntryModelName())); if (!$this->authorizer->authorize($addon->getNamespace($stream->getSlug() . '.export'))) { abort(403); } $headers = ['Content-Disposition' => 'attachment; filename=' . $stream->getSlug() . '.csv', 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-type' => 'text/csv', 'Pragma' => 'public', 'Expires' => '0']; $callback = function () { $output = fopen('php://output', 'w'); foreach ($this->repository->all() as $k => $entry) { if ($k == 0) { fputcsv($output, array_keys($entry->toArray())); } fputcsv($output, $entry->toArray()); } fclose($output); }; return $this->response->stream($callback, 200, $headers); }
/** * Execute the console command. */ public function fire(AddonCollection $addons) { $slug = $this->argument('slug'); $addon = $this->argument('addon'); /* @var Addon $addon */ if (!($addon = $addons->get($addon))) { throw new \Exception("The addon [{$this->argument('addon')}] could not be found."); } if (!($namespace = $this->option('namespace'))) { $namespace = $addon->getSlug(); } $this->dispatch(new WriteEntityModel($addon, $slug, $namespace)); $this->dispatch(new WriteEntityRoutes($addon, $slug, $namespace)); $this->dispatch(new WriteEntityRouter($addon, $slug, $namespace)); $this->dispatch(new WriteEntityObserver($addon, $slug, $namespace)); $this->dispatch(new WriteEntityCriteria($addon, $slug, $namespace)); $this->dispatch(new WriteEntityPresenter($addon, $slug, $namespace)); $this->dispatch(new WriteEntityController($addon, $slug, $namespace)); $this->dispatch(new WriteEntityCollection($addon, $slug, $namespace)); $this->dispatch(new WriteEntityRepository($addon, $slug, $namespace)); $this->dispatch(new WriteEntityFormBuilder($addon, $slug, $namespace)); $this->dispatch(new WriteEntityTableBuilder($addon, $slug, $namespace)); $this->dispatch(new WriteEntityModelInterface($addon, $slug, $namespace)); $this->dispatch(new WriteEntityRepositoryInterface($addon, $slug, $namespace)); $this->call('make:migration', ['name' => 'create_' . $slug . '_stream', '--addon' => $addon->getNamespace(), '--stream' => $slug]); }
/** * Handle the command. * * @param GetMigrationName $command * @return string */ public function handle(GetMigrationName $command) { $namespace = $command->getNamespace(); $name = $originalName = $command->getName(); if ($addon = $this->addons->get($namespace)) { $name = "{$namespace}__{$originalName}"; // Append the package version if there is one. if ($json = $addon->getComposerJson()) { if (property_exists($json, 'version')) { $version = str_slug(str_replace(['.', '-'], '_', $json->version), '_'); $name = "{$namespace}__{$version}__{$originalName}"; } } } return $name; }
/** * Get a field type from the * collection by namespace key. * * @param mixed $key * @param mixed $default * @return null|FieldType */ public function get($key, $default = null) { $type = parent::get($key, $default); if (!$type) { return null; } return clone $type; }
/** * Execute the console command. */ public function fire(AddonCollection $addons) { $schema = $this->argument('schema'); $slug = explode(':', trim($schema))[0]; $addon = $addons->get($this->argument('addon')); $path = $addon->getPath(); $this->call('make:migration', ['name' => 'create_' . $slug . '_stream', '--addon' => $addon->getNamespace(), '--stream' => $schema]); $this->call('make:migration', ['name' => 'create_' . $addon->getSlug() . '_fields', '--addon' => $addon->getNamespace(), '--stream' => $schema, '--fields' => true]); /* After a successful stream migration, create a seeder template file */ $this->dispatch(new MakeStream($slug, $path)); }
/** * Uninstall an addon. * * @param AddonCollection $addons * @param ModuleManager $modules * @param ExtensionManager $extensions * @param $addon * @return \Illuminate\Http\RedirectResponse */ public function uninstall(AddonCollection $addons, ModuleManager $modules, ExtensionManager $extensions, $addon) { /* @var Addon $addon */ $addon = $addons->get($addon); if ($addon instanceof Module) { $modules->uninstall($addon); } elseif ($addon instanceof Extension) { $extensions->uninstall($addon); } $this->messages->success('module::message.uninstall_addon_success'); return $this->redirect->back(); }
/** * Execute the console command. */ public function fire(AddonCollection $addons) { if (!$this->argument('addon')) { foreach ($addons as $addon) { $this->call('addon:publish', ['addon' => $addon->getNamespace()]); } return; } $addon = $addons->get($this->argument('addon')); $this->dispatch(new PublishViews($addon, $this)); $this->dispatch(new PublishConfig($addon, $this)); $this->dispatch(new PublishTranslations($addon, $this)); }
/** * Execute the console command. * * @param AddonCollection $addons */ public function fire(AddonCollection $addons) { if (!($addon = $addons->get($this->argument('addon')))) { $this->error('The [' . $this->argument('addon') . '] could not be found.'); } if ($addon instanceof Module) { $this->call('addon:uninstall', ['addon' => $this->argument('addon')]); $this->call('addon:install', ['addon' => $this->argument('addon'), '--seed' => $this->option('seed')]); } if ($addon instanceof Extension) { $this->call('addon:uninstall', ['addon' => $this->argument('addon')]); $this->call('addon:install', ['addon' => $this->argument('addon'), '--seed' => $this->option('seed')]); } }
/** * Execute the console command. * * @param AddonCollection $addons * @param ModuleManager $modules * @param ExtensionManager $extensions */ public function fire(AddonCollection $addons, ModuleManager $modules, ExtensionManager $extensions) { if (!($addon = $addons->get($this->argument('addon')))) { $this->error('The [' . $this->argument('addon') . '] could not be found.'); } if ($addon instanceof Module) { $modules->install($addon, $this->option('seed')); $this->info('The [' . $this->argument('addon') . '] module was installed.'); } if ($addon instanceof Extension) { $extensions->install($addon, $this->option('seed')); $this->info('The [' . $this->argument('addon') . '] extension was installed.'); } }
/** * Get the override view path. * * @param $view * @return null|string */ public function getOverloadPath(View $view) { /** * We can only overload namespaced * views right now. */ if (!str_contains($view->getName(), '::')) { return null; } /** * Split the view into it's * namespace and path. */ list($namespace, $path) = explode('::', $view->getName()); $path = str_replace('.', '/', $path); /** * If the module is shorthand * then check to see if we have * an active module to use for it. */ if ($namespace === 'module' && $this->module) { $namespace = $this->module->getNamespace(); } /** * If the view is already in * the theme then skip it. */ if ($namespace == 'theme' || str_is('*.theme.*', $namespace)) { return null; } /** * If the view is a streams view then * it's real easy to guess what the * override path should be. */ if ($namespace == 'streams') { $path = $this->theme->getNamespace('streams/' . $path); } /** * If the view uses a dot syntax namespace then * transform it all into the override view path. */ if ($addon = $this->addons->get($namespace)) { $path = $this->theme->getNamespace("addons/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path); } if ($this->view->exists($path)) { return $path; } /** * If the view uses a dot syntax namespace then * transform it all into the override view path. * * @deprecated since v3.0.0 */ if ($addon) { $path = $this->theme->getNamespace("addon/{$addon->getVendor()}/{$addon->getSlug()}-{$addon->getType()}/" . $path); } if ($this->view->exists($path)) { return $path; } return null; }
/** * Handle the command. * * @param AddonCollection $addons * * @return Addon */ public function handle(AddonCollection $addons) { return $addons->get($this->identifier); }