1 | <?php |
||
8 | class Mapper |
||
9 | { |
||
10 | private $client; |
||
11 | private $plugins = []; |
||
12 | private $schema; |
||
13 | private $bootstrap; |
||
14 | |||
15 | public function __construct(Client $client) |
||
19 | |||
20 | public function addPlugin($class) |
||
21 | { |
||
22 | if(!is_subclass_of($class, Plugin::class)) { |
||
23 | throw new Exception("Plugin should extend " . Plugin::class . " class"); |
||
24 | } |
||
25 | |||
26 | $plugin = is_object($class) ? $class : new $class($this); |
||
27 | $this->plugins[] = $plugin; |
||
28 | |||
29 | return $plugin; |
||
30 | } |
||
31 | |||
32 | public function create($space, $data) |
||
38 | |||
39 | public function findOne($space, $params = []) |
||
43 | |||
44 | public function find($space, $params = []) |
||
48 | |||
49 | public function findRepository(Entity $instance) |
||
59 | |||
60 | public function getBootstrap() |
||
61 | { |
||
62 | if(!$this->bootstrap) { |
||
63 | $this->bootstrap = new Bootstrap($this); |
||
64 | } |
||
65 | |||
66 | return $this->bootstrap; |
||
67 | } |
||
68 | |||
69 | public function getClient() |
||
73 | |||
74 | public function getPlugin($class) |
||
75 | { |
||
82 | |||
83 | public function getPlugins() |
||
87 | |||
88 | public function getRepository($space) |
||
92 | |||
93 | public function getRepositories() |
||
103 | |||
104 | public function getSchema() |
||
108 | |||
109 | public function remove(Entity $instance) |
||
113 | |||
114 | public function save(Entity $instance) |
||
118 | } |
||
119 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: