Skip to content
This repository was archived by the owner on Jan 11, 2019. It is now read-only.

Commit d7b1211

Browse files
authored
Merge pull request #7 from jspekken/master
Added the make-transformer command
2 parents 7704462 + 94b821e commit d7b1211

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

Diff for: src/MakeTransformerCommand.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Themsaid\Transformers;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class MakeTransformerCommand extends GeneratorCommand
8+
{
9+
/**
10+
* The console command name.
11+
*
12+
* @var string
13+
*/
14+
protected $name = 'make:transformer';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Create a new transformer class';
22+
23+
/**
24+
* The type of class being generated.
25+
*
26+
* @var string
27+
*/
28+
protected $type = 'Transformer';
29+
30+
/**
31+
* Get the stub file for the generator.
32+
*
33+
* @return string
34+
*/
35+
protected function getStub()
36+
{
37+
return __DIR__.'/stubs/transformer.stub';
38+
}
39+
40+
/**
41+
* Get the default namespace for the class.
42+
*
43+
* @param string $rootNamespace
44+
* @return string
45+
*/
46+
protected function getDefaultNamespace($rootNamespace)
47+
{
48+
return $rootNamespace.'\Transformers';
49+
}
50+
}

Diff for: src/TransformersServiceProvider.php

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function boot()
1717
$this->publishes([
1818
__DIR__ . '/config/modelTransformers.php' => config_path('modelTransformers.php'),
1919
]);
20+
21+
$this->commands(MakeTransformerCommand::class);
2022
}
2123
/**
2224
* Register any package services.

Diff for: src/stubs/transformer.stub

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Themsaid\Transformers\AbstractTransformer;
7+
8+
class DummyClass extends AbstractTransformer
9+
{
10+
/**
11+
* @param Model $model
12+
* @return array
13+
*/
14+
public function transformModel(Model $model): array
15+
{
16+
//
17+
}
18+
}

0 commit comments

Comments
 (0)