1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Doppelgaenger\Entities\Assertions\RawAssertion |
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
|
|
|
/** |
24
|
|
|
* This class provides a way of using php syntax assertions |
25
|
|
|
* |
26
|
|
|
* @author Bernhard Wick <[email protected]> |
27
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
30
|
|
|
* @link http://www.appserver.io/ |
31
|
|
|
*/ |
32
|
|
|
class RawAssertion extends AbstractAssertion |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string $constraint Php code string we want to execute as an assertion |
37
|
|
|
*/ |
38
|
|
|
public $constraint; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Default constructor |
42
|
|
|
* |
43
|
|
|
* @param string $constraint Php code string we want to execute as an assertion |
44
|
|
|
*/ |
45
|
|
|
public function __construct($constraint) |
46
|
|
|
{ |
47
|
|
|
$this->constraint = $constraint; |
48
|
|
|
|
49
|
|
|
parent::__construct(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Will return a string representation of this assertion |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getString() |
58
|
|
|
{ |
59
|
|
|
return (string)$this->constraint; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Invert the logical meaning of this assertion |
64
|
|
|
* |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
|
|
public function invert() |
68
|
|
|
{ |
69
|
|
|
if ($this->inverted === false) { |
70
|
|
|
$this->constraint = '!(' . $this->constraint . ')'; |
71
|
|
|
$this->inverted = true; |
72
|
|
|
|
73
|
|
|
return true; |
74
|
|
|
|
|
|
|
|
75
|
|
|
} elseif ($this->inverted === true) { |
76
|
|
|
// Just unset the parts of $this->constraint we do not need |
77
|
|
|
$this->constraint = substr($this->constraint, 2, strlen($this->constraint) - 3); |
78
|
|
|
|
79
|
|
|
$this->inverted = false; |
80
|
|
|
|
81
|
|
|
return true; |
82
|
|
|
|
|
|
|
|
83
|
|
|
} else { |
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|