Commit 89adb050 authored by Dillenn Terumalai's avatar Dillenn Terumalai
Browse files

// WIP

parent 133b1ca1
Pipeline #2276 passed with stage
in 11 seconds
......@@ -17,11 +17,35 @@ php artisan make:interface --model=Foo FooInterface
This will create an interface `FooInterface` in `App/Contracts` directory using the `Foo` Eloquent model.
```php
php artisan make:interface --base FooInterface
```
This will create a base interface `FooInterface` in `App/Contracts` directory which implements the classic CRUD methods. Pleas note that it will use `Illuminate\Database\Eloquent\Model` instead of a specific model.
```php
php artisan make:interface --extend=FooBase FooInterface
```
This will create an interface `FooInterface` which extends the `FooBase` interface.
```php
php artisan make:repository --model=Foo --interface=FooInterface FooRepository
```
This will create a repository class `FooRepository` implementing `FooInterface` and using `Foo` Eloquent model.
This will create a repository class `FooRepository` implementing the interface `FooInterface` and using `Foo` Eloquent model.
```php
php artisan make:repository --model=Foo --base=FooInterface FooRepository
```
This will create a repository class `FooRepository` implementing the base interface `FooInterface` and using `Foo` Eloquent model.
```php
php artisan make:repository-controller --model=Foo --interface=FooInterface FooController
```
This will create a controller `FooController` which will inject the give interface `FooInterface` and bind the given model `Foo`
**Note:** When using options such as `--model` or `--interface`, please note that if class/interface doesn't exist, the terminal will prompt you with a confirmation to automatically create it.
......@@ -37,7 +61,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re
## Contributing
Please see [CONTRIBUTING](.gitlab/CONTRIBUTING.md) for details.
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security Vulnerabilities
......
......@@ -160,7 +160,7 @@ class RepositoryMakeCommand extends GeneratorCommand
*/
protected function buildBaseInterfaceReplacements(array $replace)
{
$interfaceClass = 'BaseRepository';
$interfaceClass = $this->parseInterface($this->option('base'));
$modelClass = null;
......@@ -173,7 +173,8 @@ class RepositoryMakeCommand extends GeneratorCommand
if ($modelClass) {
$this->call('make:interface', [
'name' => $interfaceClass,
'--model' => $modelClass
'--model' => $modelClass,
'--base' => null
]);
} else {
$this->call('make:interface', [
......@@ -283,7 +284,7 @@ class RepositoryMakeCommand extends GeneratorCommand
{
return [
['force', null, InputOption::VALUE_NONE, 'Create the repository even if the repository already exists.'],
['base', null, InputOption::VALUE_NONE, 'Create a repository class which implements the base repository interface.'],
['base', 'b', InputOption::VALUE_OPTIONAL, 'Generate a repository class which implements the given base interface.'],
['interface', 'i', InputOption::VALUE_OPTIONAL, 'Generate a repository class which implements the given interface.'],
['model', 'm', InputOption::VALUE_OPTIONAL, 'Generate a repository class for the given model.']
];
......
......@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
interface BaseRepository
interface {{ class }}
{
/**
* Returns a paginated listing of the resource.
......
......@@ -2,14 +2,14 @@
namespace {{ namespace }};
use {{ namespacedInterface }};
use {{ namespacedModel }};
use App\Contracts\BaseRepository;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class {{ class }} implements BaseRepository
class {{ class }} implements {{ interface }}
{
/**
* @inheritDoc
......
......@@ -208,7 +208,7 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
interface BaseRepository
interface MyFooInterface
{
/**
* Returns a paginated listing of the resource.
......
......@@ -339,7 +339,7 @@ CLASS;
$fooModel = app_path('Models/Foo.php');
// destination path of the MyFoo interface
$fooInterface = app_path('Contracts/BaseRepository.php');
$fooInterface = app_path('Contracts/FooInterface.php');
// make sure we're starting from a clean state
if (File::exists($fooRepository)) {
......@@ -357,7 +357,7 @@ CLASS;
$this->assertFalse(File::exists($fooInterface));
// Run the make command
Artisan::call('make:repository MyFooRepository --model=Foo --base --no-interaction');
Artisan::call('make:repository MyFooRepository --model=Foo --base=FooInterface --no-interaction');
// Assert a new file is created
$this->assertTrue(File::exists($fooRepository));
......@@ -370,14 +370,14 @@ CLASS;
namespace App\Repositories;
use App\Contracts\BaseRepository;
use App\Contracts\FooInterface;
use App\Models\Foo;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class MyFooRepository implements BaseRepository
class MyFooRepository implements FooInterface
{
/**
* @inheritDoc
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment