From b8c16e63752ff2d7740d3dea87b3216d7add3c5b Mon Sep 17 00:00:00 2001 From: Artem Brezhnev Date: Wed, 6 Sep 2017 11:47:06 +0300 Subject: [PATCH] Added Descriptor facade methods fluent, withModules, withoutModules, setScopes, base --- README.md | 14 +++++++++ src/Descriptor.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/README.md b/README.md index fc127a0..0be7891 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,20 @@ You can disable it by setting to `false` config value `plugin.loadRoutes`. You can use `Descriptor` facade to customize or create from scratch your own descriptor contents. +For example, you can customize it by adding to the `app\Providers\AppServiceProvider` in `boot` section the following: + +``` +Descriptor::base() // base descriptor contents + ->setScopes(['admin' , 'act_as_user']) + ->withModules([ + 'webhooks' => [[ + 'event' => 'jira:issue_created', + 'url' => route('webhookHandlerRouteName') + ]] + ]) + ->set('version', $this->getLatestPluginVersion()); +``` + ### Console commands * `plugin:install` is a helper command that creates "dummy" tenant with fake data and publishes package resources (config, views, assets) diff --git a/src/Descriptor.php b/src/Descriptor.php index 130c4e2..12d0ea1 100644 --- a/src/Descriptor.php +++ b/src/Descriptor.php @@ -106,6 +106,77 @@ public function modify(callable $callback) return $this; } + /** + * The helper method to use fluent interface + * + * @return $this + */ + public function fluent() + { + return $this; + } + + /** + * Set specific modules + * + * @param array $modules + * + * @return $this + */ + public function withModules(array $modules) + { + $this->set('modules', $modules); + + return $this; + } + + /** + * Remove modules + * + * @return $this + */ + public function withoutModules() + { + $this->set('modules', []); + + return $this; + } + + /** + * Set scopes + * + * @param array $scopes + * + * @return $this + */ + public function setScopes(array $scopes) + { + $this->set('scopes', $scopes); + + return $this; + } + + /** + * Set base contents + * + * @return $this + */ + public function base() + { + $this->contents = array_only($this->defaultContents(), [ + 'name', + 'description', + 'key', + 'baseUrl', + 'vendor', + 'version', + 'authentication', + 'lifecycle' + ]); + + return $this; + } + /** * Default descriptor contents *