/** * 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 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 fields. * * @param PermissionFormBuilder $builder * @param AddonCollection $addons * @param Translator $translator * @param Repository $config */ public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config) { /* @var UserInterface $user */ $user = $builder->getEntry(); $fields = []; $namespaces = ['streams']; /* @var Addon $addon */ foreach ($addons->withConfig('permissions') as $addon) { $namespaces[] = $addon->getNamespace(); } foreach ($namespaces as $namespace) { foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) { $label = $namespace . '::permission.' . $group . '.name'; if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) { $warning = null; } if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) { $instructions = null; } $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => function () use($user, $namespace, $group) { return array_map(function ($permission) use($user, $namespace, $group) { return str_replace($namespace . '::' . $group . '.', '', $permission); }, $user->getPermissions()); }, 'config' => ['options' => function () use($group, $permissions, $namespace) { return array_combine($permissions, array_map(function ($permission) use($namespace, $group) { return $namespace . '::permission.' . $group . '.option.' . $permission; }, $permissions)); }]]; } } $builder->setFields($fields); }
/** * 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); }
/** * Handle the command. * * @param AddonCollection $addons * @param Repository $repository */ public function handle(AddonCollection $addons, Repository $repository) { $slug = $this->stream->getSlug(); $namespace = $this->stream->getNamespace(); foreach ($addons->withConfig("streams.{$namespace}.{$slug}") as $config) { $this->stream->mergeConfig($config); } $this->stream->mergeConfig($repository->get("streams::streams.{$namespace}.{$slug}", [])); }
/** * Handle the command. * * @param RelationshipFieldType $fieldType * @param AddonCollection $addons * @param Repository $config * @return array */ public function handle(RelationshipFieldType $fieldType, AddonCollection $addons, Repository $config) { $definition = []; /* @var Addon $addon */ foreach ($addons->withConfig('lookup.' . $this->table->config('related')) as $addon) { $definition = $config->get($addon->getNamespace('lookup.' . $this->table->config('related'))); } $definition = $config->get($fieldType->getNamespace('lookup.' . $this->table->config('related')), $definition); return $definition; }
/** * 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; }
/** * 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)); }
/** * Handle the command. * * @param MultipleFieldType $fieldType * @param AddonCollection $addons * @param Container $container * @param Repository $config * @return array */ public function handle(MultipleFieldType $fieldType, AddonCollection $addons, Container $container, Repository $config) { $definition = []; $key = 'multiple.lookup.' . get_class($container->make($this->table->config('related'))); /* @var Addon $addon */ foreach ($addons->withConfig($key) as $addon) { $definition = $config->get($addon->getNamespace($key)); } $definition = $config->get($fieldType->getNamespace($key), $definition); return $definition; }
/** * 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; }
/** * 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 * @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.'); } }
/** * 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')]); } }
/** * 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; }
/** * Register all addons. */ public function register() { $enabled = $this->getEnabledAddonNamespaces(); $installed = $this->getInstalledAddonNamespaces(); $paths = $this->paths->all(); /** * First load all the addons * so they're available. */ foreach ($paths as $path) { $this->loader->load($path); } $this->loader->register(); /** * Then register all of the addons now * that they're all PSR autoloaded. */ foreach ($paths as $path) { $this->integrator->register($path, $enabled, $installed); } // Sort all addons. $this->addons = $this->addons->sort(); /** * Disperse addons to their * respective collections and * finish the integration service. */ $this->addons->disperse(); $this->addons->registered(); $this->integrator->finish(); $this->dispatcher->fire(new AddonsHaveRegistered($this->addons)); }
/** * 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); }
/** * Handle the fields. * * @param PermissionFormBuilder $builder * @param AddonCollection $addons * @param Translator $translator * @param Repository $config */ public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Repository $config) { $sections = []; $sections['streams']['title'] = 'streams::message.system'; foreach ($config->get('streams::permissions', []) as $group => $permissions) { $sections['streams']['fields'][] = 'streams::' . $group; } /* @var Addon $addon */ foreach ($addons->withConfig('permissions') as $addon) { $sections[$addon->getNamespace()]['title'] = $addon->getName(); $sections[$addon->getNamespace()]['description'] = $addon->getDescription(); foreach ($config->get($addon->getNamespace('permissions'), []) as $group => $permissions) { $sections[$addon->getNamespace()]['fields'][] = $addon->getNamespace($group); } } $builder->setSections($sections); }
/** * 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; }
/** * Handle the fields. * * @param PermissionFormBuilder $builder * @param AddonCollection $addons * @param Translator $translator * @param Repository $config */ public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config) { /* @var UserInterface $user */ $user = $builder->getEntry(); $roles = $user->getRoles(); $inherited = $roles->permissions(); $fields = []; $namespaces = array_merge(['streams'], $addons->withConfig('permissions')->namespaces()); /** * gather all the addons with a * permissions configuration file. * * @var Addon $addon */ foreach ($namespaces as $namespace) { foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) { /** * Determine the general * form UI components. */ $label = $namespace . '::permission.' . $group . '.name'; if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) { $warning = null; } if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) { $instructions = null; } /** * Gather the available * permissions for the group. */ $available = array_combine(array_map(function ($permission) use($namespace, $group) { return $namespace . '::' . $group . '.' . $permission; }, $permissions), array_map(function ($permission) use($namespace, $group) { return $namespace . '::permission.' . $group . '.option.' . $permission; }, $permissions)); /** * Build the checkboxes field * type to handle the UI. */ $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => array_merge($user->getPermissions(), $inherited), 'config' => ['disabled' => $inherited, 'options' => $available]]; } } $builder->setFields($fields); }
/** * Handle the command. * * @param SettingRepositoryInterface $settings * @param AddonCollection $addons * @param Repository $config */ public function handle(SettingRepositoryInterface $settings, AddonCollection $addons, Repository $config) { /* @var Addon $addon */ foreach ($addons->withConfig('settings') as $addon) { foreach ($config->get($addon->getNamespace('settings')) as $key => $setting) { if (isset($setting['env']) && env($setting['env']) !== null) { continue; } if (!isset($setting['bind'])) { continue; } if (!$settings->has($key = $addon->getNamespace($key))) { continue; } $config->set($setting['bind'], $settings->value($key)); } } foreach ($addons->withConfig('settings/settings') as $addon) { foreach ($config->get($addon->getNamespace('settings/settings')) as $key => $setting) { if (isset($setting['env']) && env($setting['env']) !== null) { continue; } if (!isset($setting['bind'])) { continue; } if (!$settings->has($key = $addon->getNamespace($key))) { continue; } $config->set($setting['bind'], $settings->value($key)); } } foreach ($config->get('streams::settings/settings', []) as $key => $setting) { if (isset($setting['env']) && env($setting['env']) !== null) { continue; } if (!isset($setting['bind'])) { continue; } if (!$settings->has($key = 'streams::' . $key)) { continue; } $config->set($setting['bind'], $settings->value($key)); } }
/** * Handle the command. * * @param AddonCollection $addons */ public function handle(AddonCollection $addons) { foreach ($addons->enabled() as $addon) { $options = ['--addon' => $addon->getNamespace()]; if ($this->command->option('force')) { $options['--force'] = true; } if ($this->command->option('pretend')) { $options['--pretend'] = true; } if ($this->command->option('seed')) { $options['--seed'] = true; } if ($database = $this->command->option('database')) { $options['--database'] = $database; } $this->command->call('migrate', $options); } return; }
/** * Register an addon. * * @param $path * @param $enabled * @param $installed */ public function register($path, array $enabled, array $installed) { if (!is_dir($path)) { return; } $vendor = strtolower(basename(dirname($path))); $slug = strtolower(substr(basename($path), 0, strpos(basename($path), '-'))); $type = strtolower(substr(basename($path), strpos(basename($path), '-') + 1)); $class = studly_case($vendor) . '\\' . studly_case($slug) . studly_case($type) . '\\' . studly_case($slug) . studly_case($type); /* @var Addon|Module|Extension|Twig_ExtensionInterface $addon */ $addon = app($class)->setPath($path)->setType($type)->setSlug($slug)->setVendor($vendor); // If the addon supports states - set the state now. if ($addon->getType() === 'module' || $addon->getType() === 'extension') { $addon->setInstalled(in_array($addon->getNamespace(), $installed)); $addon->setEnabled(in_array($addon->getNamespace(), $enabled)); } // Bind to the service container. $this->container->alias($addon->getNamespace(), $alias = get_class($addon)); $this->container->instance($alias, $addon); // Load package configuration. $this->configurator->addNamespace($addon->getNamespace(), $addon->getPath('resources/config')); // Load system overrides. $this->configurator->addNamespaceOverrides($addon->getNamespace(), base_path('resources/addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType())); // Load application overrides. $this->configurator->addNamespaceOverrides($addon->getNamespace(), $this->application->getResourcesPath('addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType() . '/config')); // Continue loading things. $this->provider->register($addon); // Add the view / translation namespaces. $this->views->addNamespace($addon->getNamespace(), $addon->getPath('resources/views')); $this->translator->addNamespace($addon->getNamespace(), $addon->getPath('resources/lang')); /* * If the addon is a plugin then * load it into Twig when appropriate. */ if ($addon->getType() === 'plugin') { $this->events->listen('Anomaly\\Streams\\Platform\\View\\Event\\RegisteringTwigPlugins', function (RegisteringTwigPlugins $event) use($addon) { $twig = $event->getTwig(); $twig->addExtension($addon); }); } $this->collection->put($addon->getNamespace(), $addon); $this->events->fire(new AddonWasRegistered($addon)); }
/** * Handle the command. * * @param AddonCollection $addons * * @return Addon */ public function handle(AddonCollection $addons) { return $addons->get($this->identifier); }
/** * 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; }