Commit a8068088 authored by webchick's avatar webchick

Issue #1834594 by effulgentsia, Rob Loach: Update dependencies (Symfony and...

Issue #1834594 by effulgentsia, Rob Loach: Update dependencies (Symfony and Twig) follow up fixes for Composer.
parent 97969786
......@@ -3,18 +3,18 @@
"description": "Drupal is an open source content management platform powering millions of websites and applications.",
"license": "GPL-2.0+",
"require": {
"symfony/class-loader": "<2.4@dev",
"symfony/dependency-injection": "<2.4@dev",
"symfony/event-dispatcher": "<2.4@dev",
"symfony/http-foundation": "<2.4@dev",
"symfony/http-kernel": "<2.4@dev",
"symfony/routing": "<2.4@dev",
"symfony/serializer": "<2.4@dev",
"symfony/yaml": "<2.4@dev",
"twig/twig": "1.*",
"doctrine/common": "2.3.*",
"guzzle/http": "3.*",
"kriswallsmith/assetic": "1.1.*"
"symfony/class-loader": "<2.4",
"symfony/dependency-injection": "<2.4",
"symfony/event-dispatcher": "<2.4",
"symfony/http-foundation": "<2.4",
"symfony/http-kernel": "<2.4",
"symfony/routing": "<2.4",
"symfony/serializer": "<2.4",
"symfony/yaml": "<2.4",
"twig/twig": "1.*@stable",
"doctrine/common": "2.3.*@stable",
"guzzle/http": "*",
"kriswallsmith/assetic": "1.1.*@alpha"
},
"minimum-stability": "alpha"
"minimum-stability": "dev"
}
This diff is collapsed.
......@@ -3096,18 +3096,31 @@ function drupal_classloader() {
'Drupal\Component' => DRUPAL_ROOT . '/core/lib',
));
// Register namespaces for vendor libraries managed by Composer.
$namespaces = require DRUPAL_ROOT . '/core/vendor/composer/autoload_namespaces.php';
// Register namespaces and PEAR-like prefixes for vendor libraries managed
// by Composer. Composer combines libraries that use PHP 5.3 namespaces and
// ones that use PEAR-like class prefixes in a single array, but the Symfony
// class loader requires them to be registered separately.
$prefixes_and_namespaces = require DRUPAL_ROOT . '/core/vendor/composer/autoload_namespaces.php';
$prefixes = array();
foreach ($namespaces as $namespace => $path) {
// Composer combines libraries that use PHP 5.3 namespaces and ones that
// use PEAR-style class prefixes in a single array, but the Symfony class
// loader requires them to be registered separately. PSR-0 disallows
// underscores in namespace names and requires at least one in a
// PEAR-style class prefix.
if (strpos($namespace, '_') !== FALSE) {
$prefixes[$namespace] = $path;
unset($namespaces[$namespace]);
$namespaces = array();
foreach ($prefixes_and_namespaces as $key => $path) {
// If the key:
// - Contains a namespace separator, we know it's a namespace.
// - Doesn't contain a namespace separator and ends in an "_" (e.g.,
// "Twig_"), it's likely intended as a PEAR-like prefix rather than a
// namespace.
// - Doesn't contain a namespace separator or end in an "_" (e.g.,
// "Assetic"), then it could be either a namespace or an incomplete
// PEAR-like prefix, but we assume the former, since the only example of
// that currently in Drupal is Assetic.
// @todo Switch to a class loader that doesn't require this guessing:
// http://drupal.org/node/1658720.
$is_namespace = (strpos($key, '\\') !== FALSE) && (substr($key, -1) !== '_');
if ($is_namespace) {
$namespaces[rtrim($key, '\\')] = $path;
}
else {
$prefixes[$key] = $path;
}
}
$loader->registerPrefixes($prefixes);
......
......@@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98::getLoader();
return ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592::getLoader();
......@@ -7,16 +7,15 @@
return array(
'Twig_' => $vendorDir . '/twig/twig/lib/',
'Symfony\\Component\\Yaml' => $vendorDir . '/symfony/yaml/',
'Symfony\\Component\\Serializer' => $vendorDir . '/symfony/serializer/',
'Symfony\\Component\\Routing' => $vendorDir . '/symfony/routing/',
'Symfony\\Component\\Yaml\\' => $vendorDir . '/symfony/yaml/',
'Symfony\\Component\\Serializer\\' => $vendorDir . '/symfony/serializer/',
'Symfony\\Component\\Routing\\' => $vendorDir . '/symfony/routing/',
'Symfony\\Component\\Process' => $vendorDir . '/symfony/process/',
'Symfony\\Component\\HttpKernel' => $vendorDir . '/symfony/http-kernel/',
'Symfony\\Component\\HttpFoundation' => $vendorDir . '/symfony/http-foundation/',
'Symfony\\Component\\EventDispatcher' => $vendorDir . '/symfony/event-dispatcher/',
'Symfony\\Component\\DependencyInjection' => $vendorDir . '/symfony/dependency-injection/',
'Symfony\\Component\\ClassLoader' => $vendorDir . '/symfony/class-loader/',
'SessionHandlerInterface' => $vendorDir . '/symfony/http-foundation/Symfony/Component/HttpFoundation/Resources/stubs',
'Symfony\\Component\\HttpKernel\\' => $vendorDir . '/symfony/http-kernel/',
'Symfony\\Component\\HttpFoundation\\' => $vendorDir . '/symfony/http-foundation/',
'Symfony\\Component\\EventDispatcher\\' => $vendorDir . '/symfony/event-dispatcher/',
'Symfony\\Component\\DependencyInjection\\' => $vendorDir . '/symfony/dependency-injection/',
'Symfony\\Component\\ClassLoader\\' => $vendorDir . '/symfony/class-loader/',
'Guzzle\\Stream' => $vendorDir . '/guzzle/stream/',
'Guzzle\\Parser' => $vendorDir . '/guzzle/parser/',
'Guzzle\\Http' => $vendorDir . '/guzzle/http/',
......
......@@ -2,7 +2,7 @@
// autoload_real.php generated by Composer
class ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98
class ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592
{
private static $loader;
......@@ -19,9 +19,9 @@ public static function getLoader()
return static::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98', 'loadClassLoader'));
spl_autoload_register(array('ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592', 'loadClassLoader'));
static::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592', 'loadClassLoader'));
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
......
This diff is collapsed.
......@@ -6,7 +6,7 @@
"license": "MIT",
"require": {
"php": ">=5.3.2",
"symfony/event-dispatcher": "2.1.*"
"symfony/event-dispatcher": ">=2.1"
},
"autoload": {
"psr-0": { "Guzzle\\Common": "" }
......
......@@ -4,6 +4,7 @@ CHANGELOG
2.2.0
-----
* added a IpUtils class to check if an IP belongs to a CIDR
* added Request::getRealMethod() to get the "real" HTTP method (getMethod() returns the "intended" HTTP method)
* disabled _method request parameter support by default (call Request::enableHttpMethodParameterOverride() to enable it)
* Request::splitHttpAcceptHeader() method is deprecated and will be removed in 2.3
......
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation;
/**
* Http utility functions.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class IpUtils
{
/**
* This class should not be instantiated
*/
private function __construct() {}
/**
* Validates an IPv4 or IPv6 address.
*
* @param string $requestIp
* @param string $ip
*
* @return boolean Whether the IP is valid
*/
public static function checkIp($requestIp, $ip)
{
if (false !== strpos($requestIp, ':')) {
return self::checkIp6($requestIp, $ip);
}
return self::checkIp4($requestIp, $ip);
}
/**
* Validates an IPv4 address.
*
* @param string $requestIp
* @param string $ip
*
* @return boolean Whether the IP is valid
*/
public static function checkIp4($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
list($address, $netmask) = explode('/', $ip, 2);
if ($netmask < 1 || $netmask > 32) {
return false;
}
} else {
$address = $ip;
$netmask = 32;
}
return 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask);
}
/**
* Validates an IPv6 address.
*
* @author David Soria Parra <dsp at php dot net>
* @see https://github.com/dsp/v6tools
*
* @param string $requestIp
* @param string $ip
*
* @return boolean Whether the IP is valid
*
* @throws \RuntimeException When IPV6 support is not enabled
*/
public static function checkIp6($requestIp, $ip)
{
if (!((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'))) {
throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".');
}
if (false !== strpos($ip, '/')) {
list($address, $netmask) = explode('/', $ip, 2);
if ($netmask < 1 || $netmask > 128) {
return false;
}
} else {
$address = $ip;
$netmask = 128;
}
$bytesAddr = unpack("n*", inet_pton($address));
$bytesTest = unpack("n*", inet_pton($requestIp));
for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) {
$left = $netmask - 16 * ($i-1);
$left = ($left <= 16) ? $left : 16;
$mask = ~(0xffff >> $left) & 0xffff;
if (($bytesAddr[$i] & $mask) != ($bytesTest[$i] & $mask)) {
return false;
}
}
return true;
}
}
......@@ -143,96 +143,11 @@ public function matches(Request $request)
return false;
}
if (null !== $this->ip && !$this->checkIp($request->getClientIp(), $this->ip)) {
if (null !== $this->ip && !IpUtils::checkIp($request->getClientIp(), $this->ip)) {
return false;
}
return true;
}
/**
* Validates an IP address.
*
* @param string $requestIp
* @param string $ip
*
* @return boolean True valid, false if not.
*/
protected function checkIp($requestIp, $ip)
{
// IPv6 address
if (false !== strpos($requestIp, ':')) {
return $this->checkIp6($requestIp, $ip);
} else {
return $this->checkIp4($requestIp, $ip);
}
}
/**
* Validates an IPv4 address.
*
* @param string $requestIp
* @param string $ip
*
* @return boolean True valid, false if not.
*/
protected function checkIp4($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
list($address, $netmask) = explode('/', $ip, 2);
if ($netmask < 1 || $netmask > 32) {
return false;
}
} else {
$address = $ip;
$netmask = 32;
}
return 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask);
}
/**
* Validates an IPv6 address.
*
* @author David Soria Parra <dsp at php dot net>
* @see https://github.com/dsp/v6tools
*
* @param string $requestIp
* @param string $ip
*
* @return boolean True valid, false if not.
*/
protected function checkIp6($requestIp, $ip)
{
if (!((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'))) {
throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".');
}
if (false !== strpos($ip, '/')) {
list($address, $netmask) = explode('/', $ip, 2);
if ($netmask < 1 || $netmask > 128) {
return false;
}
} else {
$address = $ip;
$netmask = 128;
}
$bytesAddr = unpack("n*", inet_pton($address));
$bytesTest = unpack("n*", inet_pton($requestIp));
for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) {
$left = $netmask - 16 * ($i-1);
$left = ($left <= 16) ? $left : 16;
$mask = ~(0xffff >> $left) & 0xffff;
if (($bytesAddr[$i] & $mask) != ($bytesTest[$i] & $mask)) {
return false;
}
}
return true;
}
}
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Tests;
use Symfony\Component\HttpFoundation\IpUtils;
class IpUtilsTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider testIpv4Provider
*/
public function testIpv4($matches, $remoteAddr, $cidr)
{
$this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr));
}
public function testIpv4Provider()
{
return array(
array(true, '192.168.1.1', '192.168.1.1'),
array(true, '192.168.1.1', '192.168.1.1/1'),
array(true, '192.168.1.1', '192.168.1.0/24'),
array(false, '192.168.1.1', '1.2.3.4/1'),
array(false, '192.168.1.1', '192.168.1/33'),
);
}
/**
* @dataProvider testIpv6Provider
*/
public function testIpv6($matches, $remoteAddr, $cidr)
{
if (!defined('AF_INET6')) {
$this->markTestSkipped('Only works when PHP is compiled without the option "disable-ipv6".');
}
$this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr));
}
public function testIpv6Provider()
{
return array(
array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
array(false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'),
array(true, '0:0:0:0:0:0:0:1', '::1'),
array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'),
);
}
/**
* @expectedException \RuntimeException
*/
public function testAnIpv6WithOptionDisabledIpv6()
{
if (defined('AF_INET6')) {
$this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".');
}
IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65');
}
}
......@@ -16,78 +16,6 @@
class RequestMatcherTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider testIpv4Provider
*/
public function testIpv4($matches, $remoteAddr, $cidr)
{
$request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => $remoteAddr));
$matcher = new RequestMatcher();
$matcher->matchIp($cidr);
$this->assertEquals($matches, $matcher->matches($request));
}
public function testIpv4Provider()
{
return array(
array(true, '192.168.1.1', '192.168.1.1'),
array(true, '192.168.1.1', '192.168.1.1/1'),
array(true, '192.168.1.1', '192.168.1.0/24'),
array(false, '192.168.1.1', '1.2.3.4/1'),
array(false, '192.168.1.1', '192.168.1/33'),
);
}
/**
* @dataProvider testIpv6Provider
*/
public function testIpv6($matches, $remoteAddr, $cidr)
{
if (!defined('AF_INET6')) {
$this->markTestSkipped('Only works when PHP is compiled without the option "disable-ipv6".');
}
$request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => $remoteAddr));
$matcher = new RequestMatcher();
$matcher->matchIp($cidr);
$this->assertEquals($matches, $matcher->matches($request));
}
public function testIpv6Provider()
{
return array(
array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
array(false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'),
array(true, '0:0:0:0:0:0:0:1', '::1'),
array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'),
);
}
public function testAnIpv6WithOptionDisabledIpv6()
{
if (defined('AF_INET6')) {
$this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".');
}
$request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => '2a01:198:603:0:396e:4789:8e99:890f'));
$matcher = new RequestMatcher();
$matcher->matchIp('2a01:198:603:0::/65');
try {
$matcher->matches($request);
$this->fail('An expected RuntimeException has not been raised.');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e);
}
}
/**
* @dataProvider testMethodFixtures
*/
......@@ -200,4 +128,3 @@ public function testAttributes()
$this->assertFalse($matcher->matches($request));
}
}
......@@ -38,8 +38,9 @@ public function collect(Request $request, Response $response, \Exception $except
{
if (null !== $this->logger) {
$this->data = array(
'error_count' => $this->logger->countErrors(),
'logs' => $this->sanitizeLogs($this->logger->getLogs()),
'error_count' => $this->logger->countErrors(),
'logs' => $this->sanitizeLogs($this->logger->getLogs()),
'deprecation_count' => $this->computeDeprecationCount()
);
}
}
......@@ -66,6 +67,11 @@ public function getLogs()
return isset($this->data['logs']) ? $this->data['logs'] : array();
}
public function countDeprecations()
{
return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
}
/**
* {@inheritdoc}
*/
......@@ -103,4 +109,16 @@ private function sanitizeContext($context)
return $context;
}
private function computeDeprecationCount()
{
$count = 0;
foreach ($this->logger->getLogs() as $log) {
if (isset($log['context']['type']) && 'deprecation' === $log['context']['type']) {
$count++;
}
}
return $count;
}
}
......@@ -11,6 +11,9 @@
namespace Symfony\Component\HttpKernel\Debug;
use Symfony\Component\HttpKernel\Exception\FatalErrorException;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
/**
* ErrorHandler.
*
......@@ -28,10 +31,19 @@ class ErrorHandler
E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User Deprecated',
E_ERROR => 'Error',
E_CORE_ERROR => 'Core Error',
E_COMPILE_ERROR => 'Compile Error',
E_PARSE => 'Parse',
);
private $level;
private $reservedMemory;
/** @var LoggerInterface */
private static $logger;
/**
* Register the error handler.
*
......@@ -45,6 +57,8 @@ public static function register($level = null)
$handler->setLevel($level);
set_error_handler(array($handler, 'handle'));
register_shutdown_function(array($handler, 'handleFatal'));
$handler->reservedMemory = str_repeat('x', 10240);
return $handler;
}
......@@ -54,6 +68,11 @@ public function setLevel($level)
$this->level = null === $level ? error_reporting() : $level;
}
public static function setLogger(LoggerInterface $logger)
{
self::$logger = $logger;
}
/**
* @throws \ErrorException When error_reporting returns error
*/
......@@ -63,10 +82,42 @@ public function handle($level, $message, $file, $line, $context)
return false;
}
if ($level & E_USER_DEPRECATED || $level & E_DEPRECATED) {
if (null !== self::$logger) {
self::$logger->warn($message, array('type' => 'deprecation', 'file' => $file, 'line' => $line));
}
return true;
}
if (error_reporting() & $level && $this->level & $level) {
throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line);
}
return false;
}
public function handleFatal()
{
if (null === $error = error_get_last()) {
return;
}
unset($this->reservedMemory);
$type = $error['type'];
if (0 === $this->level || !in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
return;
}
// get current exception handler
$exceptionHandler = set_exception_handler(function() {});
restore_exception_handler();
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
$level = isset($this->levels[$type]) ? $this->levels[$type] : $type;
$message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);
$exception = new FatalErrorException($message, 0, $type, $error['file'], $error['line']);
$exceptionHandler[0]->handle($exception);
}
}
}
......@@ -234,6 +234,9 @@ private function decorate($content, $css)
img { border: 0; }
#sf-resetcontent { width:970px; margin:0 auto; }
$css
.xdebug-error {
display: none;
}
</style>
</head>
<body>
......
......@@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\DependencyInjection;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
......@@ -84,6 +85,8 @@ public function getNamespace()