39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
namespace App\Cms\Handlers\Interactions;
|
|
|
|
use App\CMS\Contracts\Interaction as InteractionContract;
|
|
use App\CMS\Exceptions\Validation\ValidationFailedException;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class Interaction
|
|
{
|
|
/**
|
|
* Handle interaction with application
|
|
*
|
|
* @param string $interactionClass
|
|
* @param array $data
|
|
* @param array $extraParameters
|
|
*
|
|
* @return mixed
|
|
* @throws ValidationFailedException
|
|
*/
|
|
public static function handle($interactionClass, $data, ...$extraParameters)
|
|
{
|
|
/**
|
|
* @var $interaction InteractionContract
|
|
*/
|
|
|
|
$interaction = App::make($interactionClass);
|
|
// validate interaction
|
|
$validator = Validator::make($data, $interaction->getValidationRules($extraParameters));
|
|
|
|
if ($validator->fails()) {
|
|
throw new ValidationFailedException($validator);
|
|
}
|
|
|
|
// handle it
|
|
|
|
return $interaction->handle($data, $extraParameters);
|
|
}
|
|
} |