本文整理汇总了PHP中Doctrine\Common\Persistence\ManagerRegistry类的典型用法代码示例。如果您正苦于以下问题:PHP ManagerRegistry类的具体用法?PHP ManagerRegistry怎么用?PHP ManagerRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ManagerRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @param ConfigurationProvider $provider
* @param ManagerRegistry $registry
* @param SqlBuilder $builder
* @param MigrationFileGenerator $generator
*/
public function fire(ConfigurationProvider $provider, ManagerRegistry $registry, SqlBuilder $builder, MigrationFileGenerator $generator)
{
$configuration = $provider->getForConnection($this->option('connection'));
$em = $registry->getManager($this->option('connection'));
$connection = $configuration->getConnection();
// Overrule the filter
if ($filterExpr = $this->option('filter-expression')) {
$connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpr);
}
$fromSchema = $connection->getSchemaManager()->createSchema();
$toSchema = $this->getSchemaProvider($em)->createSchema();
// Drop tables which don't suffice to the filter regex
if ($filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression()) {
foreach ($toSchema->getTables() as $table) {
$tableName = $table->getName();
if (!preg_match($filterExpr, $this->resolveTableName($tableName))) {
$toSchema->dropTable($tableName);
}
}
}
$up = $builder->up($configuration, $fromSchema, $toSchema);
$down = $builder->down($configuration, $fromSchema, $toSchema);
if (!$up && !$down) {
return $this->error('No changes detected in your mapping information.');
}
$path = $generator->generate($configuration, false, false, $up, $down);
$this->line(sprintf('Generated new migration class to "<info>%s</info>" from schema differences.', $path));
}
示例2: __construct
/**
* @param Factory $factory
* @param SettingsManager $settings
* @param Manager $notification
* @param ManagerRegistry $doctrine
*/
public function __construct(Factory $factory, SettingsManager $settings, Manager $notification, ManagerRegistry $doctrine)
{
$this->factory = $factory;
$this->notification = $notification;
$this->settings = $settings;
$this->entityManager = $doctrine->getManager();
}
示例3: __construct
public function __construct(ManagerRegistry $managerRegistry, ContainerInterface $container, ActivityService $activityService, LocationService $locationService)
{
$this->em = $managerRegistry->getManager();
$this->container = $container;
$this->activityService = $activityService;
$this->locationService = $locationService;
}
示例4: __construct
public function __construct(ManagerRegistry $managerRegistry, Session $session, TwigEngine $templating, EZPlatformClient $restClient)
{
$this->em = $managerRegistry->getManager();
$this->session = $session;
$this->templating = $templating;
$this->restClient = $restClient;
}
示例5: Parameters
function it_creates_data_source_via_doctrine_orm_query_builder(ManagerRegistry $managerRegistry, EntityManagerInterface $entityManager, EntityRepository $entityRepository, QueryBuilder $queryBuilder)
{
$managerRegistry->getManagerForClass('App:Book')->willReturn($entityManager);
$entityManager->getRepository('App:Book')->willReturn($entityRepository);
$entityRepository->createQueryBuilder('o')->willReturn($queryBuilder);
$this->getDataSource(['class' => 'App:Book'], new Parameters())->shouldHaveType(DataSource::class);
}
示例6: let
function let(ManagerRegistry $registry, ProductRepositoryInterface $repository, EntityManager $em, AttributeInterface $attribute, AttributeOptionInterface $option, AttributeOptionValueInterface $optionValue)
{
$registry->getRepository('product')->willReturn($repository);
$repository->findAllWithAttributeOption($option)->willReturn([]);
$option->getAttribute()->willReturn($attribute);
$optionValue->getOption()->willReturn($option);
}
示例7: EntityNotFoundException
function it_should_throw_when_applicant_does_not_exist(ManagerRegistry $managerRegistry, ObjectManager $objectManager)
{
$id = 456;
$managerRegistry->getManagerForClass(ApplicantsRepository::ENTITY_CLASS)->shouldBeCalled()->willReturn($objectManager);
$objectManager->find(ApplicantsRepository::ENTITY_CLASS, $id)->shouldBeCalled()->willReturn(null);
$this->shouldThrow(new EntityNotFoundException("Applicant does not exist."))->duringFetchApplicant($id);
}
示例8: __construct
/**
* @param string $class
* @param \Doctrine\Common\Persistence\ManagerRegistry $manager_registry
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
*/
public function __construct($class, ManagerRegistry $manager_registry, EventDispatcherInterface $event_dispatcher = null)
{
$this->class = $class;
$this->event_dispatcher = $event_dispatcher;
$this->entity_manager = $manager_registry->getManagerForClass($class);
$this->entity_repository = $this->entity_manager->getRepository($class);
}
示例9: getLastSyncDate
/**
* @return \DateTime|null
*/
public function getLastSyncDate()
{
$channel = $this->getChannel();
$repository = $this->managerRegistry->getRepository('OroIntegrationBundle:Status');
/**
* @var Status $status
*/
$status = $repository->findOneBy(['code' => Status::STATUS_COMPLETED, 'channel' => $channel, 'connector' => $this->getType()], ['date' => 'DESC']);
$timezone = new \DateTimeZone('UTC');
$date = new \DateTime('now', $timezone);
$context = $this->getStepExecution()->getExecutionContext();
$data = $context->get(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY) ?: [];
$context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, array_merge($data, [self::LAST_SYNC_DATE_KEY => $date->format(\DateTime::ISO8601)]));
if (!$status) {
return null;
}
$data = $status->getData();
if (empty($data)) {
return null;
}
if (!empty($data[self::LAST_SYNC_DATE_KEY])) {
return new \DateTime($data[self::LAST_SYNC_DATE_KEY], $timezone);
}
return null;
}
示例10: postSetData
/**
* @param FormEvent $event
*/
public function postSetData(FormEvent $event)
{
$form = $event->getForm();
if ($form->getParent()) {
return;
}
if (!$form->has($this->fieldName)) {
return;
}
$isEntityExists = false;
$entity = $event->getData();
if ($entity) {
if (!is_object($entity)) {
return;
}
$entityClass = ClassUtils::getClass($entity);
$entityManager = $this->managerRegistry->getManagerForClass($entityClass);
if (!$entityManager) {
return;
}
$entityIdentifier = $entityManager->getClassMetadata($entityClass)->getIdentifierValues($entity);
$isEntityExists = !empty($entityIdentifier);
}
// if entity exists and assign is not granted - replace field with disabled text field,
// otherwise - set default owner value
if ($isEntityExists) {
$this->replaceOwnerField($form);
} else {
$this->setPredefinedOwner($form);
}
}
示例11: onLexikjwtauthenticationOnjwtcreated
public function onLexikjwtauthenticationOnjwtcreated(JWTCreatedEvent $event)
{
$em = $this->registry->getManager();
$data = $event->getData();
$data['wownewfield'] = 'muchcool';
$event->setData($data);
}
示例12: testSubmit
public function testSubmit()
{
$choice = new \stdClass();
$choice->{$identifierPath = 'id'} = $id = 1;
$choice->{$labelPath = 'label'} = $label = 'label';
$this->resource->expects($this->once())->method('getModel')->will($this->returnValue($model = get_class($choice)));
$this->resource->expects($this->once())->method('getIdPropertyPath')->will($this->returnValue($identifierPath));
$this->resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPath));
$this->managerRegistry->expects($this->once())->method('getManagerForClass')->with($this->identicalTo($model))->will($this->returnValue($documentManager = $this->createDocumentManagerMock()));
$documentManager->expects($this->once())->method('getRepository')->with($this->identicalTo($model))->will($this->returnValue($repository = $this->createRepositoryMock()));
$documentManager->expects($this->exactly(2))->method('getClassMetadata')->with($this->identicalTo($model))->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
$classMetadata->expects($this->once())->method('getName')->will($this->returnValue($model));
$classMetadata->expects($this->once())->method('getIdentifierFieldNames')->will($this->returnValue([$identifier = $identifierPath]));
$classMetadata->expects($this->once())->method('getTypeOfField')->with($this->identicalTo($identifier))->will($this->returnValue('integer'));
$repository->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($queryBuilder = $this->createQueryBuilderMock($documentManager)));
$queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
$query->expects($this->once())->method('execute')->will($this->returnValue($iterator = $this->createIteratorMock()));
$iterator->expects($this->once())->method('toArray')->will($this->returnValue([$choice]));
$form = $this->factory->create(ResourceChoiceType::class, null, ['resource' => $this->resource])->submit($id);
$this->assertSame($this->resource, $form->getConfig()->getOption('resource'));
$this->assertSame($identifierPath, $form->getConfig()->getOption('choice_value'));
$this->assertSame($labelPath, $form->getConfig()->getOption('choice_label'));
$this->assertSame('', $form->getConfig()->getOption('placeholder'));
$this->assertSame($choice, $form->getData());
$form->createView();
}
示例13: testSubmit
public function testSubmit()
{
$choice = new \stdClass();
$choice->{$identifierPath = 'id'} = $id = 1;
$choice->{$labelPath = 'label'} = $label = 'label';
$this->resource->expects($this->once())->method('getModel')->will($this->returnValue($model = get_class($choice)));
$this->resource->expects($this->once())->method('getIdPropertyPath')->will($this->returnValue($identifierPath));
$this->resource->expects($this->once())->method('getLabelPropertyPath')->will($this->returnValue($labelPath));
$this->managerRegistry->expects($this->once())->method('getManagerForClass')->with($this->identicalTo($model))->will($this->returnValue($entityManager = $this->createEntityManagerMock()));
$entityManager->expects($this->once())->method('getRepository')->with($this->identicalTo($model))->will($this->returnValue($repository = $this->createRepositoryMock()));
$entityManager->expects($this->exactly(3))->method('getClassMetadata')->with($this->identicalTo($model))->will($this->returnValue($classMetadata = $this->createClassMetadataMock()));
$classMetadata->expects($this->once())->method('getName')->will($this->returnValue($model));
$classMetadata->expects($this->once())->method('getIdentifierFieldNames')->will($this->returnValue([$identifier = $identifierPath]));
$classMetadata->expects($this->exactly(2))->method('getTypeOfField')->with($this->identicalTo($identifier))->will($this->returnValue('integer'));
$repository->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($queryBuilder = $this->createQueryBuilderMock($entityManager)));
$queryBuilder->expects($this->exactly(2))->method('getQuery')->will($this->returnValue($query = $this->createQueryMock()));
$query->expects($this->once())->method('execute')->will($this->returnValue($choices = [$choice]));
$queryBuilder->expects($this->once())->method('getRootAliases')->will($this->returnValue([$rootAlias = 'root_alias']));
$queryBuilder->expects($this->once())->method('expr')->will($this->returnValue($expr = $this->createExprMock()));
$queryBuilder->expects($this->once())->method('getEntityManager')->will($this->returnValue($entityManager));
$queryBuilder->expects($this->once())->method('getRootEntities')->will($this->returnValue([$model]));
$expr->expects($this->once())->method('in')->with($this->identicalTo($rootAlias . '.' . $identifier), $this->identicalTo(':' . ($parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_' . $identifier)))->will($this->returnValue($where = 'where'));
$queryBuilder->expects($this->once())->method('andWhere')->with($this->identicalTo($where))->will($this->returnSelf());
$query->expects($this->once())->method('setParameter')->with($this->identicalTo($parameter), $this->identicalTo([(string) $id]), $this->identicalTo(Connection::PARAM_INT_ARRAY))->will($this->returnSelf());
$query->expects($this->once())->method('getResult')->will($this->returnValue([$choice]));
$entityManager->expects($this->exactly(2))->method('contains')->with($this->identicalTo($choice))->will($this->returnValue(true));
$classMetadata->expects($this->exactly(2))->method('getIdentifierValues')->with($this->identicalTo($choice))->will($this->returnValue([$id]));
$form = $this->factory->create(ResourceChoiceType::class, null, ['resource' => $this->resource])->submit($id);
$this->assertSame($this->resource, $form->getConfig()->getOption('resource'));
$this->assertSame($identifierPath, $form->getConfig()->getOption('choice_value'));
$this->assertSame($labelPath, $form->getConfig()->getOption('choice_label'));
$this->assertSame('', $form->getConfig()->getOption('placeholder'));
$this->assertSame($choice, $form->getData());
$form->createView();
}
示例14: process
/**
* {@inheritDoc}
*/
public function process(DatagridInterface $grid, array $config)
{
$this->datagrid = $grid;
if (isset($config['query'])) {
$queryConfig = array_intersect_key($config, array_flip(['query']));
$converter = new YamlConverter();
$this->qb = $converter->parse($queryConfig, $this->doctrine);
} elseif (isset($config['entity']) && isset($config['repository_method'])) {
$entity = $config['entity'];
$method = $config['repository_method'];
$repository = $this->doctrine->getRepository($entity);
if (method_exists($repository, $method)) {
$qb = $repository->{$method}();
if ($qb instanceof QueryBuilder) {
$this->qb = $qb;
} else {
throw new DatasourceException(sprintf('%s::%s() must return an instance of Doctrine\\ORM\\QueryBuilder, %s given', get_class($repository), $method, is_object($qb) ? get_class($qb) : gettype($qb)));
}
} else {
throw new DatasourceException(sprintf('%s has no method %s', get_class($repository), $method));
}
} else {
throw new DatasourceException(get_class($this) . ' expects to be configured with query or repository method');
}
if (isset($config['hints'])) {
$this->queryHints = $config['hints'];
}
$grid->setDatasource(clone $this);
}
示例15: setUp
protected function setUp()
{
$encoder = new TokenEncoder($this->secret);
$this->doctrine = $this->createDoctrineMock();
$this->doctrine->expects($this->any())->method('getManager')->willReturn($this->getMockForAbstractClass(EntityManagerInterface::class));
$this->manager = new TokenManager($encoder, $this->doctrine);
}