-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Doctrine ORM #33127
Closed
Closed
Introduce Doctrine ORM #33127
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e255b4b
Introduce Doctrine ORM
CarlSchwan 3ea693b
fixup! Introduce Doctrine ORM
CarlSchwan 1b9768b
fixup! Introduce Doctrine ORM
CarlSchwan 0971a9e
fixup! Introduce Doctrine ORM
CarlSchwan f2e5d72
fixup! Introduce Doctrine ORM
CarlSchwan 46012f1
Update dependencies
CarlSchwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace OC\DB\ORM; | ||
|
||
use Doctrine\Common\EventManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\EntityRepository; | ||
use Doctrine\ORM\ORMSetup; | ||
use OC\DB\ConnectionAdapter; | ||
use OCP\DB\ORM\IQuery; | ||
use OCP\DB\ORM\IEntityManager; | ||
use OCP\DB\ORM\IEntityRepository; | ||
use OCP\IDBConnection; | ||
|
||
class EntityManagerAdapter implements IEntityManager { | ||
|
||
private EntityManager $em; | ||
private ConnectionAdapter $connection; | ||
|
||
public function __construct(ConnectionAdapter $connection) { | ||
$paths = array_filter(array_map(fn ($appId) => \OC_App::getAppPath($appId) . '/lib/Entity/', \OC_App::getEnabledApps()), fn ($path) => is_dir($path)); | ||
$isDevMode = true; | ||
$proxyDir = null; | ||
$cache = null; | ||
|
||
|
||
$evm = $connection->getInner()->getEventManager(); | ||
$tablePrefix = new TablePrefix('oc_'); | ||
|
||
$evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); | ||
// TODO actually use our cache with a psr6 cache wrapper or at least our cache config | ||
$config = ORMSetup::createAnnotationMetadataConfiguration($paths, $isDevMode, $proxyDir, $cache); | ||
|
||
$this->em = EntityManager::create($connection->getInner(), $config, $evm); | ||
$this->connection = $connection; | ||
} | ||
|
||
public function createQueryBuilder(): IQueryBuilder { | ||
return new QueryBuilderAdapter($this->em->createQueryBuilder()); | ||
} | ||
|
||
public function createQuery($dql = ''): IQuery | ||
{ | ||
return new QueryAdapter($this->em->createQuery($dql)); | ||
} | ||
|
||
public function flush(): void { | ||
$this->em->flush(); | ||
} | ||
|
||
public function find(string $className, $id, ?int $lockMode = null, ?int $lockVersion = null): ?object { | ||
return $this->em->find($className, $id, $lockMode, $lockVersion); | ||
} | ||
|
||
public function clear(): void { | ||
$this->em->clear(); | ||
} | ||
|
||
public function persist(object $entity): void { | ||
$this->em->persist($entity); | ||
} | ||
|
||
public function remove(object $entity): void { | ||
$this->em->remove($entity); | ||
} | ||
|
||
public function lock(object $entity, int $lockMode, $lockVersion = null): void { | ||
$this->em->lock($entity, $lockMode, $lockVersion); | ||
} | ||
|
||
public function getRepository($className): IEntityRepository { | ||
/** @var EntityRepository $internalRepo */ | ||
$internalRepo = $this->em->getRepository($className); | ||
return new EntityRepositoryAdapter($internalRepo); | ||
} | ||
|
||
public function contains(object $entity): bool { | ||
return $this->em->contains($entity); | ||
} | ||
|
||
public function getConnection(): IDBConnection { | ||
return $this->connection; | ||
} | ||
|
||
/** | ||
* Only for internal use | ||
*/ | ||
public function get(): EntityManager { | ||
return $this->em; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace OC\DB\ORM; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use OCP\DB\ORM\IEntityRepository; | ||
|
||
class EntityRepositoryAdapter implements IEntityRepository | ||
{ | ||
private EntityRepository $entityRepository; | ||
|
||
public function __construct(EntityRepository $entityRepository) { | ||
$this->entityRepository = $entityRepository; | ||
} | ||
|
||
public function find($id): ?object { | ||
return $this->entityRepository->find($id); | ||
} | ||
|
||
public function findAll(): array { | ||
return $this->entityRepository->findAll(); | ||
} | ||
|
||
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array { | ||
return $this->entityRepository->findBy($criteria, $orderBy, $limit, $offset); | ||
} | ||
|
||
public function findOneBy(array $criteria): ?object { | ||
return $this->entityRepository->findOneBy($criteria); | ||
} | ||
|
||
public function getClassName(): string { | ||
return $this->entityRepository->getClassName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
// SPDX-FileCopyrightText: Carl Schwan <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
namespace OC\DB\ORM; | ||
|
||
use Doctrine\Common\EventManager; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\EntityRepository; | ||
use Doctrine\ORM\ORMSetup; | ||
use Doctrine\ORM\Query\Expr; | ||
use OC\DB\ConnectionAdapter; | ||
use OCP\DB\ORM\Query\IExpression; | ||
use OCP\IDBConnection; | ||
|
||
class ExpressionAdapter implements IExpression { | ||
private Expr $expr; | ||
|
||
public function __construct(Expr $expr) { | ||
$this->expr = $expr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace OC\DB\ORM; | ||
|
||
use Doctrine\ORM\Query\Parameter; | ||
use OCP\DB\ORM\IParameter; | ||
|
||
class ParameterAdapter implements IParameter { | ||
private Parameter $parameter; | ||
|
||
public function __construct(Parameter $parameter) { | ||
$this->parameter = $parameter; | ||
} | ||
|
||
public function getName(): string { | ||
return $this->parameter->getName(); | ||
} | ||
|
||
public function getValue() { | ||
return $this->parameter->getValue(); | ||
} | ||
|
||
public function getType() { | ||
return $this->parameter->getType(); | ||
} | ||
|
||
public function setValue($value, $type = null): void { | ||
$this->parameter->setValue($value, $type); | ||
} | ||
|
||
public function typeWasSpecified(): bool { | ||
return $this->parameter->typeWasSpecified(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace OC\DB\ORM; | ||
|
||
use OCP\ICache; | ||
use Psr\Cache\CacheItemInterface; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
class CacheItemAdapter implements CacheItemInterface { | ||
private ICache $cacheAdapter; | ||
private string $key; | ||
private $value; | ||
private bool $fetched = false; | ||
private ?\DateTime $_expireAt = null; | ||
private int $_expireAfter = -1; | ||
|
||
public function __construct(ICache $cache, $key) { | ||
$this->cache = $cache; | ||
$this->key = $key; | ||
} | ||
|
||
private function fetch(): void { | ||
if (!$this->fetched) { | ||
$this->value = $this->cache->get($this->key); | ||
$this->fetched = true; | ||
} | ||
} | ||
|
||
public function getKey() { | ||
return $this->key; | ||
} | ||
|
||
public function get() { | ||
$this->fetch(); | ||
return $this->value; | ||
} | ||
|
||
public function isHit() { | ||
$this->fetch(); | ||
return $this->value !== null; | ||
} | ||
|
||
public function set($value) { | ||
$this->value = $value; | ||
} | ||
|
||
public function expiresAt($expiration) { | ||
$this->_expireAt = $expiration; | ||
} | ||
|
||
public function expiresAfter($time) { | ||
$this->_expireAfter = $time; | ||
} | ||
|
||
public function getExpireAt(): ?\DateTime | ||
{ | ||
return $this->_expireAt; | ||
} | ||
|
||
public function getExpireAfter(): int | ||
{ | ||
return $this->_expireAfter; | ||
} | ||
} | ||
|
||
class Psr6CacheAdapter implements CacheItemPoolInterface { | ||
private ICache $cache; | ||
|
||
public function __construct(ICache $cache) { | ||
$this->cache = $cache; | ||
} | ||
|
||
public function getItem($key) { | ||
return new CacheItemAdapter($this->cache, $key); | ||
} | ||
|
||
public function getItems(array $keys = array()) { | ||
for (int ) | ||
// TODO: Implement getItems() method. | ||
} | ||
|
||
public function hasItem($key) | ||
{ | ||
// TODO: Implement hasItem() method. | ||
} | ||
|
||
public function clear() | ||
{ | ||
// TODO: Implement clear() method. | ||
} | ||
|
||
public function deleteItem($key) | ||
{ | ||
// TODO: Implement deleteItem() method. | ||
} | ||
|
||
public function deleteItems(array $keys) | ||
{ | ||
// TODO: Implement deleteItems() method. | ||
} | ||
|
||
public function save(CacheItemInterface $item) | ||
{ | ||
// TODO: Implement save() method. | ||
} | ||
|
||
public function saveDeferred(CacheItemInterface $item) | ||
{ | ||
// TODO: Implement saveDeferred() method. | ||
} | ||
|
||
public function commit() | ||
{ | ||
// TODO: Implement commit() method. | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO finish