|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \AppserverIo\Doppelgaenger\Entities\Assertions\RespectValidationAssertion |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Bernhard Wick <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
|
18
|
|
|
* @link http://www.appserver.io/ |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Doppelgaenger\Entities\Assertions; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Doppelgaenger\Dictionaries\ReservedKeywords; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* This class will enable us to check assertions based on the respect/validation library |
|
27
|
|
|
* |
|
28
|
|
|
* @author Bernhard Wick <[email protected]> |
|
29
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
|
32
|
|
|
* @link http://www.appserver.io/ |
|
33
|
|
|
*/ |
|
34
|
|
|
class RespectValidationAssertion extends RawAssertion |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Return a string representation of the classes logic as a piece of PHP code. |
|
39
|
|
|
* Used to transfer important logic into generated code |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public function toCode() |
|
44
|
|
|
{ |
|
45
|
|
|
$code = 'try { |
|
46
|
|
|
if ('. $this->getInvertString() .') { |
|
47
|
|
|
' . ReservedKeywords::FAILURE_VARIABLE . '[] = \'(' . str_replace('\'', '"', $this->getString()) . ')\'; |
|
48
|
|
|
} |
|
49
|
|
|
} catch (\Respect\Validation\Exceptions\ExceptionInterface $e) { |
|
50
|
|
|
if ($e instanceof \Respect\Validation\Exceptions\NestedValidationExceptionInterface) { |
|
51
|
|
|
' . ReservedKeywords::UNWRAPPED_FAILURE_VARIABLE . '[] = $e->getFullMessage(); |
|
52
|
|
|
} else { |
|
53
|
|
|
' . ReservedKeywords::UNWRAPPED_FAILURE_VARIABLE . '[] = $e->getMainMessage(); |
|
54
|
|
|
} |
|
55
|
|
|
}'; |
|
56
|
|
|
|
|
57
|
|
|
return $code; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|