1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /** |
||
6 | * Module interface |
||
7 | * |
||
8 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
9 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
10 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
11 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
12 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
13 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
14 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
15 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
16 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
17 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
18 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
19 | * |
||
20 | * @author Glynn Quelch <[email protected]> |
||
21 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
22 | * @package PinkCrab\Perique |
||
23 | * @since 1.0.6 |
||
24 | */ |
||
25 | |||
26 | namespace PinkCrab\Perique\Interfaces; |
||
27 | |||
28 | use PinkCrab\Loader\Hook_Loader; |
||
29 | use PinkCrab\Perique\Application\App_Config; |
||
30 | use PinkCrab\Perique\Interfaces\{DI_Container, Registration_Middleware}; |
||
0 ignored issues
–
show
This use statement conflicts with another class in this namespace,
PinkCrab\Perique\Interfa...Registration_Middleware . Consider defining an alias.
Let?s assume that you have a directory layout like this: .
|-- OtherDir
| |-- Bar.php
| `-- Foo.php
`-- SomeDir
`-- Foo.php
and let?s assume the following content of // Bar.php
namespace OtherDir;
use SomeDir\Foo; // This now conflicts the class OtherDir\Foo
If both files PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as // Bar.php
namespace OtherDir;
use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
![]() |
|||
31 | |||
32 | interface Module { |
||
33 | |||
34 | /** |
||
35 | * Get the middleware for the module. |
||
36 | * |
||
37 | * @return ?class-string<Registration_Middleware> |
||
0 ignored issues
–
show
|
|||
38 | */ |
||
39 | public function get_middleware(): ?string; |
||
40 | |||
41 | /** |
||
42 | * Callback fired before the Application is booted. |
||
43 | * |
||
44 | * @pram App_Config $config |
||
45 | * @pram Hook_Loader $loader |
||
46 | * @pram DI_Container $di_container |
||
47 | * @return void |
||
48 | */ |
||
49 | public function pre_boot( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void; |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Callback fired before registration is started. |
||
54 | * |
||
55 | * @pram App_Config $config |
||
56 | * @pram Hook_Loader $loader |
||
57 | * @pram DI_Container $di_container |
||
58 | * @return void |
||
59 | */ |
||
60 | public function pre_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void; |
||
61 | |||
62 | /** |
||
63 | * Callback fired after registration is completed. |
||
64 | * |
||
65 | * @pram App_Config $config |
||
66 | * @pram Hook_Loader $loader |
||
67 | * @pram DI_Container $di_container |
||
68 | * @return void |
||
69 | */ |
||
70 | public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void; |
||
71 | } |
||
72 |
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: