Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit de78137

Browse files
authored
Merge pull request #50 from gimler/fos_rest_2_0
update to FOSRestBundle 2.0
2 parents 771ce1f + b938a40 commit de78137

File tree

10 files changed

+632
-396
lines changed

10 files changed

+632
-396
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ cache:
77
- $HOME/.composer/cache
88

99
php:
10-
- 5.4
1110
- 5.5
1211
- 5.6
1312
- 7.0

app/SymfonyRequirements.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ public function __construct()
446446
);
447447
}
448448

449+
$this->addRequirement(
450+
function_exists('iconv'),
451+
'iconv() must be available',
452+
'Install and enable the <strong>iconv</strong> extension.'
453+
);
454+
449455
$this->addRequirement(
450456
function_exists('json_encode'),
451457
'json_encode() must be available',
@@ -546,10 +552,10 @@ function_exists('simplexml_import_dom'),
546552
require_once __DIR__.'/../vendor/autoload.php';
547553

548554
try {
549-
$r = new \ReflectionClass('Sensio\Bundle\DistributionBundle\SensioDistributionBundle');
555+
$r = new ReflectionClass('Sensio\Bundle\DistributionBundle\SensioDistributionBundle');
550556

551557
$contents = file_get_contents(dirname($r->getFileName()).'/Resources/skeleton/app/SymfonyRequirements.php');
552-
} catch (\ReflectionException $e) {
558+
} catch (ReflectionException $e) {
553559
$contents = '';
554560
}
555561
$this->addRecommendation(

app/bootstrap.php.cache

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ $this->set($key, $values);
172172
}
173173
public function get($key, $default = null, $first = true)
174174
{
175-
$key = strtr(strtolower($key),'_','-');
175+
$key = str_replace('_','-', strtolower($key));
176176
if (!array_key_exists($key, $this->headers)) {
177177
if (null === $default) {
178178
return $first ? null : array();
@@ -186,7 +186,7 @@ return $this->headers[$key];
186186
}
187187
public function set($key, $values, $replace = true)
188188
{
189-
$key = strtr(strtolower($key),'_','-');
189+
$key = str_replace('_','-', strtolower($key));
190190
$values = array_values((array) $values);
191191
if (true === $replace || !isset($this->headers[$key])) {
192192
$this->headers[$key] = $values;
@@ -199,15 +199,15 @@ $this->cacheControl = $this->parseCacheControl($values[0]);
199199
}
200200
public 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
}
204204
public function contains($key, $value)
205205
{
206206
return in_array($value, $this->get($key, null, false));
207207
}
208208
public function remove($key)
209209
{
210-
$key = strtr(strtolower($key),'_','-');
210+
$key = str_replace('_','-', strtolower($key));
211211
unset($this->headers[$key]);
212212
if ('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+
}
390393
if (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;
478481
public static function createFromGlobals()
479482
{
480483
$server = $_SERVER;
481-
if ('cli-server'=== php_sapi_name()) {
484+
if ('cli-server'=== PHP_SAPI) {
482485
if (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;
758761
foreach ($clientIps as $key => $clientIp) {
759762
if (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+
}
762769
if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
763770
unset($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
}
768778
public function getClientIp()
769779
{
@@ -968,8 +978,9 @@ return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
968978
}
969979
public function getFormat($mimeType)
970980
{
981+
$canonicalMimeType = null;
971982
if (false !== $pos = strpos($mimeType,';')) {
972-
$mimeType = substr($mimeType, 0, $pos);
983+
$canonicalMimeType = substr($mimeType, 0, $pos);
973984
}
974985
if (null === static::$formats) {
975986
static::initializeFormats();
@@ -978,6 +989,9 @@ foreach (static::$formats as $format => $mimeTypes) {
978989
if (in_array($mimeType, (array) $mimeTypes)) {
979990
return $format;
980991
}
992+
if (null !== $canonicalMimeType && in_array($canonicalMimeType, (array) $mimeTypes)) {
993+
return $format;
994+
}
981995
}
982996
}
983997
public function setFormat($format, $mimeTypes)
@@ -1238,7 +1252,6 @@ $baseUrl = $this->getBaseUrl();
12381252
if (null === ($requestUri = $this->getRequestUri())) {
12391253
return'/';
12401254
}
1241-
$pathInfo ='/';
12421255
if ($pos = strpos($requestUri,'?')) {
12431256
$requestUri = substr($requestUri, 0, $pos);
12441257
}
@@ -1331,7 +1344,8 @@ const HTTP_REQUEST_URI_TOO_LONG = 414;
13311344
const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
13321345
const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
13331346
const 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;
13351349
const HTTP_NOT_IMPLEMENTED = 501;
13361350
const HTTP_BAD_GATEWAY = 502;
13371351
const HTTP_SERVICE_UNAVAILABLE = 503;
@@ -1380,7 +1394,7 @@ public static $statusTexts = array(
13801394
415 =>'Unsupported Media Type',
13811395
416 =>'Requested Range Not Satisfiable',
13821396
417 =>'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',
13841398
501 =>'Not Implemented',
13851399
502 =>'Bad Gateway',
13861400
503 =>'Service Unavailable',
@@ -1394,7 +1408,7 @@ $this->setContent($content);
13941408
$this->setStatusCode($status);
13951409
$this->setProtocolVersion('1.0');
13961410
if (!$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
}
14001414
public static function create($content ='', $status = 200, $headers = array())
@@ -1458,12 +1472,12 @@ public function sendHeaders()
14581472
if (headers_sent()) {
14591473
return $this;
14601474
}
1461-
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
14621475
foreach ($this->headers->allPreserveCase() as $name => $values) {
14631476
foreach ($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);
14671481
foreach ($this->headers->getCookies() as $cookie) {
14681482
setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
14691483
}
@@ -1513,7 +1527,7 @@ if ($this->isInvalid()) {
15131527
throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
15141528
}
15151529
if (null === $text) {
1516-
$this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] :'';
1530+
$this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] :'unknown status';
15171531
return $this;
15181532
}
15191533
if (false === $text) {
@@ -1873,7 +1887,7 @@ $this->set('Cache-Control','');
18731887
public function set($key, $values, $replace = true)
18741888
{
18751889
parent::set($key, $values, $replace);
1876-
$uniqueKey = strtr(strtolower($key),'_','-');
1890+
$uniqueKey = str_replace('_','-', strtolower($key));
18771891
$this->headerNames[$uniqueKey] = $key;
18781892
if (in_array($uniqueKey, array('cache-control','etag','last-modified','expires'))) {
18791893
$computed = $this->computeCacheControlValue();
@@ -1885,7 +1899,7 @@ $this->computedCacheControl = $this->parseCacheControl($computed);
18851899
public function remove($key)
18861900
{
18871901
parent::remove($key);
1888-
$uniqueKey = strtr(strtolower($key),'_','-');
1902+
$uniqueKey = str_replace('_','-', strtolower($key));
18891903
unset($this->headerNames[$uniqueKey]);
18901904
if ('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;
20892106
if (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) {
21572174
unset($this->loading[$id]);
2158-
if (array_key_exists($id, $this->services)) {
21592175
unset($this->services[$id]);
2160-
}
21612176
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
21622177
return;
21632178
}
21642179
throw $e;
2180+
} catch (\Throwable $e) {
2181+
unset($this->loading[$id]);
2182+
unset($this->services[$id]);
2183+
throw $e;
21652184
}
21662185
unset($this->loading[$id]);
21672186
return $service;
@@ -2181,9 +2200,8 @@ return isset($this->services[$id]) || array_key_exists($id, $this->services);
21812200
public 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
}
22782296
public 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;
23632381
protected $name;
23642382
protected $startTime;
23652383
protected $loadClassCache;
2366-
const VERSION ='2.7.5';
2367-
const VERSION_ID = 20705;
2384+
const VERSION ='2.7.14';
2385+
const VERSION_ID = 20714;
23682386
const MAJOR_VERSION = 2;
23692387
const MINOR_VERSION = 7;
2370-
const RELEASE_VERSION = 5;
2388+
const RELEASE_VERSION = 14;
23712389
const EXTRA_VERSION ='';
23722390
const END_OF_MAINTENANCE ='05/2018';
23732391
const END_OF_LIFE ='05/2019';
@@ -2715,10 +2733,7 @@ $dumper = new PhpDumper($container);
27152733
if (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
}
27242739
protected 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];
27502766
do {
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+
}
27712791
return $output;
27722792
}
27732793
public function serialize()
@@ -2789,8 +2809,8 @@ private $prefix;
27892809
protected $decorated;
27902810
public 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
}
27952815
if (!method_exists($decorated,'findFile')) {
27962816
throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
@@ -2815,8 +2835,9 @@ return true;
28152835
}
28162836
public 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
}
28212842
return $file;
28222843
}
@@ -2931,13 +2952,16 @@ public function registerCommands(Application $application)
29312952
if (!is_dir($dir = $this->getPath().'/Command')) {
29322953
return;
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';
29372961
foreach ($finder as $file) {
29382962
$ns = $prefix;
29392963
if ($relativePath = $file->getRelativePath()) {
2940-
$ns .='\\'.strtr($relativePath,'/','\\');
2964+
$ns .='\\'.str_replace('/','\\', $relativePath);
29412965
}
29422966
$class = $ns.'\\'.$file->getBasename('.php');
29432967
if ($this->container) {
@@ -3224,6 +3248,10 @@ $response = parent::handle($request, $type, $catch);
32243248
$this->container->set('request', null,'request');
32253249
$this->container->leaveScope('request');
32263250
throw $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

Comments
 (0)