REFACTORING #1880 @4h30m: another ugly refactoring commit
This commit is contained in:
@@ -3,30 +3,37 @@ namespace App\Cms\Handlers\Interactions;
|
||||
|
||||
use App\CMS\Contracts\Interaction as InteractionContract;
|
||||
use App\CMS\Exceptions\Validation\ValidationFailedException;
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class Interaction {
|
||||
class Interaction
|
||||
{
|
||||
/**
|
||||
* Handle interaction with application
|
||||
*
|
||||
* @param Request $request
|
||||
* @param InteractionContract $interaction
|
||||
* @param array $parameters
|
||||
* @param string $interactionClass
|
||||
* @param array $data
|
||||
* @param array $extraParameters
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ValidationFailedException
|
||||
*/
|
||||
public static function handle(Request $request, InteractionContract $interaction, ...$parameters) {
|
||||
public static function handle($interactionClass, $data, ...$extraParameters)
|
||||
{
|
||||
/**
|
||||
* @var $interaction InteractionContract
|
||||
*/
|
||||
|
||||
$interaction = App::make($interactionClass);
|
||||
// validate interaction
|
||||
$validator = Validator::make($request->all(), $interaction->getValidationRules($parameters));
|
||||
$validator = Validator::make($data, $interaction->getValidationRules($extraParameters));
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new ValidationFailedException($validator);
|
||||
}
|
||||
|
||||
// handle it
|
||||
return $interaction->handle($request, $parameters);
|
||||
|
||||
return $interaction->handle($data, $extraParameters);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user