本文整理汇总了PHP中Symfony\Bridge\Doctrine\ManagerRegistry::getManagerForClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ManagerRegistry::getManagerForClass方法的具体用法?PHP ManagerRegistry::getManagerForClass怎么用?PHP ManagerRegistry::getManagerForClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Bridge\Doctrine\ManagerRegistry
的用法示例。
在下文中一共展示了ManagerRegistry::getManagerForClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: finishView
/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
/** @var ShoppingListRepository $shoppingListRepository */
$shoppingListRepository = $currentShoppingList = $this->registry->getManagerForClass($this->shoppingListClass)->getRepository($this->shoppingListClass);
$currentShoppingList = $shoppingListRepository->findCurrentForAccountUser($this->getAccountUser());
$view->children['shoppingList']->vars['currentShoppingList'] = $currentShoppingList;
}
示例2: getClassMetadata
/**
* Returns a metadata for the given entity
*
* @param string $className
* @return ClassMetadata
*/
protected function getClassMetadata($className)
{
if (isset($this->classMetadataLocalCache[$className])) {
return $this->classMetadataLocalCache[$className];
}
$classMetadata = $this->doctrine->getManagerForClass($className)->getClassMetadata($className);
$this->classMetadataLocalCache[$className] = $classMetadata;
return $classMetadata;
}
示例3: getFieldNameByColumnName
/**
* Gets an entity field name by entity table name and column name
*
* @param string $tableName
* @param string $columnName
* @return string|null
*/
public function getFieldNameByColumnName($tableName, $columnName)
{
$className = $this->getEntityClassByTableName($tableName);
if ($className) {
$manager = $this->doctrine->getManagerForClass($className);
if ($manager instanceof EntityManager) {
return $manager->getClassMetadata($className)->getFieldName($columnName);
}
}
return null;
}
示例4: deserializeIdCollectionFromJson
/**
* @param JsonDeserializationVisitor $visitor
* @param $data
* @param array $type
* @return ArrayCollection
*/
public function deserializeIdCollectionFromJson(JsonDeserializationVisitor $visitor, $data, array $type)
{
$collection = new ArrayCollection();
$class = $type['params'][0]['name'];
/** @var \Doctrine\Common\Persistence\ObjectRepository $repository */
$repository = $this->doctrine->getManagerForClass($class)->getRepository($class);
foreach ($data as $key => $value) {
$collection->add($repository->findOneBy(array('id' => $value)));
}
return $collection;
}
示例5: getQueryBuilder
/**
* {@inheritdoc}
*/
public function getQueryBuilder(Segment $segment)
{
$converter = new SegmentQueryConverter($this->manager, $this->virtualFieldProvider, $this->doctrine, $this->restrictionBuilder);
if ($this->virtualRelationProvider) {
$converter->setVirtualRelationProvider($this->virtualRelationProvider);
}
/** @var EntityManager $em */
$em = $this->doctrine->getManagerForClass($segment->getEntity());
$qb = $converter->convert(new RestrictionSegmentProxy($segment, $em));
return $qb;
}
示例6: getMarketingListItem
/**
* @param MarketingList $marketingList
* @param int $entityId
* @return MarketingListItem
*/
public function getMarketingListItem(MarketingList $marketingList, $entityId)
{
$marketingListItemRepository = $this->registry->getRepository(self::MARKETING_LIST_ITEM_ENTITY);
$marketingListItem = $marketingListItemRepository->findOneBy(['marketingList' => $marketingList, 'entityId' => $entityId]);
if (!$marketingListItem) {
$marketingListItem = new MarketingListItem();
$marketingListItem->setMarketingList($marketingList)->setEntityId($entityId);
$manager = $this->registry->getManagerForClass(self::MARKETING_LIST_ITEM_ENTITY);
$manager->persist($marketingListItem);
}
return $marketingListItem;
}
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$em = $this->registry->getManagerForClass($this->integrationEntityFQCN);
$formFactory = $builder->getFormFactory();
$data = $builder->create('data', 'hidden');
$data->addViewTransformer(new ArrayToJsonTransformer());
$identifier = $builder->create('identifier', 'hidden');
$identifier->addViewTransformer(new EntityToIdTransformer($em, $this->integrationEntityFQCN));
$builder->addViewTransformer(new DatasourceDataTransformer($formFactory));
$builder->add($data);
$builder->add($identifier);
$builder->add('type', 'hidden', ['data' => $options['type']]);
$builder->add('name', 'hidden');
}
示例8: processExclusions
/**
* @param object $object
* @param object|null $entity
*/
protected function processExclusions($object, $entity)
{
$class = get_class($object);
if (!$entity) {
return;
}
$reflection = new \ReflectionClass($class);
/** Backfill data that is ignored or read only from the serializer */
$metadata = $this->metadataFactory->getMetadataForClass($class);
foreach ($reflection->getProperties() as $property) {
$name = $property->getName();
if (!isset($metadata->propertyMetadata[$name]) || $metadata->propertyMetadata[$name]->readOnly) {
$property->setAccessible(true);
$property->setValue($object, $property->getValue($entity));
}
}
$em = $this->doctrine->getManagerForClass($class);
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata */
$metadata = $em->getMetadataFactory()->getMetadataFor($class);
// Look for relationships, compare against preloaded entity
foreach ($metadata->getAssociationNames() as $fieldName) {
if ($metadata->isCollectionValuedAssociation($fieldName)) {
$property = $reflection->getProperty($fieldName);
$property->setAccessible(true);
if ($property->getValue($object)) {
foreach ($property->getValue($object) as $i => $value) {
$v = $property->getValue($entity);
$this->processExclusions($value, $v[$i]);
}
}
}
}
}
示例9: getManagerForClass
/**
* Gets doctrine entity manager for the given class
*
* @param string $className
*
* @return EntityManager
* @throws InvalidEntityException
*/
protected function getManagerForClass($className)
{
$manager = null;
try {
$manager = $this->doctrine->getManagerForClass($className);
} catch (\ReflectionException $ex) {
throw new InvalidEntityException(sprintf('The "%s" entity was not found.', $className));
}
return $manager;
}
示例10: preSubmit
/**
* @param FormEvent $event
*/
public function preSubmit(FormEvent $event)
{
/** @var LineItem $lineItem */
$lineItem = $event->getForm()->getData();
$data = $event->getData();
$product = $lineItem->getProduct();
if (!$product instanceof Product && !empty($data['product'])) {
/** @var ProductRepository $repository */
$repository = $this->registry->getManagerForClass($this->productClass)->getRepository($this->productClass);
/** @var Product $product */
$product = $repository->find((int) $data['product']);
}
if (!$product || empty($data['unit']) || empty($data['quantity'])) {
return;
}
$roundedQuantity = $this->lineItemManager->roundProductQuantity($product, $data['unit'], $data['quantity']);
$data['quantity'] = $roundedQuantity;
$event->setData($data);
}
示例11: it_should_have_doctrine_data_indexer
/**
* @param \Symfony\Bridge\Doctrine\ManagerRegistry $registry
* @param \Doctrine\Common\Persistence\ObjectManager $om
* @param \Doctrine\Common\Persistence\ObjectRepository $repository
* @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
*/
public function it_should_have_doctrine_data_indexer($registry, $om, $repository, $metadata)
{
$registry->getManagerForClass('FSi/Bundle/DemoBundle/Entity/Entity')->willReturn($om);
$om->getRepository('FSiDemoBundle:Entity')->willReturn($repository);
$metadata->isMappedSuperclass = false;
$metadata->rootEntityName = 'FSi/Bundle/DemoBundle/Entity/Entity';
$om->getClassMetadata('FSi/Bundle/DemoBundle/Entity/Entity')->willReturn($metadata);
$repository->getClassName()->willReturn('FSi/Bundle/DemoBundle/Entity/Entity');
$this->setManagerRegistry($registry);
$this->getDataIndexer()->shouldReturnAnInstanceOf('FSi\\Component\\DataIndexer\\DoctrineDataIndexer');
}
示例12: isEntity
/**
* @param mixed $object
*
* @return bool
*/
private function isEntity($object)
{
$isEntity = false;
if (is_object($object)) {
$class = $object instanceof Proxy ? get_parent_class($object) : get_class($object);
if (null !== ($manager = $this->registry->getManagerForClass($class))) {
$isEntity = !$this->registry->getManager()->getMetadataFactory()->isTransient($class);
}
}
return $isEntity;
}
示例13: getClassMetadata
/**
* @param string|object $class
* @return ClassMetadata
*/
protected function getClassMetadata($class)
{
if (is_object($class)) {
$class = get_class($class);
}
if (!is_string($class)) {
throw new \InvalidArgumentException("Argument must be either string or object, got " . gettype($class));
}
$objectManager = $this->managerRegistry->getManagerForClass($class);
if (null === $objectManager) {
throw new \RuntimeException("Could not find object manager for class '{$class}'");
}
return $objectManager->getClassMetadata($class);
}
示例14: build
/**
* {inheritdoc}
*/
public function build(Segment $segment)
{
$converter = new SegmentQueryConverter($this->manager, $this->virtualFieldProvider, $this->doctrine, $this->restrictionBuilder);
$qb = $converter->convert(new RestrictionSegmentProxy($segment, $this->doctrine->getManagerForClass($segment->getEntity())));
return $qb->getQuery();
}
示例15: isEntity
/**
* Check if given class is real entity class
*
* @param string $className
* @return bool
*/
public function isEntity($className)
{
return !is_null($this->doctrine->getManagerForClass($className));
}