8000 Merge branch '2.8' · symfony/symfony@48b25f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48b25f5

Browse files
Merge branch '2.8'
* 2.8: Fix the FrameworkBundle dependencies [DoctrineBridge] Fix required guess of boolean fields [DI] don't use array_map to resolve services Remove dead code in the PropertyPath constructor [EventDispatcher] fix docblock [Process] Inherit env vars by default in PhpProcess Changed one console output style to avoid visual issues [VarDumper] Fix return type and anonymous classes dumping [FrameworkBundle] PropertyInfo support [HttpFoundation] Fixes /0 subnet handling in IpUtils [Form] Simplify DateTimeToStringTransformer Avoid unneeded catch and re-throw of the same exception. [Minor] [Serializer] Removed second license header [TwigBundle] added a Twig templates warmer when templating is disabled [HttpKernel] Remove a duplicate test for the EsiFragmentRenderer [Templating] deprecate low-level RouterHelper::generate method as it's cumbersome to use constants in templates [Templating] introduce path and url methods in php templates to be in line with twig templates [Routing] deprecate the old url generator reference type values [Routing] use constant in a test that is new in 2.7 [FrameworkBundle] Add a new ClassCache cache warmer [Validator] Add expressionLanguage to ExpressionValidator constructor Conflicts: src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php src/Symfony/Bundle/FrameworkBundle/composer.json src/Symfony/Component/BrowserKit/composer.json src/Symfony/Component/ClassLoader/ClassCollectionLoader.php src/Symfony/Component/EventDispatcher/EventDispatcher.php
2 parents 3bdcfb9 + dee62e7 commit 48b25f5

File tree

51 files changed

+715
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+715
-125
lines changed

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
namespace Symfony\Bridge\Doctrine\Form;
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
15-
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1615
use Doctrine\Common\Persistence\Mapping\MappingException;
16+
use Doctrine\DBAL\Types\Type;
17+
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1718
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
1819
use Symfony\Component\Form\FormTypeGuesserInterface;
1920
use Symfony\Component\Form\Guess\Guess;
@@ -51,28 +52,28 @@ public function guessType($class, $property)
5152
}
5253

5354
switch ($metadata->getTypeOfField($property)) {
54-
case 'array':
55+
case Type::TARRAY:
5556
return new TypeGuess('collection', array(), Guess::MEDIUM_CONFIDENCE);
56-
case 'boolean':
57+
case Type::BOOLEAN:
5758
return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE);
58-
case 'datetime':
59+
case Type::DATETIME:
60+
case Type::DATETIMETZ:
5961
case 'vardatetime':
60-
case 'datetimetz':
6162
return new TypeGuess('datetime', array(), Guess::HIGH_CONFIDENCE);
62-
case 'date':
63+
case Type::DATE:
6364
return new TypeGuess('date', array(), Guess::HIGH_CONFIDENCE);
64-
case 'time':
65+
case Type::TIME:
6566
return new TypeGuess('time', array(), Guess::HIGH_CONFIDENCE);
66-
case 'decimal':
67-
case ' 1241 float':
67+
case Type::DECIMAL:
68+
case Type::FLOAT:
6869
return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE);
69-
case 'integer':
70-
case 'bigint':
71-
case 'smallint':
70+
case Type::INTEGER:
71+
case Type::BIGINT:
72+
case Type::SMALLINT:
7273
return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE);
73-
case 'string':
74+
case Type::STRING:
7475
return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);
75-
case 'text':
76+
case Type::TEXT:
7677
return new TypeGuess('textarea', array(), Guess::MEDIUM_CONFIDENCE);
7778
default:
7879
return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);
@@ -95,7 +96,7 @@ public function guessRequired($class, $property)
9596

