1
|
|
|
<?php |
2
|
|
|
namespace TYPO3\PharStreamWrapper\Interceptor; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under the terms |
8
|
|
|
* of the MIT License (MIT). For the full copyright and license information, |
9
|
|
|
* please read the LICENSE file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* The TYPO3 project - inspiring people to share! |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
use TYPO3\PharStreamWrapper\Assertable; |
15
|
|
|
use TYPO3\PharStreamWrapper\Exception; |
16
|
|
|
|
17
|
|
|
class ConjunctionInterceptor implements Assertable |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Assertable[] |
21
|
|
|
*/ |
22
|
|
|
private $assertions; |
23
|
|
|
|
24
|
|
|
public function __construct(array $assertions) |
25
|
|
|
{ |
26
|
|
|
$this->assertAssertions($assertions); |
27
|
|
|
$this->assertions = $assertions; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Executes assertions based on all contained assertions. |
32
|
|
|
* |
33
|
|
|
* @param string $path |
34
|
|
|
* @param string $command |
35
|
|
|
* @return bool |
36
|
|
|
* @throws Exception |
37
|
|
|
*/ |
38
|
|
|
public function assert($path, $command) |
39
|
|
|
{ |
40
|
|
|
if ($this->invokeAssertions($path, $command)) { |
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
throw new Exception( |
44
|
|
|
sprintf( |
45
|
|
|
'Assertion failed in "%s"', |
46
|
|
|
$path |
47
|
|
|
), |
48
|
|
|
1539625084 |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Assertable[] $assertions |
54
|
|
|
*/ |
55
|
|
|
private function assertAssertions(array $assertions) |
56
|
|
|
{ |
57
|
|
|
foreach ($assertions as $assertion) { |
58
|
|
|
if (!$assertion instanceof Assertable) { |
59
|
|
|
throw new \InvalidArgumentException( |
60
|
|
|
sprintf( |
61
|
|
|
'Instance %s must implement Assertable', |
62
|
|
|
get_class($assertion) |
63
|
|
|
), |
64
|
|
|
1539624719 |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $path |
72
|
|
|
* @param string $command |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
|
|
private function invokeAssertions($path, $command) |
76
|
|
|
{ |
77
|
|
|
try { |
78
|
|
|
foreach ($this->assertions as $assertion) { |
79
|
|
|
if (!$assertion->assert($path, $command)) { |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} catch (Exception $exception) { |
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
return true; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|