|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
declare(strict_types=1); |
|
20
|
|
|
|
|
21
|
|
|
namespace ProxyManagerTestAsset; |
|
22
|
|
|
|
|
23
|
|
|
use ProxyManager\Proxy\VirtualProxyInterface; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Base test class to catch instantiations of lazy loading objects |
|
27
|
|
|
* |
|
28
|
|
|
* @author Marco Pivetta <[email protected]> |
|
29
|
|
|
* @license MIT |
|
30
|
|
|
*/ |
|
31
|
|
|
class LazyLoadingMock implements VirtualProxyInterface |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var callable |
|
35
|
|
|
*/ |
|
36
|
|
|
public $initializer; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param callable $initializer |
|
40
|
|
|
* |
|
41
|
|
|
* @return static |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function staticProxyConstructor($initializer) : self |
|
44
|
|
|
{ |
|
45
|
|
|
$instance = new static(); |
|
46
|
|
|
|
|
47
|
|
|
$instance->initializer = $initializer; |
|
48
|
|
|
|
|
49
|
|
|
return $instance; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritDoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function setProxyInitializer(\Closure $initializer = null) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->initializer = $initializer; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritDoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getProxyInitializer() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->initializer; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritDoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function initializeProxy() : bool |
|
72
|
|
|
{ |
|
73
|
|
|
// empty (on purpose) |
|
74
|
|
|
return true; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritDoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public function isProxyInitialized() : bool |
|
81
|
|
|
{ |
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritDoc} |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getWrappedValueHolderValue() |
|
89
|
|
|
{ |
|
90
|
|
|
// we're not supposed to call this |
|
91
|
|
|
throw new \BadMethodCallException('Not implemented'); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.