Skip to content

Commit b368424

Browse files
authored
feat: update dependencies and base code to support laravel 12 (#75)
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent cb99c77 commit b368424

File tree

9 files changed

+1018
-1065
lines changed

9 files changed

+1018
-1065
lines changed

app/Models/Utils/PreRemoveEventArgs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
**/
1515

16-
use Doctrine\ORM\Event\LifecycleEventArgs;
16+
use Doctrine\Persistence\Event\LifecycleEventArgs;
1717

1818
/**
1919
* Class PreRemoveEventArgs

app/Models/Utils/UTCTimestamp.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
* limitations under the License.
1313
**/
1414
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
15-
use Doctrine\ORM\Query\Lexer;
15+
use Doctrine\ORM\Query\Parser;
16+
use Doctrine\ORM\Query\QueryException;
17+
use Doctrine\ORM\Query\SqlWalker;
18+
use Doctrine\ORM\Query\TokenType;
19+
1620
/**
1721
* Class UTCTimestamp
1822
* @package App\Models\Utils
@@ -21,15 +25,18 @@ class UTCTimestamp extends FunctionNode
2125
{
2226
public $arithmeticExpression;
2327

24-
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
28+
public function getSql(SqlWalker $sqlWalker): string
2529
{
2630
return 'UTC_TIMESTAMP()';
2731
}
2832

29-
public function parse(\Doctrine\ORM\Query\Parser $parser)
33+
/**
34+
* @throws QueryException
35+
*/
36+
public function parse(Parser $parser): void
3037
{
31-
$parser->match(Lexer::T_IDENTIFIER);
32-
$parser->match(Lexer::T_OPEN_PARENTHESIS);
33-
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
38+
$parser->match(TokenType::T_IDENTIFIER);
39+
$parser->match(TokenType::T_OPEN_PARENTHESIS);
40+
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
3441
}
3542
}

app/Repositories/DoctrineAsymmetricKeyRepository.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
**/
14+
15+
use Doctrine\Common\Collections\ArrayCollection;
16+
use Doctrine\ORM\Query\Parameter;
1417
use Models\OAuth2\AsymmetricKey;
1518
use OAuth2\Repositories\IAsymmetricKeyRepository;
1619
/**
@@ -94,10 +97,10 @@ public function getActives():array
9497
->where('e.valid_from <= :now1')
9598
->andWhere('e.valid_to >= :now2')
9699
->andWhere("e.active = 1")
97-
->setParameters([
98-
'now1' => $now,
99-
'now2' => $now,
100-
])
100+
->setParameters(new ArrayCollection([
101+
new Parameter('now1', $now),
102+
new Parameter('now2', $now),
103+
]))
101104
->getQuery()
102105
->getResult();
103106
}

app/Repositories/DoctrineOAuth2TrailExceptionRepository.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* limitations under the License.
1313
**/
1414
use App\libs\OAuth2\Repositories\IOAuth2TrailExceptionRepository;
15+
use Doctrine\Common\Collections\ArrayCollection;
16+
use Doctrine\ORM\Query\Parameter;
1517
use Models\OAuth2\Client;
1618
use Models\OAuth2\OAuth2TrailException;
1719
/**
@@ -46,13 +48,15 @@ public function getCountByIPTypeOfLatestUserExceptions(Client $client, string $t
4648
->where("client.id = :client_id")
4749
->andWhere("e.exception_type = :exception_type")
4850
->andWhere("DATESUB(UTC_TIMESTAMP(), :minutes, 'MINUTE') < e.created_at")
49-
->setParameters(
50-
[
51-
'client_id' => $client->getId(),
52-
'exception_type' => trim($type),
53-
'minutes' => $minutes_without_ex,
54-
]
51+
->setParameters(new ArrayCollection(
52+
[
53+
new Parameter('client_id', $client->getId()),
54+
new Parameter('exception_type', trim($type)),
55+
new Parameter('minutes', $minutes_without_ex)
56+
]
57+
)
5558
)
56-
->getQuery()->getSingleScalarResult();
59+
->getQuery()
60+
->getSingleScalarResult();
5761
}
5862
}

app/Repositories/DoctrineRepository.php

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
* limitations under the License.
1313
**/
1414

