本文整理汇总了PHP中Doctrine\ORM\EntityManagerInterface::getRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::getRepository方法的具体用法?PHP EntityManagerInterface::getRepository怎么用?PHP EntityManagerInterface::getRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::getRepository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLabel
/**
* @param RuleAction $action
* @return string
*/
public function getLabel(RuleAction $action)
{
$params = $this->getParams($action);
$repo = $this->entityManager->getRepository('HomefinanceBundle:Category');
$category = $repo->findOneBy(array('id' => $params['category_id']));
return $this->translator->trans('rules.actions.set_category.label', array('%category%' => $category->getTitle()), 'rules');
}
示例2: __construct
/**
* @param EntityManagerInterface $entityManager
*/
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
$this->nextPrimaryKeyRepository = $this->entityManager->getRepository('Sinergi\\Sage50\\NextPrimaryKey\\NextPrimaryKeyEntity');
$this->journalEntryRepository = $this->entityManager->getRepository('Sinergi\\Sage50\\JournalEntry\\JournalEntryEntity');
$this->locationInventoryRepository = $this->entityManager->getRepository('Sinergi\\Sage50\\LocationInventory\\LocationInventoryEntity');
}
示例3: getRepository
/**
* {@inheritdoc}
*/
public function getRepository($entity = null)
{
if ($entity === null) {
return $this->em->getRepository($this->getEntityName());
}
return $this->em->getRepository($entity);
}
示例4: down
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$rep = $this->em->getRepository('AnimeDbCatalogBundle:Genre');
foreach (array_keys($this->genres) as $en) {
$this->em->remove($rep->findOneBy(['name' => $en]));
}
}
示例5: getMassActions
/**
* {@inheritdoc}
*/
public function getMassActions()
{
$archiveAction = new MassAction('Archive', function ($ids) {
/** @var InvoiceRepository $invoiceRepository */
$invoiceRepository = $this->entityManager->getRepository('CSBillInvoiceBundle:Invoice');
/** @var Invoice[] $invoices */
$invoices = $invoiceRepository->findBy(array('id' => $ids));
/** @var FlashBag $flashBag */
$flashBag = $this->session->getBag('flashes');
$failed = 0;
foreach ($invoices as $invoice) {
try {
$this->invoiceManager->archive($invoice);
} catch (InvalidTransitionException $e) {
$flashBag->add('warning', $e->getMessage());
++$failed;
}
}
if ($failed !== count($invoices)) {
$flashBag->add('success', 'invoice.archive.success');
}
}, true);
$archiveAction->setIcon('archive');
$archiveAction->setClass('warning');
return array($archiveAction, new DeleteMassAction());
}
示例6: getItem
/**
* @param $productId
* @return bool|Product
*/
public function getItem($productId)
{
if (isset($this->cart[$productId])) {
return $this->entityManager->getRepository('ProductBundle:Product')->find($productId);
}
return false;
}
示例7: getRepository
/**
* Get repository.
*
* @return TaskEntityRepository
*/
public function getRepository()
{
if (null === $this->repository) {
$this->repository = $this->entityManager->getRepository(TaskEntity::class);
}
return $this->repository;
}
示例8: getRepository
/**
* @return \Doctrine\Common\Persistence\ObjectRepository
*/
private function getRepository()
{
if ($this->repository === null) {
$this->repository = $this->entityManager->getRepository('ItBlasterSingleConfigBundle:Config');
}
return $this->repository;
}
示例9: getOrderInfo
/**
* @return array
*/
private function getOrderInfo()
{
$order = $this->entityManager->getRepository('AppBundle:TicketsOrder')->findOneBy(array('ref' => $this->orderRef));
$orderId = $order->getId();
$isValidate = $order->isValidate();
return array($order, $orderId, $isValidate);
}
示例10: testImportExport
/**
* @medium
*/
public function testImportExport()
{
$sourceStorage = new LocalFileStorage(new \SplFileInfo(__DIR__ . '/../../../metadata/testfiles/100.csv'), new CsvFormat());
$targetStorage = new DoctrineStorage(self::$em, 'TestEntities\\Address');
$this->assertEquals(new StorageInfo(['name' => 'SELECT o FROM TestEntities\\Address o', 'count' => 0, 'type' => 'DQL Query']), $targetStorage->info());
$importer = Importer::build($targetStorage);
$importConfiguration = new ImportConfiguration();
$importRun = $importConfiguration->toRun();
$import = Import::build($importer, $sourceStorage, $importRun);
$eventDispatcher = new EventDispatcher();
$importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));
$importRunner->run($import);
$entities = self::$em->getRepository('TestEntities\\Address')->findAll();
//import worked
$this->assertEquals(100, count($entities));
$exportFile = '/tmp/doctrine_test.csv';
@unlink($exportFile);
$sourceStorage = new DoctrineStorage(self::$em, null, self::$em->createQuery("SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'"));
$this->assertEquals(new StorageInfo(['name' => "SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'", 'count' => 10, 'type' => 'DQL Query']), $sourceStorage->info());
$targetStorage = new LocalFileStorage(new \SplFileInfo($exportFile), new CsvFormat());
$importer = Importer::build($targetStorage);
$importConfiguration = new ImportConfiguration();
$importRun = $importConfiguration->toRun();
$import = Import::build($importer, $sourceStorage, $importRun);
$eventDispatcher = new EventDispatcher();
$importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));
$importRunner->run($import);
$this->assertFileExists($exportFile);
$this->assertEquals(11, count(file($exportFile)));
//+header
$this->assertEquals(10, $import->getRun()->toArray()['statistics']['processed']);
}
示例11: notify
public function notify(UrlEvent $event)
{
if (!$this->isEnabled() || !$event->getUrl() || $event->getType() !== Shortener::NOTIFY_TYPE_REDIRECT) {
return false;
}
$additional = $event->getAdditional();
$ip = !empty($additional['ip']) ? $additional['ip'] : null;
if (!$ip) {
return false;
}
$urlRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\Url');
$urlStatRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\UrlStat');
/** @var Url $url */
$url = $urlRepository->find($event->getUrl()->getId());
$url->incrementRedirectCount();
$url->setLastRedirectOn(new \DateTime());
$urlStat = $urlStatRepository->findOneBy(['Url' => $url, 'ip' => $ip]);
if (!$urlStat) {
$url->incrementUniqueRedirectCount();
$urlStat = new UrlStat();
$urlStat->setUrl($url);
$urlStat->setCreated(new \DateTime());
$urlStat->setIp($ip);
if (!empty($additional['user-agent'])) {
$urlStat->setUserAgent($additional['user-agent']);
}
$this->em->persist($urlStat);
}
$this->em->persist($url);
$this->em->flush();
return true;
}
示例12: __construct
/**
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
$this->contentRepository = $em->getRepository(ContentItem::class);
$this->taxonomyRepository = $em->getRepository(Taxonomy::class);
$this->termRepository = $em->getRepository(Term::class);
}
示例13: __construct
/**
* UserFiledsetFilter constructor.
* @param EntityManagerInterface $em
* @param null $config
*/
public function __construct(EntityManagerInterface $em, $config = null)
{
$this->add(['name' => 'id', 'required' => true, 'filters' => [['name' => 'Int']]]);
$this->add(['name' => 'username', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 5, 'max' => 100]], ['name' => 'DoctrineModule\\Validator\\UniqueObject', 'options' => ['use_context' => true, 'object_manager' => $em, 'object_repository' => $em->getRepository($config['identityClass']), 'fields' => $config['identityProperty'], 'messages' => [UniqueObject::ERROR_OBJECT_NOT_UNIQUE => sprintf(_('The username %s already exists'), '\'%value%\'')]]]]]);
$this->add(['name' => 'email', 'required' => true, 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], 'validators' => [['name' => 'EmailAddress', 'options' => ['message' => _('Invalid email address')]], ['name' => 'DoctrineModule\\Validator\\UniqueObject', 'options' => ['use_context' => true, 'object_manager' => $em, 'object_repository' => $em->getRepository($config['identityClass']), 'fields' => $config['identityEmail'], 'messages' => [UniqueObject::ERROR_OBJECT_NOT_UNIQUE => sprintf(_('The email %s already exists'), '\'%value%\'')]]]]]);
$this->add(['name' => 'password', 'required' => true, 'filters' => [['name' => 'StringTrim'], ['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 6, 'max' => 128]]]]);
}
示例14: fetchFacebookEvents
public function fetchFacebookEvents()
{
$events = $this->em->getRepository('NFQKVKScraperBundle:EventData')->getAllEventsWithFacebookId();
foreach ($events as $eventData) {
$this->populateFacebookEvent($eventData);
}
}
示例15: updateEntity
/**
* @param $configKey
* @param $objectId
* @param $value
* @param null|string $dataField
* @throws ContentEditableException
*/
public function updateEntity($configKey, $objectId, $value, $dataField = null)
{
if (!array_key_exists($configKey, $this->configuration['configurations'])) {
throw new ContentEditableException('Missing configuration "' . $configKey . '"');
}
$config = $this->configuration['configurations'][$configKey];
if ($dataField == null) {
if (!array_key_exists('data_field', $config)) {
throw new ContentEditableException('Missing data_field');
}
$dataField = $config['data_field'];
}
$idField = 'id';
if (array_key_exists('id_field', $config)) {
$idField = $config['id_field'];
}
$repository = $this->entityManager->getRepository($config['repository_class']);
$entity = $repository->findOneBy([$idField => $objectId]);
$setter = 'set' . ucfirst($dataField);
if (!method_exists($entity, $setter)) {
throw new ContentEditableException('No setter "' . $setter . '" found for "' . get_class($entity) . '"');
}
$entity->{$setter}(trim($value));
$this->entityManager->persist($entity);
$this->entityManager->flush();
}