本文整理汇总了PHP中Symfony\Bridge\Doctrine\RegistryInterface类的典型用法代码示例。如果您正苦于以下问题:PHP RegistryInterface类的具体用法?PHP RegistryInterface怎么用?PHP RegistryInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RegistryInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* AbstractJournalItemMailer constructor.
* @param OjsMailer $ojsMailer
* @param RegistryInterface $registry
* @param TokenStorageInterface $tokenStorage
* @param RouterInterface $router
*/
public function __construct(OjsMailer $ojsMailer, RegistryInterface $registry, TokenStorageInterface $tokenStorage, RouterInterface $router)
{
$this->ojsMailer = $ojsMailer;
$this->em = $registry->getManager();
$this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
$this->router = $router;
}
示例2: __construct
/**
* @param string $name
* @param EngineInterface $templating
* @param RegistryInterface $registry
* @param CurrencyDetectorInterface $currencyDetector
* @param ProductFinderInterface $productFinder
* @param string $productClass
*/
public function __construct($name, EngineInterface $templating, RegistryInterface $registry, CurrencyDetectorInterface $currencyDetector, ProductFinderInterface $productFinder, $productClass)
{
$this->productRepository = $registry->getManager()->getRepository($productClass);
$this->currencyDetector = $currencyDetector;
$this->productFinder = $productFinder;
parent::__construct($name, $templating);
}
示例3: __construct
/**
* @param FormInterface $form
* @param Request $request
* @param RegistryInterface $registry
* @param SecurityContextInterface $security
*/
public function __construct(FormInterface $form, Request $request, RegistryInterface $registry, SecurityContextInterface $security)
{
$this->form = $form;
$this->request = $request;
$this->manager = $registry->getManager();
$this->organization = $security->getToken()->getOrganizationContext();
}
示例4: __construct
/**
* @param string $name
* @param EngineInterface $templating
* @param RegistryInterface $registry
* @param CurrencyDetectorInterface $currencyDetector
* @param ProductFinderInterface $productFinder
*/
public function __construct($name, EngineInterface $templating, RegistryInterface $registry, CurrencyDetectorInterface $currencyDetector, ProductFinderInterface $productFinder)
{
$this->productRepository = $registry->getManager()->getRepository('Application\\Sonata\\ProductBundle\\Entity\\Product');
$this->currencyDetector = $currencyDetector;
$this->productFinder = $productFinder;
parent::__construct($name, $templating);
}
示例5: __construct
/**
* Constructor
*
* @param RegistryInterface $registry
* @param string $class
* @param RouterInterface $router
* @param string $routeName
*/
public function __construct(RegistryInterface $registry, $class, RouterInterface $router, $routeName)
{
$tableName = $registry->getManager()->getClassMetadata($class)->table['name'];
$dql = "SELECT p.id as productId, p.slug as slug, p.updated_at as lastmod, 'weekly' as changefreq, '0.5' as priority " . "FROM " . $tableName . " p " . "WHERE p.enabled = 1";
$source = new DoctrineDBALConnectionSourceIterator($registry->getConnection(), $dql);
$this->iterator = new SymfonySitemapSourceIterator($source, $router, $routeName, array('productId' => null, 'slug' => null));
}
示例6: __construct
/**
* ContainerService constructor.
*
* @param RegistryInterface $registry
* @param EventDispatcherInterface $eventDispatcher
* @param ContainerInterface $serviceContainer
* @param string $cacheDir
* @param bool $debug
*/
public function __construct(RegistryInterface $registry, EventDispatcherInterface $eventDispatcher, ContainerInterface $serviceContainer, $cacheDir, $debug = false)
{
$this->objectManager = $registry->getManager();
$this->cacheDir = $cacheDir . '/twig';
$this->debug = $debug;
$this->eventDispatcher = $eventDispatcher;
$this->serviceContainer = $serviceContainer;
}
示例7: __construct
/**
* @param FormInterface $form
* @param Request $request
* @param RegistryInterface $doctrine
* @param ValidatorInterface $validator
* @param TranslatorInterface $translator
*/
public function __construct(FormInterface $form, Request $request, RegistryInterface $doctrine, ValidatorInterface $validator, TranslatorInterface $translator)
{
$this->form = $form;
$this->request = $request;
$this->manager = $doctrine->getManager();
$this->validator = $validator;
$this->translator = $translator;
}
示例8: getColumnName
private function getColumnName($field, $entity)
{
if (is_object($entity)) {
$entity = get_class($entity);
}
return $this->doctrine->getEntityManagerForClass($entity)->getClassMetadata($entity)->getColumnName($field);
}
示例9: getIntegrationFromContext
/**
* @param array $context
*
* @return Integration
* @throws \LogicException
*/
public function getIntegrationFromContext(array $context)
{
if (!isset($context['channel'])) {
throw new \LogicException('Context should contain reference to channel');
}
return $this->registry->getRepository('OroIntegrationBundle:Channel')->getOrLoadById($context['channel']);
}
示例10: isValid
/**
* @param object $entity
* @param Constraint $constraint
* @return bool
*/
public function isValid($entity, Constraint $constraint)
{
if (!is_array($constraint->fields) && !is_string($constraint->fields)) {
throw new UnexpectedTypeException($constraint->fields, 'array');
}
$fields = (array) $constraint->fields;
if (count($fields) == 0) {
throw new ConstraintDefinitionException("At least one field has to be specified.");
}
$em = $this->registry->getEntityManager($constraint->em);
$className = $this->context->getCurrentClass();
$class = $em->getClassMetadata($className);
$criteria = array();
foreach ($fields as $fieldName) {
if (!isset($class->reflFields[$fieldName])) {
throw new ConstraintDefinitionException("Only field names mapped by Doctrine can be validated for uniqueness.");
}
$criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity);
}
$repository = $em->getRepository($className);
$result = $repository->findBy($criteria);
if (count($result) > 0 && $result[0] !== $entity) {
$oldPath = $this->context->getPropertyPath();
$this->context->setPropertyPath(empty($oldPath) ? $fields[0] : $oldPath . "." . $fields[0]);
$this->context->addViolation($constraint->message, array(), $criteria[$fields[0]]);
$this->context->setPropertyPath($oldPath);
}
return true;
// all true, we added the violation already!
}
示例11: listAction
/**
* Returns a JSON response containing options
*
* @param Request $request
*
* @return JsonResponse
*/
public function listAction(Request $request)
{
$query = $request->query;
$search = $query->get('search');
$referenceDataName = $query->get('referenceDataName');
$class = $query->get('class');
if (null !== $referenceDataName) {
$class = $this->registry->get($referenceDataName)->getClass();
}
$repository = $this->doctrine->getRepository($class);
if ($repository instanceof OptionRepositoryInterface) {
$choices = $repository->getOptions($query->get('dataLocale'), $query->get('collectionId'), $search, $query->get('options', []));
} elseif ($repository instanceof ReferenceDataRepositoryInterface) {
$choices['results'] = $repository->findBySearch($search, $query->get('options', []));
} elseif ($repository instanceof SearchableRepositoryInterface) {
$choices['results'] = $repository->findBySearch($search, $query->get('options', []));
} elseif (method_exists($repository, 'getOptions')) {
$choices = $repository->getOptions($query->get('dataLocale'), $query->get('collectionId'), $search, $query->get('options', []));
} else {
throw new \LogicException(sprintf('The repository of the class "%s" can not retrieve options via Ajax.', $query->get('class')));
}
if ($query->get('isCreatable') && 0 === count($choices['results'])) {
$choices['results'] = [['id' => $search, 'text' => $search]];
}
return new JsonResponse($choices);
}
示例12: 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();
}
示例13: finishView
/**
* @inheritdoc
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
/** @var ChoiceView $choice */
foreach ($view->vars['choices'] as $choice) {
if ($options['select2_template_result']) {
$object = $choice->value;
if ($this->doctrine && $options['class']) {
$object = $this->doctrine->getRepository($options['class'])->find($object);
}
if (is_string($options['select2_template_result'])) {
$choice->attr['data-template-result'] = $this->templating->render($options['select2_template_result'], ['choice' => $choice, 'object' => $object]);
} else {
$choice->attr['data-template-result'] = call_user_func_array($options['select2_template_result'], [$choice, $object]);
}
}
if ($options['select2_template_selection']) {
$object = $choice->value;
if ($this->doctrine && $options['class']) {
$object = $this->doctrine->getRepository($options['class'])->find($object);
}
if (is_string($options['select2_template_selection'])) {
$choice->attr['data-template-selection'] = $this->templating->render($options['select2_template_selection'], ['choice' => $choice, 'object' => $object]);
} else {
$choice->attr['data-template-selection'] = call_user_func_array($options['select2_template_selection'], [$choice, $object]);
}
}
}
if ($options['select2'] === true) {
$options['select2_options'] = array_merge($this->select2DefaultOptions, $options['select2_options']);
$view->vars['select2_options'] = json_encode($options['select2_options']);
}
}
示例14: generateEntity
/**
* Generate the entity PHP code.
*
* @param BundleInterface $bundle
* @param string $name
* @param array $fields
* @param string $namePrefix
* @param string $dbPrefix
* @param string|null $extendClass
*
* @return array
* @throws \RuntimeException
*/
protected function generateEntity(BundleInterface $bundle, $name, $fields, $namePrefix, $dbPrefix, $extendClass = null)
{
// configure the bundle (needed if the bundle does not contain any Entities yet)
$config = $this->registry->getManager(null)->getConfiguration();
$config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity\\' . $namePrefix), $config->getEntityNamespaces()));
$entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $namePrefix . '\\' . $name;
$entityPath = $bundle->getPath() . '/Entity/' . $namePrefix . '/' . str_replace('\\', '/', $name) . '.php';
if (file_exists($entityPath)) {
throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
}
$class = new ClassMetadataInfo($entityClass, new UnderscoreNamingStrategy());
foreach ($fields as $fieldSet) {
foreach ($fieldSet as $fieldArray) {
foreach ($fieldArray as $field) {
if (array_key_exists('joinColumn', $field)) {
$class->mapManyToOne($field);
} elseif (array_key_exists('joinTable', $field)) {
$class->mapManyToMany($field);
} else {
$class->mapField($field);
}
}
}
}
$class->setPrimaryTable(array('name' => strtolower($dbPrefix . strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name))) . 's'));
$entityCode = $this->getEntityGenerator($extendClass)->generateEntityClass($class);
return array($entityCode, $entityPath);
}
示例15: generate
/**
* Generate Fixture from bundle name, entity name, fixture name and ids
*
* @param BundleInterface $bundle
* @param string $entity
* @param string $name
* @param array $ids
* @param string|null $connectionName
*/
public function generate(BundleInterface $bundle, $entity, $name, array $ids, $order, $connectionName = null)
{
// configure the bundle (needed if the bundle does not contain any Entities yet)
$config = $this->registry->getManager($connectionName)->getConfiguration();
$config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity'), $config->getEntityNamespaces()));
$fixtureFileName = $this->getFixtureFileName($entity, $name, $ids);
$entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
$fixturePath = $bundle->getPath() . '/DataFixtures/ORM/' . $fixtureFileName . '.php';
$bundleNameSpace = $bundle->getNamespace();
if (file_exists($fixturePath)) {
throw new \RuntimeException(sprintf('Fixture "%s" already exists.', $fixtureFileName));
}
$class = new ClassMetadataInfo($entityClass);
$fixtureGenerator = $this->getFixtureGenerator();
$fixtureGenerator->setFixtureName($fixtureFileName);
$fixtureGenerator->setBundleNameSpace($bundleNameSpace);
$fixtureGenerator->setMetadata($class);
$fixtureGenerator->setFixtureOrder($order);
/** @var EntityManager $em */
$em = $this->registry->getManager($connectionName);
$repo = $em->getRepository($class->rootEntityName);
if (empty($ids)) {
$items = $repo->findAll();
} else {
$items = $repo->findById($ids);
}
$fixtureGenerator->setItems($items);
$fixtureCode = $fixtureGenerator->generateFixtureClass($class);
$this->filesystem->mkdir(dirname($fixturePath));
file_put_contents($fixturePath, $fixtureCode);
}