Skip to content

Commit c70b64d

Browse files
committed
Remove validation, as L5 normalizes this now
1 parent 3f1bd4f commit c70b64d

4 files changed

Lines changed: 1 addition & 257 deletions

File tree

readme.md

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -285,92 +285,6 @@ class EmailNotifier extends EventListener {
285285

286286
Because this class extends `EventListener`, that parent class will manage all the details of determining if `whenJobWasPublished` should be called.
287287

288-
### Validation
289-
290-
This package also includes a validation trigger automatically. As an example, when you throw a command into the command bus, it will also determine whether an associated validator object exists. If it does,
291-
it will call a `validate` method on this class. If it doesn't exist, it'll simply continue on. So, this gives you a nice hook to perform validation before executing the command and firing domain events.
292-
The convention is:
293-
294-
- PostJobListingCommand => PostJobListingValidator
295-
296-
So, simply create that class, and include a `validate` method, which we'll receive the `PostJobListingCommand` object. Then, perform your validation however you normally do. I recommend that, for failed validation, you throw an exception - perhaps `ValidationFailedException`. This way, either within your controller - or even `global.php` - you can handle failed validation appropriately (probably by linking back to the form and notifying the user).
297-
298-
## Overriding Paths
299-
300-
By default, this package makes some assumptions about your file structure. As demonstrated above:
301-
302-
- Path/To/PostJobListingCommand => Path/To/PostJobListingCommandHandler
303-
- Path/To/PostJobListingCommand => Path/To/PostJobListingValidator
304-
305-
Perhaps you had something different in mind. No problem! Just create your own command translator class that implements the `Laracasts\Commander\CommandTranslator` interface. This interface includes two methods:
306-
307-
- `toCommandHandler`
308-
- `toValidator`
309-
310-
Maybe you want to place your validators within a `Validators/` directory. Okay:
311-
312-
```php
313-
<?php namespace Acme\Core;
314-
315-
use Laracasts\Commander\CommandTranslator;
316-
317-
class MyCommandTranslator implements CommandTranslator {
318-
319-
/**
320-
* Translate a command to its handler counterpart
321-
*
322-
* @param $command
323-
* @return mixed
324-
* @throws HandlerNotRegisteredException
325-
*/
326-
public function toCommandHandler($command)
327-
{
328-
$handler = str_replace('Command', 'Handler', get_class($command));
329-
330-
if ( ! class_exists($handler))
331-
{
332-
$message = "Command handler [$handler] does not exist.";
333-
334-
throw new HandlerNotRegisteredException($message);
335-
}
336-
337-
return $handler;
338-
}
339-
340-
/**
341-
* Translate a command to its validator counterpart
342-
*
343-
* @param $command
344-
* @return mixed
345-
*/
346-
public function toValidator($command)
347-
{
348-
$segments = explode('\\', get_class($command));
349-
350-
array_splice($segments, -1, false, 'Validators');
351-
352-
return str_replace('Command', 'Validator', implode('\\', $segments));
353-
}
354-
355-
}
356-
```
357-
358-
Now, a `Path/To/MyGreatCommand` will look for a `Path/To/Validators/MyGreatValidator` class instead.
359-
360-
> It might be useful to copy and paste the `Laracasts\Commander\BasicCommandTranslator` class, and then modify as needed.
361-
362-
The only remaining step is to update the binding in the IoC container.
363-
364-
```php
365-
// We want to use our own custom translator class
366-
App::bind(
367-
'Laracasts\Commander\CommandTranslator',
368-
'Acme\Core\MyCommandTranslator'
369-
);
370-
```
371-
372-
Done!
373-
374288
## File Generation
375289

376290
You'll likely find yourself manually creating lots and lots of commands and handler classes. Instead, use the Artisan command that is included with this package!

spec/Laracasts/Commander/ValidationCommandBusSpec.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/Laracasts/Commander/CommanderServiceProvider.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,7 @@ protected function registerCommandTranslator()
4949
*/
5050
protected function registerCommandBus()
5151
{
52-
$this->app->bindShared('Laracasts\Commander\CommandBus', function ($app)
53-
{
54-
$default = $app->make('Laracasts\Commander\DefaultCommandBus');
55-
$translator = $app->make('Laracasts\Commander\CommandTranslator');
56-
57-
return new ValidationCommandBus($default, $app, $translator);
58-
});
52+
$this->app->bindShared('Laracasts\Commander\CommandBus', 'Laracasts\Commander\DefaultCommandBus');
5953
}
6054

6155
/**

src/Laracasts/Commander/ValidationCommandBus.php

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)