-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOnFailureMethodHandler.php
More file actions
36 lines (32 loc) · 1.26 KB
/
OnFailureMethodHandler.php
File metadata and controls
36 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* This file is part of the Ray.WebFormModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Ray\WebFormModule;
use Ray\Aop\MethodInvocation;
use Ray\WebFormModule\Annotation\AbstractValidation;
use Ray\WebFormModule\Annotation\FormValidation;
use Ray\WebFormModule\Exception\InvalidOnFailureMethod;
final class OnFailureMethodHandler implements FailureHandlerInterface
{
const FAILURE_SUFFIX = 'ValidationFailed';
/**
* {@inheritdoc}
*/
public function handle(AbstractValidation $formValidation, MethodInvocation $invocation, AbstractForm $form)
{
unset($form);
$args = (array) $invocation->getArguments();
$object = $invocation->getThis();
if (! $formValidation instanceof FormValidation) {
throw new InvalidOnFailureMethod(get_class($invocation->getThis()));
}
$onFailureMethod = $formValidation->onFailure ?: $invocation->getMethod()->getName() . self::FAILURE_SUFFIX;
if (! $formValidation instanceof FormValidation || ! method_exists($object, $onFailureMethod)) {
throw new InvalidOnFailureMethod(get_class($invocation->getThis()));
}
return call_user_func_array([$invocation->getThis(), $onFailureMethod], $args);
}
}