9697
// Check whether the field exists and is nullable or not
9798
if ($classMetadata->hasField($property)) {
98-
if (!$classMetadata->isNullable($property)) {
99+
if (!$classMetadata->isNullable($property) && Type::BOOLEAN !== $classMetadata->getTypeOfField($property)) {
99100
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
100101
}
101102

@@ -130,7 +131,7 @@ public function guessMaxLength($class, $property)
130131
return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
131132
}
132133

133-
if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
134+
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
134135
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
135136
}
136137
}
@@ -143,7 +144,7 @@ public function guessPattern($class, $property)
143144
{
144145
$ret = $this->getMetadata($class);
145146
if ($ret && $ret[0]->hasField($property) && !$ret[0]->hasAssociation($property)) {
146-
if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
147+
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
147148
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
148149
}
149150
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
13+
14+
use Symfony\Component\ClassLoader\ClassCollectionLoader;
15+
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
16+
17+
/**
18+
* Generates the Class Cache (classes.php) file.
19+
*
20+
* @author Tugdual Saunier <tucksaun@gmail.com>
21+
*/
22+
class ClassCacheCacheWarmer implements CacheWarmerInterface
23+
{
24+
/**
25+
* Warms up the cache.
26+
*
27+
* @param string $cacheDir The cache directory
28+
*/
29+
public function warmUp($cacheDir)
30+
{
31+
$classmap = $cacheDir.'/classes.map';
32+
33+
if (!is_file($classmap)) {
34+
return;
35+
}
36+
37+
ClassCollectionLoader::load(include($classmap), $cacheDir, 'classes', false);
38+
}
39+
40+
/**
41+
* Checks whether this warmer is optional or not.
42+
*
43+
* @return bool always true
44+
*/
45+
public function isOptional()
46+
{
47+
return true;
48+
}
49+
}

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplateFinder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(KernelInterface $kernel, TemplateNameParserInterface
4545
/**
4646
* Find all the templates in the bundle and in the kernel Resources folder.
4747
*
48-
* @return array An array of templates of type TemplateReferenceInterface
48+
* @return TemplateReferenceInterface[]
4949
*/
5050
public function findAllTemplates()
5151
{
@@ -69,7 +69,7 @@ public function findAllTemplates()
6969
*
7070
* @param string $dir The folder where to look for templates
7171
*
72-
* @return array An array of templates of type TemplateReferenceInterface
72+
* @return TemplateReferenceInterface[]
7373
*/
7474
private function findTemplatesInFolder($dir)
7575
{
@@ -93,7 +93,7 @@ private function findTemplatesInFolder($dir)
9393
*
9494
* @param BundleInterface $bundle The bundle where to look for templates
9595
*
96-
* @return array An array of templates of type TemplateReferenceInterface
96+
* @return TemplateReferenceInterface[]
9797
*/
9898
private function findTemplatesInBundle(BundleInterface $bundle)
9999
{

src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ abstract class Controller extends ContainerAware
4040
/**
4141
* Generates a URL from the given parameters.
4242
*
43-
* @param string $route The name of the route
44-
* @param mixed $parameters An array of parameters
45-
* @param bool|string $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
43+
* @param string $route The name of the route
44+
* @param mixed $parameters An array of parameters
45+
* @param int $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
4646
*
4747
* @return string The generated URL
4848
*
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
/**
19+
* Adds extractors to the property_info service.
20+
*
21+
* @author Kévin Dunglas <dunglas@gmail.com>
22+
*/
23+
class PropertyInfoPass implements CompilerPassInterface
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function process(ContainerBuilder $container)
29+
{
30+
if (!$container->hasDefinition('property_info')) {
31+
return;
32+
}
33+
34+
$listExtractors = $this->findAndSortTaggedServices('property_info.list_extractor', $container);
35+
$container->getDefinition('property_info')->replaceArgument(0, $listExtractors);
36+
37+
$typeExtractors = $this->findAndSortTaggedServices('property_info.type_extractor', $container);
38+
$container->getDefinition('property_info')->replaceArgument(1, $typeExtractors);
39+
40+
$descriptionExtractors = $this->findAndSortTaggedServices('property_info.description_extractor', $container);
41+
$container->getDefinition('property_info')->replaceArgument(2, $descriptionExtractors);
42+
43+
$accessExtractors = $this->findAndSortTaggedServices('property_info.access_extractor', $container);
44+
$container->getDefinition('property_info')->replaceArgument(3, $accessExtractors);
45+
}
46+
47+
/**
48+
* Finds all services with the given tag name and order them by their priority.
49+
*
50+
* @param string $tagName
51+
* @param ContainerBuilder $container
52+
*
53+
* @return array
54+
*/
55+
private function findAndSortTaggedServices($tagName, ContainerBuilder $container)
56+
{
57+
$services = $container->findTaggedServiceIds($tagName);
58+
59+
$sortedServices = array();
60+
foreach ($services as $serviceId => $tags) {
61+
foreach ($tags as $attributes) {
62+
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
63+
$sortedServices[$priority][] = new Reference($serviceId);
64+
}
65+
}
66+
67+
if (empty($sortedServices)) {
68+
return array();
69+
}
70+
71+
krsort($sortedServices);
72+
73+
// Flatten the array
74+
return call_user_func_array('array_merge', $sortedServices);
75+
}
76+
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SerializerPass.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public function process(ContainerBuilder $container)
3838
$container->getDefinition('serializer')->replaceArgument(1, $encoders);
3939
}
4040

41+
/**
42+
* Finds all services with the given tag name and order them by their priority.
43+
*
44+
* @param string $tagName
45+
* @param ContainerBuilder $container
46+
*
47+
* @return array
48+
*
49+
* @throws \RuntimeException
50+
*/
4151
private function findAndSortTaggedServices($tagName, ContainerBuilder $container)
4252
{
4353
$services = $container->findTaggedServiceIds($tagName);
@@ -48,8 +58,8 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container
4858

4959
$sortedServices = array();
5060
foreach ($services as $serviceId => $tags) {
51-
foreach ($tags as $tag) {
52-
$priority = isset($tag['priority']) ? $tag['priority'] : 0;
61+
foreach ($tags as $attributes) {
62+
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
5363
$sortedServices[$priority][] = new Reference($serviceId);
5464
}
5565
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function getConfigTreeBuilder()
100100
$this->addAnnotationsSection($rootNode);
101101
$this->addSerializerSection($rootNode);
102102
$this->addPropertyAccessSection($rootNode);
103+
$this->addPropertyInfoSection($rootNode);
103104

104105
return $treeBuilder;
105106
}
@@ -492,4 +493,16 @@ private function addPropertyAccessSection(ArrayNodeDefinition $rootNode)
492493
->end()
493494
;
494495
}
496+
497+
private function addPropertyInfoSection(ArrayNodeDefinition $rootNode)
498+
{
499+
$rootNode
500+
->children()
501+
->arrayNode('property_info')
502+
->info('Property info configuration')
503+
->canBeEnabled()
504+
->end()
505+
->end()
506+
;
507+
}
495508
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public function load(array $configs, ContainerBuilder $container)
125125
$this->registerSerializerConfiguration($config['serializer'], $container, $loader);
126126
}
127127

128+
if (isset($config['property_info'])) {
129+
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
130+
}
131+
128132
$loader->load('debug_prod.xml');
129133
$definition = $container->findDefinition('debug.debug_handlers_listener');
130134

@@ -945,6 +949,28 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
945949
}
946950
}
947951

952+
/**
953+
* Loads property info configuration.
954+
*
955+
* @param array $config
956+
* @param ContainerBuilder $container
957+
* @param XmlFileLoader $loader
958+
*/
959+
private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
960+
{
961+
if (!$config['enabled']) {
962+
return;
963+
}
964+
965+
$loader->load('property_info.xml');
966+
967+
if (class_exists('phpDocumentor\Reflection\ClassReflector')) {
968+
$definition = $container->register('property_info.php_doc_extractor', 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor');
969+
$definition->addTag('property_info.description_extractor', array('priority' => -1000));
970+
$definition->addTag('property_info.type_extractor', array('priority' => -1001));
971+
}
972+
}
973+
948974
/**
949975
* Returns the base path for the XSD files.
950976
*

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
1616
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
18+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
1819
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
1920
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
2021
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
@@ -85,6 +86,7 @@ public function build(ContainerBuilder $container)
8586
$container->addCompilerPass(new TranslationDumperPass());
8687
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
8788
$container->addCompilerPass(new SerializerPass());
89+
$container->addCompilerPass(new PropertyInfoPass());
8890

8991
if ($container->getParameter('kernel.debug')) {
9092
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
<service id="property_info" class="Symfony\Component\PropertyInfo\PropertyInfoExtractor" >
9+
<argument type="collection" />
10+
<argument type="collection" />
11+
<argument type="collection" />
12+
<argument type="collection" />
13+
</service>
14+
15+
<!-- Extractor -->
16+
<service id="property_info.reflection_extractor" class="Symfony\Component\PropertyInfo\ReflectionExtractor" public="false">
17+
<tag name="property_info.list_extractor" priority="-1000" />
18+
<tag name="property_info.type_extractor" priority="-1000" />
19+
<tag name="property_info.access_extractor" priority="-1000" />
20+
</service>
21+
</services>
22+
</container>

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<xsd:element name="annotations" type="annotations" minOccurs="0" maxOccurs="1" />
2424
<xsd:element name="property-access" type="property_access" minOccurs="0" maxOccurs="1" />
2525
<xsd:element name="serializer" type="serializer" minOccurs="0" maxOccurs="1" />
26+
<xsd:element name="property-info" type="property_info" minOccurs="0" maxOccurs="1" />
2627
</xsd:all>
2728

2829
<xsd:attribute name="http-method-override" type="xsd:boolean" />
@@ -190,4 +191,8 @@
190191
<xsd:attribute name="enable-annotations" type="xsd:boolean" />
191192
<xsd:attribute name="name-converter" type="xsd:string" />
192193
</xsd:complexType>
194+
195+
<xsd:complexType name="property_info">
196+
<xsd:attribute name="enabled" type="xsd:boolean" />
197+
</xsd:complexType>
193198
</xsd:schema>

0 commit comments

Comments
 (0)
0