/**
  * {@inheritdoc}
  */
 public function reverseTransform($entityType, $throwException = true)
 {
     try {
         return $this->entityAliasResolver->getClassByPluralAlias($entityType);
     } catch (EntityAliasNotFoundException $e) {
         if ($throwException) {
             throw $e;
         }
     }
     return null;
 }
 public function testGetClassByPluralAliasCache()
 {
     $this->metadataFactory->expects($this->once())->method('getAllMetadata')->willReturn([new ClassMetadata('Test\\Entity1')]);
     $entityAliasProvider = $this->getMock('Oro\\Bundle\\EntityBundle\\Provider\\EntityAliasProviderInterface');
     $entityAliasProvider->expects($this->once())->method('getEntityAlias')->with('Test\\Entity1')->willReturn(new EntityAlias('entity1_alias', 'entity1_plural_alias'));
     $this->entityAliasResolver->addProvider($entityAliasProvider);
     $this->assertEquals('Test\\Entity1', $this->entityAliasResolver->getClassByPluralAlias('entity1_plural_alias'));
     // test that the result is cached
     $this->assertEquals('Test\\Entity1', $this->entityAliasResolver->getClassByPluralAlias('entity1_plural_alias'));
 }
 /**
  * {@inheritdoc}
  */
 public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     if ($route->getOption('group') !== DictionaryEntityRouteOptionsResolver::ROUTE_GROUP) {
         return;
     }
     $pluralAlias = $route->getDefault(DictionaryEntityRouteOptionsResolver::ENTITY_ATTRIBUTE);
     if (!$pluralAlias) {
         return;
     }
     $className = $this->entityAliasResolver->getClassByPluralAlias($pluralAlias);
     $pluralName = $this->entityClassNameProvider->getEntityClassPluralName($className);
     if ($pluralName) {
         $annotation->setDescription(strtr(static::DESCRIPTION_TEMPLATE, ['{plural_name}' => $pluralName]));
         $annotation->setDocumentation(strtr(static::DOCUMENTATION_TEMPLATE, ['{plural_name}' => $pluralName]));
     } else {
         $annotation->setDescription(strtr(static::FALLBACK_DESCRIPTION_TEMPLATE, ['{class}' => $className]));
         $annotation->setDocumentation(strtr(static::FALLBACK_DOCUMENTATION_TEMPLATE, ['{class}' => $className]));
     }
 }
 /**
  * Resolves the entity class name by entity alias
  *
  * @param string $entityAlias   The alias or plural alias of the entity
  * @param bool   $isPluralAlias Determines whether the entity name may be a singular of plural alias
  *
  * @return string The FQCN of an entity
  */
 protected function getEntityClassByAlias($entityAlias, $isPluralAlias)
 {
     return $isPluralAlias ? $this->entityAliasResolver->getClassByPluralAlias($entityAlias) : $this->entityAliasResolver->getClassByAlias($entityAlias);
 }
 /**
  * {@inheritdoc}
  */
 protected function normalizeValue($value)
 {
     return $this->entityAliasResolver->getClassByPluralAlias($value);
 }
Beispiel #6
0
 /**
  * @param Route $route
  *
  * @return string|null
  */
 protected function getEntityClass(Route $route)
 {
     $pluralAlias = $route->getDefault(RestRouteOptionsResolver::ENTITY_ATTRIBUTE);
     return $pluralAlias ? $this->entityAliasResolver->getClassByPluralAlias($pluralAlias) : null;
 }
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($entityType)
 {
     return $this->entityAliasResolver->getClassByPluralAlias($entityType);
 }