1 | <?php |
||
12 | class BaseUserRepositoryCollection |
||
13 | { |
||
14 | /** @var UserRepository[] */ |
||
15 | private $userRepositories = []; |
||
16 | |||
17 | /** |
||
18 | * @param UserRepository[] $userRepositories |
||
19 | */ |
||
20 | public function __construct(array $userRepositories) |
||
26 | |||
27 | /** |
||
28 | * Registers the UserRepository to the BaseUserRepositoryCollection. |
||
29 | * |
||
30 | * @param UserRepository $userRepository |
||
31 | */ |
||
32 | public function addUserRepository(UserRepository $userRepository) |
||
36 | |||
37 | /** |
||
38 | * Get the userRepositories. |
||
39 | * |
||
40 | * @throws NoRepositoriesRegisteredException |
||
41 | * |
||
42 | * @return UserRepository[] |
||
43 | */ |
||
44 | public function all() |
||
52 | |||
53 | /** |
||
54 | * Find the UserRepository for a given BaseUser Class. |
||
55 | * |
||
56 | * @param string $className |
||
57 | * |
||
58 | * @throws RepositoryNotRegisteredException |
||
59 | * |
||
60 | * @return UserRepository |
||
61 | */ |
||
62 | public function findRepositoryByClassName($className) |
||
72 | |||
73 | /** |
||
74 | * Check if the BaseUserRepositoryCollection supports a BaseUser class. |
||
75 | * |
||
76 | * @param string $className |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | public function supportsClass($className) |
||
90 | |||
91 | /** |
||
92 | * @param PasswordResetToken $token |
||
93 | * |
||
94 | * @throws UserNotFound |
||
95 | * |
||
96 | * @return User |
||
97 | */ |
||
98 | public function findUserByToken(PasswordResetToken $token) |
||
110 | |||
111 | /** |
||
112 | * @param string $username |
||
113 | * |
||
114 | * @throws UserNotFound |
||
115 | * |
||
116 | * @return User |
||
117 | */ |
||
118 | public function findUserByUserName($username) |
||
130 | } |
||
131 |
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: