Skip to content

Commit 661be41

Browse files
authored
Merge pull request #17 from webfactor/3.1
add naming part to readme
2 parents d854806 + 096c963 commit 661be41

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,86 @@ public $crudField = [
124124

125125
## Naming
126126

127-
`// to be written`
127+
You can provide your own naming convention classes by registering them in the config file. This classes should extend `Webfactor\Laravel\Generators\Contracts\NamingAbstract` to provide a certain base functionality.
128+
129+
Example for `Webfactor\Laravel\Generators\Schemas\Naming\CrudController`:
130+
131+
```php
132+
<?php
133+
134+
namespace Webfactor\Laravel\Generators\Schemas\Naming;
135+
136+
use Webfactor\Laravel\Generators\Contracts\NamingAbstract;
137+
138+
class CrudController extends NamingAbstract
139+
{
140+
/**
141+
* @return string
142+
*/
143+
public function getNamespace(): string
144+
{
145+
return $this->getAppNamespace() . 'Http\\Controllers\\Admin';
146+
}
147+
148+
/**
149+
* @return string
150+
*/
151+
public function getClassName(): string
152+
{
153+
return ucfirst($this->entity) . 'CrudController';
154+
}
155+
156+
/**
157+
* @return string
158+
*/
159+
public function getFileName(): string
160+
{
161+
return $this->getClassName() . '.php';
162+
}
163+
164+
/**
165+
* @return string
166+
*/
167+
public function getPath(): string
168+
{
169+
return app_path('Http/Controllers/Admin');
170+
}
171+
172+
/**
173+
* @return string
174+
*/
175+
public function getStub(): string
176+
{
177+
return __DIR__ . '/../../../stubs/crud-controller.stub';
178+
}
179+
}
180+
```
181+
182+
All naming classes defined in the config file will be parsed and saved with their keys to the `$naming`-array of the command. As the entire command is available in each service class, you can access ALL naming conventions everywhere!
183+
184+
For example you need the `Request`-namespace in the CrudController: `$this->command->naming['crudRequest']->getNamespace()`.
185+
186+
Furthermore there is a helper to keep things a bit simpler if you are IN the service class of the coresponding naming class! Just define `$key` and you can access the naming conventions directly through `$this->naming`:
187+
188+
```php
189+
<?php
190+
191+
namespace Webfactor\Laravel\Generators\Services;
192+
193+
class MyService extends ServiceAbstract implements ServiceInterface
194+
{
195+
protected $key = 'myNaming';
196+
197+
protected function call()
198+
{
199+
echo $this->naming;
200+
// same to
201+
echo $this->command->naming['myNaming'];
202+
// but you can additionally access
203+
echo $this->command->naming['otherNaming'];
204+
}
205+
}
206+
```
128207

129208
## Add files to git
130209

0 commit comments

Comments
 (0)