Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Models/Utils/PreRemoveEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
**/

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs;

/**
* Class PreRemoveEventArgs
Expand Down
19 changes: 13 additions & 6 deletions app/Models/Utils/UTCTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
* limitations under the License.
**/
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

/**
* Class UTCTimestamp
* @package App\Models\Utils
Expand All @@ -21,15 +25,18 @@ class UTCTimestamp extends FunctionNode
{
public $arithmeticExpression;

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
public function getSql(SqlWalker $sqlWalker): string
{
return 'UTC_TIMESTAMP()';
}

public function parse(\Doctrine\ORM\Query\Parser $parser)
/**
* @throws QueryException
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
11 changes: 7 additions & 4 deletions app/Repositories/DoctrineAsymmetricKeyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Query\Parameter;
use Models\OAuth2\AsymmetricKey;
use OAuth2\Repositories\IAsymmetricKeyRepository;
/**
Expand Down Expand Up @@ -94,10 +97,10 @@ public function getActives():array
->where('e.valid_from <= :now1')
->andWhere('e.valid_to >= :now2')
->andWhere("e.active = 1")
->setParameters([
'now1' => $now,
'now2' => $now,
])
->setParameters(new ArrayCollection([
new Parameter('now1', $now),
new Parameter('now2', $now),
]))
->getQuery()
->getResult();
}
Expand Down
18 changes: 11 additions & 7 deletions app/Repositories/DoctrineOAuth2TrailExceptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* limitations under the License.
**/
use App\libs\OAuth2\Repositories\IOAuth2TrailExceptionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Query\Parameter;
use Models\OAuth2\Client;
use Models\OAuth2\OAuth2TrailException;
/**
Expand Down Expand Up @@ -46,13 +48,15 @@ public function getCountByIPTypeOfLatestUserExceptions(Client $client, string $t
->where("client.id = :client_id")
->andWhere("e.exception_type = :exception_type")
->andWhere("DATESUB(UTC_TIMESTAMP(), :minutes, 'MINUTE') < e.created_at")
->setParameters(
[
'client_id' => $client->getId(),
'exception_type' => trim($type),
'minutes' => $minutes_without_ex,
]
->setParameters(new ArrayCollection(
[
new Parameter('client_id', $client->getId()),
new Parameter('exception_type', trim($type)),
new Parameter('minutes', $minutes_without_ex)
]
)
)
->getQuery()->getSingleScalarResult();
->getQuery()
->getSingleScalarResult();
}
}
71 changes: 21 additions & 50 deletions app/Repositories/DoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* limitations under the License.
**/

use Doctrine\Common\Collections\AbstractLazyCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\LazyCriteriaCollection;
use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use LaravelDoctrine\ORM\Facades\Registry;
Expand All @@ -41,7 +42,7 @@ abstract class DoctrineRepository extends EntityRepository implements IBaseRepos
/**
* @return EntityManager
*/
protected function getEntityManager()
protected function getEntityManager(): \Doctrine\ORM\EntityManagerInterface
{
return Registry::getManager($this->manager_name);
}
Expand Down Expand Up @@ -171,11 +172,11 @@ public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Ord
*
* @return QueryBuilder
*/
public function createQueryBuilder($alias, $indexBy = null)
public function createQueryBuilder($alias, $indexBy = null): QueryBuilder
{
return $this->getEntityManager()->createQueryBuilder()
->select($alias)
->from($this->_entityName, $alias, $indexBy);
->from($this->getEntityName(), $alias, $indexBy);
}

/**
Expand All @@ -187,50 +188,22 @@ public function createQueryBuilder($alias, $indexBy = null)
*
* @return Query\ResultSetMappingBuilder
*/
public function createResultSetMappingBuilder($alias)
public function createResultSetMappingBuilder($alias): Query\ResultSetMappingBuilder
{
$rsm = new Query\ResultSetMappingBuilder($this->getEntityManager(), ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
$rsm->addRootEntityFromClassMetadata($this->_entityName, $alias);
$rsm->addRootEntityFromClassMetadata($this->getEntityName(), $alias);

return $rsm;
}

/**
* Creates a new Query instance based on a predefined metadata named query.
*
* @param string $queryName
*
* @return Query
*/
public function createNamedQuery($queryName)
{
return $this->getEntityManager()->createQuery($this->_class->getNamedQuery($queryName));
}

/**
* Creates a native SQL query.
*
* @param string $queryName
*
* @return NativeQuery
*/
public function createNativeNamedQuery($queryName)
{
$queryMapping = $this->_class->getNamedNativeQuery($queryName);
$rsm = new Query\ResultSetMappingBuilder($this->getEntityManager());
$rsm->addNamedNativeQueryMapping($this->_class, $queryMapping);

return $this->getEntityManager()->createNativeQuery($queryMapping['query'], $rsm);
}

/**
* Clears the repository, causing all managed entities to become detached.
*
* @return void
*/
public function clear()
public function clear(): void
{
$this->getEntityManager()->clear($this->_class->rootEntityName);
$this->getEntityManager()->clear($this->getClassMetadata()->rootEntityName);
}

/**
Expand All @@ -244,9 +217,9 @@ public function clear()
*
* @return object|null The entity instance or NULL if the entity can not be found.
*/
public function find($id, $lockMode = null, $lockVersion = null)
public function find($id, $lockMode = null, $lockVersion = null): ?object
{
return $this->getEntityManager()->find($this->_entityName, $id, $lockMode, $lockVersion);
return $this->getEntityManager()->find($this->getEntityName(), $id, $lockMode, $lockVersion);
}

/**
Expand All @@ -259,10 +232,9 @@ public function find($id, $lockMode = null, $lockVersion = null)
*
* @return array The objects.
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->_entityName);

$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->getEntityName());
return $persister->loadAll($criteria, $orderBy, $limit, $offset);
}

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

return $persister->load($criteria, null, null, [], null, 1, $orderBy);
}
Expand All @@ -290,23 +262,22 @@ public function findOneBy(array $criteria, array $orderBy = null)
*
* @return int The cardinality of the objects that match the given criteria.
*/
public function count(array $criteria)
public function count(array $criteria = []): int
{
return $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->_entityName)->count($criteria);
return $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->getEntityName())->count($criteria);
}

