Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! Introduce Doctrine ORM
  • Loading branch information
CarlSchwan committed Aug 24, 2022
commit 3ea693bf5db0fe3a908ee284f3db5a3d377e0663
20 changes: 20 additions & 0 deletions lib/private/DB/ORM/EntityRepositoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,24 @@ class EntityRepositoryAdapter implements IEntityRepository
public function __construct(EntityRepository $entityRepository) {
$this->entityRepository = $entityRepository;
}

public function find($id) {
return $this->entityRepository->find($id);
}

public function findAll() {
return $this->entityRepository->findAll();
}

public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null) {
return $this->entityRepository->findBy($criteria, $orderBy, $limit, $offset);
}

public function findOneBy(array $criteria) {
return $this->entityRepository->findOneBy($criteria);
}

public function getClassName() {
return $this->entityRepository->getClassName();
}
}
61 changes: 61 additions & 0 deletions lib/public/DB/ORM/IEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,68 @@

namespace OCP\DB\ORM;

/**
* Contract for a Doctrine persistence layer ObjectRepository class to implement.
*
* @template-covariant T of object
*/
interface IEntityRepository
{
/**
* Finds an object by its primary key / identifier.
*
* @param mixed $id The identifier.
*
* @return object|null The object.
* @psalm-return T|null
*/
public function find($id);

/**
* Finds all objects in the repository.
*
* @return array<int, object> The objects.
* @psalm-return T[]
*/
public function findAll();

/**
* Finds objects by a set of criteria.
*
* Optionally sorting and limiting details can be passed. An implementation may throw
* an UnexpectedValueException if certain values of the sorting or limiting details are
* not supported.
*
* @param array<string, mixed> $criteria
* @param array<string, string>|null $orderBy
* @psalm-param array<string, 'asc'|'desc'|'ASC'|'DESC'>|null $orderBy
*
* @return array<int, object> The objects.
* @psalm-return T[]
*
* @throws \RuntimeException
*/
public function findBy(
array $criteria,
?array $orderBy = null,
?int $limit = null,
?int $offset = null
);

/**
* Finds a single object by a set of criteria.
*
* @param array<string, mixed> $criteria The criteria.
*
* @return object|null The object.
* @psalm-return T|null
*/
public function findOneBy(array $criteria);

/**
* Returns the class name of the object managed by the repository.
*
* @psalm-return class-string<T>
*/
public function getClassName();
}
37 changes: 37 additions & 0 deletions lib/public/DB/ORM/IParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace OCP\DB\ORM;

interface IParameter {

/**
* Retrieves the Parameter name.
*/
public function getName(): string

/**
* Retrieves the Parameter value.
*
* @return mixed
*/
public function getValue();

/**
* Retrieves the Parameter type.
*
* @return mixed
*/
public function getType();

/**
* Defines the Parameter value.
*
* @param mixed $value Parameter value.
* @param mixed $type Parameter type.
*
* @return void
*/
public function setValue($value, $type = null): void

public function typeWasSpecified(): bool;
}
53 changes: 51 additions & 2 deletions lib/public/DB/ORM/IQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,56 @@

namespace OCP\DB\ORM;

interface IQuery
{
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\Query\Parameter;

interface IQuery {
/**
* Enable/disable second level query (result) caching for this query.
*/
public function setCacheable(bool $cacheable): self;

/**
* @return bool TRUE if the query results are enabled for second level cache, FALSE otherwise.
*/
public function isCacheable(): bool;

/**
* Gets a query parameter.
*
* @param string|int $key The key (index or name) of the bound parameter.
*
* @return IParameter|null The value of the bound parameter, or NULL if not available.
*/
public function getParameter($key): ?IParameter;

/**
* Sets a collection of query parameters.
*
* @param mixed[] $parameters
* @psalm-param mixed[] $parameters
*/
public function setParameters($parameters): self;

/**
* Sets a query parameter.
*
* @param string|int $key The parameter position or name.
* @param mixed $value The parameter value.
* @param string|int|null $type The parameter type. If specified, the given value will be run through
* the type conversion of this type. This is usually not needed for
* strings and numeric types.
*/
public function setParameter($key, $value, $type = null): self;

public function setMaxResults(): self;

/**
* Gets the list of results for the query.
*
* @return mixed
*/
public function getResult();

}