@@ -172,7 +172,7 @@ $this->set($key, $values);
172172}
173173public function get($key, $default = null, $first = true)
174174{
175- $key = strtr(strtolower($key), '_','-');
175+ $key = str_replace( '_','-', strtolower($key) );
176176if (!array_key_exists($key, $this->headers)) {
177177if (null === $default) {
178178return $first ? null : array();
@@ -186,7 +186,7 @@ return $this->headers[$key];
186186}
187187public function set($key, $values, $replace = true)
188188{
189- $key = strtr(strtolower($key), '_','-');
189+ $key = str_replace( '_','-', strtolower($key) );
190190$values = array_values((array) $values);
191191if (true === $replace || !isset($this->headers[$key])) {
192192$this->headers[$key] = $values;
@@ -199,15 +199,15 @@ $this->cacheControl = $this->parseCacheControl($values[0]);
199199}
200200public function has($key)
201201{
202- return array_key_exists(strtr(strtolower($key), '_','-'), $this->headers);
202+ return array_key_exists(str_replace( '_','-', strtolower($key) ), $this->headers);
203203}
204204public function contains($key, $value)
205205{
206206return in_array($value, $this->get($key, null, false));
207207}
208208public function remove($key)
209209{
210- $key = strtr(strtolower($key), '_','-');
210+ $key = str_replace( '_','-', strtolower($key) );
211211unset($this->headers[$key]);
212212if ('cache-control'=== $key) {
213213$this->cacheControl = array();
@@ -387,6 +387,9 @@ $headers['AUTHORIZATION'] = $authorizationHeader;
387387}
388388}
389389}
390+ if (isset($headers['AUTHORIZATION'])) {
391+ return $headers;
392+ }
390393if (isset($headers['PHP_AUTH_USER'])) {
391394$headers['AUTHORIZATION'] ='Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
392395} elseif (isset($headers['PHP_AUTH_DIGEST'])) {
@@ -478,7 +481,7 @@ $this->format = null;
478481public static function createFromGlobals()
479482{
480483$server = $_SERVER;
481- if ('cli-server'=== php_sapi_name() ) {
484+ if ('cli-server'=== PHP_SAPI ) {
482485if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) {
483486$server['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH'];
484487}
@@ -754,16 +757,23 @@ $clientIps = $matches[3];
754757} elseif (self::$trustedHeaders[self::HEADER_CLIENT_IP] && $this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
755758$clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
756759}
757- $clientIps[] = $ip; $ip = $clientIps[0] ;
760+ $clientIps[] = $ip; $firstTrustedIp = null ;
758761foreach ($clientIps as $key => $clientIp) {
759762if (preg_match('{((?:\d+\.){3}\d+)\:\d+}', $clientIp, $match)) {
760763$clientIps[$key] = $clientIp = $match[1];
761764}
765+ if (!filter_var($clientIp, FILTER_VALIDATE_IP)) {
766+ unset($clientIps[$key]);
767+ continue;
768+ }
762769if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
763770unset($clientIps[$key]);
771+ if (null === $firstTrustedIp) {
772+ $firstTrustedIp = $clientIp;
773+ }
764774}
765775}
766- return $clientIps ? array_reverse($clientIps) : array($ip );
776+ return $clientIps ? array_reverse($clientIps) : array($firstTrustedIp );
767777}
768778public function getClientIp()
769779{
@@ -968,8 +978,9 @@ return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
968978}
969979public function getFormat($mimeType)
970980{
981+ $canonicalMimeType = null;
971982if (false !== $pos = strpos($mimeType,';')) {
972- $mimeType = substr($mimeType, 0, $pos);
983+ $canonicalMimeType = substr($mimeType, 0, $pos);
973984}
974985if (null === static::$formats) {
975986static::initializeFormats();
@@ -978,6 +989,9 @@ foreach (static::$formats as $format => $mimeTypes) {
978989if (in_array($mimeType, (array) $mimeTypes)) {
979990return $format;
980991}
992+ if (null !== $canonicalMimeType && in_array($canonicalMimeType, (array) $mimeTypes)) {
993+ return $format;
994+ }
981995}
982996}
983997public function setFormat($format, $mimeTypes)
@@ -1238,7 +1252,6 @@ $baseUrl = $this->getBaseUrl();
12381252if (null === ($requestUri = $this->getRequestUri())) {
12391253return'/';
12401254}
1241- $pathInfo ='/';
12421255if ($pos = strpos($requestUri,'?')) {
12431256$requestUri = substr($requestUri, 0, $pos);
12441257}
@@ -1331,7 +1344,8 @@ const HTTP_REQUEST_URI_TOO_LONG = 414;
13311344const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
13321345const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
13331346const HTTP_EXPECTATION_FAILED = 417;
1334- const HTTP_I_AM_A_TEAPOT = 418; const HTTP_UNPROCESSABLE_ENTITY = 422; const HTTP_LOCKED = 423; const HTTP_FAILED_DEPENDENCY = 424; const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; const HTTP_UPGRADE_REQUIRED = 426; const HTTP_PRECONDITION_REQUIRED = 428; const HTTP_TOO_MANY_REQUESTS = 429; const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; const HTTP_INTERNAL_SERVER_ERROR = 500;
1347+ const HTTP_I_AM_A_TEAPOT = 418; const HTTP_MISDIRECTED_REQUEST = 421; const HTTP_UNPROCESSABLE_ENTITY = 422; const HTTP_LOCKED = 423; const HTTP_FAILED_DEPENDENCY = 424; const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; const HTTP_UPGRADE_REQUIRED = 426; const HTTP_PRECONDITION_REQUIRED = 428; const HTTP_TOO_MANY_REQUESTS = 429; const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451;
1348+ const HTTP_INTERNAL_SERVER_ERROR = 500;
13351349const HTTP_NOT_IMPLEMENTED = 501;
13361350const HTTP_BAD_GATEWAY = 502;
13371351const HTTP_SERVICE_UNAVAILABLE = 503;
@@ -1380,7 +1394,7 @@ public static $statusTexts = array(
13801394415 =>'Unsupported Media Type',
13811395416 =>'Requested Range Not Satisfiable',
13821396417 =>'Expectation Failed',
1383- 418 =>'I\'m a teapot', 422 =>'Unprocessable Entity', 423 =>'Locked', 424 =>'Failed Dependency', 425 =>'Reserved for WebDAV advanced collections expired proposal', 426 =>'Upgrade Required', 428 =>'Precondition Required', 429 =>'Too Many Requests', 431 =>'Request Header Fields Too Large', 500 =>'Internal Server Error',
1397+ 418 =>'I\'m a teapot', 421 =>'Misdirected Request', 422 =>'Unprocessable Entity', 423 =>'Locked', 424 =>'Failed Dependency', 425 =>'Reserved for WebDAV advanced collections expired proposal', 426 =>'Upgrade Required', 428 =>'Precondition Required', 429 =>'Too Many Requests', 431 =>'Request Header Fields Too Large', 451 =>'Unavailable For Legal Reasons ', 500 =>'Internal Server Error',
13841398501 =>'Not Implemented',
13851399502 =>'Bad Gateway',
13861400503 =>'Service Unavailable',
@@ -1394,7 +1408,7 @@ $this->setContent($content);
13941408$this->setStatusCode($status);
13951409$this->setProtocolVersion('1.0');
13961410if (!$this->headers->has('Date')) {
1397- $this->setDate(new \DateTime(null , new \DateTimeZone('UTC')));
1411+ $this->setDate(\DateTime::createFromFormat('U', time() , new \DateTimeZone('UTC')));
13981412}
13991413}
14001414public static function create($content ='', $status = 200, $headers = array())
@@ -1458,12 +1472,12 @@ public function sendHeaders()
14581472if (headers_sent()) {
14591473return $this;
14601474}
1461- header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
14621475foreach ($this->headers->allPreserveCase() as $name => $values) {
14631476foreach ($values as $value) {
1464- header($name.': '.$value, false, $this->statusCode );
1477+ header($name.': '.$value, false);
14651478}
14661479}
1480+ header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
14671481foreach ($this->headers->getCookies() as $cookie) {
14681482setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
14691483}
@@ -1513,7 +1527,7 @@ if ($this->isInvalid()) {
15131527throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
15141528}
15151529if (null === $text) {
1516- $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] :'';
1530+ $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] :'unknown status ';
15171531return $this;
15181532}
15191533if (false === $text) {
@@ -1873,7 +1887,7 @@ $this->set('Cache-Control','');
18731887public function set($key, $values, $replace = true)
18741888{
18751889parent::set($key, $values, $replace);
1876- $uniqueKey = strtr(strtolower($key), '_','-');
1890+ $uniqueKey = str_replace( '_','-', strtolower($key) );
18771891$this->headerNames[$uniqueKey] = $key;
18781892if (in_array($uniqueKey, array('cache-control','etag','last-modified','expires'))) {
18791893$computed = $this->computeCacheControlValue();
@@ -1885,7 +1899,7 @@ $this->computedCacheControl = $this->parseCacheControl($computed);
18851899public function remove($key)
18861900{
18871901parent::remove($key);
1888- $uniqueKey = strtr(strtolower($key), '_','-');
1902+ $uniqueKey = str_replace( '_','-', strtolower($key) );
18891903unset($this->headerNames[$uniqueKey]);
18901904if ('cache-control'=== $uniqueKey) {
18911905$this->computedCacheControl = array();
@@ -2085,6 +2099,9 @@ throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scop
20852099}
20862100$this->scopedServices[$scope][$id] = $service;
20872101}
2102+ if (isset($this->aliases[$id])) {
2103+ unset($this->aliases[$id]);
2104+ }
20882105$this->services[$id] = $service;
20892106if (method_exists($this, $method ='synchronize'.strtr($id, $this->underscoreMap).'Service')) {
20902107$this->$method();
@@ -2155,13 +2172,15 @@ try {
21552172$service = $this->$method();
21562173} catch (\Exception $e) {
21572174unset($this->loading[$id]);
2158- if (array_key_exists($id, $this->services)) {
21592175unset($this->services[$id]);
2160- }
21612176if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
21622177return;
21632178}
21642179throw $e;
2180+ } catch (\Throwable $e) {
2181+ unset($this->loading[$id]);
2182+ unset($this->services[$id]);
2183+ throw $e;
21652184}
21662185unset($this->loading[$id]);
21672186return $service;
@@ -2181,9 +2200,8 @@ return isset($this->services[$id]) || array_key_exists($id, $this->services);
21812200public function getServiceIds()
21822201{
21832202$ids = array();
2184- $r = new \ReflectionClass($this);
2185- foreach ($r->getMethods() as $method) {
2186- if (preg_match('/^get(.+)Service$/', $method->name, $match)) {
2203+ foreach (get_class_methods($this) as $method) {
2204+ if (preg_match('/^get(.+)Service$/', $method, $match)) {
21872205$ids[] = self::underscore($match[1]);
21882206}
21892207}
@@ -2277,7 +2295,7 @@ return strtr(ucwords(strtr($id, array('_'=>' ','.'=>'_ ','\\'=>'_ '))), array('
22772295}
22782296public static function underscore($id)
22792297{
2280- return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/','/([a-z\d])([A-Z])/'), array('\\1_\\2','\\1_\\2'), strtr($id, '_','.')));
2298+ return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/','/([a-z\d])([A-Z])/'), array('\\1_\\2','\\1_\\2'), str_replace( '_','.', $id )));
22812299}
22822300}
22832301}
@@ -2363,11 +2381,11 @@ protected $booted = false;
23632381protected $name;
23642382protected $startTime;
23652383protected $loadClassCache;
2366- const VERSION ='2.7.5 ';
2367- const VERSION_ID = 20705 ;
2384+ const VERSION ='2.7.14 ';
2385+ const VERSION_ID = 20714 ;
23682386const MAJOR_VERSION = 2;
23692387const MINOR_VERSION = 7;
2370- const RELEASE_VERSION = 5 ;
2388+ const RELEASE_VERSION = 14 ;
23712389const EXTRA_VERSION ='';
23722390const END_OF_MAINTENANCE ='05/2018';
23732391const END_OF_LIFE ='05/2019';
@@ -2715,10 +2733,7 @@ $dumper = new PhpDumper($container);
27152733if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) {
27162734$dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath())));
27172735}
2718- $content = $dumper->dump(array('class'=> $class,'base_class'=> $baseClass,'file'=> $cache->getPath()));
2719- if (!$this->debug) {
2720- $content = static::stripComments($content);
2721- }
2736+ $content = $dumper->dump(array('class'=> $class,'base_class'=> $baseClass,'file'=> $cache->getPath(),'debug'=> $this->debug));
27222737$cache->write($content, $container->getResources());
27232738}
27242739protected function getContainerLoader(ContainerInterface $container)
@@ -2742,14 +2757,15 @@ $rawChunk ='';
27422757$output ='';
27432758$tokens = token_get_all($source);
27442759$ignoreSpace = false;
2745- for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
2746- if (is_string($token)) {
2760+ for ($i = 0; isset($tokens[$i]); ++$i) {
2761+ $token = $tokens[$i];
2762+ if (!isset($token[1]) ||'b"'=== $token) {
27472763$rawChunk .= $token;
27482764} elseif (T_START_HEREDOC === $token[0]) {
27492765$output .= $rawChunk.$token[1];
27502766do {
2751- $token = next( $tokens) ;
2752- $output .= $token[1];
2767+ $token = $tokens[++$i] ;
2768+ $output .= isset( $token[1]) &&'b"'!== $token ? $token[1] : $token ;
27532769} while ($token[0] !== T_END_HEREDOC);
27542770$rawChunk ='';
27552771} elseif (T_WHITESPACE === $token[0]) {
@@ -2768,6 +2784,10 @@ $ignoreSpace = true;
27682784}
27692785}
27702786$output .= $rawChunk;
2787+ if (PHP_VERSION_ID >= 70000) {
2788+ unset($tokens, $rawChunk);
2789+ gc_mem_caches();
2790+ }
27712791return $output;
27722792}
27732793public function serialize()
@@ -2789,8 +2809,8 @@ private $prefix;
27892809protected $decorated;
27902810public function __construct($prefix, $decorated)
27912811{
2792- if (!extension_loaded('apc ')) {
2793- throw new \RuntimeException('Unable to use ApcClassLoader as APC is not enabled .');
2812+ if (!function_exists('apcu_fetch ')) {
2813+ throw new \RuntimeException('Unable to use ApcClassLoader as APC is not installed .');
27942814}
27952815if (!method_exists($decorated,'findFile')) {
27962816throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
@@ -2815,8 +2835,9 @@ return true;
28152835}
28162836public function findFile($class)
28172837{
2818- if (false === $file = apc_fetch($this->prefix.$class)) {
2819- apc_store($this->prefix.$class, $file = $this->decorated->findFile($class));
2838+ $file = apcu_fetch($this->prefix.$class, $success);
2839+ if (!$success) {
2840+ apcu_store($this->prefix.$class, $file = $this->decorated->findFile($class) ?: null);
28202841}
28212842return $file;
28222843}
@@ -2931,13 +2952,16 @@ public function registerCommands(Application $application)
29312952if (!is_dir($dir = $this->getPath().'/Command')) {
29322953return;
29332954}
2955+ if (!class_exists('Symfony\Component\Finder\Finder')) {
2956+ throw new \RuntimeException('You need the symfony/finder component to register bundle commands.');
2957+ }
29342958$finder = new Finder();
29352959$finder->files()->name('*Command.php')->in($dir);
29362960$prefix = $this->getNamespace().'\\Command';
29372961foreach ($finder as $file) {
29382962$ns = $prefix;
29392963if ($relativePath = $file->getRelativePath()) {
2940- $ns .='\\'.strtr($relativePath, '/','\\');
2964+ $ns .='\\'.str_replace( '/','\\', $relativePath );
29412965}
29422966$class = $ns.'\\'.$file->getBasename('.php');
29432967if ($this->container) {
@@ -3224,6 +3248,10 @@ $response = parent::handle($request, $type, $catch);
32243248$this->container->set('request', null,'request');
32253249$this->container->leaveScope('request');
32263250throw $e;
3251+ } catch (\Throwable $e) {
3252+ $this->container->set('request', null,'request');
3253+ $this->container->leaveScope('request');
3254+ throw $e;
32273255}
32283256$this->container->set('request', null,'request');
32293257$this->container->leaveScope('request');
0 commit comments