Merge branch '2.8' into 3.4

* 2.8:
  PropertyInfo\DoctrineExtractor - There is bug when indexBy is meta key
  [minor] SCA
This commit is contained in:
Nicolas Grekas 2018-04-20 12:02:27 +02:00
commit 9a0422ce45
11 changed files with 40 additions and 13 deletions

View File

@ -95,9 +95,19 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
if (isset($associationMapping['indexBy'])) {
$indexProperty = $associationMapping['indexBy'];
/** @var ClassMetadataInfo $subMetadata */
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
if (null === $typeOfField) {
$associationMapping = $subMetadata->getAssociationMapping($indexProperty);
/** @var ClassMetadataInfo $subMetadata */
$indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($indexProperty);
$subMetadata = $this->classMetadataFactory->getMetadataFor($associationMapping['targetEntity']);
$typeOfField = $subMetadata->getTypeOfField($indexProperty);
}
$collectionKeyType = $this->getPhpType($typeOfField);
}
}

View File

@ -61,6 +61,7 @@ class DoctrineExtractorTest extends TestCase
'foo',
'bar',
'indexedBar',
'indexedFoo',
),
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy')
);
@ -141,6 +142,14 @@ class DoctrineExtractorTest extends TestCase
new Type(Type::BUILTIN_TYPE_STRING),
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
))),
array('indexedFoo', array(new Type(
Type::BUILTIN_TYPE_OBJECT,
false,
'Doctrine\Common\Collections\Collection',
true,
new Type(Type::BUILTIN_TYPE_STRING),
new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineRelation')
))),
array('simpleArray', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
array('customFoo', null),
array('notMapped', null),

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\ManyToOne;
@ -45,6 +46,11 @@ class DoctrineDummy
*/
protected $indexedBar;
/**
* @OneToMany(targetEntity="DoctrineRelation", mappedBy="foo", indexBy="foo")
*/
protected $indexedFoo;
/**
* @Column(type="guid")
*/

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
/**
* @Entity
@ -32,4 +33,10 @@ class DoctrineRelation
* @Column(type="guid")
*/
protected $rguid;
/**
* @Column(type="guid")
* @ManyToOne(targetEntity="DoctrineDummy", inversedBy="indexedFoo")
*/
protected $foo;
}

View File

@ -97,11 +97,10 @@ class TemplateFinder implements TemplateFinderInterface
private function findTemplatesInBundle(BundleInterface $bundle)
{
$name = $bundle->getName();
$templates = array_merge(
$templates = array_unique(array_merge(
$this->findTemplatesInFolder($bundle->getPath().'/Resources/views'),
$this->findTemplatesInFolder($this->rootDir.'/'.$name.'/views')
);
$templates = array_unique($templates);
));
foreach ($templates as $i => $template) {
$templates[$i] = $template->set('bundle', $name);

View File

@ -157,7 +157,7 @@ class CodeHelper extends Helper
$file = trim($file);
$fileStr = $file;
if (0 === strpos($fileStr, $this->rootDir)) {
$fileStr = str_replace($this->rootDir, '', str_replace('\\', '/', $fileStr));
$fileStr = str_replace(array('\\', $this->rootDir), array('/', ''), $fileStr);
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
}

View File

@ -121,7 +121,7 @@ class JsonDescriptor extends Descriptor
{
return array(
'name' => '--'.$option->getName(),
'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '',
'accept_value' => $option->acceptValue(),
'is_value_required' => $option->isValueRequired(),
'is_multiple' => $option->isArray(),

View File

@ -70,7 +70,7 @@ class MarkdownDescriptor extends Descriptor
{
$name = '--'.$option->getName();
if ($option->getShortcut()) {
$name .= '|-'.implode('|-', explode('|', $option->getShortcut())).'';
$name .= '|-'.str_replace('|', '|-', $option->getShortcut()).'';
}
$this->write(

View File

@ -224,7 +224,7 @@ class XmlDescriptor extends Descriptor
$pos = strpos($option->getShortcut(), '|');
if (false !== $pos) {
$objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
$objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
$objectXML->setAttribute('shortcuts', '-'.str_replace('|', '|-', $option->getShortcut()));
} else {
$objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
}

View File

@ -195,7 +195,7 @@ class InputOption
*
* @return bool
*/
public function equals(InputOption $option)
public function equals(self $option)
{
return $option->getName() === $this->getName()
&& $option->getShortcut() === $this->getShortcut()

View File

@ -160,10 +160,6 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
if (class_exists($class) || interface_exists($class)) {
return true;
}
return false;
return class_exists($class) || interface_exists($class, false);
}
}