Merge branch '2.0' into 2.1
* 2.0: [DependencyInjection] Allow frozen containers to be dumped to graphviz Add dot character `.` to legal mime subtype regular expression [HttpFoundation] fixed the creation of sub-requests under some circumstancies (closes #6923, closes #6936)
This commit is contained in:
commit
648527355d
@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\Definition;
|
|||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Parameter;
|
use Symfony\Component\DependencyInjection\Parameter;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GraphvizDumper dumps a service container as a graphviz file.
|
* GraphvizDumper dumps a service container as a graphviz file.
|
||||||
@ -159,7 +161,7 @@ class GraphvizDumper extends Dumper
|
|||||||
{
|
{
|
||||||
$nodes = array();
|
$nodes = array();
|
||||||
|
|
||||||
$container = clone $this->container;
|
$container = $this->cloneContainer();
|
||||||
|
|
||||||
foreach ($container->getDefinitions() as $id => $definition) {
|
foreach ($container->getDefinitions() as $id => $definition) {
|
||||||
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $this->container->getParameterBag()->resolveValue($definition->getClass())), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted')));
|
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $this->container->getParameterBag()->resolveValue($definition->getClass())), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted')));
|
||||||
@ -175,13 +177,31 @@ class GraphvizDumper extends Dumper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$container->hasDefinition($id)) {
|
if (!$container->hasDefinition($id)) {
|
||||||
$nodes[$id] = array('class' => str_replace('\\', '\\\\', get_class($service)), 'attributes' => $this->options['node.instance']);
|
$class = ('service_container' === $id) ? get_class($this->container) : get_class($service);
|
||||||
|
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => $this->options['node.instance']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $nodes;
|
return $nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function cloneContainer()
|
||||||
|
{
|
||||||
|
$parameterBag = new ParameterBag($this->container->getParameterBag()->all());
|
||||||
|
|
||||||
|
$container = new ContainerBuilder($parameterBag);
|
||||||
|
$container->setDefinitions($this->container->getDefinitions());
|
||||||
|
$container->setAliases($this->container->getAliases());
|
||||||
|
foreach ($this->container->getScopes() as $scope) {
|
||||||
|
$container->addScope($scope);
|
||||||
|
}
|
||||||
|
foreach ($this->container->getExtensions() as $extension) {
|
||||||
|
$container->registerExtension($extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $container;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the start dot.
|
* Returns the start dot.
|
||||||
*
|
*
|
||||||
|
@ -55,4 +55,18 @@ class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'),
|
'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'),
|
||||||
)), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services');
|
)), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDumpWithFrozenContainer()
|
||||||
|
{
|
||||||
|
$container = include self::$fixturesPath.'/containers/container13.php';
|
||||||
|
$dumper = new GraphvizDumper($container);
|
||||||
|
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services13.dot')), $dumper->dump(), '->dump() dumps services');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDumpWithFrozenCustomClassContainer()
|
||||||
|
{
|
||||||
|
$container = include self::$fixturesPath.'/containers/container14.php';
|
||||||
|
$dumper = new GraphvizDumper($container);
|
||||||
|
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
|
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->
|
||||||
|
register('foo', 'FooClass')->
|
||||||
|
addArgument(new Reference('bar'))
|
||||||
|
;
|
||||||
|
$container->compile();
|
||||||
|
|
||||||
|
return $container;
|
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Container14;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
class ProjectServiceContainer extends ContainerBuilder
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ProjectServiceContainer();
|
@ -0,0 +1,8 @@
|
|||||||
|
digraph sc {
|
||||||
|
ratio="compress"
|
||||||
|
node [fontsize="11" fontname="Arial" shape="record"];
|
||||||
|
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
|
||||||
|
|
||||||
|
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
|
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
digraph sc {
|
||||||
|
ratio="compress"
|
||||||
|
node [fontsize="11" fontname="Arial" shape="record"];
|
||||||
|
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
|
||||||
|
|
||||||
|
node_service_container [label="service_container\nContainer14\\ProjectServiceContainer\n", shape=record, fillcolor="#9999ff", style="filled"];
|
||||||
|
}
|
@ -77,7 +77,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
|
|
||||||
$type = trim(ob_get_clean());
|
$type = trim(ob_get_clean());
|
||||||
|
|
||||||
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-]+)#i', $type, $match)) {
|
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) {
|
||||||
// it's not a type, but an error message
|
// it's not a type, but an error message
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1427,12 +1427,16 @@ class Request
|
|||||||
if ($this->headers->has('X_ORIGINAL_URL') && false !== stripos(PHP_OS, 'WIN')) {
|
if ($this->headers->has('X_ORIGINAL_URL') && false !== stripos(PHP_OS, 'WIN')) {
|
||||||
// IIS with Microsoft Rewrite Module
|
// IIS with Microsoft Rewrite Module
|
||||||
$requestUri = $this->headers->get('X_ORIGINAL_URL');
|
$requestUri = $this->headers->get('X_ORIGINAL_URL');
|
||||||
|
$this->headers->remove('X_ORIGINAL_URL');
|
||||||
} elseif ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
|
} elseif ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
|
||||||
// IIS with ISAPI_Rewrite
|
// IIS with ISAPI_Rewrite
|
||||||
$requestUri = $this->headers->get('X_REWRITE_URL');
|
$requestUri = $this->headers->get('X_REWRITE_URL');
|
||||||
|
$this->headers->remove('X_REWRITE_URL');
|
||||||
} elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
|
} elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
|
||||||
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
|
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
|
||||||
$requestUri = $this->server->get('UNENCODED_URL');
|
$requestUri = $this->server->get('UNENCODED_URL');
|
||||||
|
$this->server->remove('UNENCODED_URL');
|
||||||
|
$this->server->remove('IIS_WasUrlRewritten');
|
||||||
} elseif ($this->server->has('REQUEST_URI')) {
|
} elseif ($this->server->has('REQUEST_URI')) {
|
||||||
$requestUri = $this->server->get('REQUEST_URI');
|
$requestUri = $this->server->get('REQUEST_URI');
|
||||||
// HTTP proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
|
// HTTP proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
|
||||||
@ -1446,8 +1450,12 @@ class Request
|
|||||||
if ('' != $this->server->get('QUERY_STRING')) {
|
if ('' != $this->server->get('QUERY_STRING')) {
|
||||||
$requestUri .= '?'.$this->server->get('QUERY_STRING');
|
$requestUri .= '?'.$this->server->get('QUERY_STRING');
|
||||||
}
|
}
|
||||||
|
$this->server->remove('ORIG_PATH_INFO');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normalize the request URI to ease creating sub-requests from this request
|
||||||
|
$this->server->set('REQUEST_URI', $requestUri);
|
||||||
|
|
||||||
return $requestUri;
|
return $requestUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user