From 6fc726f7cf275f00332eb429e4d5f39c15916424 Mon Sep 17 00:00:00 2001 From: Lorand Gombos Date: Thu, 8 Sep 2016 09:06:54 +0300 Subject: [PATCH 01/14] Use DIRECTORY_SEPARATOR --- src/Finder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Finder.php b/src/Finder.php index 6f1a241..07b643c 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -488,7 +488,7 @@ public function findJob($name) $files = $finder->name($fileName)->in($this->findDomainsRootPath())->files(); foreach ($files as $file) { $path = $file->getRealPath(); - $domainName = strstr($file->getRelativePath(), '/', true); + $domainName = strstr($file->getRelativePath(), DIRECTORY_SEPARATOR, true); $domain = $this->findDomain($domainName); $content = file_get_contents($path); From 5c1c5a9c8ccc7900ff37f4ced2c8f228fce3b7d1 Mon Sep 17 00:00:00 2001 From: Dmitriy Lezhnev Date: Thu, 13 Oct 2016 20:31:07 +0500 Subject: [PATCH 02/14] Added directory creation before file creation (to avoid dir not found error) --- src/Filesystem.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Filesystem.php b/src/Filesystem.php index 8c881b8..f547002 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -41,6 +41,8 @@ public function exists($path) */ public function createFile($path, $contents = '', $lock = false) { + $this->createDirectory(dirname($path)); + return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); } From eedea3cc4d65fcc043cb2e4ae661e568546248eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Jufr=C3=A9?= Date: Sun, 20 Nov 2016 22:04:36 +0100 Subject: [PATCH 03/14] Added commands for making / deleting: models, requests, policies --- .idea/blade.xml | 4 + .idea/console-laravel.iml | 8 + .idea/copyright/profiles_settings.xml | 3 + .idea/jsLibraryMappings.xml | 6 + .idea/misc.xml | 28 ++ .idea/modules.xml | 8 + .idea/php.xml | 4 + .idea/vcs.xml | 6 + .idea/workspace.xml | 528 ++++++++++++++++++++++++++ README.md | 12 + lucid | 7 + src/Commands/ModelDeleteCommand.php | 97 +++++ src/Commands/ModelMakeCommand.php | 89 +++++ src/Commands/PolicyDeleteCommand.php | 97 +++++ src/Commands/PolicyMakeCommand.php | 88 +++++ src/Commands/RequestDeleteCommand.php | 99 +++++ src/Commands/RequestMakeCommand.php | 90 +++++ src/Components/Model.php | 23 ++ src/Components/Policy.php | 22 ++ src/Components/Request.php | 24 ++ src/Finder.php | 86 +++++ src/Generators/ModelGenerator.php | 63 +++ src/Generators/PolicyGenerator.php | 74 ++++ src/Generators/RequestGenerator.php | 67 ++++ src/Generators/stubs/model.stub | 10 + src/Generators/stubs/policy.stub | 21 + src/Generators/stubs/request.stub | 30 ++ src/Str.php | 36 ++ 28 files changed, 1630 insertions(+) create mode 100644 .idea/blade.xml create mode 100644 .idea/console-laravel.iml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 src/Commands/ModelDeleteCommand.php create mode 100644 src/Commands/ModelMakeCommand.php create mode 100644 src/Commands/PolicyDeleteCommand.php create mode 100644 src/Commands/PolicyMakeCommand.php create mode 100644 src/Commands/RequestDeleteCommand.php create mode 100644 src/Commands/RequestMakeCommand.php create mode 100644 src/Components/Model.php create mode 100644 src/Components/Policy.php create mode 100644 src/Components/Request.php create mode 100644 src/Generators/ModelGenerator.php create mode 100644 src/Generators/PolicyGenerator.php create mode 100644 src/Generators/RequestGenerator.php create mode 100644 src/Generators/stubs/model.stub create mode 100644 src/Generators/stubs/policy.stub create mode 100644 src/Generators/stubs/request.stub diff --git a/.idea/blade.xml b/.idea/blade.xml new file mode 100644 index 0000000..ddb9fb5 --- /dev/null +++ b/.idea/blade.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/console-laravel.iml b/.idea/console-laravel.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/console-laravel.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d23208f --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f524616 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6fcf8ba --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..10b171f --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..90c5ea6 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,528 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + project + + + true + + + + DIRECTORY + + false + + + + + + + + + 1479672993120 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index a50142e..c3b74b2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) - `make:feature ` Create a new Feature in a service - `make:job ` Create a new Job in a domain - `make:service ` Create a new Service + - `make:model ` Create a new Model + - `make:request ` Create a new Request in a service + - `make:policy ` Create a new Policy - **list** - `list:features` List the features. - `list:services` List the services in this project. @@ -26,6 +29,9 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) - `delete:feature` Delete an existing Feature in a service - `delete:job ` Delete an existing Job in a domain - `delete:service` Delete an existing Service + - `delete:model ` Delete an existing Model + - `delete:request ` Delete an existing Request in a service + - `delete:policy ` Delete an existing Policy ### Commands Usage @@ -34,6 +40,9 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) - `make:feature []` - `make:job ` - `make:service ` +- `make:model ` +- `make:request []` +- `make:policy ` #### List - `list:services` @@ -43,3 +52,6 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) - `delete:service ` - `delete:feature []` - `delete:job ` +- `delete:model ` +- `delete:request []` +- `delete:policy ` diff --git a/lucid b/lucid index ca50761..f908460 100755 --- a/lucid +++ b/lucid @@ -19,6 +19,13 @@ $commands = [ new Lucid\Console\Commands\ControllerMakeCommand(), new Lucid\Console\Commands\ServicesListCommand(), new Lucid\Console\Commands\FeaturesListCommand(), + + new \Lucid\Console\Commands\ModelMakeCommand(), + new \Lucid\Console\Commands\ModelDeleteCommand(), + new \Lucid\Console\Commands\RequestMakeCommand(), + new \Lucid\Console\Commands\RequestDeleteCommand(), + new \Lucid\Console\Commands\PolicyMakeCommand(), + new \Lucid\Console\Commands\PolicyDeleteCommand(), ]; $app = new Symfony\Component\Console\Application('Lucid Console', '0.5.0'); diff --git a/src/Commands/ModelDeleteCommand.php b/src/Commands/ModelDeleteCommand.php new file mode 100644 index 0000000..349529f --- /dev/null +++ b/src/Commands/ModelDeleteCommand.php @@ -0,0 +1,97 @@ +parseModelName($this->argument('model')); + + if ( ! $this->exists($path = $this->findModelPath($model))) { + $this->error('Model class ' . $model . ' cannot be found.'); + } else { + $this->delete($path); + + $this->info('Model class ' . $model . ' deleted successfully.'); + } + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + public function getArguments() + { + return [ + ['model', InputArgument::REQUIRED, 'The Model\'s name.'] + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/model.stub'; + } + + /** + * Parse the model name. + * + * @param string $name + * @return string + */ + public function parseModelName($name) + { + return Str::model($name); + } +} \ No newline at end of file diff --git a/src/Commands/ModelMakeCommand.php b/src/Commands/ModelMakeCommand.php new file mode 100644 index 0000000..d834ca1 --- /dev/null +++ b/src/Commands/ModelMakeCommand.php @@ -0,0 +1,89 @@ +argument('model'); + + try { + $model = $generator->generate($name); + + $this->info('Model class created successfully.' . + "\n" . + "\n" . + 'Find it at ' . $model->relativePath . '' . "\n" + ); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + public function getArguments() + { + return [ + ['model', InputArgument::REQUIRED, 'The Model\'s name.'] + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/model.stub'; + } +} \ No newline at end of file diff --git a/src/Commands/PolicyDeleteCommand.php b/src/Commands/PolicyDeleteCommand.php new file mode 100644 index 0000000..5606992 --- /dev/null +++ b/src/Commands/PolicyDeleteCommand.php @@ -0,0 +1,97 @@ +parsePolicyName($this->argument('policy')); + + if ( ! $this->exists($path = $this->findPolicyPath($policy))) { + $this->error('Policy class ' . $policy . ' cannot be found.'); + } else { + $this->delete($path); + + $this->info('Policy class ' . $policy . ' deleted successfully.'); + } + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + public function getArguments() + { + return [ + ['policy', InputArgument::REQUIRED, 'The Policy\'s name.'] + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/policy.stub'; + } + + /** + * Parse the model name. + * + * @param string $name + * @return string + */ + public function parsePolicyName($name) + { + return Str::policy($name); + } +} \ No newline at end of file diff --git a/src/Commands/PolicyMakeCommand.php b/src/Commands/PolicyMakeCommand.php new file mode 100644 index 0000000..96272dd --- /dev/null +++ b/src/Commands/PolicyMakeCommand.php @@ -0,0 +1,88 @@ +argument('policy'); + + try { + $policy = $generator->generate($name); + + $this->info('Policy class created successfully.' . + "\n" . + "\n" . + 'Find it at ' . $policy->relativePath . '' . "\n" + ); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + public function getArguments() + { + return [ + ['policy', InputArgument::REQUIRED, 'The Policy\'s name.'] + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/policy.stub'; + } +} \ No newline at end of file diff --git a/src/Commands/RequestDeleteCommand.php b/src/Commands/RequestDeleteCommand.php new file mode 100644 index 0000000..655e980 --- /dev/null +++ b/src/Commands/RequestDeleteCommand.php @@ -0,0 +1,99 @@ +parseRequestName($this->argument('request')); + $service = Str::service($this->argument('service')); + + if ( ! $this->exists($path = $this->findRequestPath($service, $request))) { + $this->error('Request class ' . $request . ' cannot be found.'); + } else { + $this->delete($path); + + $this->info('Request class ' . $request . ' deleted successfully.'); + } + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + public function getArguments() + { + return [ + ['request', InputArgument::REQUIRED, 'The Request\'s name.'], + ['service', InputArgument::REQUIRED, 'The Service\'s name.'], + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/request.stub'; + } + + /** + * Parse the model name. + * + * @param string $name + * @return string + */ + public function parseRequestName($name) + { + return Str::request($name); + } +} \ No newline at end of file diff --git a/src/Commands/RequestMakeCommand.php b/src/Commands/RequestMakeCommand.php new file mode 100644 index 0000000..3a57d39 --- /dev/null +++ b/src/Commands/RequestMakeCommand.php @@ -0,0 +1,90 @@ +argument('request'); + $service = $this->argument('service'); + + try { + $request = $generator->generate($name, $service); + + $this->info('Request class created successfully.' . + "\n" . + "\n" . + 'Find it at ' . $request->relativePath . '' . "\n" + ); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + public function getArguments() + { + return [ + ['request', InputArgument::REQUIRED, 'The Request\'s name.'], + ['service', InputArgument::REQUIRED, 'The Service\'s name.'], + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/request.stub'; + } +} \ No newline at end of file diff --git a/src/Components/Model.php b/src/Components/Model.php new file mode 100644 index 0000000..915d751 --- /dev/null +++ b/src/Components/Model.php @@ -0,0 +1,23 @@ +setAttributes([ + 'model' => $title, + 'namespace' => $namespace, + 'file' => $file, + 'path' => $path, + 'relativePath' => $relativePath, + 'content' => $content, + ]); + } +} \ No newline at end of file diff --git a/src/Components/Policy.php b/src/Components/Policy.php new file mode 100644 index 0000000..89c029b --- /dev/null +++ b/src/Components/Policy.php @@ -0,0 +1,22 @@ +setAttributes([ + 'policy' => $title, + 'namespace' => $namespace, + 'file' => $file, + 'path' => $path, + 'relativePath' => $relativePath, + 'content' => $content, + ]); + } +} \ No newline at end of file diff --git a/src/Components/Request.php b/src/Components/Request.php new file mode 100644 index 0000000..7bd4ace --- /dev/null +++ b/src/Components/Request.php @@ -0,0 +1,24 @@ +setAttributes([ + 'request' => $title, + 'service' => $service, + 'namespace' => $namespace, + 'file' => $file, + 'path' => $path, + 'relativePath' => $relativePath, + 'content' => $content, + ]); + } +} \ No newline at end of file diff --git a/src/Finder.php b/src/Finder.php index b98c165..e8d371e 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -653,6 +653,92 @@ public function listFeatures($serviceName = '') return $features; } + /** + * Get the path to the passed model. + * + * @param string $model + * @return string + */ + public function findModelPath($model) + { + return $this->getSourceDirectoryName() . '/Data/' . $model . '.php'; + } + + /** + * Get the path to the policies directory. + * + * @return string + */ + public function findPoliciesPath() + { + return $this->getSourceDirectoryName() . '/Domains/Policies'; + } + + /** + * Get the path to the passed policy. + * + * @param string $policy + * @return string + */ + public function findPolicyPath($policy) + { + return $this->findPoliciesPath() . '/' . $policy . '.php'; + } + + /** + * Get the path to the request directory of a specific service. + * + * @param string $service + * @return string + */ + public function findRequestsPath($service) + { + return $this->findServicePath($service) . '/Http/Requests'; + } + + /** + * Get the path to a specific request. + * + * @param string $service + * @param string $request + * @return string + */ + public function findRequestPath($service, $request) + { + return $this->findRequestsPath($service) . '/' . $request . '.php'; + } + + /** + * Get the namespace for the Models. + * + * @return string + */ + public function findModelNamespace() + { + return $this->findRootNamespace() . '\\Data'; + } + + /** + * Get the namespace for Policies + * + * @return mixed + */ + public function findPolicyNamespace() + { + return $this->findDomainNamespace('Policies'); + } + + /** + * Get the requests namespace for the service passed in. + * + * @param string $service + * @return string + */ + public function findRequestsNamespace($service) + { + return $this->findServiceNamespace($service) . '\\Http\\Requests'; + } + /** * Get the relative version of the given real path. * diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php new file mode 100644 index 0000000..bd560c9 --- /dev/null +++ b/src/Generators/ModelGenerator.php @@ -0,0 +1,63 @@ +findModelPath($model); + + if ($this->exists($path)) { + throw new Exception('Model already exists'); + + return false; + } + + $namespace = $this->findModelNamespace(); + + $content = file_get_contents($this->getStub()); + $content = str_replace( + ['{{model}}', '{{namespace}}', '{{foundation_namespace}}'], + [$model, $namespace, $this->findFoundationNamespace()], + $content + ); + + $this->createFile($path, $content); + + return new Model( + $model, + $namespace, + basename($path), + $path, + $this->relativeFromReal($path), + $content + ); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/model.stub'; + } +} \ No newline at end of file diff --git a/src/Generators/PolicyGenerator.php b/src/Generators/PolicyGenerator.php new file mode 100644 index 0000000..ae9c8f9 --- /dev/null +++ b/src/Generators/PolicyGenerator.php @@ -0,0 +1,74 @@ +findPolicyPath($policy); + + if ($this->exists($path)) { + throw new Exception('Policy already exists'); + + return false; + } + + $this->createPolicyDirectory(); + + $namespace = $this->findPolicyNamespace(); + + $content = file_get_contents($this->getStub()); + $content = str_replace( + ['{{policy}}', '{{namespace}}', '{{foundation_namespace}}'], + [$policy, $namespace, $this->findFoundationNamespace()], + $content + ); + + $this->createFile($path, $content); + + return new Policy( + $policy, + $namespace, + basename($path), + $path, + $this->relativeFromReal($path), + $content + ); + } + + /** + * Create Policies directory. + */ + public function createPolicyDirectory() + { + $this->createDirectory($this->findPoliciesPath()); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/policy.stub'; + } +} \ No newline at end of file diff --git a/src/Generators/RequestGenerator.php b/src/Generators/RequestGenerator.php new file mode 100644 index 0000000..27d88dd --- /dev/null +++ b/src/Generators/RequestGenerator.php @@ -0,0 +1,67 @@ +findRequestPath($service, $request); + + if ($this->exists($path)) { + throw new Exception('Request already exists'); + + return false; + } + + $namespace = $this->findRequestsNamespace($service); + + $content = file_get_contents($this->getStub()); + $content = str_replace( + ['{{request}}', '{{namespace}}', '{{foundation_namespace}}'], + [$request, $namespace, $this->findFoundationNamespace()], + $content + ); + + $this->createFile($path, $content); + + return new Request( + $request, + $service, + $namespace, + basename($path), + $path, + $this->relativeFromReal($path), + $content + ); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__ . '/../Generators/stubs/request.stub'; + } +} \ No newline at end of file diff --git a/src/Generators/stubs/model.stub b/src/Generators/stubs/model.stub new file mode 100644 index 0000000..2f7e7de --- /dev/null +++ b/src/Generators/stubs/model.stub @@ -0,0 +1,10 @@ + Date: Sun, 20 Nov 2016 22:05:05 +0100 Subject: [PATCH 04/14] Added commands for making / deleting: models, requests, policies --- .gitignore | 1 + .idea/blade.xml | 4 - .idea/console-laravel.iml | 8 - .idea/copyright/profiles_settings.xml | 3 - .idea/jsLibraryMappings.xml | 6 - .idea/misc.xml | 28 -- .idea/modules.xml | 8 - .idea/php.xml | 4 - .idea/vcs.xml | 6 - .idea/workspace.xml | 528 -------------------------- 10 files changed, 1 insertion(+), 595 deletions(-) delete mode 100644 .idea/blade.xml delete mode 100644 .idea/console-laravel.iml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/php.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index d8a7996..6b772a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ composer.lock vendor/ +.idea diff --git a/.idea/blade.xml b/.idea/blade.xml deleted file mode 100644 index ddb9fb5..0000000 --- a/.idea/blade.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/console-laravel.iml b/.idea/console-laravel.iml deleted file mode 100644 index c956989..0000000 --- a/.idea/console-laravel.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index d23208f..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index f524616..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6fcf8ba..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index 10b171f..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 90c5ea6..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,528 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - project - - - - - - - - - - - - - - - - project - - - true - - - - DIRECTORY - - false - - - - - - - - - 1479672993120 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 645ec5f060fa0c75403d82a8cfe8f6b577bbeb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Jufr=C3=A9?= Date: Sun, 20 Nov 2016 22:11:49 +0100 Subject: [PATCH 05/14] Change some minor comments and details --- src/Commands/ModelDeleteCommand.php | 4 ++++ src/Commands/ModelMakeCommand.php | 3 +++ src/Commands/PolicyDeleteCommand.php | 4 ++++ src/Commands/PolicyMakeCommand.php | 4 ++++ src/Commands/RequestDeleteCommand.php | 4 ++++ src/Commands/RequestMakeCommand.php | 4 ++++ src/Components/Model.php | 3 +++ src/Components/Policy.php | 4 ++++ src/Components/Request.php | 4 ++++ src/Generators/ModelGenerator.php | 4 ++++ src/Generators/PolicyGenerator.php | 4 ++++ src/Generators/RequestGenerator.php | 4 ++++ 12 files changed, 46 insertions(+) diff --git a/src/Commands/ModelDeleteCommand.php b/src/Commands/ModelDeleteCommand.php index 349529f..c484b55 100644 --- a/src/Commands/ModelDeleteCommand.php +++ b/src/Commands/ModelDeleteCommand.php @@ -10,8 +10,12 @@ use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputArgument; + /** * Class ModelDeleteCommand + * + * @author Bernat Jufré + * * @package Lucid\Console\Commands */ class ModelDeleteCommand extends SymfonyCommand diff --git a/src/Commands/ModelMakeCommand.php b/src/Commands/ModelMakeCommand.php index d834ca1..1667a34 100644 --- a/src/Commands/ModelMakeCommand.php +++ b/src/Commands/ModelMakeCommand.php @@ -13,6 +13,9 @@ /** * Class ModelMakeCommand + * + * @author Bernat Jufré + * * @package Lucid\Console\Commands */ class ModelMakeCommand extends SymfonyCommand diff --git a/src/Commands/PolicyDeleteCommand.php b/src/Commands/PolicyDeleteCommand.php index 5606992..c10df9b 100644 --- a/src/Commands/PolicyDeleteCommand.php +++ b/src/Commands/PolicyDeleteCommand.php @@ -10,8 +10,12 @@ use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputArgument; + /** * Class PolicyDeleteCommand + * + * @author Bernat Jufré + * * @package Lucid\Console\Commands */ class PolicyDeleteCommand extends SymfonyCommand diff --git a/src/Commands/PolicyMakeCommand.php b/src/Commands/PolicyMakeCommand.php index 96272dd..7dd26b3 100644 --- a/src/Commands/PolicyMakeCommand.php +++ b/src/Commands/PolicyMakeCommand.php @@ -10,8 +10,12 @@ use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputArgument; + /** * Class PolicyMakeCommand + * + * @author Bernat Jufré + * * @package Lucid\Console\Commands */ class PolicyMakeCommand extends SymfonyCommand diff --git a/src/Commands/RequestDeleteCommand.php b/src/Commands/RequestDeleteCommand.php index 655e980..e0ebc0c 100644 --- a/src/Commands/RequestDeleteCommand.php +++ b/src/Commands/RequestDeleteCommand.php @@ -10,8 +10,12 @@ use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputArgument; + /** * Class RequestDeleteCommand + * + * @author Bernat Jufré + * * @package Lucid\Console\Commands */ class RequestDeleteCommand extends SymfonyCommand diff --git a/src/Commands/RequestMakeCommand.php b/src/Commands/RequestMakeCommand.php index 3a57d39..f1a7316 100644 --- a/src/Commands/RequestMakeCommand.php +++ b/src/Commands/RequestMakeCommand.php @@ -10,8 +10,12 @@ use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputArgument; + /** * Class RequestMakeCommand + * + * @author Bernat Jufré + * * @package Lucid\Console\Commands */ class RequestMakeCommand extends SymfonyCommand diff --git a/src/Components/Model.php b/src/Components/Model.php index 915d751..1cd7966 100644 --- a/src/Components/Model.php +++ b/src/Components/Model.php @@ -5,6 +5,9 @@ /** * Class Model + * + * @author Bernat Jufré + * * @package Lucid\Console\Components */ class Model extends Component diff --git a/src/Components/Policy.php b/src/Components/Policy.php index 89c029b..3f71c91 100644 --- a/src/Components/Policy.php +++ b/src/Components/Policy.php @@ -2,8 +2,12 @@ namespace Lucid\Console\Components; + /** * Class Policy + * + * @author Bernat Jufré + * * @package Lucid\Console\Components */ class Policy extends Component diff --git a/src/Components/Request.php b/src/Components/Request.php index 7bd4ace..3110486 100644 --- a/src/Components/Request.php +++ b/src/Components/Request.php @@ -3,8 +3,12 @@ namespace Lucid\Console\Components; + /** * Class Request + * + * @author Bernat Jufré + * * @package Lucid\Console\Components */ class Request extends Component diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index bd560c9..ab353c8 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -6,8 +6,12 @@ use Lucid\Console\Str; use Lucid\Console\Components\Model; + /** * Class ModelGenerator + * + * @author Bernat Jufré + * * @package Lucid\Console\Generators */ class ModelGenerator extends Generator diff --git a/src/Generators/PolicyGenerator.php b/src/Generators/PolicyGenerator.php index ae9c8f9..bec571b 100644 --- a/src/Generators/PolicyGenerator.php +++ b/src/Generators/PolicyGenerator.php @@ -7,8 +7,12 @@ use Lucid\Console\Str; use Lucid\Console\Components\Policy; + /** * Class PolicyGenerator + * + * @author Bernat Jufré + * * @package Lucid\Console\Generators */ class PolicyGenerator extends Generator diff --git a/src/Generators/RequestGenerator.php b/src/Generators/RequestGenerator.php index 27d88dd..4d891e2 100644 --- a/src/Generators/RequestGenerator.php +++ b/src/Generators/RequestGenerator.php @@ -7,8 +7,12 @@ use Lucid\Console\Str; use Lucid\Console\Components\Request; + /** * Class RequestGenerator + * + * @author Bernat Jufré + * * @package Lucid\Console\Generators */ class RequestGenerator extends Generator From efbe2b5e8fd872545641d3bef4eddc9efd027358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Jufr=C3=A9?= Date: Mon, 21 Nov 2016 17:45:49 +0100 Subject: [PATCH 06/14] gitignore modified & policy namespace / path --- .gitignore | 1 - src/Finder.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6b772a8..d8a7996 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ composer.lock vendor/ -.idea diff --git a/src/Finder.php b/src/Finder.php index e8d371e..73f1b98 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -671,7 +671,7 @@ public function findModelPath($model) */ public function findPoliciesPath() { - return $this->getSourceDirectoryName() . '/Domains/Policies'; + return $this->getSourceDirectoryName() . '/Policies'; } /** @@ -725,7 +725,7 @@ public function findModelNamespace() */ public function findPolicyNamespace() { - return $this->findDomainNamespace('Policies'); + return $this->findRootNamespace() . '\\Policies'; } /** From bd9db1e78e02385de465e0305d86d1581ae94a42 Mon Sep 17 00:00:00 2001 From: Ali Issa Date: Thu, 1 Dec 2016 17:19:22 +0200 Subject: [PATCH 07/14] added the queueable job feature --- src/Commands/JobMakeCommand.php | 22 ++++++++++++------- src/Generators/JobGenerator.php | 14 +++++++++---- src/Generators/stubs/queueable-job.stub | 28 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 src/Generators/stubs/queueable-job.stub diff --git a/src/Commands/JobMakeCommand.php b/src/Commands/JobMakeCommand.php index 983e1de..f220d6b 100644 --- a/src/Commands/JobMakeCommand.php +++ b/src/Commands/JobMakeCommand.php @@ -11,13 +11,14 @@ namespace Lucid\Console\Commands; -use Lucid\Console\Str; -use Lucid\Console\Finder; use Lucid\Console\Command; use Lucid\Console\Filesystem; +use Lucid\Console\Finder; use Lucid\Console\Generators\JobGenerator; -use Symfony\Component\Console\Input\InputArgument; +use Lucid\Console\Str; use Symfony\Component\Console\Command\Command as SymfonyCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; /** * @author Abed Halawi @@ -33,7 +34,7 @@ class JobMakeCommand extends SymfonyCommand * * @var string */ - protected $name = 'make:job'; + protected $name = 'make:job {--Q|queue}'; /** * The console command description. @@ -60,9 +61,9 @@ public function fire() $domain = studly_case($this->argument('domain')); $title = $this->parseName($this->argument('job')); - + $isQueueable = $this->option('queue'); try { - $job = $generator->generate($title, $domain); + $job = $generator->generate($title, $domain, $isQueueable); $this->info( 'Job class '.$title.' created successfully.'. @@ -79,7 +80,14 @@ public function getArguments() { return [ ['job', InputArgument::REQUIRED, 'The job\'s name.'], - ['domain', InputArgument::REQUIRED, 'The domain to be responsible for the job.'], + ['domain', InputArgument::OPTIONAL, 'The domain to be responsible for the job.'], + ]; + } + + public function getOptions() + { + return [ + ['queue', 'Q', InputOption::VALUE_NONE, 'Whether a job is queueable or not.'], ]; } diff --git a/src/Generators/JobGenerator.php b/src/Generators/JobGenerator.php index 93086ad..7541c8a 100644 --- a/src/Generators/JobGenerator.php +++ b/src/Generators/JobGenerator.php @@ -20,7 +20,7 @@ */ class JobGenerator extends Generator { - public function generate($job, $domain) + public function generate($job, $domain, $isQueueable = false) { $job = Str::job($job); $domain = Str::domain($domain); @@ -38,7 +38,7 @@ public function generate($job, $domain) // Create the job $namespace = $this->findDomainJobsNamespace($domain); - $content = file_get_contents($this->getStub()); + $content = file_get_contents($this->getStub($isQueueable)); $content = str_replace( ['{{job}}', '{{namespace}}', '{{foundation_namespace}}'], [$job, $namespace, $this->findFoundationNamespace()], @@ -101,9 +101,15 @@ private function createDomainDirectory($domain) * * @return string */ - public function getStub() + public function getStub($isQueueable = false) { - return __DIR__.'/stubs/job.stub'; + $stubName; + if ($isQueueable) { + $stubName = '/stubs/queueable-job.stub'; + } else { + $stubName = '/stubs/job.stub'; + } + return __DIR__.$stubName; } /** diff --git a/src/Generators/stubs/queueable-job.stub b/src/Generators/stubs/queueable-job.stub new file mode 100644 index 0000000..cbfdbd0 --- /dev/null +++ b/src/Generators/stubs/queueable-job.stub @@ -0,0 +1,28 @@ + Date: Thu, 1 Dec 2016 17:31:43 +0200 Subject: [PATCH 08/14] remove unnecessary code --- README.md | 2 +- src/Generators/stubs/job.stub | 14 ++++++++++++-- src/Generators/stubs/queueable-job.stub | 3 +-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c3b74b2..2acc63a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) #### Make - `make:controller []` - `make:feature []` -- `make:job ` +- `make:job [--queue]` - `make:service ` - `make:model ` - `make:request []` diff --git a/src/Generators/stubs/job.stub b/src/Generators/stubs/job.stub index 39bc0ad..9869db2 100644 --- a/src/Generators/stubs/job.stub +++ b/src/Generators/stubs/job.stub @@ -5,13 +5,23 @@ use {{foundation_namespace}}\Job; class {{job}} extends Job { + /** + * Create a new job instance. + * + * @return void + */ public function __construct() { - + // } + /** + * Execute the job. + * + * @return void + */ public function handle() { - + // } } diff --git a/src/Generators/stubs/queueable-job.stub b/src/Generators/stubs/queueable-job.stub index cbfdbd0..0adaa05 100644 --- a/src/Generators/stubs/queueable-job.stub +++ b/src/Generators/stubs/queueable-job.stub @@ -1,8 +1,7 @@ Date: Mon, 5 Dec 2016 10:39:14 +0200 Subject: [PATCH 09/14] domain required --- src/Commands/JobMakeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/JobMakeCommand.php b/src/Commands/JobMakeCommand.php index f220d6b..2b45972 100644 --- a/src/Commands/JobMakeCommand.php +++ b/src/Commands/JobMakeCommand.php @@ -80,7 +80,7 @@ public function getArguments() { return [ ['job', InputArgument::REQUIRED, 'The job\'s name.'], - ['domain', InputArgument::OPTIONAL, 'The domain to be responsible for the job.'], + ['domain', InputArgument::REQUIRED, 'The domain to be responsible for the job.'], ]; } From 9fb0b1abd5df8a4999270201e012492b047c4cfb Mon Sep 17 00:00:00 2001 From: Ali Issa Date: Mon, 12 Dec 2016 13:38:23 +0200 Subject: [PATCH 10/14] add operation and queueable operation commands --- README.md | 4 +- lucid | 3 + src/Commands/OperationDeleteCommand.php | 110 ++++++++++++++++ src/Commands/OperationMakeCommand.php | 117 +++++++++++++++++ src/Components/Operation.php | 33 +++++ src/Finder.php | 87 ++++++++++-- src/Generators/OperationGenerator.php | 124 ++++++++++++++++++ src/Generators/stubs/operation-test.stub | 13 ++ src/Generators/stubs/operation.stub | 13 ++ src/Generators/stubs/queueable-operation.stub | 13 ++ src/Str.php | 16 +++ 11 files changed, 523 insertions(+), 10 deletions(-) create mode 100644 src/Commands/OperationDeleteCommand.php create mode 100644 src/Commands/OperationMakeCommand.php create mode 100644 src/Components/Operation.php create mode 100644 src/Generators/OperationGenerator.php create mode 100644 src/Generators/stubs/operation-test.stub create mode 100644 src/Generators/stubs/operation.stub create mode 100644 src/Generators/stubs/queueable-operation.stub diff --git a/README.md b/README.md index 2acc63a..394b008 100644 --- a/README.md +++ b/README.md @@ -17,16 +17,18 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) - **make** - `make:controller` Create a new resource Controller class in a service - `make:feature ` Create a new Feature in a service + - `make:operaion ` Create a new Operation in a service - `make:job ` Create a new Job in a domain - `make:service ` Create a new Service - `make:model ` Create a new Model - `make:request ` Create a new Request in a service - - `make:policy ` Create a new Policy + - `make:policy ` Create a new Policy - **list** - `list:features` List the features. - `list:services` List the services in this project. - **delete** - `delete:feature` Delete an existing Feature in a service + - `delete:operaion` Delete an existing Operation in a service - `delete:job ` Delete an existing Job in a domain - `delete:service` Delete an existing Service - `delete:model ` Delete an existing Model diff --git a/lucid b/lucid index f908460..37de904 100755 --- a/lucid +++ b/lucid @@ -26,6 +26,9 @@ $commands = [ new \Lucid\Console\Commands\RequestDeleteCommand(), new \Lucid\Console\Commands\PolicyMakeCommand(), new \Lucid\Console\Commands\PolicyDeleteCommand(), + + new \Lucid\Console\Commands\OperationMakeCommand(), + new \Lucid\Console\Commands\OperationDeleteCommand(), ]; $app = new Symfony\Component\Console\Application('Lucid Console', '0.5.0'); diff --git a/src/Commands/OperationDeleteCommand.php b/src/Commands/OperationDeleteCommand.php new file mode 100644 index 0000000..ac44680 --- /dev/null +++ b/src/Commands/OperationDeleteCommand.php @@ -0,0 +1,110 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Lucid\Console\Commands; + +use Lucid\Console\Str; +use Lucid\Console\Finder; +use Lucid\Console\Command; +use Lucid\Console\Filesystem; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Command\Command as SymfonyCommand; + +/** + * @author Ali Issa + */ +class OperationDeleteCommand extends SymfonyCommand +{ + use Finder; + use Command; + use Filesystem; + + /** + * The console command name. + * + * @var string + */ + protected $name = 'delete:operation'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Delete an existing Operation in a service'; + + /** + * The type of class being deleted. + * + * @var string + */ + protected $type = 'Operation'; + + /** + * Execute the console command. + * + * @return bool|null + */ + public function fire() + { + try { + $service = Str::service($this->argument('service')); + $title = $this->parseName($this->argument('operation')); + + if (!$this->exists($operation = $this->findOperationPath($service, $title))) { + $this->error('Operation class '.$title.' cannot be found.'); + } else { + $this->delete($operation); + + $this->info('Operation class '.$title.' deleted successfully.'); + } + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return [ + ['operation', InputArgument::REQUIRED, 'The operation\'s name.'], + ['service', InputArgument::OPTIONAL, 'The service from which the operation should be deleted.'], + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + return __DIR__.'/../Generators/stubs/operation.stub'; + } + + /** + * Parse the operation name. + * remove the Operation.php suffix if found + * we're adding it ourselves. + * + * @param string $name + * + * @return string + */ + protected function parseName($name) + { + return Str::operation($name); + } +} diff --git a/src/Commands/OperationMakeCommand.php b/src/Commands/OperationMakeCommand.php new file mode 100644 index 0000000..463a98f --- /dev/null +++ b/src/Commands/OperationMakeCommand.php @@ -0,0 +1,117 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Lucid\Console\Commands; + +use Lucid\Console\Command; +use Lucid\Console\Filesystem; +use Lucid\Console\Finder; +use Lucid\Console\Generators\OperationGenerator; +use Lucid\Console\Str; +use Symfony\Component\Console\Command\Command as SymfonyCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; + +/** + * @author Ali Issa + */ +class OperationMakeCommand extends SymfonyCommand +{ + use Finder; + use Command; + use Filesystem; + + /** + * The console command name. + * + * @var string + */ + protected $name = 'make:operation {--Q|queue}'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Create a new Operation in a domain'; + + /** + * The type of class being generated. + * + * @var string + */ + protected $type = 'Operation'; + + /** + * Execute the console command. + * + * @return bool|null + */ + public function fire() + { + $generator = new OperationGenerator(); + + $service = studly_case($this->argument('service')); + $title = $this->parseName($this->argument('operation')); + $isQueueable = $this->option('queue'); + try { + $operation = $generator->generate($title, $service, $isQueueable); + + $this->info( + 'Operation class '.$title.' created successfully.'. + "\n". + "\n". + 'Find it at '.$operation->relativePath.''."\n" + ); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + + public function getArguments() + { + return [ + ['operation', InputArgument::REQUIRED, 'The operation\'s name.'], + ['service', InputArgument::OPTIONAL, 'The service in which the operation should be implemented.'], + ]; + } + + public function getOptions() + { + return [ + ['queue', 'Q', InputOption::VALUE_NONE, 'Whether a operation is queueable or not.'], + ]; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + public function getStub() + { + return __DIR__.'/../Generators/stubs/operation.stub'; + } + + /** + * Parse the operation name. + * remove the Operation.php suffix if found + * we're adding it ourselves. + * + * @param string $name + * + * @return string + */ + protected function parseName($name) + { + return Str::operation($name); + } +} diff --git a/src/Components/Operation.php b/src/Components/Operation.php new file mode 100644 index 0000000..f2515f6 --- /dev/null +++ b/src/Components/Operation.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Lucid\Console\Components; + +/** + * @author Ali Issa + */ +class Operation extends Component +{ + public function __construct($title, $file, $realPath, $relativePath, Service $service = null, $content = '') + { + $className = str_replace(' ', '', $title).'Operation'; + + $this->setAttributes([ + 'title' => $title, + 'className' => $className, + 'service' => $service, + 'file' => $file, + 'realPath' => $realPath, + 'relativePath' => $relativePath, + 'content' => $content, + ]); + } +} diff --git a/src/Finder.php b/src/Finder.php index da6964c..5a4171e 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -274,6 +274,70 @@ public function findFeatureTestNamespace($service) return $this->findServiceNamespace($service).'\\Tests\\Features'; } + /** + * Find the operations root path in the given service. + * + * @param string $service + * + * @return string + */ + public function findOperationsRootPath($service) + { + return $this->findServicePath($service).'/Operations'; + } + + /** + * Find the file path for the given operation. + * + * @param string $service + * @param string $operation + * + * @return string + */ + public function findOperationPath($service, $operation) + { + return $this->findOperationsRootPath($service)."/$operation.php"; + } + + /** + * Find the test file path for the given operation. + * + * @param string $service + * @param string $operation + * + * @return string + */ + public function findOperationTestPath($service, $test) + { + $root = ($service) ? $this->findServicePath($service).'/Tests' : base_path().'/tests'; + + return "$root/Operations/$test.php"; + } + + /** + * Find the namespace for operations in the given service. + * + * @param string $service + * + * @return string + */ + public function findOperationNamespace($service) + { + return $this->findServiceNamespace($service).'\\Operations'; + } + + /** + * Find the namespace for operations tests in the given service. + * + * @param string $service + * + * @return string + */ + public function findOperationTestNamespace($service) + { + return $this->findServiceNamespace($service).'\\Tests\\Operations'; + } + /** * Find the root path of domains. * @@ -657,11 +721,12 @@ public function listFeatures($serviceName = '') * Get the path to the passed model. * * @param string $model + * * @return string */ public function findModelPath($model) { - return $this->getSourceDirectoryName() . '/Data/' . $model . '.php'; + return $this->getSourceDirectoryName().'/Data/'.$model.'.php'; } /** @@ -671,29 +736,31 @@ public function findModelPath($model) */ public function findPoliciesPath() { - return $this->getSourceDirectoryName() . '/Policies'; + return $this->getSourceDirectoryName().'/Policies'; } /** * Get the path to the passed policy. * * @param string $policy + * * @return string */ public function findPolicyPath($policy) { - return $this->findPoliciesPath() . '/' . $policy . '.php'; + return $this->findPoliciesPath().'/'.$policy.'.php'; } /** * Get the path to the request directory of a specific service. * * @param string $service + * * @return string */ public function findRequestsPath($service) { - return $this->findServicePath($service) . '/Http/Requests'; + return $this->findServicePath($service).'/Http/Requests'; } /** @@ -701,11 +768,12 @@ public function findRequestsPath($service) * * @param string $service * @param string $request + * * @return string */ public function findRequestPath($service, $request) { - return $this->findRequestsPath($service) . '/' . $request . '.php'; + return $this->findRequestsPath($service).'/'.$request.'.php'; } /** @@ -715,28 +783,29 @@ public function findRequestPath($service, $request) */ public function findModelNamespace() { - return $this->findRootNamespace() . '\\Data'; + return $this->findRootNamespace().'\\Data'; } /** - * Get the namespace for Policies + * Get the namespace for Policies. * * @return mixed */ public function findPolicyNamespace() { - return $this->findRootNamespace() . '\\Policies'; + return $this->findRootNamespace().'\\Policies'; } /** * Get the requests namespace for the service passed in. * * @param string $service + * * @return string */ public function findRequestsNamespace($service) { - return $this->findServiceNamespace($service) . '\\Http\\Requests'; + return $this->findServiceNamespace($service).'\\Http\\Requests'; } /** diff --git a/src/Generators/OperationGenerator.php b/src/Generators/OperationGenerator.php new file mode 100644 index 0000000..5a5fd93 --- /dev/null +++ b/src/Generators/OperationGenerator.php @@ -0,0 +1,124 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Lucid\Console\Generators; + +use Exception; +use Lucid\Console\Str; +use Lucid\Console\Components\Operation; + +/** + * @author Ali Issa + */ +class OperationGenerator extends Generator +{ + public function generate($operation, $service, $isQueueable = false, array $jobs = []) + { + $operation = Str::operation($operation); + $service = Str::service($service); + + $path = $this->findOperationPath($service, $operation); + + if ($this->exists($path)) { + throw new Exception('Operation already exists!'); + + return false; + } + + $namespace = $this->findOperationNamespace($service); + + $content = file_get_contents($this->getStub($isQueueable)); + + $useJobs = ''; // stores the `use` statements of the jobs + $runJobs = ''; // stores the `$this->run` statements of the jobs + + foreach ($jobs as $index => $job) { + $useJobs .= 'use '.$job['namespace'].'\\'.$job['className'].";\n"; + $runJobs .= "\t\t".'$this->run('.$job['className'].'::class);'; + + // only add carriage returns when it's not the last job + if ($index != count($jobs) - 1) { + $runJobs .= "\n\n"; + } + } + + $content = str_replace( + ['{{operation}}', '{{namespace}}', '{{foundation_namespace}}', '{{use_jobs}}', '{{run_jobs}}'], + [$operation, $namespace, $this->findFoundationNamespace(), $useJobs, $runJobs], + $content + ); + + $this->createFile($path, $content); + + // generate test file + $this->generateTestFile($operation, $service); + + return new Operation( + $operation, + basename($path), + $path, + $this->relativeFromReal($path), + ($service) ? $this->findService($service) : null, + $content + ); + } + + /** + * Generate the test file. + * + * @param string $operation + * @param string $service + */ + private function generateTestFile($operation, $service) + { + $content = file_get_contents($this->getTestStub()); + + $namespace = $this->findOperationTestNamespace($service); + $operationNamespace = $this->findOperationNamespace($service)."\\$operation"; + $testClass = $operation.'Test'; + + $content = str_replace( + ['{{namespace}}', '{{testclass}}', '{{operation}}', '{{operation_namespace}}'], + [$namespace, $testClass, mb_strtolower($operation), $operationNamespace], + $content + ); + + $path = $this->findOperationTestPath($service, $testClass); + + $this->createFile($path, $content); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub($isQueueable = false) + { + $stubName; + if ($isQueueable) { + $stubName = '/stubs/queueable-operation.stub'; + } else { + $stubName = '/stubs/operation.stub'; + } + return __DIR__.$stubName; + } + + /** + * Get the test stub file for the generator. + * + * @return string + */ + private function getTestStub() + { + return __DIR__.'/stubs/operation-test.stub'; + } +} diff --git a/src/Generators/stubs/operation-test.stub b/src/Generators/stubs/operation-test.stub new file mode 100644 index 0000000..814fc52 --- /dev/null +++ b/src/Generators/stubs/operation-test.stub @@ -0,0 +1,13 @@ +markTestIncomplete(); + } +} diff --git a/src/Generators/stubs/operation.stub b/src/Generators/stubs/operation.stub new file mode 100644 index 0000000..8e801d8 --- /dev/null +++ b/src/Generators/stubs/operation.stub @@ -0,0 +1,13 @@ + Date: Tue, 13 Dec 2016 12:36:58 +0200 Subject: [PATCH 11/14] fix typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 394b008..5389e79 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) - **make** - `make:controller` Create a new resource Controller class in a service - `make:feature ` Create a new Feature in a service - - `make:operaion ` Create a new Operation in a service + - `make:operation ` Create a new Operation in a service - `make:job ` Create a new Job in a domain - `make:service ` Create a new Service - `make:model ` Create a new Model @@ -28,7 +28,7 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc) - `list:services` List the services in this project. - **delete** - `delete:feature` Delete an existing Feature in a service - - `delete:operaion` Delete an existing Operation in a service + - `delete:operation` Delete an existing Operation in a service - `delete:job ` Delete an existing Job in a domain - `delete:service` Delete an existing Service - `delete:model ` Delete an existing Model From e44ce44a14e41b79f5237750d56cd80da526295d Mon Sep 17 00:00:00 2001 From: speccode Date: Tue, 20 Dec 2016 07:09:49 +0000 Subject: [PATCH 12/14] lucid config file --- config/lucid.php | 32 ++++++++++++++++++++++++++++++++ src/LucidServiceProvider.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 config/lucid.php diff --git a/config/lucid.php b/config/lucid.php new file mode 100644 index 0000000..c0fdb44 --- /dev/null +++ b/config/lucid.php @@ -0,0 +1,32 @@ + null, + + /* + |-------------------------------------------------------------------------- + | Microservice + |-------------------------------------------------------------------------- + | + | By default Lucid Architecture is setup as microservice. Microservice + | means that you will have only one service and all features / jobs / data + | etc. will be generated into /app/ directory. + | + | When you set this value to "false" it means you application have multiple + | services and all classes will be generated into /src/ directrory. After + | changing that value all "lucid" classes should be moved from /app/ to + | /src/. + */ + //'microservice' => true, + +]; \ No newline at end of file diff --git a/src/LucidServiceProvider.php b/src/LucidServiceProvider.php index 2923271..185905e 100644 --- a/src/LucidServiceProvider.php +++ b/src/LucidServiceProvider.php @@ -24,8 +24,19 @@ class LucidServiceProvider extends ServiceProvider */ public function boot() { - if (!$this->app->routesAreCached()) { - require_once __DIR__.'/Http/routes.php'; + $configPath = __DIR__ . '/../config/lucid.php'; + $this->publishes([$configPath => $this->getConfigPath()], 'config'); + + $dashboard_enabled = $this->app['config']->get('lucid.dashboard'); + + if ($dashboard_enabled === null) { + $dashboard_enabled = $this->app['config']->get('app.debug'); + } + + if ($dashboard_enabled === true) { + if (!$this->app->routesAreCached() ) { + require_once __DIR__.'/Http/routes.php'; + } } $this->loadViewsFrom(__DIR__.'/../resources/views', 'lucid'); @@ -40,6 +51,19 @@ public function boot() */ public function register() { + $configPath = __DIR__ . '/../config/lucid.php'; + $this->mergeConfigFrom($configPath, 'lucid'); + $this->app->register(LogReaderServiceProvider::class); } + + /** + * Return path to config file. + * + * @return string + */ + private function getConfigPath() + { + return config_path('lucid.php'); + } } From 79b17e8ac647844fab076467d220400a41756367 Mon Sep 17 00:00:00 2001 From: speccode Date: Tue, 20 Dec 2016 07:18:05 +0000 Subject: [PATCH 13/14] misspells --- config/lucid.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/lucid.php b/config/lucid.php index c0fdb44..ea50997 100644 --- a/config/lucid.php +++ b/config/lucid.php @@ -6,9 +6,9 @@ | Dashboard |-------------------------------------------------------------------------- | - | By default /lucid/dashboard is avilable on when env('APP_DEBUG') is true. - | If you set this value to "true" it will be always accessable even on - | production environment. + | By default /lucid/dashboard is available on when env('APP_DEBUG') + | is true. If you set this value to "true" it will be always accessible + | even on production environment. | */ 'dashboard' => null, @@ -23,9 +23,10 @@ | etc. will be generated into /app/ directory. | | When you set this value to "false" it means you application have multiple - | services and all classes will be generated into /src/ directrory. After - | changing that value all "lucid" classes should be moved from /app/ to - | /src/. + | services and all classes will be generated into /src/ directrory. + | After changing that value all "lucid" classes should be moved + | from /app/ to /src/. + | */ //'microservice' => true, From bc1e7c22580468d14a5d33ff51e8fe49c150ff94 Mon Sep 17 00:00:00 2001 From: speccode Date: Wed, 21 Dec 2016 06:10:04 +0100 Subject: [PATCH 14/14] pr fixes --- config/lucid.php | 24 +++--------------------- src/LucidServiceProvider.php | 8 ++++---- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/config/lucid.php b/config/lucid.php index ea50997..fbbd85a 100644 --- a/config/lucid.php +++ b/config/lucid.php @@ -6,28 +6,10 @@ | Dashboard |-------------------------------------------------------------------------- | - | By default /lucid/dashboard is available on when env('APP_DEBUG') - | is true. If you set this value to "true" it will be always accessible - | even on production environment. + | By default /lucid/dashboard is available when env('APP_DEBUG') is true. + | If you set this value to "true" it will be always accessible even on + | production environment. | */ 'dashboard' => null, - - /* - |-------------------------------------------------------------------------- - | Microservice - |-------------------------------------------------------------------------- - | - | By default Lucid Architecture is setup as microservice. Microservice - | means that you will have only one service and all features / jobs / data - | etc. will be generated into /app/ directory. - | - | When you set this value to "false" it means you application have multiple - | services and all classes will be generated into /src/ directrory. - | After changing that value all "lucid" classes should be moved - | from /app/ to /src/. - | - */ - //'microservice' => true, - ]; \ No newline at end of file diff --git a/src/LucidServiceProvider.php b/src/LucidServiceProvider.php index 185905e..ffef666 100644 --- a/src/LucidServiceProvider.php +++ b/src/LucidServiceProvider.php @@ -27,13 +27,13 @@ public function boot() $configPath = __DIR__ . '/../config/lucid.php'; $this->publishes([$configPath => $this->getConfigPath()], 'config'); - $dashboard_enabled = $this->app['config']->get('lucid.dashboard'); + $dashboardEnabled = $this->app['config']->get('lucid.dashboard'); - if ($dashboard_enabled === null) { - $dashboard_enabled = $this->app['config']->get('app.debug'); + if ($dashboardEnabled === null) { + $dashboardEnabled = $this->app['config']->get('app.debug'); } - if ($dashboard_enabled === true) { + if ($dashboardEnabled === true) { if (!$this->app->routesAreCached() ) { require_once __DIR__.'/Http/routes.php'; }