Skip to content

Instantly share code, notes, and snippets.

@Majkl578
Created June 27, 2017 02:21
Show Gist options
  • Save Majkl578/9eb51ca704091074c603a732f61f5011 to your computer and use it in GitHub Desktop.
Save Majkl578/9eb51ca704091074c603a732f61f5011 to your computer and use it in GitHub Desktop.
EntityManagerInterface @ PHP 7.2
19a20,21
> declare(strict_types=1);
>
21a24
> use Doctrine\Common\EventManager;
22a26,31
> use Doctrine\DBAL\Connection;
> use Doctrine\ORM\Cache;
> use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
> use Doctrine\ORM\Proxy\ProxyFactory;
> use Doctrine\ORM\Query\Expr;
> use Doctrine\ORM\Query\FilterCollection;
25,32d33
< /**
< * EntityManager interface
< *
< * @since 2.4
< * @author Lars Strojny <[email protected]>
< *
< * @method Mapping\ClassMetadata getClassMetadata($className)
< */
37,38d37
< *
< * @return \Doctrine\ORM\Cache|null
40c39
< public function getCache();
---
> public function getCache(): ?Cache;
44,45d42
< *
< * @return \Doctrine\DBAL\Connection
47c44
< public function getConnection();
---
> public function getConnection(): Connection;
60,61d56
< *
< * @return \Doctrine\ORM\Query\Expr
63c58
< public function getExpressionBuilder();
---
> public function getExpressionBuilder(): Expr;
67,68d61
< *
< * @return void
70c63
< public function beginTransaction();
---
> public function beginTransaction(): void;
86c79
< public function transactional($func);
---
> public function transactional(callable $func);
90,91d82
< *
< * @return void
93c84
< public function commit();
---
> public function commit(): void;
97,98d87
< *
< * @return void
100c89
< public function rollback();
---
> public function rollback(): void;
104,107d92
< *
< * @param string $dql The DQL string.
< *
< * @return Query
109c94
< public function createQuery($dql = '');
---
> public function createQuery(string $dql = ''): Query;
113,116d97
< *
< * @param string $name
< *
< * @return Query
118c99
< public function createNamedQuery($name);
---
> public function createNamedQuery(string $name): Query;
122,126d102
< *
< * @param string $sql
< * @param ResultSetMapping $rsm The ResultSetMapping to use.
< *
< * @return NativeQuery
128c104
< public function createNativeQuery($sql, ResultSetMapping $rsm);
---
> public function createNativeQuery(string $sql, ResultSetMapping $rsm): NativeQuery;
157c133
< public function getReference($entityName, $id);
---
> public function getReference(string $entityName, $id): object;
179c155
< public function getPartialReference($entityName, $identifier);
---
> public function getPartialReference(string $entityName, $identifier): object;
188c164
< public function close();
---
> public function close(): void;
200c176
< public function copy($entity, $deep = false);
---
> public function copy(string $entity, bool $deep = false): object;
205,210d180
< * @param object $entity
< * @param int $lockMode
< * @param int|null $lockVersion
< *
< * @return void
< *
214c184
< public function lock($entity, $lockMode, $lockVersion = null);
---
> public function lock(object $entity, int $lockMode, ?int $lockVersion = null): void;
218,219d187
< *
< * @return \Doctrine\Common\EventManager
221c189
< public function getEventManager();
---
> public function getEventManager(): EventManager;
225,226d192
< *
< * @return Configuration
228c194
< public function getConfiguration();
---
> public function getConfiguration(): Configuration;
232,233d197
< *
< * @return bool
235c199
< public function isOpen();
---
> public function isOpen(): bool;
239,240d202
< *
< * @return UnitOfWork
242,256c204
< public function getUnitOfWork();
<
< /**
< * Gets a hydrator for the given hydration mode.
< *
< * This method caches the hydrator instances which is used for all queries that don't
< * selectively iterate over the result.
< *
< * @deprecated
< *
< * @param int $hydrationMode
< *
< * @return \Doctrine\ORM\Internal\Hydration\AbstractHydrator
< */
< public function getHydrator($hydrationMode);
---
> public function getUnitOfWork(): UnitOfWork;
261,264d208
< * @param int $hydrationMode
< *
< * @return \Doctrine\ORM\Internal\Hydration\AbstractHydrator
< *
267c211
< public function newHydrator($hydrationMode);
---
> public function newHydrator(int $hydrationMode): AbstractHydrator;
271,272d214
< *
< * @return \Doctrine\ORM\Proxy\ProxyFactory
274c216
< public function getProxyFactory();
---
> public function getProxyFactory(): ProxyFactory;
279c221
< * @return \Doctrine\ORM\Query\FilterCollection The active filter collection.
---
> * @return FilterCollection The active filter collection.
281c223
< public function getFilters();
---
> public function getFilters(): FilterCollection;
286c228
< * @return boolean True, if the filter collection is clean.
---
> * @return bool True, if the filter collection is clean.
288c230
< public function isFiltersStateClean();
---
> public function isFiltersStateClean(): bool;
293c235
< * @return boolean True, if the EM has a filter collection.
---
> * @return bool True, if the EM has a filter collection.
295c237
< public function hasFilters();
---
> public function hasFilters(): bool;
296a239
>
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
declare(strict_types=1);
namespace Doctrine\ORM;
use Doctrine\Common\EventManager;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Cache;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\FilterCollection;
use Doctrine\ORM\Query\ResultSetMapping;
interface EntityManagerInterface extends ObjectManager
{
/**
* Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.
*/
public function getCache(): ?Cache;
/**
* Gets the database connection object used by the EntityManager.
*/
public function getConnection(): Connection;
/**
* Gets an ExpressionBuilder used for object-oriented construction of query expressions.
*
* Example:
*
* <code>
* $qb = $em->createQueryBuilder();
* $expr = $em->getExpressionBuilder();
* $qb->select('u')->from('User', 'u')
* ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));
* </code>
*/
public function getExpressionBuilder(): Expr;
/**
* Starts a transaction on the underlying database connection.
*/
public function beginTransaction(): void;
/**
* Executes a function in a transaction.
*
* The function gets passed this EntityManager instance as an (optional) parameter.
*
* {@link flush} is invoked prior to transaction commit.
*
* If an exception occurs during execution of the function or flushing or transaction commit,
* the transaction is rolled back, the EntityManager closed and the exception re-thrown.
*
* @param callable $func The function to execute transactionally.
*
* @return mixed The non-empty value returned from the closure or true instead.
*/
public function transactional(callable $func);
/**
* Commits a transaction on the underlying database connection.
*/
public function commit(): void;
/**
* Performs a rollback on the underlying database connection.
*/
public function rollback(): void;
/**
* Creates a new Query object.
*/
public function createQuery(string $dql = ''): Query;
/**
* Creates a Query from a named query.
*/
public function createNamedQuery(string $name): Query;
/**
* Creates a native SQL query.
*/
public function createNativeQuery(string $sql, ResultSetMapping $rsm): NativeQuery;
/**
* Creates a NativeQuery from a named native query.
*
* @param string $name
*
* @return NativeQuery
*/
public function createNamedNativeQuery($name);
/**
* Create a QueryBuilder instance
*
* @return QueryBuilder
*/
public function createQueryBuilder();
/**
* Gets a reference to the entity identified by the given type and identifier
* without actually loading it, if the entity is not yet loaded.
*
* @param string $entityName The name of the entity type.
* @param mixed $id The entity identifier.
*
* @return object The entity reference.
*
* @throws ORMException
*/
public function getReference(string $entityName, $id): object;
/**
* Gets a partial reference to the entity identified by the given type and identifier
* without actually loading it, if the entity is not yet loaded.
*
* The returned reference may be a partial object if the entity is not yet loaded/managed.
* If it is a partial object it will not initialize the rest of the entity state on access.
* Thus you can only ever safely access the identifier of an entity obtained through
* this method.
*
* The use-cases for partial references involve maintaining bidirectional associations
* without loading one side of the association or to update an entity without loading it.
* Note, however, that in the latter case the original (persistent) entity data will
* never be visible to the application (especially not event listeners) as it will
* never be loaded in the first place.
*
* @param string $entityName The name of the entity type.
* @param mixed $identifier The entity identifier.
*
* @return object The (partial) entity reference.
*/
public function getPartialReference(string $entityName, $identifier): object;
/**
* Closes the EntityManager. All entities that are currently managed
* by this EntityManager become detached. The EntityManager may no longer
* be used after it is closed.
*
* @return void
*/
public function close(): void;
/**
* Creates a copy of the given entity. Can create a shallow or a deep copy.
*
* @param object $entity The entity to copy.
* @param boolean $deep FALSE for a shallow copy, TRUE for a deep copy.
*
* @return object The new entity.
*
* @throws \BadMethodCallException
*/
public function copy(string $entity, bool $deep = false): object;
/**
* Acquire a lock on the given entity.
*
* @throws OptimisticLockException
* @throws PessimisticLockException
*/
public function lock(object $entity, int $lockMode, ?int $lockVersion = null): void;
/**
* Gets the EventManager used by the EntityManager.
*/
public function getEventManager(): EventManager;
/**
* Gets the Configuration used by the EntityManager.
*/
public function getConfiguration(): Configuration;
/**
* Check if the Entity manager is open or closed.
*/
public function isOpen(): bool;
/**
* Gets the UnitOfWork used by the EntityManager to coordinate operations.
*/
public function getUnitOfWork(): UnitOfWork;
/**
* Create a new instance for the given hydration mode.
*
* @throws ORMException
*/
public function newHydrator(int $hydrationMode): AbstractHydrator;
/**
* Gets the proxy factory used by the EntityManager to create entity proxies.
*/
public function getProxyFactory(): ProxyFactory;
/**
* Gets the enabled filters.
*
* @return FilterCollection The active filter collection.
*/
public function getFilters(): FilterCollection;
/**
* Checks whether the state of the filter collection is clean.
*
* @return bool True, if the filter collection is clean.
*/
public function isFiltersStateClean(): bool;
/**
* Checks whether the Entity Manager has filters.
*
* @return bool True, if the EM has a filter collection.
*/
public function hasFilters(): bool;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment