mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2025-04-19 15:42:27 +03:00
Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f1debe575e | ||
|
2efa3595a5 | ||
|
c46846d978 | ||
|
8d804e09eb | ||
|
a6008f4a40 | ||
|
86493ab228 | ||
|
50c3e78483 | ||
|
ee03649641 | ||
|
8ee7bbe6b7 | ||
|
73e470ec15 | ||
|
c5218a1fd8 | ||
|
014c617cc5 | ||
|
8b6e2db315 | ||
|
a2cb5e4437 | ||
|
9a82b80cb1 | ||
|
56f0d9c0a9 | ||
|
573d55c9b2 | ||
|
a951151697 | ||
|
5e2c21855e | ||
|
2817f3591b | ||
|
a2cf22d426 | ||
|
6e00a91eea | ||
|
afa5bf1f0c | ||
|
982dee15fc | ||
|
434e7f6b2c | ||
|
dafa7f2f22 | ||
|
874e793594 | ||
|
7d42825426 | ||
|
7f1b5407ee | ||
|
cc39d720c4 | ||
|
9ab561df2f | ||
|
5662a5d4bb | ||
|
b22b59ab5d | ||
|
5cf6f6ed9c | ||
|
8e57d36894 | ||
|
5ad49aa58a | ||
|
057199cb8b |
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ tests/_output/*
|
||||
lumen-test/app
|
||||
lumen-test/database
|
||||
lumen-test/tests/tmp
|
||||
|
||||
.idea
|
||||
|
50
README.md
50
README.md
@ -5,7 +5,7 @@
|
||||
[](https://insight.sensiolabs.com/projects/838624c3-208d-4ba5-84aa-3afc76b093bb)
|
||||
[](https://github.com/webNeat/lumen-generators/blob/master/LICENSE)
|
||||
|
||||
A collection of generators for [Lumen](http://lumen.laravel.com) and [Laravel 5](http://laravel.com/).
|
||||
A collection of generators for [Lumen](http://lumen.laravel.com) and [Laravel 6](http://laravel.com/).
|
||||
|
||||
## Contents
|
||||
|
||||
@ -259,10 +259,10 @@ More then that, you can generate multiple resources with only one command ! [Cli
|
||||
The `wn:model` command is used to generate a model class based on Eloquent. It has the following syntax:
|
||||
|
||||
```
|
||||
wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--timestamps=false] [--path=...] [--force=true]
|
||||
wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--timestamps=false] [--path=...] [--soft-deletes=true] [--force=true]
|
||||
```
|
||||
|
||||
- **name**: the name of the model.
|
||||
- **name**: the name of the model.
|
||||
|
||||
`php artisan wn:model Task` generates the following:
|
||||
|
||||
@ -361,6 +361,8 @@ gives:
|
||||
|
||||
- **--timestamps**: Enables timestamps on the model. Giving `--timestamps=false` will add `public $timestamps = false;` to the generated model. The default value is `true`.
|
||||
|
||||
- **--soft-deletes**: Adds `Illuminate\Database\Eloquent\SoftDeletes` trait to the model. This is disabled by default.
|
||||
|
||||
- **--force**: tells the generator to override the existing file. By default, if the model file already exists, it will not be overriden and the output will be something like:
|
||||
|
||||
```
|
||||
@ -507,7 +509,9 @@ The second command is `wn:controller` which actually generates the controller. T
|
||||
|
||||
- **--no-routes**: Since routes are generated by default for the controller, this option is used to tell the generator "do not generate routes !".
|
||||
|
||||
- **--force**: tells the generator to override the existing file.
|
||||
- **--force**: tells the generator to override the existing file.
|
||||
|
||||
- **--laravel**: create Laravel style routes
|
||||
|
||||
`php artisan wn:controller Task --no-routes` gives:
|
||||
|
||||
@ -537,6 +541,9 @@ The `wn:route` command is used to generate RESTfull routes for a controller. It
|
||||
|
||||
- **--force**: tells the generator to override the existing file.
|
||||
|
||||
- **--laravel**: create Laravel style routes
|
||||
|
||||
|
||||
`php artisan wn:route project-type` adds the following routes:
|
||||
|
||||
```php
|
||||
@ -547,6 +554,17 @@ $app->put('project-type/{id}', 'ProjectTypesController@put');
|
||||
$app->delete('project-type/{id}', 'ProjectTypesController@remove');
|
||||
```
|
||||
|
||||
|
||||
`php artisan wn:route project-type --laravel` adds the following routes:
|
||||
|
||||
```php
|
||||
Route::get('project-type', 'ProjectTypesController@all');
|
||||
Route::get('project-type/{id}', 'ProjectTypesController@get');
|
||||
Route::post('project-type', 'ProjectTypesController@add');
|
||||
Route::put('project-type/{id}', 'ProjectTypesController@put');
|
||||
Route::delete('project-type/{id}', 'ProjectTypesController@remove');
|
||||
```
|
||||
|
||||
### Resource Generator
|
||||
|
||||
The `wn:resource` command makes it very easy to generate a RESTful resource. It generates a model, migration, controller and routes. The syntax is : `wn:resource name fields [--add=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--migration-file=...] [--path=...] [--force=true]`
|
||||
@ -579,6 +597,9 @@ The `wn:resource` command makes it very easy to generate a RESTful resource. It
|
||||
|
||||
- **--force**: tells the generator to override the existing file.
|
||||
|
||||
- **--laravel**: create Laravel style routes
|
||||
|
||||
|
||||
### Multiple Resources From File
|
||||
|
||||
The `wn:resources` (note the "s" in "resources") command takes the generation process to an other level by parsing a file and generating multiple resources based on it. The syntax is
|
||||
@ -593,6 +614,9 @@ The file given to the command should be a valid YAML file ( for the moment, supp
|
||||
|
||||
- **--path**: Defines where to store the model files as well as their namespace.
|
||||
|
||||
- **--laravel**: create Laravel style routes
|
||||
|
||||
|
||||
```yaml
|
||||
---
|
||||
Store:
|
||||
@ -638,6 +662,24 @@ To test the generators, I included a fresh lumen installation under the folder `
|
||||
- **Seeder and Test generators**
|
||||
|
||||
- Requested Feature: [Custom Templates](https://github.com/webNeat/lumen-generators/issues/13)
|
||||
|
||||
- Requested Feature: [Fractal integration](https://github.com/webNeat/lumen-generators/issues/24)
|
||||
|
||||
- Requested Feature: [Add possibility to not run migrations when using `wn:resources`](https://github.com/webNeat/lumen-generators/issues/23)
|
||||
|
||||
- Documentation: [Adding examples](https://github.com/webNeat/lumen-generators/issues/20)
|
||||
|
||||
- **Version 1.3.3**
|
||||
|
||||
- Bug Fixed: [Rules issue when creating resources from YAML file](https://github.com/webNeat/lumen-generators/issues/30)
|
||||
|
||||
- **Version 1.3.2**
|
||||
|
||||
- Bug Fixed: [softDeletes not added to model](https://github.com/webNeat/lumen-generators/issues/25)
|
||||
|
||||
- **Version 1.3.1**
|
||||
|
||||
- Bug Fixed: [duplicate column for the foriegn key when using `wn:resources`](https://github.com/webNeat/lumen-generators/issues/22)
|
||||
|
||||
- **Version 1.3.0**
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "wn/lumen-generators",
|
||||
"name": "zorgcc/lumen-generators",
|
||||
"description": "A collection of generators for Lumen and Laravel 5.",
|
||||
"keywords": ["lumen", "laravel", "rest", "api", "generators"],
|
||||
"license": "MIT",
|
||||
@ -10,10 +10,10 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5.0",
|
||||
"illuminate/console": "^5.1",
|
||||
"illuminate/filesystem": "^5.1",
|
||||
"fzaninotto/faker": "^1.5"
|
||||
"php": "^7.2",
|
||||
"illuminate/console": "^5.1|^6",
|
||||
"illuminate/filesystem": "^5.1|^6",
|
||||
"fzaninotto/faker": "^1.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
1917
composer.lock
generated
1917
composer.lock
generated
File diff suppressed because it is too large
Load Diff
6
lumen-test/.gitignore
vendored
6
lumen-test/.gitignore
vendored
@ -1,7 +1,11 @@
|
||||
/vendor
|
||||
.env
|
||||
codecept.phar
|
||||
|
||||
tests/_output/*
|
||||
|
||||
composer.lock
|
||||
tests/_output/*
|
||||
tests/_output/*
|
||||
|
||||
codecept.phar
|
||||
|
||||
|
@ -8,3 +8,4 @@ class Controller extends BaseController
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
51
lumen-test/clean.sh
Executable file
51
lumen-test/clean.sh
Executable file
@ -0,0 +1,51 @@
|
||||
# models
|
||||
rm app/*.php 2> /dev/null
|
||||
|
||||
# migrations
|
||||
rm database/migrations/*.php 2> /dev/null
|
||||
|
||||
# routes
|
||||
echo "<?php
|
||||
|
||||
\$app->get(\"/\", function () use (\$app) {
|
||||
return \$app->welcome();
|
||||
});" > app/Http/routes.php
|
||||
|
||||
echo "<?php
|
||||
/*
|
||||
|------------------------------------------
|
||||
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|
||||
|------------------------------------------
|
||||
*/
|
||||
" > routes/api.php
|
||||
|
||||
# Controllers
|
||||
rm app/Http/Controllers/*.php 2> /dev/null
|
||||
echo "<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
//
|
||||
}
|
||||
" > app/Http/Controllers/Controller.php
|
||||
|
||||
# factories
|
||||
echo "<?php
|
||||
|
||||
\$factory->define(App\User::class, function (\$faker) {
|
||||
return [
|
||||
'name' => \$faker->name,
|
||||
'email' => \$faker->email,
|
||||
'password' => str_random(10),
|
||||
'remember_token' => str_random(10),
|
||||
];
|
||||
});
|
||||
" > database/factories/ModelFactory.php
|
||||
|
||||
# database
|
||||
rm database/database.sqlite 2> /dev/null
|
||||
touch database/database.sqlite
|
@ -5,6 +5,7 @@ paths:
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
envs: tests/_envs
|
||||
helpers: nil
|
||||
settings:
|
||||
bootstrap: _bootstrap.php
|
||||
colors: false
|
||||
|
@ -13,7 +13,7 @@
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"fzaninotto/faker": "~1.0",
|
||||
"phpspec/phpspec": "2.0.0",
|
||||
"codeception/codeception": "2.0.0"
|
||||
"codeception/codeception": "^2.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -1,23 +0,0 @@
|
||||
---
|
||||
Post:
|
||||
belongsToMany: tags
|
||||
add: timestamps softDeletes
|
||||
fields:
|
||||
title:
|
||||
schema: string
|
||||
rules: required
|
||||
tags: fillable
|
||||
content:
|
||||
schema: text nullable
|
||||
tags: fillable
|
||||
published_at:
|
||||
schema: date
|
||||
rules: date
|
||||
tags: date fillable
|
||||
Tag:
|
||||
belongsToMany: posts
|
||||
fields:
|
||||
name:
|
||||
schema: string unique
|
||||
rules: required
|
||||
tags: fillable
|
26
lumen-test/tests/_data/ResourcesTest.yml
Normal file
26
lumen-test/tests/_data/ResourcesTest.yml
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
Author:
|
||||
belongsTo: book
|
||||
fields:
|
||||
name:
|
||||
schema: string
|
||||
tags: fillable
|
||||
Book:
|
||||
belongsTo: librarys # Yes I know it's misspelled...
|
||||
hasOne: author
|
||||
fields:
|
||||
title:
|
||||
schema: string
|
||||
tags: fillable
|
||||
published:
|
||||
schema: date
|
||||
tags: fillable
|
||||
Library:
|
||||
hasMany: books
|
||||
fields:
|
||||
name:
|
||||
schema: string
|
||||
tags: fillable
|
||||
address:
|
||||
schema: string
|
||||
tags: fillable
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] 6172d62f52ee53bf8d6f975a52df4f0d
|
||||
<?php //[STAMP] d6606f78456705b0875c6b8343fc6a4a
|
||||
namespace _generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
@ -17,6 +17,22 @@ trait AcceptanceTesterActions
|
||||
abstract protected function getScenario();
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that array contains subset.
|
||||
*
|
||||
* @param array $subset
|
||||
* @param array $array
|
||||
* @param bool $strict
|
||||
* @param string $message
|
||||
* @see \Codeception\Module::assertArraySubset()
|
||||
*/
|
||||
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
@ -95,7 +111,7 @@ trait AcceptanceTesterActions
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
*
|
||||
* @param $regex
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Cli::seeShellOutputMatches()
|
||||
*/
|
||||
@ -105,7 +121,7 @@ trait AcceptanceTesterActions
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
*
|
||||
* @param $regex
|
||||
* @see \Codeception\Module\Cli::seeShellOutputMatches()
|
||||
*/
|
||||
public function seeShellOutputMatches($regex) {
|
||||
@ -113,13 +129,83 @@ trait AcceptanceTesterActions
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks result code
|
||||
*
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->seeResultCodeIs(0);
|
||||
* ```
|
||||
*
|
||||
* @param $code
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Cli::seeResultCodeIs()
|
||||
*/
|
||||
public function canSeeResultCodeIs($code) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResultCodeIs', func_get_args()));
|
||||
}
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks result code
|
||||
*
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->seeResultCodeIs(0);
|
||||
* ```
|
||||
*
|
||||
* @param $code
|
||||
* @see \Codeception\Module\Cli::seeResultCodeIs()
|
||||
*/
|
||||
public function seeResultCodeIs($code) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResultCodeIs', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks result code
|
||||
*
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->seeResultCodeIsNot(0);
|
||||
* ```
|
||||
*
|
||||
* @param $code
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Cli::seeResultCodeIsNot()
|
||||
*/
|
||||
public function canSeeResultCodeIsNot($code) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResultCodeIsNot', func_get_args()));
|
||||
}
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks result code
|
||||
*
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->seeResultCodeIsNot(0);
|
||||
* ```
|
||||
*
|
||||
* @param $code
|
||||
* @see \Codeception\Module\Cli::seeResultCodeIsNot()
|
||||
*/
|
||||
public function seeResultCodeIsNot($code) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResultCodeIsNot', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Enters a directory In local filesystem.
|
||||
* Project root directory is used by default
|
||||
*
|
||||
* @param $path
|
||||
* @param string $path
|
||||
* @see \Codeception\Module\Filesystem::amInPath()
|
||||
*/
|
||||
public function amInPath($path) {
|
||||
@ -141,7 +227,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $filename
|
||||
* @param string $filename
|
||||
* @see \Codeception\Module\Filesystem::openFile()
|
||||
*/
|
||||
public function openFile($filename) {
|
||||
@ -160,7 +246,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $filename
|
||||
* @param string $filename
|
||||
* @see \Codeception\Module\Filesystem::deleteFile()
|
||||
*/
|
||||
public function deleteFile($filename) {
|
||||
@ -179,7 +265,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $dirname
|
||||
* @param string $dirname
|
||||
* @see \Codeception\Module\Filesystem::deleteDir()
|
||||
*/
|
||||
public function deleteDir($dirname) {
|
||||
@ -198,8 +284,8 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $src
|
||||
* @param $dst
|
||||
* @param string $src
|
||||
* @param string $dst
|
||||
* @see \Codeception\Module\Filesystem::copyDir()
|
||||
*/
|
||||
public function copyDir($src, $dst) {
|
||||
@ -221,7 +307,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $text
|
||||
* @param string $text
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Filesystem::seeInThisFile()
|
||||
*/
|
||||
@ -242,7 +328,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $text
|
||||
* @param string $text
|
||||
* @see \Codeception\Module\Filesystem::seeInThisFile()
|
||||
*/
|
||||
public function seeInThisFile($text) {
|
||||
@ -298,7 +384,7 @@ trait AcceptanceTesterActions
|
||||
*
|
||||
* Checks that contents of currently opened file matches $regex
|
||||
*
|
||||
* @param $regex
|
||||
* @param string $regex
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
|
||||
*/
|
||||
@ -310,7 +396,7 @@ trait AcceptanceTesterActions
|
||||
*
|
||||
* Checks that contents of currently opened file matches $regex
|
||||
*
|
||||
* @param $regex
|
||||
* @param string $regex
|
||||
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
|
||||
*/
|
||||
public function seeThisFileMatches($regex) {
|
||||
@ -333,7 +419,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $text
|
||||
* @param string $text
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Filesystem::seeFileContentsEqual()
|
||||
*/
|
||||
@ -355,7 +441,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $text
|
||||
* @param string $text
|
||||
* @see \Codeception\Module\Filesystem::seeFileContentsEqual()
|
||||
*/
|
||||
public function seeFileContentsEqual($text) {
|
||||
@ -375,7 +461,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $text
|
||||
* @param string $text
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Filesystem::dontSeeInThisFile()
|
||||
*/
|
||||
@ -394,7 +480,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $text
|
||||
* @param string $text
|
||||
* @see \Codeception\Module\Filesystem::dontSeeInThisFile()
|
||||
*/
|
||||
public function dontSeeInThisFile($text) {
|
||||
@ -425,7 +511,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $filename
|
||||
* @param string $filename
|
||||
* @param string $path
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Filesystem::seeFileFound()
|
||||
@ -445,7 +531,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $filename
|
||||
* @param string $filename
|
||||
* @param string $path
|
||||
* @see \Codeception\Module\Filesystem::seeFileFound()
|
||||
*/
|
||||
@ -459,7 +545,7 @@ trait AcceptanceTesterActions
|
||||
*
|
||||
* Checks if file does not exist in path
|
||||
*
|
||||
* @param $filename
|
||||
* @param string $filename
|
||||
* @param string $path
|
||||
* Conditional Assertion: Test won't be stopped on fail
|
||||
* @see \Codeception\Module\Filesystem::dontSeeFileFound()
|
||||
@ -472,7 +558,7 @@ trait AcceptanceTesterActions
|
||||
*
|
||||
* Checks if file does not exist in path
|
||||
*
|
||||
* @param $filename
|
||||
* @param string $filename
|
||||
* @param string $path
|
||||
* @see \Codeception\Module\Filesystem::dontSeeFileFound()
|
||||
*/
|
||||
@ -492,7 +578,7 @@ trait AcceptanceTesterActions
|
||||
* ?>
|
||||
* ```
|
||||
*
|
||||
* @param $dirname
|
||||
* @param string $dirname
|
||||
* @see \Codeception\Module\Filesystem::cleanDir()
|
||||
*/
|
||||
public function cleanDir($dirname) {
|
||||
@ -505,8 +591,8 @@ trait AcceptanceTesterActions
|
||||
*
|
||||
* Saves contents to file
|
||||
*
|
||||
* @param $filename
|
||||
* @param $contents
|
||||
* @param string $filename
|
||||
* @param string $contents
|
||||
* @see \Codeception\Module\Filesystem::writeToFile()
|
||||
*/
|
||||
public function writeToFile($filename, $contents) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] 113b78942a9c8ce85a7c18397003b17c
|
||||
<?php //[STAMP] d2a298893573661fdbd787dcfa27a7b0
|
||||
namespace _generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
@ -15,4 +15,18 @@ trait FunctionalTesterActions
|
||||
abstract protected function getScenario();
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that array contains subset.
|
||||
*
|
||||
* @param array $subset
|
||||
* @param array $array
|
||||
* @param bool $strict
|
||||
* @param string $message
|
||||
* @see \Codeception\Module::assertArraySubset()
|
||||
*/
|
||||
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php //[STAMP] afa4f0350422fae145b4236dce66191a
|
||||
<?php //[STAMP] 1467e0d5027bbc2413077351642a21f3
|
||||
namespace _generated;
|
||||
|
||||
// This class was automatically generated by build task
|
||||
@ -19,14 +19,29 @@ trait UnitTesterActions
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are equal.
|
||||
* Checks that two variables are equal. If you're comparing floating-point values,
|
||||
* you can specify the optional "delta" parameter which dictates how great of a precision
|
||||
* error are you willing to tolerate in order to consider the two values equal.
|
||||
*
|
||||
* Regular example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertEquals($element->getChildrenCount(), 5);
|
||||
* ```
|
||||
*
|
||||
* Floating-point example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertEquals($calculator->add(0.1, 0.2), 0.3, 'Calculator should add the two numbers correctly.', 0.01);
|
||||
* ```
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @param float $delta
|
||||
* @see \Codeception\Module\Asserts::assertEquals()
|
||||
*/
|
||||
public function assertEquals($expected, $actual, $message = null) {
|
||||
public function assertEquals($expected, $actual, $message = null, $delta = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
|
||||
}
|
||||
|
||||
@ -34,14 +49,29 @@ trait UnitTesterActions
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that two variables are not equal
|
||||
* Checks that two variables are not equal. If you're comparing floating-point values,
|
||||
* you can specify the optional "delta" parameter which dictates how great of a precision
|
||||
* error are you willing to tolerate in order to consider the two values not equal.
|
||||
*
|
||||
* Regular example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertNotEquals($element->getChildrenCount(), 0);
|
||||
* ```
|
||||
*
|
||||
* Floating-point example:
|
||||
* ```php
|
||||
* <?php
|
||||
* $I->assertNotEquals($calculator->add(0.1, 0.2), 0.4, 'Calculator should add the two numbers correctly.', 0.01);
|
||||
* ```
|
||||
*
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @param float $delta
|
||||
* @see \Codeception\Module\Asserts::assertNotEquals()
|
||||
*/
|
||||
public function assertNotEquals($expected, $actual, $message = null) {
|
||||
public function assertNotEquals($expected, $actual, $message = null, $delta = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
|
||||
}
|
||||
|
||||
@ -54,7 +84,6 @@ trait UnitTesterActions
|
||||
* @param $expected
|
||||
* @param $actual
|
||||
* @param string $message
|
||||
* @return mixed|void
|
||||
* @see \Codeception\Module\Asserts::assertSame()
|
||||
*/
|
||||
public function assertSame($expected, $actual, $message = null) {
|
||||
@ -197,6 +226,36 @@ trait UnitTesterActions
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that a string starts with the given prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertStringStartsWith()
|
||||
*/
|
||||
public function assertStringStartsWith($prefix, $string, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that a string doesn't start with the given prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @see \Codeception\Module\Asserts::assertStringStartsNotWith()
|
||||
*/
|
||||
public function assertStringStartsNotWith($prefix, $string, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
@ -373,6 +432,22 @@ trait UnitTesterActions
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
* Checks that array contains subset.
|
||||
*
|
||||
* @param array $subset
|
||||
* @param array $array
|
||||
* @param bool $strict
|
||||
* @param string $message
|
||||
* @see \Codeception\Module::assertArraySubset()
|
||||
*/
|
||||
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
|
||||
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [!] Method is generated. Documentation taken from corresponding module.
|
||||
*
|
||||
|
@ -106,3 +106,29 @@ $I->seeInThisFile(
|
||||
);
|
||||
|
||||
$I->deleteFile('./tests/tmp/TestingModel.php');
|
||||
|
||||
$I->wantTo('generate a model with softDeletes');
|
||||
$I->runShellCommand('php artisan wn:model TestingModel --soft-deletes=true --path=tests/tmp --force=true');
|
||||
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
||||
$I->openFile('./tests/tmp/TestingModel.php');
|
||||
$I->seeFileContentsEqual('<?php namespace Tests\Tmp;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TestingModel extends Model {
|
||||
|
||||
use \Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
protected $fillable = [];
|
||||
|
||||
protected $dates = [];
|
||||
|
||||
public static $rules = [
|
||||
// Validation rules
|
||||
];
|
||||
|
||||
// Relationships
|
||||
|
||||
}
|
||||
');
|
||||
$I->deleteFile('./tests/tmp/TestingModel.php');
|
||||
|
136
lumen-test/tests/acceptance/ResourcesCommandCept.php
Normal file
136
lumen-test/tests/acceptance/ResourcesCommandCept.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
$I = new AcceptanceTester($scenario);
|
||||
|
||||
$I->wantTo('Generate RESTful resources from a file');
|
||||
$I->writeToFile('database/database.sqlite', '');
|
||||
|
||||
$I->runShellCommand('php artisan wn:resources tests/_data/ResourcesTest.yml');
|
||||
|
||||
// Checking the model
|
||||
$I->seeInShellOutput('Author model generated');
|
||||
$I->seeInShellOutput('Book model generated');
|
||||
$I->seeInShellOutput('Library model generated');
|
||||
$I->seeFileFound('./app/Author.php');
|
||||
$I->seeFileFound('./app/Book.php');
|
||||
$I->seeFileFound('./app/Library.php');
|
||||
$I->deleteFile('./app/Author.php');
|
||||
$I->deleteFile('./app/Book.php');
|
||||
$I->deleteFile('./app/Library.php');
|
||||
|
||||
// Checking the migration
|
||||
$I->seeInShellOutput('authors migration generated');
|
||||
$I->seeInShellOutput('books migration generated');
|
||||
$I->seeInShellOutput('libraries migration generated');
|
||||
// Can't check for specific file names, so we'll just strip the directory
|
||||
$I->cleanDir('database/migrations');
|
||||
$I->writeToFile('database/migrations/.gitkeep', '');
|
||||
|
||||
// Checking the RESTActions trait
|
||||
$I->seeFileFound('./app/Http/Controllers/RESTActions.php');
|
||||
$I->deleteFile('./app/Http/Controllers/RESTActions.php');
|
||||
|
||||
// Checking the controller
|
||||
$I->seeInShellOutput('AuthorsController generated');
|
||||
$I->seeInShellOutput('LibrariesController generated');
|
||||
$I->seeInShellOutput('BooksController generated');
|
||||
$I->seeFileFound('./app/Http/Controllers/AuthorsController.php');
|
||||
$I->seeFileFound('./app/Http/Controllers/LibrariesController.php');
|
||||
$I->seeFileFound('./app/Http/Controllers/BooksController.php');
|
||||
|
||||
$I->deleteFile('./app/Http/Controllers/AuthorsController.php');
|
||||
$I->deleteFile('./app/Http/Controllers/LibrariesController.php');
|
||||
$I->deleteFile('./app/Http/Controllers/BooksController.php');
|
||||
|
||||
|
||||
// Checking routes
|
||||
$I->openFile('./app/Http/routes.php');
|
||||
$I->seeInThisFile('
|
||||
$app->get(\'author\', \'AuthorsController@all\');
|
||||
$app->get(\'author/{id}\', \'AuthorsController@get\');
|
||||
$app->post(\'author\', \'AuthorsController@add\');
|
||||
$app->put(\'author/{id}\', \'AuthorsController@put\');
|
||||
$app->delete(\'author/{id}\', \'AuthorsController@remove\');');
|
||||
|
||||
$I->seeInThisFile('
|
||||
$app->get(\'book\', \'BooksController@all\');
|
||||
$app->get(\'book/{id}\', \'BooksController@get\');
|
||||
$app->post(\'book\', \'BooksController@add\');
|
||||
$app->put(\'book/{id}\', \'BooksController@put\');
|
||||
$app->delete(\'book/{id}\', \'BooksController@remove\');');
|
||||
|
||||
$I->seeInThisFile('
|
||||
$app->get(\'library\', \'LibrariesController@all\');
|
||||
$app->get(\'library/{id}\', \'LibrariesController@get\');
|
||||
$app->post(\'library\', \'LibrariesController@add\');
|
||||
$app->put(\'library/{id}\', \'LibrariesController@put\');
|
||||
$app->delete(\'library/{id}\', \'LibrariesController@remove\');');
|
||||
$I->writeToFile('./app/Http/routes.php', '<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register all of the routes for an application.
|
||||
| It is a breeze. Simply tell Lumen the URIs it should respond to
|
||||
| and give it the Closure to call when that URI is requested.
|
||||
|
|
||||
*/
|
||||
|
||||
$app->get("/", function () use ($app) {
|
||||
return $app->welcome();
|
||||
});
|
||||
');
|
||||
|
||||
// Checking model factory
|
||||
// $I->openFile('./database/factories/ModelFactory.php');
|
||||
// $I->seeInThisFile(
|
||||
// "/**
|
||||
// * Factory definition for model App\TaskCategory.
|
||||
// */
|
||||
// \$factory->define(App\TaskCategory::class, function (\$faker) {
|
||||
// return [
|
||||
// 'name' => \$faker->word,
|
||||
// 'descr' => \$faker->paragraph,
|
||||
// 'due' => \$faker->date,
|
||||
// ];
|
||||
// });");
|
||||
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model Factories
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of your model factories. Model factories give
|
||||
| you a convenient way to create models for testing and seeding your
|
||||
| database. Just tell the factory how a default model should look.
|
||||
|
|
||||
*/
|
||||
|
||||
\$factory->define(App\User::class, function (\$faker) {
|
||||
return [
|
||||
'name' => \$faker->name,
|
||||
'email' => \$faker->email,
|
||||
'password' => str_random(10),
|
||||
'remember_token' => str_random(10),
|
||||
];
|
||||
});
|
||||
");
|
||||
|
||||
$I->deleteFile('database/database.sqlite');
|
||||
|
||||
|
||||
// Checking database seeder
|
||||
// $I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
||||
// $I->seeInThisFile('
|
||||
// use Illuminate\Database\Seeder;
|
||||
|
||||
// class TaskCategoriesTableSeeder extends Seeder
|
||||
// {
|
||||
// public function run()
|
||||
// {
|
||||
// factory(App\TaskCategory::class, 10)->create();
|
||||
// }
|
||||
// }');
|
||||
// $I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
124
lumen-test/tests/acceptance/ResourcesWithLaravelRoutesCept.php
Normal file
124
lumen-test/tests/acceptance/ResourcesWithLaravelRoutesCept.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
$I = new AcceptanceTester($scenario);
|
||||
|
||||
$I->wantTo('Generate RESTful resources from a file with Laravel Routes');
|
||||
$I->writeToFile('database/database.sqlite', '');
|
||||
$I->runShellCommand('php artisan wn:resources tests/_data/ResourcesTest.yml --laravel=true');
|
||||
|
||||
// Checking the model
|
||||
$I->seeInShellOutput('Author model generated');
|
||||
$I->seeInShellOutput('Book model generated');
|
||||
$I->seeInShellOutput('Library model generated');
|
||||
$I->seeFileFound('./app/Author.php');
|
||||
$I->seeFileFound('./app/Book.php');
|
||||
$I->seeFileFound('./app/Library.php');
|
||||
$I->deleteFile('./app/Author.php');
|
||||
$I->deleteFile('./app/Book.php');
|
||||
$I->deleteFile('./app/Library.php');
|
||||
|
||||
// Checking the migration
|
||||
$I->seeInShellOutput('authors migration generated');
|
||||
$I->seeInShellOutput('books migration generated');
|
||||
$I->seeInShellOutput('libraries migration generated');
|
||||
// Can't check for specific file names, so we'll just strip the directory
|
||||
$I->cleanDir('database/migrations');
|
||||
$I->writeToFile('database/migrations/.gitkeep', '');
|
||||
|
||||
// Checking the RESTActions trait
|
||||
$I->seeFileFound('./app/Http/Controllers/RESTActions.php');
|
||||
$I->deleteFile('./app/Http/Controllers/RESTActions.php');
|
||||
|
||||
// Checking the controller
|
||||
$I->seeInShellOutput('AuthorsController generated');
|
||||
$I->seeInShellOutput('LibrariesController generated');
|
||||
$I->seeInShellOutput('BooksController generated');
|
||||
$I->seeFileFound('./app/Http/Controllers/AuthorsController.php');
|
||||
$I->seeFileFound('./app/Http/Controllers/LibrariesController.php');
|
||||
$I->seeFileFound('./app/Http/Controllers/BooksController.php');
|
||||
|
||||
$I->deleteFile('./app/Http/Controllers/AuthorsController.php');
|
||||
$I->deleteFile('./app/Http/Controllers/LibrariesController.php');
|
||||
$I->deleteFile('./app/Http/Controllers/BooksController.php');
|
||||
|
||||
$I->seeFileFound('./routes/api.php');
|
||||
|
||||
$I->seeInThisFile('
|
||||
Route::get(\'author\', \'AuthorsController@all\');
|
||||
Route::get(\'author/{id}\', \'AuthorsController@get\');
|
||||
Route::post(\'author\', \'AuthorsController@add\');
|
||||
Route::put(\'author/{id}\', \'AuthorsController@put\');
|
||||
Route::delete(\'author/{id}\', \'AuthorsController@remove\');');
|
||||
|
||||
$I->seeInThisFile('
|
||||
Route::get(\'book\', \'BooksController@all\');
|
||||
Route::get(\'book/{id}\', \'BooksController@get\');
|
||||
Route::post(\'book\', \'BooksController@add\');
|
||||
Route::put(\'book/{id}\', \'BooksController@put\');
|
||||
Route::delete(\'book/{id}\', \'BooksController@remove\');');
|
||||
|
||||
$I->seeInThisFile('
|
||||
Route::get(\'library\', \'LibrariesController@all\');
|
||||
Route::get(\'library/{id}\', \'LibrariesController@get\');
|
||||
Route::post(\'library\', \'LibrariesController@add\');
|
||||
Route::put(\'library/{id}\', \'LibrariesController@put\');
|
||||
Route::delete(\'library/{id}\', \'LibrariesController@remove\');');
|
||||
$I->writeToFile('./app/Http/routes.php', '<?php
|
||||
|
||||
/*
|
||||
|------------------------------------------
|
||||
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|
||||
|------------------------------------------
|
||||
*/
|
||||
');
|
||||
|
||||
// Checking model factory
|
||||
// $I->openFile('./database/factories/ModelFactory.php');
|
||||
// $I->seeInThisFile(
|
||||
// "/**
|
||||
// * Factory definition for model App\TaskCategory.
|
||||
// */
|
||||
// \$factory->define(App\TaskCategory::class, function (\$faker) {
|
||||
// return [
|
||||
// 'name' => \$faker->word,
|
||||
// 'descr' => \$faker->paragraph,
|
||||
// 'due' => \$faker->date,
|
||||
// ];
|
||||
// });");
|
||||
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model Factories
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of your model factories. Model factories give
|
||||
| you a convenient way to create models for testing and seeding your
|
||||
| database. Just tell the factory how a default model should look.
|
||||
|
|
||||
*/
|
||||
|
||||
\$factory->define(App\User::class, function (\$faker) {
|
||||
return [
|
||||
'name' => \$faker->name,
|
||||
'email' => \$faker->email,
|
||||
'password' => str_random(10),
|
||||
'remember_token' => str_random(10),
|
||||
];
|
||||
});
|
||||
");
|
||||
|
||||
$I->deleteFile('database/database.sqlite');
|
||||
|
||||
// Checking database seeder
|
||||
// $I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
||||
// $I->seeInThisFile('
|
||||
// use Illuminate\Database\Seeder;
|
||||
|
||||
// class TaskCategoriesTableSeeder extends Seeder
|
||||
// {
|
||||
// public function run()
|
||||
// {
|
||||
// factory(App\TaskCategory::class, 10)->create();
|
||||
// }
|
||||
// }');
|
||||
// $I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
@ -62,7 +62,9 @@ $app->get("/", function () use ($app) {
|
||||
|
||||
|
||||
$I->wantTo('run wn:routes in Lumen 5.3+');
|
||||
mkdir('./routes');
|
||||
if(!file_exists('./routes')) {
|
||||
mkdir('./routes');
|
||||
}
|
||||
$I->writeToFile('./routes/web.php', '<?php
|
||||
|
||||
/*
|
||||
|
@ -1,12 +1,15 @@
|
||||
<?php namespace Wn\Generators\Commands;
|
||||
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ControllerCommand extends BaseCommand {
|
||||
|
||||
protected $signature = 'wn:controller
|
||||
{model : Name of the model (with namespace if not App)}
|
||||
{--no-routes= : without routes}
|
||||
{--force= : override the existing files}
|
||||
{--laravel : Use Laravel style route definitions}
|
||||
';
|
||||
|
||||
protected $description = 'Generates RESTful controller using the RESTActions trait';
|
||||
@ -31,12 +34,17 @@ class ControllerCommand extends BaseCommand {
|
||||
->get();
|
||||
|
||||
$this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
|
||||
|
||||
if(! $this->option('no-routes')){
|
||||
$this->call('wn:route', [
|
||||
$options = [
|
||||
'resource' => snake_case($name, '-'),
|
||||
'--controller' => $controller
|
||||
]);
|
||||
'--controller' => $controller,
|
||||
];
|
||||
|
||||
if ($this->option('laravel')) {
|
||||
$options['--laravel'] = true;
|
||||
}
|
||||
|
||||
$this->call('wn:route', $options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
class MigrationCommand extends BaseCommand {
|
||||
|
||||
protected $signature = 'wn:migration
|
||||
protected $signature = 'wn:migration
|
||||
{table : The table name.}
|
||||
{--schema= : the schema.}
|
||||
{--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.}
|
||||
@ -12,15 +12,16 @@ class MigrationCommand extends BaseCommand {
|
||||
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
|
||||
{--force= : override the existing files}
|
||||
';
|
||||
// {action : One of create, add, remove or drop options.}
|
||||
// The action is only create for the moment
|
||||
// {action : One of create, add, remove or drop options.}
|
||||
// The action is only create for the moment
|
||||
|
||||
protected $description = 'Generates a migration to create a table with schema';
|
||||
protected $description = 'Generates a migration to create a table with schema';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$table = $this->argument('table');
|
||||
$name = 'Create' . ucwords(camel_case($table));
|
||||
$snakeName = snake_case($name);
|
||||
|
||||
$content = $this->getTemplate('migration')
|
||||
->with([
|
||||
@ -34,12 +35,26 @@ class MigrationCommand extends BaseCommand {
|
||||
|
||||
$file = $this->option('file');
|
||||
if(! $file){
|
||||
$file = date('Y_m_d_His_') . snake_case($name) . '_table';
|
||||
$file = date('Y_m_d_His_') . $snakeName . '_table';
|
||||
$this->deleteOldMigration($snakeName);
|
||||
}else{
|
||||
$this->deleteOldMigration($file);
|
||||
}
|
||||
|
||||
$this->save($content, "./database/migrations/{$file}.php", "{$table} migration");
|
||||
}
|
||||
|
||||
protected function deleteOldMigration($fileName)
|
||||
{
|
||||
foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){
|
||||
if($fileInfo->isDot()) continue;
|
||||
|
||||
if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){
|
||||
unlink($fileInfo->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getSchema()
|
||||
{
|
||||
$schema = $this->option('schema');
|
||||
@ -127,20 +142,20 @@ class MigrationCommand extends BaseCommand {
|
||||
|
||||
if($key['on_delete']){
|
||||
$constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint')
|
||||
->with([
|
||||
'event' => 'Delete',
|
||||
'action' => $key['on_delete']
|
||||
])
|
||||
->get();
|
||||
->with([
|
||||
'event' => 'Delete',
|
||||
'action' => $key['on_delete']
|
||||
])
|
||||
->get();
|
||||
}
|
||||
|
||||
if($key['on_update']){
|
||||
$constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint')
|
||||
->with([
|
||||
'event' => 'Update',
|
||||
'action' => $key['on_update']
|
||||
])
|
||||
->get();
|
||||
->with([
|
||||
'event' => 'Update',
|
||||
'action' => $key['on_update']
|
||||
])
|
||||
->get();
|
||||
}
|
||||
|
||||
return $constraint . ';';
|
||||
|
@ -14,6 +14,7 @@ class ModelCommand extends BaseCommand {
|
||||
{--rules= : fields validation rules.}
|
||||
{--timestamps=true : enables timestamps on the model.}
|
||||
{--path=app : where to store the model php file.}
|
||||
{--soft-deletes= : adds SoftDeletes trait to the model.}
|
||||
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
|
||||
{--force= : override the existing files}
|
||||
';
|
||||
@ -33,7 +34,8 @@ class ModelCommand extends BaseCommand {
|
||||
'dates' => $this->getAsArrayFields('dates'),
|
||||
'relations' => $this->getRelations(),
|
||||
'rules' => $this->getRules(),
|
||||
'additional' => $this->getAdditional()
|
||||
'additional' => $this->getAdditional(),
|
||||
'uses' => $this->getUses()
|
||||
])
|
||||
->get();
|
||||
|
||||
@ -123,4 +125,11 @@ class ModelCommand extends BaseCommand {
|
||||
: '';
|
||||
}
|
||||
|
||||
protected function getUses()
|
||||
{
|
||||
return $this->option('soft-deletes') == 'true'
|
||||
? ' use \Illuminate\Database\Eloquent\SoftDeletes;' . PHP_EOL . PHP_EOL
|
||||
: '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php namespace Wn\Generators\Commands;
|
||||
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ResourceCommand extends BaseCommand {
|
||||
|
||||
protected $signature = 'wn:resource
|
||||
@ -15,6 +17,7 @@ class ResourceCommand extends BaseCommand {
|
||||
{--path=app : where to store the model file.}
|
||||
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
|
||||
{--force= : override the existing files}
|
||||
{--laravel= : Use Laravel style route definitions}
|
||||
';
|
||||
|
||||
protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
|
||||
@ -42,6 +45,7 @@ class ResourceCommand extends BaseCommand {
|
||||
'--path' => $this->option('path'),
|
||||
'--force' => $this->option('force'),
|
||||
'--timestamps' => $this->hasTimestamps() ? 'true' : 'false',
|
||||
'--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false',
|
||||
'--parsed' => true
|
||||
]);
|
||||
|
||||
@ -60,13 +64,16 @@ class ResourceCommand extends BaseCommand {
|
||||
if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){
|
||||
$this->call('wn:controller:rest-actions');
|
||||
}
|
||||
|
||||
// generating the controller and routes
|
||||
$this->call('wn:controller', [
|
||||
$controllerOptions = [
|
||||
'model' => $modelName,
|
||||
'--force' => $this->option('force'),
|
||||
'--no-routes' => false
|
||||
]);
|
||||
'--no-routes' => false,
|
||||
];
|
||||
if ($this->option('laravel')) {
|
||||
$controllerOptions['--laravel'] = true;
|
||||
}
|
||||
$this->call('wn:controller', $controllerOptions);
|
||||
|
||||
// generating model factory
|
||||
$this->call('wn:factory', [
|
||||
@ -191,4 +198,10 @@ class ResourceCommand extends BaseCommand {
|
||||
|| in_array('timestampsTz', $additionals);
|
||||
}
|
||||
|
||||
protected function hasSoftDeletes()
|
||||
{
|
||||
$additionals = explode(',', $this->option('add'));
|
||||
return in_array('softDeletes', $additionals);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php namespace Wn\Generators\Commands;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
|
||||
@ -9,6 +10,8 @@ class ResourcesCommand extends BaseCommand {
|
||||
{file : Path to the file containing resources declarations}
|
||||
{--path=app : where to store the model files.}
|
||||
{--force= : override the existing files}
|
||||
{--laravel= : Use Laravel style route definitions}
|
||||
|
||||
';
|
||||
|
||||
protected $description = 'Generates multiple resources from a file';
|
||||
@ -20,10 +23,14 @@ class ResourcesCommand extends BaseCommand {
|
||||
$content = $this->fs->get($this->argument('file'));
|
||||
$content = Yaml::parse($content);
|
||||
|
||||
$modelIndex = 0;
|
||||
foreach ($content as $model => $i){
|
||||
$i = $this->getResourceParams($model, $i);
|
||||
$migrationName = 'Create' . ucwords(str_plural($i['name']));
|
||||
$migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , 3, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table';
|
||||
|
||||
$this->call('wn:resource', [
|
||||
|
||||
$options = [
|
||||
'name' => $i['name'],
|
||||
'fields' => $i['fields'],
|
||||
'--add' => $i['add'],
|
||||
@ -32,11 +39,18 @@ class ResourcesCommand extends BaseCommand {
|
||||
'--belongs-to' => $i['belongsTo'],
|
||||
'--belongs-to-many' => $i['belongsToMany'],
|
||||
'--path' => $this->option('path'),
|
||||
'--force' => $this->option('force')
|
||||
]);
|
||||
'--force' => $this->option('force'),
|
||||
'--migration-file' => $migrationFile
|
||||
];
|
||||
if ($this->option('laravel')) {
|
||||
$options['--laravel'] = true;
|
||||
}
|
||||
|
||||
$this->call('wn:resource', $options);
|
||||
$modelIndex++;
|
||||
}
|
||||
|
||||
$this->call('migrate');
|
||||
// $this->call('migrate'); // actually needed for pivot seeders !
|
||||
|
||||
$this->pivotTables = array_map(
|
||||
'unserialize',
|
||||
@ -72,25 +86,6 @@ class ResourcesCommand extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if($i['belongsTo']){
|
||||
$relations = $this->getArgumentParser('relations')->parse($i['belongsTo']);
|
||||
foreach ($relations as $relation){
|
||||
$foreignName = '';
|
||||
|
||||
if(! $relation['model']){
|
||||
$foreignName = snake_case($relation['name']) . '_id';
|
||||
} else {
|
||||
$names = array_reverse(explode("\\", $relation['model']));
|
||||
$foreignName = snake_case($names[0]) . '_id';
|
||||
}
|
||||
|
||||
$i['fields'][$foreignName] = [
|
||||
'schema' => 'integer',
|
||||
'tags' => 'key'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if($i['belongsToMany']){
|
||||
$relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']);
|
||||
foreach ($relations as $relation){
|
||||
@ -124,6 +119,9 @@ class ResourcesCommand extends BaseCommand {
|
||||
$name = $field['name'];
|
||||
$schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':');
|
||||
$rules = (isset($field['rules'])) ? trim($field['rules']) : '';
|
||||
// Replace space by comma
|
||||
$rules = str_replace(' ', ',', $rules);
|
||||
|
||||
$tags = $this->convertArray($field['tags'], ' ', ',');
|
||||
|
||||
$string = "{$name};{$schema};{$rules};{$tags}";
|
||||
|
@ -1,31 +1,66 @@
|
||||
<?php namespace Wn\Generators\Commands;
|
||||
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class RouteCommand extends BaseCommand {
|
||||
|
||||
protected $signature = 'wn:route
|
||||
{resource : Name of the resource.}
|
||||
{--controller= : Name of the RESTful controller.}';
|
||||
{--controller= : Name of the RESTful controller.}
|
||||
{--laravel= : Use Laravel style route definitions}
|
||||
';
|
||||
|
||||
protected $description = 'Generates RESTful routes.';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$resource = $this->argument('resource');
|
||||
$laravelRoutes = $this->option('laravel');
|
||||
$templateFile = 'routes';
|
||||
$routesPath = 'routes/web.php';
|
||||
if ($laravelRoutes) {
|
||||
$templateFile = 'routes-laravel';
|
||||
$routesPath = 'routes/api.php';
|
||||
if (!$this->fs->isFile($routesPath)) {
|
||||
if (!$this->fs->isDirectory('./routes')) {
|
||||
$this->fs->makeDirectory('./routes');
|
||||
}
|
||||
$this->fs->put($routesPath, "
|
||||
<?php
|
||||
|
||||
$routesPath = './routes/web.php';
|
||||
if (! $this->fs->exists($routesPath))
|
||||
$routesPath = './app/Http/routes.php';
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register API routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| is assigned the \"api\" middleware group. Enjoy building your API!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::middleware('auth:api')->get('/user', function (Request \$request) {
|
||||
return \$request->user();
|
||||
});
|
||||
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->fs->isFile($routesPath)) {
|
||||
$routesPath = 'app/Http/routes.php';
|
||||
}
|
||||
$content = $this->fs->get($routesPath);
|
||||
|
||||
$content .= PHP_EOL . $this->getTemplate('routes')
|
||||
->with([
|
||||
'resource' => $resource,
|
||||
'controller' => $this->getController()
|
||||
])
|
||||
->get();
|
||||
|
||||
$content .= PHP_EOL . $this->getTemplate($templateFile)
|
||||
->with([
|
||||
'resource' => $resource,
|
||||
'controller' => $this->getController()
|
||||
])
|
||||
->get();
|
||||
$this->save($content, $routesPath, "{$resource} routes", true);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
class {{name}} extends Controller {
|
||||
|
||||
const MODEL = "{{model}}";
|
||||
const MODEL = '{{model}}';
|
||||
|
||||
use RESTActions;
|
||||
|
||||
|
@ -53,6 +53,12 @@ trait RESTActions {
|
||||
|
||||
protected function respond($status, $data = [])
|
||||
{
|
||||
if($status == Response::HTTP_NO_CONTENT){
|
||||
return response(null,Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
if($status == Response::HTTP_NOT_FOUND){
|
||||
return response(['message'=>'resource not found'],Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
return response()->json($data, $status);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class {{name}} extends Model {
|
||||
|
||||
protected $fillable = [{{fillable}}];
|
||||
{{uses}} protected $fillable = [{{fillable}}];
|
||||
|
||||
protected $dates = [{{dates}}];
|
||||
|
||||
|
8
templates/routes-laravel.wnt
Normal file
8
templates/routes-laravel.wnt
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Routes for resource {{resource}}
|
||||
*/
|
||||
Route::get('{{resource}}', '{{controller}}@all');
|
||||
Route::get('{{resource}}/{id}', '{{controller}}@get');
|
||||
Route::post('{{resource}}', '{{controller}}@add');
|
||||
Route::put('{{resource}}/{id}', '{{controller}}@put');
|
||||
Route::delete('{{resource}}/{id}', '{{controller}}@remove');
|
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* Routes for resource {{resource}}
|
||||
*/
|
||||
$app->get('{{resource}}', '{{controller}}@all');
|
||||
$app->get('{{resource}}/{id}', '{{controller}}@get');
|
||||
$app->post('{{resource}}', '{{controller}}@add');
|
||||
$app->put('{{resource}}/{id}', '{{controller}}@put');
|
||||
$app->delete('{{resource}}/{id}', '{{controller}}@remove');
|
||||
$router->get('{{resource}}', '{{controller}}@all');
|
||||
$router->get('{{resource}}/{id}', '{{controller}}@get');
|
||||
$router->post('{{resource}}', '{{controller}}@add');
|
||||
$router->put('{{resource}}/{id}', '{{controller}}@put');
|
||||
$router->delete('{{resource}}/{id}', '{{controller}}@remove');
|
||||
|
Loading…
x
Reference in New Issue
Block a user