本文整理匯總了PHP中Symfony\Bridge\Doctrine\RegistryInterface::getManagerForClass方法的典型用法代碼示例。如果您正苦於以下問題:PHP RegistryInterface::getManagerForClass方法的具體用法?PHP RegistryInterface::getManagerForClass怎麽用?PHP RegistryInterface::getManagerForClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Bridge\Doctrine\RegistryInterface
的用法示例。
在下文中一共展示了RegistryInterface::getManagerForClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: updateUserRepositories
/**
* @param User $user
* @param array $actualRepositories
*/
protected function updateUserRepositories(User $user, array $actualRepositories)
{
// Reindex array by GH repository ids
$actualRepositories = array_column($actualRepositories, null, 'id');
$userRepositoryIds = [];
/** @var Repository $repository */
foreach ($user->getRepositories() as $repository) {
// Repository was removed from github
if (!array_key_exists($repository->getGithubId(), $actualRepositories)) {
$user->getRepositories()->removeElement($repository);
continue;
}
// Collect ids of user repositories
$userRepositoryIds[] = $repository->getGithubId();
}
$repositoryManager = $this->doctrine->getManagerForClass(Repository::class);
// Create repository entities for new repositories from github
array_map(function ($repository) use($userRepositoryIds, $user, $repositoryManager) {
if (!in_array($repository['id'], $userRepositoryIds)) {
$repository = (new Repository())->setGithubId($repository['id'])->setFullName($repository['full_name'])->setName($repository['name'])->setOwner($user);
$repositoryManager->persist($repository);
$user->addRepository($repository);
}
}, $actualRepositories);
$repositoryManager->flush();
}
示例2: getListTypeChoices
/**
* Get marketing list types choices.
*
* @return array
*/
public function getListTypeChoices()
{
/** @var MarketingListType[] $types */
$types = $this->registry->getManagerForClass(self::MARKETING_LIST_TYPE)->getRepository(self::MARKETING_LIST_TYPE)->findBy(array(), array('name' => 'ASC'));
$results = array();
foreach ($types as $type) {
$results[$type->getName()] = $type->getLabel();
}
return $results;
}
示例3: addManager
/**
* {@inheritdoc}
*/
public function addManager(ManagerInterface $manager)
{
$class = $manager->getClass();
$em = $this->doctrine->getManagerForClass($class);
$manager->setObjectManager($em);
$manager->setRepository($em->getRepository($class));
$manager->setEventDispatcher($this->eventDispatcher);
$manager->setFactory($this);
$this->managers[$class] = $manager;
}
示例4: getEntityManager
/**
* {@inheritdoc}
*/
public function getEntityManager()
{
if ($this->entityManager instanceof ObjectManager) {
return $this->entityManager;
}
$em = $this->registry->getManagerForClass(self::TRANSACTION_CLASS);
if (!$em) {
throw new \RuntimeException(sprintf('No entity manager defined for class %s', self::TRANSACTION_CLASS));
}
return $em;
}
示例5: getAccountsLifetimeQueryBuilder
/**
* Returns query builder that allows to fetch list of lifetime values for each account
*
* @param null $ids the identifiers of accounts the lifetimeValues for which is need to be fetched
*
* @return QueryBuilder
*/
public function getAccountsLifetimeQueryBuilder($ids = null)
{
/** @var EntityManager $em */
$em = $this->registry->getManagerForClass('OroCRMChannelBundle:LifetimeValueHistory');
$qb = $em->createQueryBuilder();
$qb->select('IDENTITY(h.account) AS accountId, SUM(h.amount) AS lifetimeValue')->from('OroCRMChannelBundle:LifetimeValueHistory', 'h')->leftJoin('h.dataChannel', 'ch')->andWhere('ch.status = :channelStatus')->setParameter('channelStatus', $qb->expr()->literal((int) Channel::STATUS_ACTIVE))->andWhere('h.status = :status')->setParameter('status', $qb->expr()->literal(LifetimeValueHistory::STATUS_NEW))->groupBy('h.account');
if ($ids) {
$qb->andWhere('IDENTITY(h.account) IN(:ids)')->setParameter('ids', array_values($ids));
}
return $qb;
}
示例6: process
/**
* Process form
*
* @param EmailCampaign $entity
*
* @return bool
*/
public function process(EmailCampaign $entity)
{
$this->form->setData($entity);
if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
$this->form->submit($this->request);
if (!$this->request->get(self::UPDATE_MARKER, false) && $this->form->isValid()) {
$em = $this->registry->getManagerForClass('OroCRMCampaignBundle:EmailCampaign');
$em->persist($entity);
$em->flush();
return true;
}
}
return false;
}
示例7: toggleRepositoryWebhook
/**
* @param Repository $repository
*/
public function toggleRepositoryWebhook(Repository $repository)
{
/** @var User $user */
$user = $this->tokenStorage->getToken()->getUser();
if ($repository->getEnabled()) {
$this->githubManager->removeWebhook($user->getUsername(), $repository->getName(), $repository->getWebhookId());
$webhookId = null;
} else {
$webhookId = $this->githubManager->createWebhook($user->getUsername(), $repository->getName());
}
// Update state of repository webhook
$repository->setWebhookId($webhookId);
$repositoryManager = $this->doctrine->getManagerForClass(ClassUtils::getClass($repository));
$repositoryManager->flush();
}
示例8: findEntity
/**
* Finds an entity
*
* @param string $class
* @param array $data
*
* @return object|null
*/
protected function findEntity($class, array $data)
{
$repository = $this->doctrine->getManagerForClass($class)->getRepository($class);
$identifierProperties = $this->getEntityIdentifierProperties($repository);
$identifier = $this->getEntityIdentifier($identifierProperties, $data);
return $this->findOneByIdentifier($repository, $identifier);
}
示例9: getEntity
/**
* @param object $originEntity
* @param array $criteria
* @throws \RuntimeException
* @return object|null
*/
protected function getEntity($originEntity, $criteria)
{
if (!$this->registry) {
throw new \RuntimeException('Registry was not set');
}
$className = ClassUtils::getRealClass($originEntity);
return $this->registry->getManagerForClass($className)->getRepository($className)->findOneBy($criteria);
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$serializerMetadata = $this->metadataFactory->getMetadataForClass($this->class);
$manager = $this->registry->getManagerForClass($this->class);
$doctrineMetadata = $manager->getClassMetadata($this->class);
foreach ($serializerMetadata->propertyMetadata as $propertyMetadata) {
$name = $propertyMetadata->name;
if (in_array($name, $doctrineMetadata->getIdentifierFieldNames()) && !$this->identifierOverwrite) {
continue;
}
if (!in_array($this->group, $propertyMetadata->groups)) {
continue;
}
$type = null;
$nullable = true;
if (isset($doctrineMetadata->fieldMappings[$name])) {
$fieldMetadata = $doctrineMetadata->fieldMappings[$name];
$type = isset($fieldMetadata['type']) ? $fieldMetadata['type'] : null;
$nullable = isset($fieldMetadata['nullable']) ? $fieldMetadata['nullable'] : false;
} else {
if (isset($doctrineMetadata->associationMappings[$name])) {
$associationMetadata = $doctrineMetadata->associationMappings[$name];
if (isset($associationMetadata['joinColumns']['nullable'])) {
$nullable = $associationMetadata['joinColumns']['nullable'];
} else {
if (isset($associationMetadata['inverseJoinColumns']['nullable'])) {
$nullable = $associationMetadata['inverseJoinColumns']['nullable'];
}
}
}
}
switch ($type) {
case 'datetime':
$builder->add($name, $type, array('required' => !$nullable, 'widget' => 'single_text'));
break;
case 'boolean':
$childBuilder = $builder->create($name, null, array('required' => !$nullable));
$childBuilder->addEventSubscriber(new FixCheckboxDataListener());
$builder->add($childBuilder);
break;
default:
$builder->add($name, null, array('required' => !$nullable));
break;
}
}
}
示例11: getEntityManager
/**
* @param \Class $class
*
* @return EntityManager
*/
public function getEntityManager($class = null)
{
if (!$class) {
return $this->_registry->getEntityManager();
}
if (is_object($class)) {
$class = get_class($class);
}
if (!isset($this->_cache[$class])) {
$em = $this->_registry->getManagerForClass($class);
if (!$em) {
throw new \RuntimeException(sprintf('No entity manager defined for class %s', $class));
}
$this->_cache[$class] = $em;
}
return $this->_cache[$class];
}
示例12: findEntity
/**
* Finds an entity
*
* @param string $class
* @param array $data
*
* @throws \LogicException
*
* @return object|null
*/
protected function findEntity($class, array $data)
{
$repository = $this->doctrine->getManagerForClass($class)->getRepository($class);
if ($repository instanceof IdentifiableObjectRepositoryInterface) {
$identifierProperties = $repository->getIdentifierProperties();
$identifier = $this->getEntityIdentifier($identifierProperties, $data);
return $repository->findOneByIdentifier($identifier);
}
return null;
}
示例13: getIdentifyingValue
/**
* {@inheritdoc}
*/
public function getIdentifyingValue($object)
{
$className = get_class($object);
$em = $this->registry->getManagerForClass($className);
$metadata = $em->getClassMetadata($className);
$identifier = $metadata->getIdentifier();
if (count($identifier) > 1) {
throw new CompositePrimaryKeyException(sprintf('Composite Primary Keys cannot be resolved to a single scalar value on Entity: %s', get_class($object)));
}
try {
$pkValue = $this->propertyAccessor->getValue($object, $identifier[0]);
} catch (AccessException $e) {
throw new IdentifyingFieldNotReachableException(sprintf('The property accessor was unable to access %s.', $identifier[0]));
}
if (is_object($pkValue)) {
$pkValue = $this->getIdentifyingValue($pkValue);
}
return $pkValue;
}
示例14: getChannelAccountLifetimeQueryBuilder
/**
* Returns query builder that allows to fetch account lifetime value from history table
* Following parameters are required to be passed:
* - account Account entity or identifier
*
* Following parameters are optional:
* - dataChannel - Channel entity or id to be used for fetch criteria, required if $addChannelParam is set to true
*
* @param bool $addChannelParam
*
* @return QueryBuilder
*/
public function getChannelAccountLifetimeQueryBuilder($addChannelParam = false)
{
/** @var EntityManager $em */
$em = $this->registry->getManagerForClass('OroCRMChannelBundle:LifetimeValueHistory');
$qb = $em->createQueryBuilder();
$qb->from('OroCRMChannelBundle:LifetimeValueHistory', 'h');
$qb->select('SUM(h.amount)');
$qb->andWhere('h.account = :account');
if ($addChannelParam) {
// do not change order, need for idx
$qb->andWhere('h.dataChannel = :dataChannel');
}
$qb->leftJoin('h.dataChannel', 'ch');
$qb->andWhere('ch.status = :channelStatus');
$qb->setParameter('channelStatus', $qb->expr()->literal((int) Channel::STATUS_ACTIVE));
$qb->andWhere('h.status = :status');
$qb->setParameter('status', $qb->expr()->literal(LifetimeValueHistory::STATUS_NEW));
$qb->setMaxResults(1);
return $qb;
}
示例15: findEntity
/**
* Finds an entity
*
* @param string $class
* @param array $data
*
* @return object|null
*/
protected function findEntity($class, array $data)
{
$repository = $this->doctrine->getManagerForClass($class)->getRepository($class);
if ($repository instanceof ReferableEntityRepositoryInterface) {
$reference = implode('.', array_map(function ($property) use($class, $data) {
if (!isset($data[$property])) {
throw new MissingIdentifierException();
}
return $data[$property];
}, $repository->getReferenceProperties()));
return $repository->findByReference($reference);
}
}