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 @@ ...@@ -3,18 +3,18 @@
"description": "Drupal is an open source content management platform powering millions of websites and applications.", "description": "Drupal is an open source content management platform powering millions of websites and applications.",
"license": "GPL-2.0+", "license": "GPL-2.0+",
"require": { "require": {
"symfony/class-loader": "<2.4@dev", "symfony/class-loader": "<2.4",
"symfony/dependency-injection": "<2.4@dev", "symfony/dependency-injection": "<2.4",
"symfony/event-dispatcher": "<2.4@dev", "symfony/event-dispatcher": "<2.4",
"symfony/http-foundation": "<2.4@dev", "symfony/http-foundation": "<2.4",
"symfony/http-kernel": "<2.4@dev", "symfony/http-kernel": "<2.4",
"symfony/routing": "<2.4@dev", "symfony/routing": "<2.4",
"symfony/serializer": "<2.4@dev", "symfony/serializer": "<2.4",
"symfony/yaml": "<2.4@dev", "symfony/yaml": "<2.4",
"twig/twig": "1.*", "twig/twig": "1.*@stable",
"doctrine/common": "2.3.*", "doctrine/common": "2.3.*@stable",
"guzzle/http": "3.*", "guzzle/http": "*",
"kriswallsmith/assetic": "1.1.*" "kriswallsmith/assetic": "1.1.*@alpha"
}, },
"minimum-stability": "alpha" "minimum-stability": "dev"
} }
This diff is collapsed.
...@@ -3096,18 +3096,31 @@ function drupal_classloader() { ...@@ -3096,18 +3096,31 @@ function drupal_classloader() {
'Drupal\Component' => DRUPAL_ROOT . '/core/lib', 'Drupal\Component' => DRUPAL_ROOT . '/core/lib',
)); ));
// Register namespaces for vendor libraries managed by Composer. // Register namespaces and PEAR-like prefixes for vendor libraries managed
$namespaces = require DRUPAL_ROOT . '/core/vendor/composer/autoload_namespaces.php'; // 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(); $prefixes = array();
foreach ($namespaces as $namespace => $path) { $namespaces = array();
// Composer combines libraries that use PHP 5.3 namespaces and ones that foreach ($prefixes_and_namespaces as $key => $path) {
// use PEAR-style class prefixes in a single array, but the Symfony class // If the key:
// loader requires them to be registered separately. PSR-0 disallows // - Contains a namespace separator, we know it's a namespace.
// underscores in namespace names and requires at least one in a // - Doesn't contain a namespace separator and ends in an "_" (e.g.,
// PEAR-style class prefix. // "Twig_"), it's likely intended as a PEAR-like prefix rather than a
if (strpos($namespace, '_') !== FALSE) { // namespace.
$prefixes[$namespace] = $path; // - Doesn't contain a namespace separator or end in an "_" (e.g.,
unset($namespaces[$namespace]); // "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); $loader->registerPrefixes($prefixes);
......
...@@ -4,4 +4,4 @@ ...@@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php'; require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98::getLoader(); return ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592::getLoader();
...@@ -7,16 +7,15 @@ ...@@ -7,16 +7,15 @@
return array( return array(
'Twig_' => $vendorDir . '/twig/twig/lib/', 'Twig_' => $vendorDir . '/twig/twig/lib/',
'Symfony\\Component\\Yaml' => $vendorDir . '/symfony/yaml/', 'Symfony\\Component\\Yaml\\' => $vendorDir . '/symfony/yaml/',
'Symfony\\Component\\Serializer' => $vendorDir . '/symfony/serializer/', 'Symfony\\Component\\Serializer\\' => $vendorDir . '/symfony/serializer/',
'Symfony\\Component\\Routing' => $vendorDir . '/symfony/routing/', 'Symfony\\Component\\Routing\\' => $vendorDir . '/symfony/routing/',
'Symfony\\Component\\Process' => $vendorDir . '/symfony/process/', 'Symfony\\Component\\Process' => $vendorDir . '/symfony/process/',
'Symfony\\Component\\HttpKernel' => $vendorDir . '/symfony/http-kernel/', 'Symfony\\Component\\HttpKernel\\' => $vendorDir . '/symfony/http-kernel/',
'Symfony\\Component\\HttpFoundation' => $vendorDir . '/symfony/http-foundation/', 'Symfony\\Component\\HttpFoundation\\' => $vendorDir . '/symfony/http-foundation/',
'Symfony\\Component\\EventDispatcher' => $vendorDir . '/symfony/event-dispatcher/', 'Symfony\\Component\\EventDispatcher\\' => $vendorDir . '/symfony/event-dispatcher/',
'Symfony\\Component\\DependencyInjection' => $vendorDir . '/symfony/dependency-injection/', 'Symfony\\Component\\DependencyInjection\\' => $vendorDir . '/symfony/dependency-injection/',
'Symfony\\Component\\ClassLoader' => $vendorDir . '/symfony/class-loader/', 'Symfony\\Component\\ClassLoader\\' => $vendorDir . '/symfony/class-loader/',
'SessionHandlerInterface' => $vendorDir . '/symfony/http-foundation/Symfony/Component/HttpFoundation/Resources/stubs',
'Guzzle\\Stream' => $vendorDir . '/guzzle/stream/', 'Guzzle\\Stream' => $vendorDir . '/guzzle/stream/',
'Guzzle\\Parser' => $vendorDir . '/guzzle/parser/', 'Guzzle\\Parser' => $vendorDir . '/guzzle/parser/',
'Guzzle\\Http' => $vendorDir . '/guzzle/http/', 'Guzzle\\Http' => $vendorDir . '/guzzle/http/',
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// autoload_real.php generated by Composer // autoload_real.php generated by Composer
class ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98 class ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592
{ {
private static $loader; private static $loader;
...@@ -19,9 +19,9 @@ public static function getLoader() ...@@ -19,9 +19,9 @@ public static function getLoader()
return static::$loader; return static::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98', 'loadClassLoader')); spl_autoload_register(array('ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592', 'loadClassLoader'));
static::$loader = $loader = new \Composer\Autoload\ClassLoader(); static::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitac017267abab05dbc458e3a320f5ad98', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit295209ab8f7c3b45c210d28fa6db3592', 'loadClassLoader'));
$vendorDir = dirname(__DIR__); $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": ">=5.3.2", "php": ">=5.3.2",
"symfony/event-dispatcher": "2.1.*" "symfony/event-dispatcher": ">=2.1"
}, },
"autoload": { "autoload": {
"psr-0": { "Guzzle\\Common": "" } "psr-0": { "Guzzle\\Common": "" }
......
...@@ -4,6 +4,7 @@ CHANGELOG ...@@ -4,6 +4,7 @@ CHANGELOG
2.2.0 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) * 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) * 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 * 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) ...@@ -143,96 +143,11 @@ public function matches(Request $request)
return false; 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 false;
} }
return true; 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 @@ ...@@ -16,78 +16,6 @@
class RequestMatcherTest extends \PHPUnit_Framework_TestCase 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 * @dataProvider testMethodFixtures
*/ */
...@@ -200,4 +128,3 @@ public function testAttributes() ...@@ -200,4 +128,3 @@ public function testAttributes()
$this->assertFalse($matcher->matches($request)); $this->assertFalse($matcher->matches($request));
} }
} }
...@@ -38,8 +38,9 @@ public function collect(Request $request, Response $response, \Exception $except ...@@ -38,8 +38,9 @@ public function collect(Request $request, Response $response, \Exception $except
{ {
if (null !== $this->logger) { if (null !== $this->logger) {
$this->data = array( $this->data = array(
'error_count' => $this->logger->countErrors(), 'error_count' => $this->logger->countErrors(),
'logs' => $this->sanitizeLogs($this->logger->getLogs()), 'logs' => $this->sanitizeLogs($this->logger->getLogs()),
'deprecation_count' => $this->computeDeprecationCount()
); );
} }
} }
...@@ -66,6 +67,11 @@ public function getLogs() ...@@ -66,6 +67,11 @@ public function getLogs()
return isset($this->data['logs']) ? $this->data['logs'] : array(); return isset($this->data['logs']) ? $this->data['logs'] : array();
} }
public function countDeprecations()
{
return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -103,4 +109,16 @@ private function sanitizeContext($context) ...@@ -103,4 +109,16 @@ private function sanitizeContext($context)
return $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 @@ ...@@ -11,6 +11,9 @@
namespace Symfony\Component\HttpKernel\Debug; namespace Symfony\Component\HttpKernel\Debug;
use Symfony\Component\HttpKernel\Exception\FatalErrorException;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
/** /**
* ErrorHandler. * ErrorHandler.
* *
...@@ -28,10 +31,19 @@ class ErrorHandler ...@@ -28,10 +31,19 @@ class ErrorHandler
E_RECOVERABLE_ERROR => 'Catchable Fatal Error', E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
E_DEPRECATED => 'Deprecated', E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User 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 $level;
private $reservedMemory;
/** @var LoggerInterface */
private static $logger;
/** /**
* Register the error handler. * Register the error handler.
* *
...@@ -45,6 +57,8 @@ public static function register($level = null) ...@@ -45,6 +57,8 @@ public static function register($level = null)
$handler->setLevel($level); $handler->setLevel($level);
set_error_handler(array($handler, 'handle')); set_error_handler(array($handler, 'handle'));
register_shutdown_function(array($handler, 'handleFatal'));
$handler->reservedMemory = str_repeat('x', 10240);
return $handler; return $handler;
} }
...@@ -54,6 +68,11 @@ public function setLevel($level) ...@@ -54,6 +68,11 @@ public function setLevel($level)
$this->level = null === $level ? error_reporting() : $level; $this->level = null === $level ? error_reporting() : $level;
} }
public static function setLogger(LoggerInterface $logger)