15+
use Doctrine\Common\Collections\AbstractLazyCollection;
1516
use Doctrine\Common\Collections\Criteria;
17+
use Doctrine\Common\Collections\Selectable;
1618
use Doctrine\ORM\EntityManager;
1719
use Doctrine\ORM\EntityRepository;
1820
use Doctrine\ORM\LazyCriteriaCollection;
19-
use Doctrine\ORM\NativeQuery;
2021
use Doctrine\ORM\Query;
2122
use Doctrine\ORM\QueryBuilder;
2223
use LaravelDoctrine\ORM\Facades\Registry;
@@ -41,7 +42,7 @@ abstract class DoctrineRepository extends EntityRepository implements IBaseRepos
4142
/**
4243
* @return EntityManager
4344
*/
44-
protected function getEntityManager()
45+
protected function getEntityManager(): \Doctrine\ORM\EntityManagerInterface
4546
{
4647
return Registry::getManager($this->manager_name);
4748
}
@@ -171,11 +172,11 @@ public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Ord
171172
*
172173
* @return QueryBuilder
173174
*/
174-
public function createQueryBuilder($alias, $indexBy = null)
175+
public function createQueryBuilder($alias, $indexBy = null): QueryBuilder
175176
{
176177
return $this->getEntityManager()->createQueryBuilder()
177178
->select($alias)
178-
->from($this->_entityName, $alias, $indexBy);
179+
->from($this->getEntityName(), $alias, $indexBy);
179180
}
180181

181182
/**
@@ -187,50 +188,22 @@ public function createQueryBuilder($alias, $indexBy = null)
187188
*
188189
* @return Query\ResultSetMappingBuilder
189190
*/
190-
public function createResultSetMappingBuilder($alias)
191+
public function createResultSetMappingBuilder($alias): Query\ResultSetMappingBuilder
191192
{
192193
$rsm = new Query\ResultSetMappingBuilder($this->getEntityManager(), ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
193-
$rsm->addRootEntityFromClassMetadata($this->_entityName, $alias);
194+
$rsm->addRootEntityFromClassMetadata($this->getEntityName(), $alias);
194195

195196
return $rsm;
196197
}
197198

198-
/**
199-
* Creates a new Query instance based on a predefined metadata named query.
200-
*
201-
* @param string $queryName
202-
*
203-
* @return Query
204-
*/
205-
public function createNamedQuery($queryName)
206-
{
207-
return $this->getEntityManager()->createQuery($this->_class->getNamedQuery($queryName));
208-
}
209-
210-
/**
211-
* Creates a native SQL query.
212-
*
213-
* @param string $queryName
214-
*
215-
* @return NativeQuery
216-
*/
217-
public function createNativeNamedQuery($queryName)
218-
{
219-
$queryMapping = $this->_class->getNamedNativeQuery($queryName);
220-
$rsm = new Query\ResultSetMappingBuilder($this->getEntityManager());
221-
$rsm->addNamedNativeQueryMapping($this->_class, $queryMapping);
222-
223-
return $this->getEntityManager()->createNativeQuery($queryMapping['query'], $rsm);
224-
}
225-
226199
/**
227200
* Clears the repository, causing all managed entities to become detached.
228201
*
229202
* @return void
230203
*/
231-
public function clear()
204+
public function clear(): void
232205
{
233-
$this->getEntityManager()->clear($this->_class->rootEntityName);
206+
$this->getEntityManager()->clear($this->getClassMetadata()->rootEntityName);
234207
}
235208

236209
/**
@@ -244,9 +217,9 @@ public function clear()
244217
*
245218
* @return object|null The entity instance or NULL if the entity can not be found.
246219
*/
247-
public function find($id, $lockMode = null, $lockVersion = null)
220+
public function find($id, $lockMode = null, $lockVersion = null): ?object
248221
{
249-
return $this->getEntityManager()->find($this->_entityName, $id, $lockMode, $lockVersion);
222+
return $this->getEntityManager()->find($this->getEntityName(), $id, $lockMode, $lockVersion);
250223
}
251224

252225
/**
@@ -259,10 +232,9 @@ public function find($id, $lockMode = null, $lockVersion = null)
259232
*
260233
* @return array The objects.
261234
*/
262-
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
235+
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
263236
{
264-
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->_entityName);
265-
237+
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->getEntityName());
266238
return $persister->loadAll($criteria, $orderBy, $limit, $offset);
267239
}
268240

@@ -274,9 +246,9 @@ public function findBy(array $criteria, array $orderBy = null, $limit = null, $o
274246
*
275247
* @return object|null The entity instance or NULL if the entity can not be found.
276248
*/
277-
public function findOneBy(array $criteria, array $orderBy = null)
249+
public function findOneBy(array $criteria, array $orderBy = null): ?object
278250
{
279-
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->_entityName);
251+
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->getEntityName());
280252

281253
return $persister->load($criteria, null, null, [], null, 1, $orderBy);
282254
}
@@ -290,23 +262,22 @@ public function findOneBy(array $criteria, array $orderBy = null)
290262
*
291263
* @return int The cardinality of the objects that match the given criteria.
292264
*/
293-
public function count(array $criteria)
265+
public function count(array $criteria = []): int
294266
{
295-
return $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->_entityName)->count($criteria);
267+
return $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->getEntityName())->count($criteria);
296268
}
297269

