@@ -67,6 +67,6 @@ |
||
| 67 | 67 | $implements |= Backend::COUNT_USERS; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - return (bool)($actions & $implements); |
|
| 70 | + return (bool) ($actions & $implements); |
|
| 71 | 71 | } |
| 72 | 72 | } |
@@ -34,41 +34,41 @@ |
||
| 34 | 34 | * @since 14.0.0 |
| 35 | 35 | */ |
| 36 | 36 | abstract class ABackend implements IUserBackend, UserInterface { |
| 37 | - /** |
|
| 38 | - * @deprecated 14.0.0 |
|
| 39 | - * @since 14.0.0 |
|
| 40 | - * |
|
| 41 | - * @param int $actions The action to check for |
|
| 42 | - * @return bool |
|
| 43 | - */ |
|
| 44 | - public function implementsActions($actions): bool { |
|
| 45 | - $implements = 0; |
|
| 37 | + /** |
|
| 38 | + * @deprecated 14.0.0 |
|
| 39 | + * @since 14.0.0 |
|
| 40 | + * |
|
| 41 | + * @param int $actions The action to check for |
|
| 42 | + * @return bool |
|
| 43 | + */ |
|
| 44 | + public function implementsActions($actions): bool { |
|
| 45 | + $implements = 0; |
|
| 46 | 46 | |
| 47 | - if ($this instanceof ICreateUserBackend) { |
|
| 48 | - $implements |= Backend::CREATE_USER; |
|
| 49 | - } |
|
| 50 | - if ($this instanceof ISetPasswordBackend) { |
|
| 51 | - $implements |= Backend::SET_PASSWORD; |
|
| 52 | - } |
|
| 53 | - if ($this instanceof ICheckPasswordBackend) { |
|
| 54 | - $implements |= Backend::CHECK_PASSWORD; |
|
| 55 | - } |
|
| 56 | - if ($this instanceof IGetHomeBackend) { |
|
| 57 | - $implements |= Backend::GET_HOME; |
|
| 58 | - } |
|
| 59 | - if ($this instanceof IGetDisplayNameBackend) { |
|
| 60 | - $implements |= Backend::GET_DISPLAYNAME; |
|
| 61 | - } |
|
| 62 | - if ($this instanceof ISetDisplayNameBackend) { |
|
| 63 | - $implements |= Backend::SET_DISPLAYNAME; |
|
| 64 | - } |
|
| 65 | - if ($this instanceof IProvideAvatarBackend) { |
|
| 66 | - $implements |= Backend::PROVIDE_AVATAR; |
|
| 67 | - } |
|
| 68 | - if ($this instanceof ICountUsersBackend) { |
|
| 69 | - $implements |= Backend::COUNT_USERS; |
|
| 70 | - } |
|
| 47 | + if ($this instanceof ICreateUserBackend) { |
|
| 48 | + $implements |= Backend::CREATE_USER; |
|
| 49 | + } |
|
| 50 | + if ($this instanceof ISetPasswordBackend) { |
|
| 51 | + $implements |= Backend::SET_PASSWORD; |
|
| 52 | + } |
|
| 53 | + if ($this instanceof ICheckPasswordBackend) { |
|
| 54 | + $implements |= Backend::CHECK_PASSWORD; |
|
| 55 | + } |
|
| 56 | + if ($this instanceof IGetHomeBackend) { |
|
| 57 | + $implements |= Backend::GET_HOME; |
|
| 58 | + } |
|
| 59 | + if ($this instanceof IGetDisplayNameBackend) { |
|
| 60 | + $implements |= Backend::GET_DISPLAYNAME; |
|
| 61 | + } |
|
| 62 | + if ($this instanceof ISetDisplayNameBackend) { |
|
| 63 | + $implements |= Backend::SET_DISPLAYNAME; |
|
| 64 | + } |
|
| 65 | + if ($this instanceof IProvideAvatarBackend) { |
|
| 66 | + $implements |= Backend::PROVIDE_AVATAR; |
|
| 67 | + } |
|
| 68 | + if ($this instanceof ICountUsersBackend) { |
|
| 69 | + $implements |= Backend::COUNT_USERS; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return (bool)($actions & $implements); |
|
| 73 | - } |
|
| 72 | + return (bool)($actions & $implements); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -25,10 +25,10 @@ |
||
| 25 | 25 | use OCP\IL10N; |
| 26 | 26 | |
| 27 | 27 | class KerberosAuth extends AuthMechanism { |
| 28 | - public function __construct(IL10N $l) { |
|
| 29 | - $this |
|
| 30 | - ->setIdentifier('smb::kerberos') |
|
| 31 | - ->setScheme(self::SCHEME_SMB) |
|
| 32 | - ->setText($l->t('Kerberos ticket')); |
|
| 33 | - } |
|
| 28 | + public function __construct(IL10N $l) { |
|
| 29 | + $this |
|
| 30 | + ->setIdentifier('smb::kerberos') |
|
| 31 | + ->setScheme(self::SCHEME_SMB) |
|
| 32 | + ->setText($l->t('Kerberos ticket')); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -129,7 +129,7 @@ |
||
| 129 | 129 | $data = $result->fetchAll(); |
| 130 | 130 | $result->closeCursor(); |
| 131 | 131 | |
| 132 | - $entities = array_map(function ($row) { |
|
| 132 | + $entities = array_map(function($row) { |
|
| 133 | 133 | return PublicKeyToken::fromRow($row); |
| 134 | 134 | }, $data); |
| 135 | 135 | |
@@ -18,235 +18,235 @@ |
||
| 18 | 18 | * @template-extends QBMapper<PublicKeyToken> |
| 19 | 19 | */ |
| 20 | 20 | class PublicKeyTokenMapper extends QBMapper { |
| 21 | - public function __construct(IDBConnection $db) { |
|
| 22 | - parent::__construct($db, 'authtoken'); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Invalidate (delete) a given token |
|
| 27 | - */ |
|
| 28 | - public function invalidate(string $token) { |
|
| 29 | - /* @var $qb IQueryBuilder */ |
|
| 30 | - $qb = $this->db->getQueryBuilder(); |
|
| 31 | - $qb->delete($this->tableName) |
|
| 32 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 33 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 34 | - ->executeStatement(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param int $olderThan |
|
| 39 | - * @param int $type |
|
| 40 | - * @param int|null $remember |
|
| 41 | - */ |
|
| 42 | - public function invalidateOld(int $olderThan, int $type = IToken::TEMPORARY_TOKEN, ?int $remember = null) { |
|
| 43 | - /* @var $qb IQueryBuilder */ |
|
| 44 | - $qb = $this->db->getQueryBuilder(); |
|
| 45 | - $delete = $qb->delete($this->tableName) |
|
| 46 | - ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
| 47 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 48 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 49 | - if ($remember !== null) { |
|
| 50 | - $delete->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))); |
|
| 51 | - } |
|
| 52 | - $delete->executeStatement(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function invalidateLastUsedBefore(string $uid, int $before): int { |
|
| 56 | - $qb = $this->db->getQueryBuilder(); |
|
| 57 | - $qb->delete($this->tableName) |
|
| 58 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 59 | - ->andWhere($qb->expr()->lt('last_activity', $qb->createNamedParameter($before, IQueryBuilder::PARAM_INT))) |
|
| 60 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 61 | - return $qb->executeStatement(); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the user UID for the given token |
|
| 66 | - * |
|
| 67 | - * @throws DoesNotExistException |
|
| 68 | - */ |
|
| 69 | - public function getToken(string $token): PublicKeyToken { |
|
| 70 | - /* @var $qb IQueryBuilder */ |
|
| 71 | - $qb = $this->db->getQueryBuilder(); |
|
| 72 | - $result = $qb->select('*') |
|
| 73 | - ->from($this->tableName) |
|
| 74 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 75 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 76 | - ->executeQuery(); |
|
| 77 | - |
|
| 78 | - $data = $result->fetch(); |
|
| 79 | - $result->closeCursor(); |
|
| 80 | - if ($data === false) { |
|
| 81 | - throw new DoesNotExistException('token does not exist'); |
|
| 82 | - } |
|
| 83 | - return PublicKeyToken::fromRow($data); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Get the token for $id |
|
| 88 | - * |
|
| 89 | - * @throws DoesNotExistException |
|
| 90 | - */ |
|
| 91 | - public function getTokenById(int $id): PublicKeyToken { |
|
| 92 | - /* @var $qb IQueryBuilder */ |
|
| 93 | - $qb = $this->db->getQueryBuilder(); |
|
| 94 | - $result = $qb->select('*') |
|
| 95 | - ->from($this->tableName) |
|
| 96 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 97 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 98 | - ->executeQuery(); |
|
| 99 | - |
|
| 100 | - $data = $result->fetch(); |
|
| 101 | - $result->closeCursor(); |
|
| 102 | - if ($data === false) { |
|
| 103 | - throw new DoesNotExistException('token does not exist'); |
|
| 104 | - } |
|
| 105 | - return PublicKeyToken::fromRow($data); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get all tokens of a user |
|
| 110 | - * |
|
| 111 | - * The provider may limit the number of result rows in case of an abuse |
|
| 112 | - * where a high number of (session) tokens is generated |
|
| 113 | - * |
|
| 114 | - * @param string $uid |
|
| 115 | - * @return PublicKeyToken[] |
|
| 116 | - */ |
|
| 117 | - public function getTokenByUser(string $uid): array { |
|
| 118 | - /* @var $qb IQueryBuilder */ |
|
| 119 | - $qb = $this->db->getQueryBuilder(); |
|
| 120 | - $qb->select('*') |
|
| 121 | - ->from($this->tableName) |
|
| 122 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 123 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 124 | - ->setMaxResults(1000); |
|
| 125 | - $result = $qb->executeQuery(); |
|
| 126 | - $data = $result->fetchAll(); |
|
| 127 | - $result->closeCursor(); |
|
| 128 | - |
|
| 129 | - $entities = array_map(function ($row) { |
|
| 130 | - return PublicKeyToken::fromRow($row); |
|
| 131 | - }, $data); |
|
| 132 | - |
|
| 133 | - return $entities; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function getTokenByUserAndId(string $uid, int $id): ?string { |
|
| 137 | - /* @var $qb IQueryBuilder */ |
|
| 138 | - $qb = $this->db->getQueryBuilder(); |
|
| 139 | - $qb->select('token') |
|
| 140 | - ->from($this->tableName) |
|
| 141 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 142 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 143 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 144 | - return $qb->executeQuery()->fetchOne() ?: null; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * delete all auth token which belong to a specific client if the client was deleted |
|
| 149 | - * |
|
| 150 | - * @param string $name |
|
| 151 | - */ |
|
| 152 | - public function deleteByName(string $name) { |
|
| 153 | - $qb = $this->db->getQueryBuilder(); |
|
| 154 | - $qb->delete($this->tableName) |
|
| 155 | - ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
| 156 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 157 | - $qb->executeStatement(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function deleteTempToken(PublicKeyToken $except) { |
|
| 161 | - $qb = $this->db->getQueryBuilder(); |
|
| 162 | - |
|
| 163 | - $qb->delete($this->tableName) |
|
| 164 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
| 165 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
| 166 | - ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
| 167 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 168 | - |
|
| 169 | - $qb->executeStatement(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function hasExpiredTokens(string $uid): bool { |
|
| 173 | - $qb = $this->db->getQueryBuilder(); |
|
| 174 | - $qb->select('*') |
|
| 175 | - ->from($this->tableName) |
|
| 176 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 177 | - ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
| 178 | - ->setMaxResults(1); |
|
| 179 | - |
|
| 180 | - $cursor = $qb->executeQuery(); |
|
| 181 | - $data = $cursor->fetchAll(); |
|
| 182 | - $cursor->closeCursor(); |
|
| 183 | - |
|
| 184 | - return count($data) === 1; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Update the last activity timestamp |
|
| 189 | - * |
|
| 190 | - * In highly concurrent setups it can happen that two parallel processes |
|
| 191 | - * trigger the update at (nearly) the same time. In that special case it's |
|
| 192 | - * not necessary to hit the database with two actual updates. Therefore the |
|
| 193 | - * target last activity is included in the WHERE clause with a few seconds |
|
| 194 | - * of tolerance. |
|
| 195 | - * |
|
| 196 | - * Example: |
|
| 197 | - * - process 1 (P1) reads the token at timestamp 1500 |
|
| 198 | - * - process 1 (P2) reads the token at timestamp 1501 |
|
| 199 | - * - activity update interval is 100 |
|
| 200 | - * |
|
| 201 | - * This means |
|
| 202 | - * |
|
| 203 | - * - P1 will see a last_activity smaller than the current time and update |
|
| 204 | - * the token row |
|
| 205 | - * - If P2 reads after P1 had written, it will see 1600 as last activity |
|
| 206 | - * and the comparison on last_activity won't be truthy. This means no rows |
|
| 207 | - * need to be updated a second time |
|
| 208 | - * - If P2 reads before P1 had written, it will see 1501 as last activity, |
|
| 209 | - * but the comparison on last_activity will still not be truthy and the |
|
| 210 | - * token row is not updated a second time |
|
| 211 | - * |
|
| 212 | - * @param IToken $token |
|
| 213 | - * @param int $now |
|
| 214 | - */ |
|
| 215 | - public function updateActivity(IToken $token, int $now): void { |
|
| 216 | - $qb = $this->db->getQueryBuilder(); |
|
| 217 | - $update = $qb->update($this->getTableName()) |
|
| 218 | - ->set('last_activity', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT)) |
|
| 219 | - ->where( |
|
| 220 | - $qb->expr()->eq('id', $qb->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT), |
|
| 221 | - $qb->expr()->lt('last_activity', $qb->createNamedParameter($now - 15, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT) |
|
| 222 | - ); |
|
| 223 | - $update->executeStatement(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - public function updateHashesForUser(string $userId, string $passwordHash): void { |
|
| 227 | - $qb = $this->db->getQueryBuilder(); |
|
| 228 | - $update = $qb->update($this->getTableName()) |
|
| 229 | - ->set('password_hash', $qb->createNamedParameter($passwordHash)) |
|
| 230 | - ->where( |
|
| 231 | - $qb->expr()->eq('uid', $qb->createNamedParameter($userId)) |
|
| 232 | - ); |
|
| 233 | - $update->executeStatement(); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - public function getFirstTokenForUser(string $userId): ?PublicKeyToken { |
|
| 237 | - $qb = $this->db->getQueryBuilder(); |
|
| 238 | - $qb->select('*') |
|
| 239 | - ->from($this->getTableName()) |
|
| 240 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($userId))) |
|
| 241 | - ->setMaxResults(1) |
|
| 242 | - ->orderBy('id'); |
|
| 243 | - $result = $qb->executeQuery(); |
|
| 244 | - |
|
| 245 | - $data = $result->fetch(); |
|
| 246 | - $result->closeCursor(); |
|
| 247 | - if ($data === false) { |
|
| 248 | - return null; |
|
| 249 | - } |
|
| 250 | - return PublicKeyToken::fromRow($data); |
|
| 251 | - } |
|
| 21 | + public function __construct(IDBConnection $db) { |
|
| 22 | + parent::__construct($db, 'authtoken'); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Invalidate (delete) a given token |
|
| 27 | + */ |
|
| 28 | + public function invalidate(string $token) { |
|
| 29 | + /* @var $qb IQueryBuilder */ |
|
| 30 | + $qb = $this->db->getQueryBuilder(); |
|
| 31 | + $qb->delete($this->tableName) |
|
| 32 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 33 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 34 | + ->executeStatement(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param int $olderThan |
|
| 39 | + * @param int $type |
|
| 40 | + * @param int|null $remember |
|
| 41 | + */ |
|
| 42 | + public function invalidateOld(int $olderThan, int $type = IToken::TEMPORARY_TOKEN, ?int $remember = null) { |
|
| 43 | + /* @var $qb IQueryBuilder */ |
|
| 44 | + $qb = $this->db->getQueryBuilder(); |
|
| 45 | + $delete = $qb->delete($this->tableName) |
|
| 46 | + ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
| 47 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 48 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 49 | + if ($remember !== null) { |
|
| 50 | + $delete->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))); |
|
| 51 | + } |
|
| 52 | + $delete->executeStatement(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function invalidateLastUsedBefore(string $uid, int $before): int { |
|
| 56 | + $qb = $this->db->getQueryBuilder(); |
|
| 57 | + $qb->delete($this->tableName) |
|
| 58 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 59 | + ->andWhere($qb->expr()->lt('last_activity', $qb->createNamedParameter($before, IQueryBuilder::PARAM_INT))) |
|
| 60 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 61 | + return $qb->executeStatement(); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the user UID for the given token |
|
| 66 | + * |
|
| 67 | + * @throws DoesNotExistException |
|
| 68 | + */ |
|
| 69 | + public function getToken(string $token): PublicKeyToken { |
|
| 70 | + /* @var $qb IQueryBuilder */ |
|
| 71 | + $qb = $this->db->getQueryBuilder(); |
|
| 72 | + $result = $qb->select('*') |
|
| 73 | + ->from($this->tableName) |
|
| 74 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 75 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 76 | + ->executeQuery(); |
|
| 77 | + |
|
| 78 | + $data = $result->fetch(); |
|
| 79 | + $result->closeCursor(); |
|
| 80 | + if ($data === false) { |
|
| 81 | + throw new DoesNotExistException('token does not exist'); |
|
| 82 | + } |
|
| 83 | + return PublicKeyToken::fromRow($data); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Get the token for $id |
|
| 88 | + * |
|
| 89 | + * @throws DoesNotExistException |
|
| 90 | + */ |
|
| 91 | + public function getTokenById(int $id): PublicKeyToken { |
|
| 92 | + /* @var $qb IQueryBuilder */ |
|
| 93 | + $qb = $this->db->getQueryBuilder(); |
|
| 94 | + $result = $qb->select('*') |
|
| 95 | + ->from($this->tableName) |
|
| 96 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 97 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 98 | + ->executeQuery(); |
|
| 99 | + |
|
| 100 | + $data = $result->fetch(); |
|
| 101 | + $result->closeCursor(); |
|
| 102 | + if ($data === false) { |
|
| 103 | + throw new DoesNotExistException('token does not exist'); |
|
| 104 | + } |
|
| 105 | + return PublicKeyToken::fromRow($data); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get all tokens of a user |
|
| 110 | + * |
|
| 111 | + * The provider may limit the number of result rows in case of an abuse |
|
| 112 | + * where a high number of (session) tokens is generated |
|
| 113 | + * |
|
| 114 | + * @param string $uid |
|
| 115 | + * @return PublicKeyToken[] |
|
| 116 | + */ |
|
| 117 | + public function getTokenByUser(string $uid): array { |
|
| 118 | + /* @var $qb IQueryBuilder */ |
|
| 119 | + $qb = $this->db->getQueryBuilder(); |
|
| 120 | + $qb->select('*') |
|
| 121 | + ->from($this->tableName) |
|
| 122 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 123 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 124 | + ->setMaxResults(1000); |
|
| 125 | + $result = $qb->executeQuery(); |
|
| 126 | + $data = $result->fetchAll(); |
|
| 127 | + $result->closeCursor(); |
|
| 128 | + |
|
| 129 | + $entities = array_map(function ($row) { |
|
| 130 | + return PublicKeyToken::fromRow($row); |
|
| 131 | + }, $data); |
|
| 132 | + |
|
| 133 | + return $entities; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function getTokenByUserAndId(string $uid, int $id): ?string { |
|
| 137 | + /* @var $qb IQueryBuilder */ |
|
| 138 | + $qb = $this->db->getQueryBuilder(); |
|
| 139 | + $qb->select('token') |
|
| 140 | + ->from($this->tableName) |
|
| 141 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 142 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 143 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 144 | + return $qb->executeQuery()->fetchOne() ?: null; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * delete all auth token which belong to a specific client if the client was deleted |
|
| 149 | + * |
|
| 150 | + * @param string $name |
|
| 151 | + */ |
|
| 152 | + public function deleteByName(string $name) { |
|
| 153 | + $qb = $this->db->getQueryBuilder(); |
|
| 154 | + $qb->delete($this->tableName) |
|
| 155 | + ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
| 156 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 157 | + $qb->executeStatement(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function deleteTempToken(PublicKeyToken $except) { |
|
| 161 | + $qb = $this->db->getQueryBuilder(); |
|
| 162 | + |
|
| 163 | + $qb->delete($this->tableName) |
|
| 164 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
| 165 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
| 166 | + ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
| 167 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 168 | + |
|
| 169 | + $qb->executeStatement(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function hasExpiredTokens(string $uid): bool { |
|
| 173 | + $qb = $this->db->getQueryBuilder(); |
|
| 174 | + $qb->select('*') |
|
| 175 | + ->from($this->tableName) |
|
| 176 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 177 | + ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
| 178 | + ->setMaxResults(1); |
|
| 179 | + |
|
| 180 | + $cursor = $qb->executeQuery(); |
|
| 181 | + $data = $cursor->fetchAll(); |
|
| 182 | + $cursor->closeCursor(); |
|
| 183 | + |
|
| 184 | + return count($data) === 1; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Update the last activity timestamp |
|
| 189 | + * |
|
| 190 | + * In highly concurrent setups it can happen that two parallel processes |
|
| 191 | + * trigger the update at (nearly) the same time. In that special case it's |
|
| 192 | + * not necessary to hit the database with two actual updates. Therefore the |
|
| 193 | + * target last activity is included in the WHERE clause with a few seconds |
|
| 194 | + * of tolerance. |
|
| 195 | + * |
|
| 196 | + * Example: |
|
| 197 | + * - process 1 (P1) reads the token at timestamp 1500 |
|
| 198 | + * - process 1 (P2) reads the token at timestamp 1501 |
|
| 199 | + * - activity update interval is 100 |
|
| 200 | + * |
|
| 201 | + * This means |
|
| 202 | + * |
|
| 203 | + * - P1 will see a last_activity smaller than the current time and update |
|
| 204 | + * the token row |
|
| 205 | + * - If P2 reads after P1 had written, it will see 1600 as last activity |
|
| 206 | + * and the comparison on last_activity won't be truthy. This means no rows |
|
| 207 | + * need to be updated a second time |
|
| 208 | + * - If P2 reads before P1 had written, it will see 1501 as last activity, |
|
| 209 | + * but the comparison on last_activity will still not be truthy and the |
|
| 210 | + * token row is not updated a second time |
|
| 211 | + * |
|
| 212 | + * @param IToken $token |
|
| 213 | + * @param int $now |
|
| 214 | + */ |
|
| 215 | + public function updateActivity(IToken $token, int $now): void { |
|
| 216 | + $qb = $this->db->getQueryBuilder(); |
|
| 217 | + $update = $qb->update($this->getTableName()) |
|
| 218 | + ->set('last_activity', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT)) |
|
| 219 | + ->where( |
|
| 220 | + $qb->expr()->eq('id', $qb->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT), |
|
| 221 | + $qb->expr()->lt('last_activity', $qb->createNamedParameter($now - 15, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT) |
|
| 222 | + ); |
|
| 223 | + $update->executeStatement(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + public function updateHashesForUser(string $userId, string $passwordHash): void { |
|
| 227 | + $qb = $this->db->getQueryBuilder(); |
|
| 228 | + $update = $qb->update($this->getTableName()) |
|
| 229 | + ->set('password_hash', $qb->createNamedParameter($passwordHash)) |
|
| 230 | + ->where( |
|
| 231 | + $qb->expr()->eq('uid', $qb->createNamedParameter($userId)) |
|
| 232 | + ); |
|
| 233 | + $update->executeStatement(); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + public function getFirstTokenForUser(string $userId): ?PublicKeyToken { |
|
| 237 | + $qb = $this->db->getQueryBuilder(); |
|
| 238 | + $qb->select('*') |
|
| 239 | + ->from($this->getTableName()) |
|
| 240 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($userId))) |
|
| 241 | + ->setMaxResults(1) |
|
| 242 | + ->orderBy('id'); |
|
| 243 | + $result = $qb->executeQuery(); |
|
| 244 | + |
|
| 245 | + $data = $result->fetch(); |
|
| 246 | + $result->closeCursor(); |
|
| 247 | + if ($data === false) { |
|
| 248 | + return null; |
|
| 249 | + } |
|
| 250 | + return PublicKeyToken::fromRow($data); |
|
| 251 | + } |
|
| 252 | 252 | } |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | * @return string language |
| 108 | 108 | * @since 7.0.0 |
| 109 | 109 | */ |
| 110 | - public function getLanguageCode(): string ; |
|
| 110 | + public function getLanguageCode(): string; |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
@@ -17,77 +17,77 @@ |
||
| 17 | 17 | * @since 6.0.0 |
| 18 | 18 | */ |
| 19 | 19 | interface IL10N { |
| 20 | - /** |
|
| 21 | - * Translating |
|
| 22 | - * @param string $text The text we need a translation for |
|
| 23 | - * @param array|string $parameters default:array() Parameters for sprintf |
|
| 24 | - * @return string Translation or the same text |
|
| 25 | - * |
|
| 26 | - * Returns the translation. If no translation is found, $text will be |
|
| 27 | - * returned. |
|
| 28 | - * @since 6.0.0 |
|
| 29 | - */ |
|
| 30 | - public function t(string $text, $parameters = []): string; |
|
| 20 | + /** |
|
| 21 | + * Translating |
|
| 22 | + * @param string $text The text we need a translation for |
|
| 23 | + * @param array|string $parameters default:array() Parameters for sprintf |
|
| 24 | + * @return string Translation or the same text |
|
| 25 | + * |
|
| 26 | + * Returns the translation. If no translation is found, $text will be |
|
| 27 | + * returned. |
|
| 28 | + * @since 6.0.0 |
|
| 29 | + */ |
|
| 30 | + public function t(string $text, $parameters = []): string; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Translating |
|
| 34 | - * @param string $text_singular the string to translate for exactly one object |
|
| 35 | - * @param string $text_plural the string to translate for n objects |
|
| 36 | - * @param integer $count Number of objects |
|
| 37 | - * @param array $parameters default:array() Parameters for sprintf |
|
| 38 | - * @return string Translation or the same text |
|
| 39 | - * |
|
| 40 | - * Returns the translation. If no translation is found, $text will be |
|
| 41 | - * returned. %n will be replaced with the number of objects. |
|
| 42 | - * |
|
| 43 | - * The correct plural is determined by the plural_forms-function |
|
| 44 | - * provided by the po file. |
|
| 45 | - * @since 6.0.0 |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - public function n(string $text_singular, string $text_plural, int $count, array $parameters = []): string; |
|
| 32 | + /** |
|
| 33 | + * Translating |
|
| 34 | + * @param string $text_singular the string to translate for exactly one object |
|
| 35 | + * @param string $text_plural the string to translate for n objects |
|
| 36 | + * @param integer $count Number of objects |
|
| 37 | + * @param array $parameters default:array() Parameters for sprintf |
|
| 38 | + * @return string Translation or the same text |
|
| 39 | + * |
|
| 40 | + * Returns the translation. If no translation is found, $text will be |
|
| 41 | + * returned. %n will be replaced with the number of objects. |
|
| 42 | + * |
|
| 43 | + * The correct plural is determined by the plural_forms-function |
|
| 44 | + * provided by the po file. |
|
| 45 | + * @since 6.0.0 |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + public function n(string $text_singular, string $text_plural, int $count, array $parameters = []): string; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Localization |
|
| 52 | - * @param string $type Type of localization |
|
| 53 | - * @param \DateTime|int|string|null $data parameters for this localization |
|
| 54 | - * @param array $options currently supports following options: |
|
| 55 | - * - 'width': handed into \Punic\Calendar::formatDate as second parameter |
|
| 56 | - * @return string|int|false |
|
| 57 | - * |
|
| 58 | - * Returns the localized data. |
|
| 59 | - * |
|
| 60 | - * Implemented types: |
|
| 61 | - * - date |
|
| 62 | - * - Creates a date |
|
| 63 | - * - l10n-field: date |
|
| 64 | - * - params: timestamp (int/string) |
|
| 65 | - * - datetime |
|
| 66 | - * - Creates date and time |
|
| 67 | - * - l10n-field: datetime |
|
| 68 | - * - params: timestamp (int/string) |
|
| 69 | - * - time |
|
| 70 | - * - Creates a time |
|
| 71 | - * - l10n-field: time |
|
| 72 | - * - params: timestamp (int/string) |
|
| 73 | - * @since 6.0.0 - parameter $options was added in 8.0.0 |
|
| 74 | - */ |
|
| 75 | - public function l(string $type, $data, array $options = []); |
|
| 50 | + /** |
|
| 51 | + * Localization |
|
| 52 | + * @param string $type Type of localization |
|
| 53 | + * @param \DateTime|int|string|null $data parameters for this localization |
|
| 54 | + * @param array $options currently supports following options: |
|
| 55 | + * - 'width': handed into \Punic\Calendar::formatDate as second parameter |
|
| 56 | + * @return string|int|false |
|
| 57 | + * |
|
| 58 | + * Returns the localized data. |
|
| 59 | + * |
|
| 60 | + * Implemented types: |
|
| 61 | + * - date |
|
| 62 | + * - Creates a date |
|
| 63 | + * - l10n-field: date |
|
| 64 | + * - params: timestamp (int/string) |
|
| 65 | + * - datetime |
|
| 66 | + * - Creates date and time |
|
| 67 | + * - l10n-field: datetime |
|
| 68 | + * - params: timestamp (int/string) |
|
| 69 | + * - time |
|
| 70 | + * - Creates a time |
|
| 71 | + * - l10n-field: time |
|
| 72 | + * - params: timestamp (int/string) |
|
| 73 | + * @since 6.0.0 - parameter $options was added in 8.0.0 |
|
| 74 | + */ |
|
| 75 | + public function l(string $type, $data, array $options = []); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * The code (en, de, ...) of the language that is used for this IL10N object |
|
| 80 | - * |
|
| 81 | - * @return string language |
|
| 82 | - * @since 7.0.0 |
|
| 83 | - */ |
|
| 84 | - public function getLanguageCode(): string ; |
|
| 78 | + /** |
|
| 79 | + * The code (en, de, ...) of the language that is used for this IL10N object |
|
| 80 | + * |
|
| 81 | + * @return string language |
|
| 82 | + * @since 7.0.0 |
|
| 83 | + */ |
|
| 84 | + public function getLanguageCode(): string ; |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
|
| 88 | - * |
|
| 89 | - * @return string locale |
|
| 90 | - * @since 14.0.0 |
|
| 91 | - */ |
|
| 92 | - public function getLocaleCode(): string; |
|
| 86 | + /** |
|
| 87 | + * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
|
| 88 | + * |
|
| 89 | + * @return string locale |
|
| 90 | + * @since 14.0.0 |
|
| 91 | + */ |
|
| 92 | + public function getLocaleCode(): string; |
|
| 93 | 93 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |