abstract class Repository extends EntityRepository implements RepositoryInterface (View source)

The Flow default Repository, based on Doctrine 2

Properties

protected PersistenceManagerInterface $persistenceManager
protected EntityManagerInterface $entityManager
protected class-string $objectType

Warning: if you think you want to set this, look at RepositoryInterface::ENTITY_CLASSNAME first!

protected array $defaultOrderings

Methods

__construct(EntityManagerInterface $entityManager, ClassMetadata $classMetadata = null)

Initializes a new Repository.

string
getEntityClassName()

Returns the classname of the entities this repository is managing.

void
add(object $object)

Adds an object to this repository.

void
remove(object $object)

Removes an object from this repository.

findAll()

Finds all entities in the repository.

IterableResult
findAllIterator()

Find all objects and return an IterableResult

Generator|null
iterate(IterableResult $iterator, callable $callback = null)

Iterate over an IterableResult and return a Generator

object|null
findByIdentifier(mixed $identifier)

Finds an object matching the given identifier.

createQuery()

Returns a query for objects of this repository

Query
createDqlQuery(string $dqlString)

Creates a DQL query from the given query string

int
countAll()

Counts all objects of this repository

void
removeAll()

Removes all objects of this repository as if remove() was called for all of them.

void
setDefaultOrderings(array $defaultOrderings)

Sets the property names to order results by. Expected like this: array( 'foo' => \Neos\Flow\Persistence\QueryInterface::ORDER_ASCENDING, 'bar' => \Neos\Flow\Persistence\QueryInterface::ORDER_DESCENDING )

void
update(object $object)

Schedules a modified object for persistence.

mixed
__call(string $method, array $arguments)

Magic call method for repository methods.

Details

__construct(EntityManagerInterface $entityManager, ClassMetadata $classMetadata = null)

Initializes a new Repository.

Parameters

EntityManagerInterface $entityManager

The EntityManager to use.

ClassMetadata $classMetadata

The class descriptor.

string getEntityClassName()

Returns the classname of the entities this repository is managing.

Return Value

string

void add(object $object)

Adds an object to this repository.

Parameters

object $object

The object to add

Return Value

void

Exceptions

IllegalObjectTypeException
ORMException

void remove(object $object)

Removes an object from this repository.

Parameters

object $object

The object to remove

Return Value

void

Exceptions

IllegalObjectTypeException
ORMException

QueryResultInterface findAll()

Finds all entities in the repository.

Return Value

QueryResultInterface

The query result

IterableResult findAllIterator()

Find all objects and return an IterableResult

Return Value

IterableResult

Generator|null iterate(IterableResult $iterator, callable $callback = null)

Iterate over an IterableResult and return a Generator

This method is useful for batch processing a huge result set.

Parameters

IterableResult $iterator
callable $callback

Return Value

Generator|null

object|null findByIdentifier(mixed $identifier)

Finds an object matching the given identifier.

Parameters

mixed $identifier

The identifier of the object to find

Return Value

object|null

The matching object if found, otherwise NULL

Exceptions

ORMException
OptimisticLockException
TransactionRequiredException

QueryInterface createQuery()

Returns a query for objects of this repository

Return Value

QueryInterface

Query createDqlQuery(string $dqlString)

Creates a DQL query from the given query string

Parameters

string $dqlString

The query string

Return Value

Query

The DQL query object

int countAll()

Counts all objects of this repository

void removeAll()

Removes all objects of this repository as if remove() was called for all of them.

maybe use DQL here, would be much more performant

Return Value

void

Exceptions

IllegalObjectTypeException
ORMException

void setDefaultOrderings(array $defaultOrderings)

Sets the property names to order results by. Expected like this: array( 'foo' => \Neos\Flow\Persistence\QueryInterface::ORDER_ASCENDING, 'bar' => \Neos\Flow\Persistence\QueryInterface::ORDER_DESCENDING )

Parameters

array $defaultOrderings

The property names to order by by default

Return Value

void

void update(object $object)

Schedules a modified object for persistence.

Parameters

object $object

The modified object

Return Value

void

Exceptions

IllegalObjectTypeException
UnknownObjectException

mixed __call(string $method, array $arguments)

Magic call method for repository methods.

Provides three methods

  • findBy($value, $caseSensitive = true, $cacheResult = false)
  • findOneBy($value, $caseSensitive = true, $cacheResult = false)
  • countBy($value, $caseSensitive = true)

Parameters

string $method

Name of the method

array $arguments

The arguments

Return Value

mixed

The result of the repository method