298270
/**
299271
* Select all elements from a selectable that match the expression and
300272
* return a new collection containing these elements.
301273
*
302-
* @param \Doctrine\Common\Collections\Criteria $criteria
274+
* @param Criteria $criteria
303275
*
304-
* @return \Doctrine\Common\Collections\Collection
276+
* @return AbstractLazyCollection&Selectable
305277
*/
306-
public function matching(Criteria $criteria)
278+
public function matching(Criteria $criteria): AbstractLazyCollection&Selectable
307279
{
308-
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->_entityName);
309-
280+
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->getEntityName());
310281
return new LazyCriteriaCollection($persister, $criteria);
311282
}
312283
}

app/Repositories/DoctrineUserExceptionTrailRepository.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* limitations under the License.
1313
**/
1414
use App\libs\Auth\Repositories\IUserExceptionTrailRepository;
15+
use Doctrine\Common\Collections\ArrayCollection;
16+
use Doctrine\ORM\Query\Parameter;
1517
use Models\UserExceptionTrail;
1618
/**
1719
* Class DoctrineUserExceptionTrailRepository
@@ -37,21 +39,22 @@ protected function getBaseEntity()
3739
*/
3840
public function getCountByIPTypeOfLatestUserExceptions(string $ip, string $type, int $minutes_without_ex): int
3941
{
40-
4142
return $this->getEntityManager()
4243
->createQueryBuilder()
4344
->select("count(e.id)")
4445
->from($this->getBaseEntity(), "e")
4546
->where("e.from_ip = :ip")
4647
->andWhere("e.exception_type = :exception_type")
4748
->andWhere("DATESUB(UTC_TIMESTAMP(), :minutes, 'MINUTE') < e.created_at")
48-
->setParameters(
49-
[
50-
'ip' => trim($ip),
51-
'exception_type' => trim($type),
52-
'minutes' => $minutes_without_ex,
53-
]
49+
->setParameters(new ArrayCollection(
50+
[
51+
new Parameter('ip', trim($ip)),
52+
new Parameter('exception_type', trim($type)),
53+
new Parameter('minutes', $minutes_without_ex)
54+
]
55+
)
5456
)
55-
->getQuery()->getSingleScalarResult();
57+
->getQuery()
58+
->getSingleScalarResult();
5659
}
5760
}

app/libs/Utils/Doctrine/EscapingQuoteStrategy.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EscapingQuoteStrategy implements QuoteStrategy
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform)
29+
public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform): string
3030
{
3131
if (isset($class->fieldMappings[$fieldName]['quoted'])) {
3232
return $platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName']);
@@ -42,7 +42,7 @@ public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function getTableName(ClassMetadata $class, AbstractPlatform $platform)
45+
public function getTableName(ClassMetadata $class, AbstractPlatform $platform): string
4646
{
4747
if (isset($class->table['quoted'])) {
4848
return $platform->quoteIdentifier($class->table['name']);
@@ -58,7 +58,7 @@ public function getTableName(ClassMetadata $class, AbstractPlatform $platform)
5858
/**
5959
* {@inheritdoc}
6060
*/
61-
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform)
61+
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string
6262
{
6363
if (isset($definition['quoted'])) {
6464
return $platform->quoteIdentifier($class->table['name']);
@@ -74,7 +74,7 @@ public function getSequenceName(array $definition, ClassMetadata $class, Abstrac
7474
/**
7575
* {@inheritdoc}
7676
*/
77-
public function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
77+
public function getJoinColumnName(array|\Doctrine\ORM\Mapping\JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
7878
{
7979
if (isset($joinColumn['quoted'])) {
8080
return $platform->quoteIdentifier($joinColumn['name']);
@@ -90,7 +90,7 @@ public function getJoinColumnName(array $joinColumn, ClassMetadata $class, Abstr
9090
/**
9191
* {@inheritdoc}
9292
*/
93-
public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
93+
public function getReferencedJoinColumnName(array|\Doctrine\ORM\Mapping\JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
9494
{
9595
if (isset($joinColumn['quoted'])) {
9696
return $platform->quoteIdentifier($joinColumn['referencedColumnName']);
@@ -106,7 +106,7 @@ public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $cl
106106
/**
107107
* {@inheritdoc}
108108
*/
109-
public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform)
109+
public function getJoinTableName(array|\Doctrine\ORM\Mapping\ManyToManyOwningSideMapping $association, ClassMetadata $class, AbstractPlatform $platform): string
110110
{
111111
if (isset($association['joinTable']['quoted'])) {
112112
return $platform->quoteIdentifier($association['joinTable']['name']);
@@ -122,7 +122,7 @@ public function getJoinTableName(array $association, ClassMetadata $class, Abstr
122122
/**
123123
* {@inheritdoc}
124124
*/
125-
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform)
125+
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform): array
126126
{
127127
$quotedColumnNames = array();
128128

@@ -159,7 +159,7 @@ function ($joinColumn) use ($platform) {
159159
/**
160160
* {@inheritdoc}
161161
*/
162-
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null)
162+
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null): string
163163
{
164164
// 1 ) Concatenate column name and counter
165165
// 2 ) Trim the column alias to the maximum identifier length of the platform.

0 commit comments

Comments
 (0)