8000 Merge branch '3.0' · symfony/symfony@f5cf886 · GitHub
[go: up one dir, main page]

Skip to content

Commit f5cf886

Browse files
committed
Merge branch '3.0'
* 3.0: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
2 parents 5ebecca + 4a08c88 commit f5cf886

File tree

48 files changed

+416
-1014
lines changed

Some content is hidden

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

48 files changed

+416
-1014
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ public function loadChoicesForValues(array $values, $value = null)
146146

147147
// Optimize performance in case we have an object loader and
148148
// a single-field identifier
149-
if (null === $value && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
149+
$optimize = null === $value || is_array($value) && $value[0] === $this->idReader;
150+
151+
if ($optimize && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
150152
$unorderedObjects = $this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values);
151153
$objectsById = array();
152154
$objects = array();

src/Symfony/Bridge/Doctrine/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ various Symfony components.
77
Resources
88
---------
99

10-
You can run the unit tests with the following command:
11-
12-
$ cd path/to/Symfony/Bridge/Doctrine/
13-
$ composer install
14-
$ phpunit
10+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
11+
* [Report issues](https://github.com/symfony/symfony/issues) and
12+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
13+
in the [main Symfony repository](https://github.com/symfony/symfony)

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,30 @@ public function testOverrideChoicesValuesWithCallable()
802802
$this->assertSame('BooGroup/Bar', $field->getViewData());
803803
}
804804

805+
public function testChoicesForValuesOptimization()
806+
{
807+
$entity1 = new SingleIntIdEntity(1, 'Foo');
808+
$entity2 = new SingleIntIdEntity(2, 'Bar');
809+
810+
$this->persist(array($entity1, $entity2));
811+
812+
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
813+
'em' => 'default',
814+
'class' => self::SINGLE_IDENT_CLASS,
815+
'choice_label' => 'name',
816+
));
817+
818+
$this->em->clear();
819+
820+
$field->submit(1);
821+
822+
$unitOfWorkIdentityMap = $this->em->getUnitOfWork()->getIdentityMap();
823+
$managedEntitiesNames = array_map('strval', $unitOfWorkIdentityMap['Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity']);
824+
825+
$this->assertContains((string) $entity1, $managedEntitiesNames);
826+
$this->assertNotContains((string) $entity2, $managedEntitiesNames);
827+
}
828+
805829
public function testGroupByChoices()
806830
{
807831
$item1 = new GroupableEntity(1, 'Foo', 'Group1');

src/Symfony/Bridge/Monolog/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ Provides integration for Monolog with various Symfony components.
66
Resources
77
---------
88

9-
You can run the unit tests with the following command:
10-
11-
$ cd path/to/Symfony/Bridge/Monolog/
12-
$ composer install
13-
$ phpunit
9+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
10+
* [Report issues](https://github.com/symfony/symfony/issues) and
11+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
12+
in the [main Symfony repository](https://github.com/symfony/symfony)

src/Symfony/Bridge/Propel1/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Propel Bridge
2+
=============
3+
4+
Provides integration for Propel with various Symfony components.
5+
6+
Resources
7+
---------
8+
9+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
10+
* [Report issues](https://github.com/symfony/symfony/issues) and
11+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
12+
in the [main Symfony repository](https://github.com/symfony/symfony)

src/Symfony/Bridge/ProxyManager/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ Provides integration for [ProxyManager][1] with various Symfony components.
66
Resources
77
---------
88

9-
You can run the unit tests with the following command:
10-
11-
$ cd path/to/Symfony/Bridge/ProxyManager/
12-
$ composer install
13-
$ phpunit
9+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
10+
* [Report issues](https://github.com/symfony/symfony/issues) and
11+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
12+
in the [main Symfony repository](https://github.com/symfony/symfony)
1413

1514
[1]: https://github.com/Ocramius/ProxyManager

src/Symfony/Bridge/Twig/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Symfony components.
77
Resources
88
---------
99

10-
If you want to run the unit tests, install dev dependencies before
11-
running PHPUnit:
12-
13-
$ cd path/to/Symfony/Bridge/Twig/
14-
$ composer install
15-
$ phpunit
10+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
11+
* [Report issues](https://github.com/symfony/symfony/issues) and
12+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
13+
in the [main Symfony repository](https://github.com/symfony/symfony)

src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function parse($name)
5555
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
5656
}
5757

58-
if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
58+
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || $this->isAbsolutePath($name) || 0 === strpos($name, '@')) {
5959
return parent::parse($name);
6060
}
6161

@@ -71,4 +71,9 @@ public function parse($name)
7171

7272
return $this->cache[$name] = $template;
7373
}
74+
75+
private function isAbsolutePath($file)
76+
{
77+
return (bool) preg_match('#^(?:/|[a-zA-Z]:)#', $file);
78+
}
7479
}

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public function parseProvider()
6666
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
6767
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
6868
array('FooBundle:Post:foo.bar.index.html.php', 'FooBundle:Post:foo.bar.index.html.php', '@FooBundle/Resources/views/Post/foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
69+
array('@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', new BaseTemplateReference('@FooBundle/Resources/views/layout.html.twig', 'twig')),
70+
array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
71+
array('/path/to/section/index.html.php', '/path/to/section/index.html.php', '/path/to/section/index.html.php', new BaseTemplateReference('/path/to/section/index.html.php', 'php')),
72+
array('C:\\path\\to\\section\\name.html.php', 'C:path/to/section/name.html.php', 'C:path/to/section/name.html.php', new BaseTemplateReference('C:path/to/section/name.html.php', 'php')),
73+
array('C:\\path\\to\\section\\name:foo.html.php', 'C:path/to/section/name:foo.html.php', 'C:path/to/section/name:foo.html.php', new BaseTemplateReference('C:path/to/section/name:foo.html.php', 'php')),
74+
array('\\path\\to\\section\\name.html.php', '/path/to/section/name.html.php', '/path/to/section/name.html.php', new BaseTemplateReference('/path/to/section/name.html.php', 'php')),
6975
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
7076
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
7177
array('name', 'name', 'name', new BaseTemplateReference('name')),

src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,18 @@ protected function findTemplate($template, $throw = true)
7676
try {
7777
$file = parent::findTemplate($logicalName);
7878
} catch (\Twig_Error_Loader $e) {
79-
$previous = $e;
79+
$twigLoaderException = $e;
8080

8181
// for BC
8282
try {
8383
$template = $this->parser->parse($template);
8484
$file = $this->locator->locate($template);
8585
} catch (\Exception $e) {
86-
$previous = $e;
8786
}
8887
}
8988

9089
if (false === $file || null === $file) {
91-
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous);
90+
throw $twigLoaderException;
9291
}
9392

9493
return $this->cache[$logicalName] = $file;

src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,21 @@ public function testTwigErrorIfLocatorReturnsFalse()
9898
$loader = new FilesystemLoader($locator, $parser);
9999
$loader->getCacheKey('name.format.engine');
100100
}
101+
102+
/**
103+
* @expectedException \Twig_Error_Loader
104+
* @expectedExceptionMessageRegExp /Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.Resources.views\)/
105+
*/
106+
public function testTwigErrorIfTemplateDoesNotExist()
107+
{
108+
$parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
109+
$locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
110+
111+
$loader = new FilesystemLoader($locator, $parser);
112+
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views');
113+
114+
$method = new \ReflectionMethod('Symfony\Bundle\TwigBundle\Loader\FilesystemLoader', 'findTemplate');
115+
$method->setAccessible(true);
116+
$method->invoke($loader, 'name.format.engine');
117+
}
101118
}

src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Routing\RouterInterface;
1919
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2020
use Symfony\Component\HttpKernel\Profiler\Profiler;
21+
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
2122

2223
/**
2324
* RouterController.
@@ -62,16 +63,39 @@ public function panelAction($token)
6263

6364
$profile = $this->profiler->loadProfile($token);
6465

65-
$context = $this->matcher->getContext();
66-
$context->setMethod($profile->getMethod());
67-
$matcher = new TraceableUrlMatcher($this->routes, $context);
68-
66+
/** @var RequestDataCollector $request */
6967
$request = $profile->getCollector('request');
7068

7169
return new Response($this->twig->render('@WebProfiler/Router/panel.html.twig', array(
7270
'request' => $request,
7371
'router' => $profile->getCollector('router'),
74-
'traces' => $matcher->getTraces($request->getPathInfo()),
72+
'traces' => $this->getTraces($request, $profile->getMethod()),
7573
)), 200, array('Content-Type' => 'text/html'));
7674
}
75+
76+
/**
77+
* Returns the routing traces associated to the given request.
78+
*
79+
* @param RequestDataCollector $request
80+
* @param string $method
81+
*
82+
* @return array
83+
*/
84+
private function getTraces(RequestDataCollector $request, $method)
85+
{
86+
$traceRequest = Request::create(
87+
$request->getPathInfo(),
88+
$request->getRequestServer()->get('REQUEST_METHOD'),
89+
$request->getRequestAttributes()->all(),
90+
$request->getRequestCookies()->all(),
91+
array(),
92+
$request->getRequestServer()->all()
93+
);
94+
95+
$context = $this->matcher->getContext();
96+
$context->setMethod($method);
97+
$matcher = new TraceableUrlMatcher($this->routes, $context);
98+
99+
return $matcher->getTracesForRequest($traceRequest);
100+
}
77101
}
Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
BrowserKit Component
22
====================
33

4-
BrowserKit simulates the behavior of a web browser.
5-
6-
The component only provides an abstract client and does not provide any
7-
"default" backend for the HTTP layer.
4+
The BrowserKit component simulates the behavior of a web browser, allowing you
5+
to make requests, click on links and submit forms programmatically.
86

97
Resources
108
---------
119

12-
For a simple implementation of a browser based on an HTTP layer, have a look
13-
at [Goutte](https://github.com/FriendsOfPHP/Goutte).
14-
15-
For an implementation based on HttpKernelInterface, have a look at the
16-
[Client](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Client.php)
17-
provided by the HttpKernel component.
18-
19-
You can run the unit tests with the following command:
20-
21-
$ cd path/to/Symfony/Component/BrowserKit/
22-
$ composer install
23-
$ phpunit
10+
* [Documentation](https://symfony.com/doc/current/components/browser_kit/introduction.html)
11+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
12+
* [Report issues](https://github.com/symfony/symfony/issues) and
13+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
14+
in the [main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,14 @@
11
ClassLoader Component
22
=====================
33

4-
ClassLoader loads your project classes automatically if they follow some
5-
standard PHP conventions.
6-
7-
The ClassLoader object is able to autoload classes that implement the PSR-0
8-
standard or the PEAR naming convention.
9-
10-
First, register the autoloader:
11-
12-
```php
13-
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
14-
15-
use Symfony\Component\ClassLoader\ClassLoader;
16-
17-
$loader = new ClassLoader();
18-
$loader->register();
19-
```
20-
21-
Then, register some namespaces with the `addPrefix()` method:
22-
23-
```php
24-
$loader->addPrefix('Symfony', __DIR__.'/src');
25-
$loader->addPrefix('Monolog', __DIR__.'/vendor/monolog/src');
26-
```
27-
28-
The `addPrefix()` method takes a namespace prefix and a path where to look for
29-
the classes as arguments.
30-
31-
You can also register a sub-namespaces:
32-
33-
```php
34-
$loader->addPrefix('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
35-
```
36-
37-
The order of registration is significant and the first registered namespace
38-
takes precedence over later registered one.
39-
40-
You can also register more than one path for a given namespace:
41-
42-
```php
43-
$loader->addPrefix('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
44-
```
45-
46-
Alternatively, you can use the `addPrefixes()` method to register more
47-
than one namespace at once:
48-
49-
```php
50-
$loader->addPrefixes(array(
51-
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
52-
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
53-
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
54-
'Monolog' => __DIR__.'/vendor/monolog/src',
55-
));
56-
```
57-
58-
For better performance, you can use the APC class loader:
59-
60-
```php
61-
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader.php';
62-
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcClassLoader.php';
63-
64-
use Symfony\Component\ClassLoader\ClassLoader;
65-
use Symfony\Component\ClassLoader\ApcClassLoader;
66-
67-
$loader = new ClassLoader();
68-
$loader->addPrefix('Symfony', __DIR__.'/src');
69-
70-
$loader = new ApcClassLoader('apc.prefix.', $loader);
71-
$loader->register();
72-
```
73-
74-
Furthermore, the component provides tools to aggregate classes into a single
75-
file, which is especially useful to improve performance on servers that do not
76-
provide byte caches.
4+
The ClassLoader component provides tools to autoload your classes and cache
5+
their locations for performance.
776

787
Resources
798
---------
809

81-
You can run the unit tests with the following command:
82-
83-
$ cd path/to/Symfony/Component/ClassLoader/
84-
$ composer install
85-
$ phpunit
10+
* [Documentation](https://symfony.com/doc/current/components/class_loader/index.html)
11+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
12+
* [Report issues](https://github.com/symfony/symfony/issues) and
13+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
14+
in the [main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
Config Component
22
================
33

4-
Config provides the infrastructure for loading configurations from different
5-
data sources and optionally monitoring these data sources for changes. There
6-
are additional tools for validating, normalizing and handling of defaults that
7-
can optionally be used to convert from different formats to arrays.
4+
The Config component provides several classes to help you find, load, combine,
5+
autofill and validate configuration values of any kind, whatever their source
6+
may be (YAML, XML, INI files, or for instance a database).
87

98
Resources
109
---------
1110

12-
You can run the unit tests with the following command:
13-
14-
$ cd path/to/Symfony/Component/Config/
15-
$ composer install
16-
$ phpunit
17-
11+
* [Documentation](https://symfony.com/doc/current/components/config/index.html)
12+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
13+
* [Report issues](https://github.com/symfony/symfony/issues) and
14+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
15+
in the [main Symfony repository](https://github.com/symfony/symfony)

0 commit comments

Comments
 (0)
0