/**
* Select all elements from a selectable that match the expression and
* return a new collection containing these elements.
*
* @param \Doctrine\Common\Collections\Criteria $criteria
* @param Criteria $criteria
*
* @return \Doctrine\Common\Collections\Collection
* @return AbstractLazyCollection&Selectable
*/
public function matching(Criteria $criteria)
public function matching(Criteria $criteria): AbstractLazyCollection&Selectable
{
$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->_entityName);

$persister = $this->getEntityManager()->getUnitOfWork()->getEntityPersister($this->getEntityName());
return new LazyCriteriaCollection($persister, $criteria);
}
}
19 changes: 11 additions & 8 deletions app/Repositories/DoctrineUserExceptionTrailRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* limitations under the License.
**/
use App\libs\Auth\Repositories\IUserExceptionTrailRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Query\Parameter;
use Models\UserExceptionTrail;
/**
* Class DoctrineUserExceptionTrailRepository
Expand All @@ -37,21 +39,22 @@ protected function getBaseEntity()
*/
public function getCountByIPTypeOfLatestUserExceptions(string $ip, string $type, int $minutes_without_ex): int
{

return $this->getEntityManager()
->createQueryBuilder()
->select("count(e.id)")
->from($this->getBaseEntity(), "e")
->where("e.from_ip = :ip")
->andWhere("e.exception_type = :exception_type")
->andWhere("DATESUB(UTC_TIMESTAMP(), :minutes, 'MINUTE') < e.created_at")
->setParameters(
[
'ip' => trim($ip),
'exception_type' => trim($type),
'minutes' => $minutes_without_ex,
]
->setParameters(new ArrayCollection(
[
new Parameter('ip', trim($ip)),
new Parameter('exception_type', trim($type)),
new Parameter('minutes', $minutes_without_ex)
]
)
)
->getQuery()->getSingleScalarResult();
->getQuery()
->getSingleScalarResult();
}
}
16 changes: 8 additions & 8 deletions app/libs/Utils/Doctrine/EscapingQuoteStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EscapingQuoteStrategy implements QuoteStrategy
/**
* {@inheritdoc}
*/
public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform)
public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform): string
{
if (isset($class->fieldMappings[$fieldName]['quoted'])) {
return $platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName']);
Expand All @@ -42,7 +42,7 @@ public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform
/**
* {@inheritdoc}
*/
public function getTableName(ClassMetadata $class, AbstractPlatform $platform)
public function getTableName(ClassMetadata $class, AbstractPlatform $platform): string
{
if (isset($class->table['quoted'])) {
return $platform->quoteIdentifier($class->table['name']);
Expand All @@ -58,7 +58,7 @@ public function getTableName(ClassMetadata $class, AbstractPlatform $platform)
/**
* {@inheritdoc}
*/
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform)
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string
{
if (isset($definition['quoted'])) {
return $platform->quoteIdentifier($class->table['name']);
Expand All @@ -74,7 +74,7 @@ public function getSequenceName(array $definition, ClassMetadata $class, Abstrac
/**
* {@inheritdoc}
*/
public function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
public function getJoinColumnName(array|\Doctrine\ORM\Mapping\JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
{
if (isset($joinColumn['quoted'])) {
return $platform->quoteIdentifier($joinColumn['name']);
Expand All @@ -90,7 +90,7 @@ public function getJoinColumnName(array $joinColumn, ClassMetadata $class, Abstr
/**
* {@inheritdoc}
*/
public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform)
public function getReferencedJoinColumnName(array|\Doctrine\ORM\Mapping\JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
{
if (isset($joinColumn['quoted'])) {
return $platform->quoteIdentifier($joinColumn['referencedColumnName']);
Expand All @@ -106,7 +106,7 @@ public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $cl
/**
* {@inheritdoc}
*/
public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform)
public function getJoinTableName(array|\Doctrine\ORM\Mapping\ManyToManyOwningSideMapping $association, ClassMetadata $class, AbstractPlatform $platform): string
{
if (isset($association['joinTable']['quoted'])) {
return $platform->quoteIdentifier($association['joinTable']['name']);
Expand All @@ -122,7 +122,7 @@ public function getJoinTableName(array $association, ClassMetadata $class, Abstr
/**
* {@inheritdoc}
*/
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform)
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform): array
{
$quotedColumnNames = array();

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