本文整理汇总了PHP中EntityRepository::find方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityRepository::find方法的具体用法?PHP EntityRepository::find怎么用?PHP EntityRepository::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityRepository
的用法示例。
在下文中一共展示了EntityRepository::find方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showEntityNameAction
/**
* @param int $id
*
* @return Entity
*
* @throws \Exception
*/
public function showEntityNameAction($id)
{
if ($entity = $this->entityRepository->find($id)) {
return $entity->getName();
}
throw new \Exception();
}
示例2: writeItem
/**
* {@inheritdoc}
*/
public function writeItem(array $item)
{
$this->counter++;
$entity = null;
// If the table was not truncated to begin with, find current entities
// first
if (false === $this->truncate) {
if ($this->index) {
// If the table has a composite key
if (!empty($this->compositeKey) && is_array($this->compositeKey)) {
$composite = '';
foreach ($this->compositeKey as $key => $index) {
$composite .= $item[$index];
}
$value = $composite;
} else {
$value = $item[$this->index];
}
$entity = $this->entityRepository->findOneBy(array($this->index => $value));
} else {
$entity = $this->entityRepository->find(current($item));
}
}
if (!$entity) {
$entity = $this->getNewInstance();
}
$fieldNames = array_merge($this->entityMetadata->getFieldNames(), $this->entityMetadata->getAssociationNames());
foreach ($fieldNames as $fieldName) {
$value = null;
if (isset($item[$fieldName])) {
$value = $item[$fieldName];
} elseif (method_exists($item, 'get' . ucfirst($fieldName))) {
$value = $item->{'get' . ucfirst($fieldName)};
}
if (null === $value) {
continue;
}
if (!$value instanceof \DateTime || $value != $this->entityMetadata->getFieldValue($entity, $fieldName)) {
$setter = 'set' . ucfirst($fieldName);
$this->setValue($entity, $value, $setter);
}
}
$this->entityManager->persist($entity);
if ($this->counter % $this->batchSize == 0) {
$this->entityManager->flush();
$this->entityManager->clear($this->entityName);
}
return $this;
}
示例3: findOrCreateItem
/**
* Finds existing entity or create a new instance
*/
protected function findOrCreateItem(array $item)
{
$entity = null;
// If the table was not truncated to begin with, find current entity
// first
if (false === $this->truncate) {
if ($this->lookupFields) {
$lookupConditions = array();
foreach ($this->lookupFields as $fieldName) {
$lookupConditions[$fieldName] = $item[$fieldName];
}
$entity = $this->entityRepository->findOneBy($lookupConditions);
} else {
$entity = $this->entityRepository->find(current($item));
}
}
if (!$entity) {
return $this->getNewInstance();
}
return $entity;
}
示例4: find
/**
* {@inheritDoc}
*/
public function find($id)
{
return $this->entityRepository->find($id);
}
示例5: findCommentById
/**
* Find one comment by its ID
*
* @return Comment or null
**/
public function findCommentById($id)
{
return $this->repository->find($id);
}
示例6: getEvent
/**
* Get the CalendarEvent entity.
*
* @param integer $id
* @return CalendarEventInterface
*/
public function getEvent($id)
{
return $this->repository->find($id);
}
示例7: findInvoiceById
/**
* {@inheritDoc}
*/
public function findInvoiceById($id)
{
return $this->repository->find($id);
}
示例8: findOrder
/**
* {@inheritdoc}
*/
public function findOrder($id)
{
return $this->repository->find($id);
}