annotate app/bootstrap.php.cache @ 1:f38015048f48 tip

Added GPL
author Daniel Wolff
date Sat, 13 Feb 2016 20:43:38 +0100
parents 493bcb69166c
children
rev   line source
Daniel@0 1 <?php
Daniel@0 2
Daniel@0 3 namespace { $loader = require_once __DIR__.'/./autoload.php'; }
Daniel@0 4
Daniel@0 5
Daniel@0 6 namespace Symfony\Component\HttpFoundation
Daniel@0 7 {
Daniel@0 8 class ParameterBag implements \IteratorAggregate, \Countable
Daniel@0 9 {
Daniel@0 10 protected $parameters;
Daniel@0 11 public function __construct(array $parameters = array())
Daniel@0 12 {
Daniel@0 13 $this->parameters = $parameters;
Daniel@0 14 }
Daniel@0 15 public function all()
Daniel@0 16 {
Daniel@0 17 return $this->parameters;
Daniel@0 18 }
Daniel@0 19 public function keys()
Daniel@0 20 {
Daniel@0 21 return array_keys($this->parameters);
Daniel@0 22 }
Daniel@0 23 public function replace(array $parameters = array())
Daniel@0 24 {
Daniel@0 25 $this->parameters = $parameters;
Daniel@0 26 }
Daniel@0 27 public function add(array $parameters = array())
Daniel@0 28 {
Daniel@0 29 $this->parameters = array_replace($this->parameters, $parameters);
Daniel@0 30 }
Daniel@0 31 public function get($path, $default = null, $deep = false)
Daniel@0 32 {
Daniel@0 33 if (!$deep || false === $pos = strpos($path,'[')) {
Daniel@0 34 return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default;
Daniel@0 35 }
Daniel@0 36 $root = substr($path, 0, $pos);
Daniel@0 37 if (!array_key_exists($root, $this->parameters)) {
Daniel@0 38 return $default;
Daniel@0 39 }
Daniel@0 40 $value = $this->parameters[$root];
Daniel@0 41 $currentKey = null;
Daniel@0 42 for ($i = $pos, $c = strlen($path); $i < $c; $i++) {
Daniel@0 43 $char = $path[$i];
Daniel@0 44 if ('['=== $char) {
Daniel@0 45 if (null !== $currentKey) {
Daniel@0 46 throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
Daniel@0 47 }
Daniel@0 48 $currentKey ='';
Daniel@0 49 } elseif (']'=== $char) {
Daniel@0 50 if (null === $currentKey) {
Daniel@0 51 throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
Daniel@0 52 }
Daniel@0 53 if (!is_array($value) || !array_key_exists($currentKey, $value)) {
Daniel@0 54 return $default;
Daniel@0 55 }
Daniel@0 56 $value = $value[$currentKey];
Daniel@0 57 $currentKey = null;
Daniel@0 58 } else {
Daniel@0 59 if (null === $currentKey) {
Daniel@0 60 throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
Daniel@0 61 }
Daniel@0 62 $currentKey .= $char;
Daniel@0 63 }
Daniel@0 64 }
Daniel@0 65 if (null !== $currentKey) {
Daniel@0 66 throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
Daniel@0 67 }
Daniel@0 68 return $value;
Daniel@0 69 }
Daniel@0 70 public function set($key, $value)
Daniel@0 71 {
Daniel@0 72 $this->parameters[$key] = $value;
Daniel@0 73 }
Daniel@0 74 public function has($key)
Daniel@0 75 {
Daniel@0 76 return array_key_exists($key, $this->parameters);
Daniel@0 77 }
Daniel@0 78 public function remove($key)
Daniel@0 79 {
Daniel@0 80 unset($this->parameters[$key]);
Daniel@0 81 }
Daniel@0 82 public function getAlpha($key, $default ='', $deep = false)
Daniel@0 83 {
Daniel@0 84 return preg_replace('/[^[:alpha:]]/','', $this->get($key, $default, $deep));
Daniel@0 85 }
Daniel@0 86 public function getAlnum($key, $default ='', $deep = false)
Daniel@0 87 {
Daniel@0 88 return preg_replace('/[^[:alnum:]]/','', $this->get($key, $default, $deep));
Daniel@0 89 }
Daniel@0 90 public function getDigits($key, $default ='', $deep = false)
Daniel@0 91 {
Daniel@0 92 return str_replace(array('-','+'),'', $this->filter($key, $default, $deep, FILTER_SANITIZE_NUMBER_INT));
Daniel@0 93 }
Daniel@0 94 public function getInt($key, $default = 0, $deep = false)
Daniel@0 95 {
Daniel@0 96 return (int) $this->get($key, $default, $deep);
Daniel@0 97 }
Daniel@0 98 public function filter($key, $default = null, $deep = false, $filter = FILTER_DEFAULT, $options = array())
Daniel@0 99 {
Daniel@0 100 $value = $this->get($key, $default, $deep);
Daniel@0 101 if (!is_array($options) && $options) {
Daniel@0 102 $options = array('flags'=> $options);
Daniel@0 103 }
Daniel@0 104 if (is_array($value) && !isset($options['flags'])) {
Daniel@0 105 $options['flags'] = FILTER_REQUIRE_ARRAY;
Daniel@0 106 }
Daniel@0 107 return filter_var($value, $filter, $options);
Daniel@0 108 }
Daniel@0 109 public function getIterator()
Daniel@0 110 {
Daniel@0 111 return new \ArrayIterator($this->parameters);
Daniel@0 112 }
Daniel@0 113 public function count()
Daniel@0 114 {
Daniel@0 115 return count($this->parameters);
Daniel@0 116 }
Daniel@0 117 }
Daniel@0 118 }
Daniel@0 119 namespace Symfony\Component\HttpFoundation
Daniel@0 120 {
Daniel@0 121 class HeaderBag implements \IteratorAggregate, \Countable
Daniel@0 122 {
Daniel@0 123 protected $headers = array();
Daniel@0 124 protected $cacheControl = array();
Daniel@0 125 public function __construct(array $headers = array())
Daniel@0 126 {
Daniel@0 127 foreach ($headers as $key => $values) {
Daniel@0 128 $this->set($key, $values);
Daniel@0 129 }
Daniel@0 130 }
Daniel@0 131 public function __toString()
Daniel@0 132 {
Daniel@0 133 if (!$this->headers) {
Daniel@0 134 return'';
Daniel@0 135 }
Daniel@0 136 $max = max(array_map('strlen', array_keys($this->headers))) + 1;
Daniel@0 137 $content ='';
Daniel@0 138 ksort($this->headers);
Daniel@0 139 foreach ($this->headers as $name => $values) {
Daniel@0 140 $name = implode('-', array_map('ucfirst', explode('-', $name)));
Daniel@0 141 foreach ($values as $value) {
Daniel@0 142 $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
Daniel@0 143 }
Daniel@0 144 }
Daniel@0 145 return $content;
Daniel@0 146 }
Daniel@0 147 public function all()
Daniel@0 148 {
Daniel@0 149 return $this->headers;
Daniel@0 150 }
Daniel@0 151 public function keys()
Daniel@0 152 {
Daniel@0 153 return array_keys($this->headers);
Daniel@0 154 }
Daniel@0 155 public function replace(array $headers = array())
Daniel@0 156 {
Daniel@0 157 $this->headers = array();
Daniel@0 158 $this->add($headers);
Daniel@0 159 }
Daniel@0 160 public function add(array $headers)
Daniel@0 161 {
Daniel@0 162 foreach ($headers as $key => $values) {
Daniel@0 163 $this->set($key, $values);
Daniel@0 164 }
Daniel@0 165 }
Daniel@0 166 public function get($key, $default = null, $first = true)
Daniel@0 167 {
Daniel@0 168 $key = strtr(strtolower($key),'_','-');
Daniel@0 169 if (!array_key_exists($key, $this->headers)) {
Daniel@0 170 if (null === $default) {
Daniel@0 171 return $first ? null : array();
Daniel@0 172 }
Daniel@0 173 return $first ? $default : array($default);
Daniel@0 174 }
Daniel@0 175 if ($first) {
Daniel@0 176 return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
Daniel@0 177 }
Daniel@0 178 return $this->headers[$key];
Daniel@0 179 }
Daniel@0 180 public function set($key, $values, $replace = true)
Daniel@0 181 {
Daniel@0 182 $key = strtr(strtolower($key),'_','-');
Daniel@0 183 $values = array_values((array) $values);
Daniel@0 184 if (true === $replace || !isset($this->headers[$key])) {
Daniel@0 185 $this->headers[$key] = $values;
Daniel@0 186 } else {
Daniel@0 187 $this->headers[$key] = array_merge($this->headers[$key], $values);
Daniel@0 188 }
Daniel@0 189 if ('cache-control'=== $key) {
Daniel@0 190 $this->cacheControl = $this->parseCacheControl($values[0]);
Daniel@0 191 }
Daniel@0 192 }
Daniel@0 193 public function has($key)
Daniel@0 194 {
Daniel@0 195 return array_key_exists(strtr(strtolower($key),'_','-'), $this->headers);
Daniel@0 196 }
Daniel@0 197 public function contains($key, $value)
Daniel@0 198 {
Daniel@0 199 return in_array($value, $this->get($key, null, false));
Daniel@0 200 }
Daniel@0 201 public function remove($key)
Daniel@0 202 {
Daniel@0 203 $key = strtr(strtolower($key),'_','-');
Daniel@0 204 unset($this->headers[$key]);
Daniel@0 205 if ('cache-control'=== $key) {
Daniel@0 206 $this->cacheControl = array();
Daniel@0 207 }
Daniel@0 208 }
Daniel@0 209 public function getDate($key, \DateTime $default = null)
Daniel@0 210 {
Daniel@0 211 if (null === $value = $this->get($key)) {
Daniel@0 212 return $default;
Daniel@0 213 }
Daniel@0 214 if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
Daniel@0 215 throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
Daniel@0 216 }
Daniel@0 217 return $date;
Daniel@0 218 }
Daniel@0 219 public function addCacheControlDirective($key, $value = true)
Daniel@0 220 {
Daniel@0 221 $this->cacheControl[$key] = $value;
Daniel@0 222 $this->set('Cache-Control', $this->getCacheControlHeader());
Daniel@0 223 }
Daniel@0 224 public function hasCacheControlDirective($key)
Daniel@0 225 {
Daniel@0 226 return array_key_exists($key, $this->cacheControl);
Daniel@0 227 }
Daniel@0 228 public function getCacheControlDirective($key)
Daniel@0 229 {
Daniel@0 230 return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
Daniel@0 231 }
Daniel@0 232 public function removeCacheControlDirective($key)
Daniel@0 233 {
Daniel@0 234 unset($this->cacheControl[$key]);
Daniel@0 235 $this->set('Cache-Control', $this->getCacheControlHeader());
Daniel@0 236 }
Daniel@0 237 public function getIterator()
Daniel@0 238 {
Daniel@0 239 return new \ArrayIterator($this->headers);
Daniel@0 240 }
Daniel@0 241 public function count()
Daniel@0 242 {
Daniel@0 243 return count($this->headers);
Daniel@0 244 }
Daniel@0 245 protected function getCacheControlHeader()
Daniel@0 246 {
Daniel@0 247 $parts = array();
Daniel@0 248 ksort($this->cacheControl);
Daniel@0 249 foreach ($this->cacheControl as $key => $value) {
Daniel@0 250 if (true === $value) {
Daniel@0 251 $parts[] = $key;
Daniel@0 252 } else {
Daniel@0 253 if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
Daniel@0 254 $value ='"'.$value.'"';
Daniel@0 255 }
Daniel@0 256 $parts[] = "$key=$value";
Daniel@0 257 }
Daniel@0 258 }
Daniel@0 259 return implode(', ', $parts);
Daniel@0 260 }
Daniel@0 261 protected function parseCacheControl($header)
Daniel@0 262 {
Daniel@0 263 $cacheControl = array();
Daniel@0 264 preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
Daniel@0 265 foreach ($matches as $match) {
Daniel@0 266 $cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
Daniel@0 267 }
Daniel@0 268 return $cacheControl;
Daniel@0 269 }
Daniel@0 270 }
Daniel@0 271 }
Daniel@0 272 namespace Symfony\Component\HttpFoundation
Daniel@0 273 {
Daniel@0 274 use Symfony\Component\HttpFoundation\File\UploadedFile;
Daniel@0 275 class FileBag extends ParameterBag
Daniel@0 276 {
Daniel@0 277 private static $fileKeys = array('error','name','size','tmp_name','type');
Daniel@0 278 public function __construct(array $parameters = array())
Daniel@0 279 {
Daniel@0 280 $this->replace($parameters);
Daniel@0 281 }
Daniel@0 282 public function replace(array $files = array())
Daniel@0 283 {
Daniel@0 284 $this->parameters = array();
Daniel@0 285 $this->add($files);
Daniel@0 286 }
Daniel@0 287 public function set($key, $value)
Daniel@0 288 {
Daniel@0 289 if (!is_array($value) && !$value instanceof UploadedFile) {
Daniel@0 290 throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
Daniel@0 291 }
Daniel@0 292 parent::set($key, $this->convertFileInformation($value));
Daniel@0 293 }
Daniel@0 294 public function add(array $files = array())
Daniel@0 295 {
Daniel@0 296 foreach ($files as $key => $file) {
Daniel@0 297 $this->set($key, $file);
Daniel@0 298 }
Daniel@0 299 }
Daniel@0 300 protected function convertFileInformation($file)
Daniel@0 301 {
Daniel@0 302 if ($file instanceof UploadedFile) {
Daniel@0 303 return $file;
Daniel@0 304 }
Daniel@0 305 $file = $this->fixPhpFilesArray($file);
Daniel@0 306 if (is_array($file)) {
Daniel@0 307 $keys = array_keys($file);
Daniel@0 308 sort($keys);
Daniel@0 309 if ($keys == self::$fileKeys) {
Daniel@0 310 if (UPLOAD_ERR_NO_FILE == $file['error']) {
Daniel@0 311 $file = null;
Daniel@0 312 } else {
Daniel@0 313 $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
Daniel@0 314 }
Daniel@0 315 } else {
Daniel@0 316 $file = array_map(array($this,'convertFileInformation'), $file);
Daniel@0 317 }
Daniel@0 318 }
Daniel@0 319 return $file;
Daniel@0 320 }
Daniel@0 321 protected function fixPhpFilesArray($data)
Daniel@0 322 {
Daniel@0 323 if (!is_array($data)) {
Daniel@0 324 return $data;
Daniel@0 325 }
Daniel@0 326 $keys = array_keys($data);
Daniel@0 327 sort($keys);
Daniel@0 328 if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
Daniel@0 329 return $data;
Daniel@0 330 }
Daniel@0 331 $files = $data;
Daniel@0 332 foreach (self::$fileKeys as $k) {
Daniel@0 333 unset($files[$k]);
Daniel@0 334 }
Daniel@0 335 foreach (array_keys($data['name']) as $key) {
Daniel@0 336 $files[$key] = $this->fixPhpFilesArray(array('error'=> $data['error'][$key],'name'=> $data['name'][$key],'type'=> $data['type'][$key],'tmp_name'=> $data['tmp_name'][$key],'size'=> $data['size'][$key],
Daniel@0 337 ));
Daniel@0 338 }
Daniel@0 339 return $files;
Daniel@0 340 }
Daniel@0 341 }
Daniel@0 342 }
Daniel@0 343 namespace Symfony\Component\HttpFoundation
Daniel@0 344 {
Daniel@0 345 class ServerBag extends ParameterBag
Daniel@0 346 {
Daniel@0 347 public function getHeaders()
Daniel@0 348 {
Daniel@0 349 $headers = array();
Daniel@0 350 $contentHeaders = array('CONTENT_LENGTH'=> true,'CONTENT_MD5'=> true,'CONTENT_TYPE'=> true);
Daniel@0 351 foreach ($this->parameters as $key => $value) {
Daniel@0 352 if (0 === strpos($key,'HTTP_')) {
Daniel@0 353 $headers[substr($key, 5)] = $value;
Daniel@0 354 }
Daniel@0 355 elseif (isset($contentHeaders[$key])) {
Daniel@0 356 $headers[$key] = $value;
Daniel@0 357 }
Daniel@0 358 }
Daniel@0 359 if (isset($this->parameters['PHP_AUTH_USER'])) {
Daniel@0 360 $headers['PHP_AUTH_USER'] = $this->parameters['PHP_AUTH_USER'];
Daniel@0 361 $headers['PHP_AUTH_PW'] = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] :'';
Daniel@0 362 } else {
Daniel@0 363 $authorizationHeader = null;
Daniel@0 364 if (isset($this->parameters['HTTP_AUTHORIZATION'])) {
Daniel@0 365 $authorizationHeader = $this->parameters['HTTP_AUTHORIZATION'];
Daniel@0 366 } elseif (isset($this->parameters['REDIRECT_HTTP_AUTHORIZATION'])) {
Daniel@0 367 $authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION'];
Daniel@0 368 }
Daniel@0 369 if (null !== $authorizationHeader) {
Daniel@0 370 if (0 === stripos($authorizationHeader,'basic ')) {
Daniel@0 371 $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)), 2);
Daniel@0 372 if (count($exploded) == 2) {
Daniel@0 373 list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
Daniel@0 374 }
Daniel@0 375 } elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader,'digest '))) {
Daniel@0 376 $headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
Daniel@0 377 $this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
Daniel@0 378 }
Daniel@0 379 }
Daniel@0 380 }
Daniel@0 381 if (isset($headers['PHP_AUTH_USER'])) {
Daniel@0 382 $headers['AUTHORIZATION'] ='Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
Daniel@0 383 } elseif (isset($headers['PHP_AUTH_DIGEST'])) {
Daniel@0 384 $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
Daniel@0 385 }
Daniel@0 386 return $headers;
Daniel@0 387 }
Daniel@0 388 }
Daniel@0 389 }
Daniel@0 390 namespace Symfony\Component\HttpFoundation
Daniel@0 391 {
Daniel@0 392 use Symfony\Component\HttpFoundation\Session\SessionInterface;
Daniel@0 393 class Request
Daniel@0 394 {
Daniel@0 395 const HEADER_CLIENT_IP ='client_ip';
Daniel@0 396 const HEADER_CLIENT_HOST ='client_host';
Daniel@0 397 const HEADER_CLIENT_PROTO ='client_proto';
Daniel@0 398 const HEADER_CLIENT_PORT ='client_port';
Daniel@0 399 protected static $trustedProxies = array();
Daniel@0 400 protected static $trustedHostPatterns = array();
Daniel@0 401 protected static $trustedHosts = array();
Daniel@0 402 protected static $trustedHeaders = array(
Daniel@0 403 self::HEADER_CLIENT_IP =>'X_FORWARDED_FOR',
Daniel@0 404 self::HEADER_CLIENT_HOST =>'X_FORWARDED_HOST',
Daniel@0 405 self::HEADER_CLIENT_PROTO =>'X_FORWARDED_PROTO',
Daniel@0 406 self::HEADER_CLIENT_PORT =>'X_FORWARDED_PORT',
Daniel@0 407 );
Daniel@0 408 protected static $httpMethodParameterOverride = false;
Daniel@0 409 public $attributes;
Daniel@0 410 public $request;
Daniel@0 411 public $query;
Daniel@0 412 public $server;
Daniel@0 413 public $files;
Daniel@0 414 public $cookies;
Daniel@0 415 public $headers;
Daniel@0 416 protected $content;
Daniel@0 417 protected $languages;
Daniel@0 418 protected $charsets;
Daniel@0 419 protected $encodings;
Daniel@0 420 protected $acceptableContentTypes;
Daniel@0 421 protected $pathInfo;
Daniel@0 422 protected $requestUri;
Daniel@0 423 protected $baseUrl;
Daniel@0 424 protected $basePath;
Daniel@0 425 protected $method;
Daniel@0 426 protected $format;
Daniel@0 427 protected $session;
Daniel@0 428 protected $locale;
Daniel@0 429 protected $defaultLocale ='en';
Daniel@0 430 protected static $formats;
Daniel@0 431 protected static $requestFactory;
Daniel@0 432 public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
Daniel@0 433 {
Daniel@0 434 $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
Daniel@0 435 }
Daniel@0 436 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
Daniel@0 437 {
Daniel@0 438 $this->request = new ParameterBag($request);
Daniel@0 439 $this->query = new ParameterBag($query);
Daniel@0 440 $this->attributes = new ParameterBag($attributes);
Daniel@0 441 $this->cookies = new ParameterBag($cookies);
Daniel@0 442 $this->files = new FileBag($files);
Daniel@0 443 $this->server = new ServerBag($server);
Daniel@0 444 $this->headers = new HeaderBag($this->server->getHeaders());
Daniel@0 445 $this->content = $content;
Daniel@0 446 $this->languages = null;
Daniel@0 447 $this->charsets = null;
Daniel@0 448 $this->encodings = null;
Daniel@0 449 $this->acceptableContentTypes = null;
Daniel@0 450 $this->pathInfo = null;
Daniel@0 451 $this->requestUri = null;
Daniel@0 452 $this->baseUrl = null;
Daniel@0 453 $this->basePath = null;
Daniel@0 454 $this->method = null;
Daniel@0 455 $this->format = null;
Daniel@0 456 }
Daniel@0 457 public static function createFromGlobals()
Daniel@0 458 {
Daniel@0 459 $server = $_SERVER;
Daniel@0 460 if ('cli-server'=== php_sapi_name()) {
Daniel@0 461 if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) {
Daniel@0 462 $server['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH'];
Daniel@0 463 }
Daniel@0 464 if (array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
Daniel@0 465 $server['CONTENT_TYPE'] = $_SERVER['HTTP_CONTENT_TYPE'];
Daniel@0 466 }
Daniel@0 467 }
Daniel@0 468 $request = self::createRequestFromFactory($_GET, $_POST, array(), $_COOKIE, $_FILES, $server);
Daniel@0 469 if (0 === strpos($request->headers->get('CONTENT_TYPE'),'application/x-www-form-urlencoded')
Daniel@0 470 && in_array(strtoupper($request->server->get('REQUEST_METHOD','GET')), array('PUT','DELETE','PATCH'))
Daniel@0 471 ) {
Daniel@0 472 parse_str($request->getContent(), $data);
Daniel@0 473 $request->request = new ParameterBag($data);
Daniel@0 474 }
Daniel@0 475 return $request;
Daniel@0 476 }
Daniel@0 477 public static function create($uri, $method ='GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
Daniel@0 478 {
Daniel@0 479 $server = array_replace(array('SERVER_NAME'=>'localhost','SERVER_PORT'=> 80,'HTTP_HOST'=>'localhost','HTTP_USER_AGENT'=>'Symfony/2.X','HTTP_ACCEPT'=>'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','HTTP_ACCEPT_LANGUAGE'=>'en-us,en;q=0.5','HTTP_ACCEPT_CHARSET'=>'ISO-8859-1,utf-8;q=0.7,*;q=0.7','REMOTE_ADDR'=>'127.0.0.1','SCRIPT_NAME'=>'','SCRIPT_FILENAME'=>'','SERVER_PROTOCOL'=>'HTTP/1.1','REQUEST_TIME'=> time(),
Daniel@0 480 ), $server);
Daniel@0 481 $server['PATH_INFO'] ='';
Daniel@0 482 $server['REQUEST_METHOD'] = strtoupper($method);
Daniel@0 483 $components = parse_url($uri);
Daniel@0 484 if (isset($components['host'])) {
Daniel@0 485 $server['SERVER_NAME'] = $components['host'];
Daniel@0 486 $server['HTTP_HOST'] = $components['host'];
Daniel@0 487 }
Daniel@0 488 if (isset($components['scheme'])) {
Daniel@0 489 if ('https'=== $components['scheme']) {
Daniel@0 490 $server['HTTPS'] ='on';
Daniel@0 491 $server['SERVER_PORT'] = 443;
Daniel@0 492 } else {
Daniel@0 493 unset($server['HTTPS']);
Daniel@0 494 $server['SERVER_PORT'] = 80;
Daniel@0 495 }
Daniel@0 496 }
Daniel@0 497 if (isset($components['port'])) {
Daniel@0 498 $server['SERVER_PORT'] = $components['port'];
Daniel@0 499 $server['HTTP_HOST'] = $server['HTTP_HOST'].':'.$components['port'];
Daniel@0 500 }
Daniel@0 501 if (isset($components['user'])) {
Daniel@0 502 $server['PHP_AUTH_USER'] = $components['user'];
Daniel@0 503 }
Daniel@0 504 if (isset($components['pass'])) {
Daniel@0 505 $server['PHP_AUTH_PW'] = $components['pass'];
Daniel@0 506 }
Daniel@0 507 if (!isset($components['path'])) {
Daniel@0 508 $components['path'] ='/';
Daniel@0 509 }
Daniel@0 510 switch (strtoupper($method)) {
Daniel@0 511 case'POST':
Daniel@0 512 case'PUT':
Daniel@0 513 case'DELETE':
Daniel@0 514 if (!isset($server['CONTENT_TYPE'])) {
Daniel@0 515 $server['CONTENT_TYPE'] ='application/x-www-form-urlencoded';
Daniel@0 516 }
Daniel@0 517 case'PATCH':
Daniel@0 518 $request = $parameters;
Daniel@0 519 $query = array();
Daniel@0 520 break;
Daniel@0 521 default:
Daniel@0 522 $request = array();
Daniel@0 523 $query = $parameters;
Daniel@0 524 break;
Daniel@0 525 }
Daniel@0 526 $queryString ='';
Daniel@0 527 if (isset($components['query'])) {
Daniel@0 528 parse_str(html_entity_decode($components['query']), $qs);
Daniel@0 529 if ($query) {
Daniel@0 530 $query = array_replace($qs, $query);
Daniel@0 531 $queryString = http_build_query($query,'','&');
Daniel@0 532 } else {
Daniel@0 533 $query = $qs;
Daniel@0 534 $queryString = $components['query'];
Daniel@0 535 }
Daniel@0 536 } elseif ($query) {
Daniel@0 537 $queryString = http_build_query($query,'','&');
Daniel@0 538 }
Daniel@0 539 $server['REQUEST_URI'] = $components['path'].(''!== $queryString ?'?'.$queryString :'');
Daniel@0 540 $server['QUERY_STRING'] = $queryString;
Daniel@0 541 return self::createRequestFromFactory($query, $request, array(), $cookies, $files, $server, $content);
Daniel@0 542 }
Daniel@0 543 public static function setFactory($callable)
Daniel@0 544 {
Daniel@0 545 self::$requestFactory = $callable;
Daniel@0 546 }
Daniel@0 547 public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
Daniel@0 548 {
Daniel@0 549 $dup = clone $this;
Daniel@0 550 if ($query !== null) {
Daniel@0 551 $dup->query = new ParameterBag($query);
Daniel@0 552 }
Daniel@0 553 if ($request !== null) {
Daniel@0 554 $dup->request = new ParameterBag($request);
Daniel@0 555 }
Daniel@0 556 if ($attributes !== null) {
Daniel@0 557 $dup->attributes = new ParameterBag($attributes);
Daniel@0 558 }
Daniel@0 559 if ($cookies !== null) {
Daniel@0 560 $dup->cookies = new ParameterBag($cookies);
Daniel@0 561 }
Daniel@0 562 if ($files !== null) {
Daniel@0 563 $dup->files = new FileBag($files);
Daniel@0 564 }
Daniel@0 565 if ($server !== null) {
Daniel@0 566 $dup->server = new ServerBag($server);
Daniel@0 567 $dup->headers = new HeaderBag($dup->server->getHeaders());
Daniel@0 568 }
Daniel@0 569 $dup->languages = null;
Daniel@0 570 $dup->charsets = null;
Daniel@0 571 $dup->encodings = null;
Daniel@0 572 $dup->acceptableContentTypes = null;
Daniel@0 573 $dup->pathInfo = null;
Daniel@0 574 $dup->requestUri = null;
Daniel@0 575 $dup->baseUrl = null;
Daniel@0 576 $dup->basePath = null;
Daniel@0 577 $dup->method = null;
Daniel@0 578 $dup->format = null;
Daniel@0 579 if (!$dup->get('_format') && $this->get('_format')) {
Daniel@0 580 $dup->attributes->set('_format', $this->get('_format'));
Daniel@0 581 }
Daniel@0 582 if (!$dup->getRequestFormat(null)) {
Daniel@0 583 $dup->setRequestFormat($this->getRequestFormat(null));
Daniel@0 584 }
Daniel@0 585 return $dup;
Daniel@0 586 }
Daniel@0 587 public function __clone()
Daniel@0 588 {
Daniel@0 589 $this->query = clone $this->query;
Daniel@0 590 $this->request = clone $this->request;
Daniel@0 591 $this->attributes = clone $this->attributes;
Daniel@0 592 $this->cookies = clone $this->cookies;
Daniel@0 593 $this->files = clone $this->files;
Daniel@0 594 $this->server = clone $this->server;
Daniel@0 595 $this->headers = clone $this->headers;
Daniel@0 596 }
Daniel@0 597 public function __toString()
Daniel@0 598 {
Daniel@0 599 return
Daniel@0 600 sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
Daniel@0 601 $this->headers."\r\n".
Daniel@0 602 $this->getContent();
Daniel@0 603 }
Daniel@0 604 public function overrideGlobals()
Daniel@0 605 {
Daniel@0 606 $this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null,'&')));
Daniel@0 607 $_GET = $this->query->all();
Daniel@0 608 $_POST = $this->request->all();
Daniel@0 609 $_SERVER = $this->server->all();
Daniel@0 610 $_COOKIE = $this->cookies->all();
Daniel@0 611 foreach ($this->headers->all() as $key => $value) {
Daniel@0 612 $key = strtoupper(str_replace('-','_', $key));
Daniel@0 613 if (in_array($key, array('CONTENT_TYPE','CONTENT_LENGTH'))) {
Daniel@0 614 $_SERVER[$key] = implode(', ', $value);
Daniel@0 615 } else {
Daniel@0 616 $_SERVER['HTTP_'.$key] = implode(', ', $value);
Daniel@0 617 }
Daniel@0 618 }
Daniel@0 619 $request = array('g'=> $_GET,'p'=> $_POST,'c'=> $_COOKIE);
Daniel@0 620 $requestOrder = ini_get('request_order') ?: ini_get('variables_order');
Daniel@0 621 $requestOrder = preg_replace('#[^cgp]#','', strtolower($requestOrder)) ?:'gp';
Daniel@0 622 $_REQUEST = array();
Daniel@0 623 foreach (str_split($requestOrder) as $order) {
Daniel@0 624 $_REQUEST = array_merge($_REQUEST, $request[$order]);
Daniel@0 625 }
Daniel@0 626 }
Daniel@0 627 public static function setTrustedProxies(array $proxies)
Daniel@0 628 {
Daniel@0 629 self::$trustedProxies = $proxies;
Daniel@0 630 }
Daniel@0 631 public static function getTrustedProxies()
Daniel@0 632 {
Daniel@0 633 return self::$trustedProxies;
Daniel@0 634 }
Daniel@0 635 public static function setTrustedHosts(array $hostPatterns)
Daniel@0 636 {
Daniel@0 637 self::$trustedHostPatterns = array_map(function ($hostPattern) {
Daniel@0 638 return sprintf('{%s}i', str_replace('}','\\}', $hostPattern));
Daniel@0 639 }, $hostPatterns);
Daniel@0 640 self::$trustedHosts = array();
Daniel@0 641 }
Daniel@0 642 public static function getTrustedHosts()
Daniel@0 643 {
Daniel@0 644 return self::$trustedHostPatterns;
Daniel@0 645 }
Daniel@0 646 public static function setTrustedHeaderName($key, $value)
Daniel@0 647 {
Daniel@0 648 if (!array_key_exists($key, self::$trustedHeaders)) {
Daniel@0 649 throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
Daniel@0 650 }
Daniel@0 651 self::$trustedHeaders[$key] = $value;
Daniel@0 652 }
Daniel@0 653 public static function getTrustedHeaderName($key)
Daniel@0 654 {
Daniel@0 655 if (!array_key_exists($key, self::$trustedHeaders)) {
Daniel@0 656 throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
Daniel@0 657 }
Daniel@0 658 return self::$trustedHeaders[$key];
Daniel@0 659 }
Daniel@0 660 public static function normalizeQueryString($qs)
Daniel@0 661 {
Daniel@0 662 if (''== $qs) {
Daniel@0 663 return'';
Daniel@0 664 }
Daniel@0 665 $parts = array();
Daniel@0 666 $order = array();
Daniel@0 667 foreach (explode('&', $qs) as $param) {
Daniel@0 668 if (''=== $param ||'='=== $param[0]) {
Daniel@0 669 continue;
Daniel@0 670 }
Daniel@0 671 $keyValuePair = explode('=', $param, 2);
Daniel@0 672 $parts[] = isset($keyValuePair[1]) ?
Daniel@0 673 rawurlencode(urldecode($keyValuePair[0])).'='.rawurlencode(urldecode($keyValuePair[1])) :
Daniel@0 674 rawurlencode(urldecode($keyValuePair[0]));
Daniel@0 675 $order[] = urldecode($keyValuePair[0]);
Daniel@0 676 }
Daniel@0 677 array_multisort($order, SORT_ASC, $parts);
Daniel@0 678 return implode('&', $parts);
Daniel@0 679 }
Daniel@0 680 public static function enableHttpMethodParameterOverride()
Daniel@0 681 {
Daniel@0 682 self::$httpMethodParameterOverride = true;
Daniel@0 683 }
Daniel@0 684 public static function getHttpMethodParameterOverride()
Daniel@0 685 {
Daniel@0 686 return self::$httpMethodParameterOverride;
Daniel@0 687 }
Daniel@0 688 public function get($key, $default = null, $deep = false)
Daniel@0 689 {
Daniel@0 690 if ($this !== $result = $this->query->get($key, $this, $deep)) {
Daniel@0 691 return $result;
Daniel@0 692 }
Daniel@0 693 if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
Daniel@0 694 return $result;
Daniel@0 695 }
Daniel@0 696 if ($this !== $result = $this->request->get($key, $this, $deep)) {
Daniel@0 697 return $result;
Daniel@0 698 }
Daniel@0 699 return $default;
Daniel@0 700 }
Daniel@0 701 public function getSession()
Daniel@0 702 {
Daniel@0 703 return $this->session;
Daniel@0 704 }
Daniel@0 705 public function hasPreviousSession()
Daniel@0 706 {
Daniel@0 707 return $this->hasSession() && $this->cookies->has($this->session->getName());
Daniel@0 708 }
Daniel@0 709 public function hasSession()
Daniel@0 710 {
Daniel@0 711 return null !== $this->session;
Daniel@0 712 }
Daniel@0 713 public function setSession(SessionInterface $session)
Daniel@0 714 {
Daniel@0 715 $this->session = $session;
Daniel@0 716 }
Daniel@0 717 public function getClientIps()
Daniel@0 718 {
Daniel@0 719 $ip = $this->server->get('REMOTE_ADDR');
Daniel@0 720 if (!self::$trustedProxies) {
Daniel@0 721 return array($ip);
Daniel@0 722 }
Daniel@0 723 if (!self::$trustedHeaders[self::HEADER_CLIENT_IP] || !$this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
Daniel@0 724 return array($ip);
Daniel@0 725 }
Daniel@0 726 $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
Daniel@0 727 $clientIps[] = $ip;
Daniel@0 728 $ip = $clientIps[0];
Daniel@0 729 foreach ($clientIps as $key => $clientIp) {
Daniel@0 730 if (preg_match('{((?:\d+\.){3}\d+)\:\d+}', $clientIp, $match)) {
Daniel@0 731 $clientIps[$key] = $clientIp = $match[1];
Daniel@0 732 }
Daniel@0 733 if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
Daniel@0 734 unset($clientIps[$key]);
Daniel@0 735 }
Daniel@0 736 }
Daniel@0 737 return $clientIps ? array_reverse($clientIps) : array($ip);
Daniel@0 738 }
Daniel@0 739 public function getClientIp()
Daniel@0 740 {
Daniel@0 741 $ipAddresses = $this->getClientIps();
Daniel@0 742 return $ipAddresses[0];
Daniel@0 743 }
Daniel@0 744 public function getScriptName()
Daniel@0 745 {
Daniel@0 746 return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME',''));
Daniel@0 747 }
Daniel@0 748 public function getPathInfo()
Daniel@0 749 {
Daniel@0 750 if (null === $this->pathInfo) {
Daniel@0 751 $this->pathInfo = $this->preparePathInfo();
Daniel@0 752 }
Daniel@0 753 return $this->pathInfo;
Daniel@0 754 }
Daniel@0 755 public function getBasePath()
Daniel@0 756 {
Daniel@0 757 if (null === $this->basePath) {
Daniel@0 758 $this->basePath = $this->prepareBasePath();
Daniel@0 759 }
Daniel@0 760 return $this->basePath;
Daniel@0 761 }
Daniel@0 762 public function getBaseUrl()
Daniel@0 763 {
Daniel@0 764 if (null === $this->baseUrl) {
Daniel@0 765 $this->baseUrl = $this->prepareBaseUrl();
Daniel@0 766 }
Daniel@0 767 return $this->baseUrl;
Daniel@0 768 }
Daniel@0 769 public function getScheme()
Daniel@0 770 {
Daniel@0 771 return $this->isSecure() ?'https':'http';
Daniel@0 772 }
Daniel@0 773 public function getPort()
Daniel@0 774 {
Daniel@0 775 if (self::$trustedProxies) {
Daniel@0 776 if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && $port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT])) {
Daniel@0 777 return $port;
Daniel@0 778 }
Daniel@0 779 if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] &&'https'=== $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO],'http')) {
Daniel@0 780 return 443;
Daniel@0 781 }
Daniel@0 782 }
Daniel@0 783 if ($host = $this->headers->get('HOST')) {
Daniel@0 784 if ($host[0] ==='[') {
Daniel@0 785 $pos = strpos($host,':', strrpos($host,']'));
Daniel@0 786 } else {
Daniel@0 787 $pos = strrpos($host,':');
Daniel@0 788 }
Daniel@0 789 if (false !== $pos) {
Daniel@0 790 return intval(substr($host, $pos + 1));
Daniel@0 791 }
Daniel@0 792 return'https'=== $this->getScheme() ? 443 : 80;
Daniel@0 793 }
Daniel@0 794 return $this->server->get('SERVER_PORT');
Daniel@0 795 }
Daniel@0 796 public function getUser()
Daniel@0 797 {
Daniel@0 798 return $this->headers->get('PHP_AUTH_USER');
Daniel@0 799 }
Daniel@0 800 public function getPassword()
Daniel@0 801 {
Daniel@0 802 return $this->headers->get('PHP_AUTH_PW');
Daniel@0 803 }
Daniel@0 804 public function getUserInfo()
Daniel@0 805 {
Daniel@0 806 $userinfo = $this->getUser();
Daniel@0 807 $pass = $this->getPassword();
Daniel@0 808 if (''!= $pass) {
Daniel@0 809 $userinfo .= ":$pass";
Daniel@0 810 }
Daniel@0 811 return $userinfo;
Daniel@0 812 }
Daniel@0 813 public function getHttpHost()
Daniel@0 814 {
Daniel@0 815 $scheme = $this->getScheme();
Daniel@0 816 $port = $this->getPort();
Daniel@0 817 if (('http'== $scheme && $port == 80) || ('https'== $scheme && $port == 443)) {
Daniel@0 818 return $this->getHost();
Daniel@0 819 }
Daniel@0 820 return $this->getHost().':'.$port;
Daniel@0 821 }
Daniel@0 822 public function getRequestUri()
Daniel@0 823 {
Daniel@0 824 if (null === $this->requestUri) {
Daniel@0 825 $this->requestUri = $this->prepareRequestUri();
Daniel@0 826 }
Daniel@0 827 return $this->requestUri;
Daniel@0 828 }
Daniel@0 829 public function getSchemeAndHttpHost()
Daniel@0 830 {
Daniel@0 831 return $this->getScheme().'://'.$this->getHttpHost();
Daniel@0 832 }
Daniel@0 833 public function getUri()
Daniel@0 834 {
Daniel@0 835 if (null !== $qs = $this->getQueryString()) {
Daniel@0 836 $qs ='?'.$qs;
Daniel@0 837 }
Daniel@0 838 return $this->getSchemeAndHttpHost().$this->getBaseUrl().$this->getPathInfo().$qs;
Daniel@0 839 }
Daniel@0 840 public function getUriForPath($path)
Daniel@0 841 {
Daniel@0 842 return $this->getSchemeAndHttpHost().$this->getBaseUrl().$path;
Daniel@0 843 }
Daniel@0 844 public function getQueryString()
Daniel@0 845 {
Daniel@0 846 $qs = static::normalizeQueryString($this->server->get('QUERY_STRING'));
Daniel@0 847 return''=== $qs ? null : $qs;
Daniel@0 848 }
Daniel@0 849 public function isSecure()
Daniel@0 850 {
Daniel@0 851 if (self::$trustedProxies && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && $proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO])) {
Daniel@0 852 return in_array(strtolower(current(explode(',', $proto))), array('https','on','ssl','1'));
Daniel@0 853 }
Daniel@0 854 $https = $this->server->get('HTTPS');
Daniel@0 855 return !empty($https) &&'off'!== strtolower($https);
Daniel@0 856 }
Daniel@0 857 public function getHost()
Daniel@0 858 {
Daniel@0 859 if (self::$trustedProxies && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && $host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST])) {
Daniel@0 860 $elements = explode(',', $host);
Daniel@0 861 $host = $elements[count($elements) - 1];
Daniel@0 862 } elseif (!$host = $this->headers->get('HOST')) {
Daniel@0 863 if (!$host = $this->server->get('SERVER_NAME')) {
Daniel@0 864 $host = $this->server->get('SERVER_ADDR','');
Daniel@0 865 }
Daniel@0 866 }
Daniel@0 867 $host = strtolower(preg_replace('/:\d+$/','', trim($host)));
Daniel@0 868 if ($host &&''!== preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/','', $host)) {
Daniel@0 869 throw new \UnexpectedValueException(sprintf('Invalid Host "%s"', $host));
Daniel@0 870 }
Daniel@0 871 if (count(self::$trustedHostPatterns) > 0) {
Daniel@0 872 if (in_array($host, self::$trustedHosts)) {
Daniel@0 873 return $host;
Daniel@0 874 }
Daniel@0 875 foreach (self::$trustedHostPatterns as $pattern) {
Daniel@0 876 if (preg_match($pattern, $host)) {
Daniel@0 877 self::$trustedHosts[] = $host;
Daniel@0 878 return $host;
Daniel@0 879 }
Daniel@0 880 }
Daniel@0 881 throw new \UnexpectedValueException(sprintf('Untrusted Host "%s"', $host));
Daniel@0 882 }
Daniel@0 883 return $host;
Daniel@0 884 }
Daniel@0 885 public function setMethod($method)
Daniel@0 886 {
Daniel@0 887 $this->method = null;
Daniel@0 888 $this->server->set('REQUEST_METHOD', $method);
Daniel@0 889 }
Daniel@0 890 public function getMethod()
Daniel@0 891 {
Daniel@0 892 if (null === $this->method) {
Daniel@0 893 $this->method = strtoupper($this->server->get('REQUEST_METHOD','GET'));
Daniel@0 894 if ('POST'=== $this->method) {
Daniel@0 895 if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
Daniel@0 896 $this->method = strtoupper($method);
Daniel@0 897 } elseif (self::$httpMethodParameterOverride) {
Daniel@0 898 $this->method = strtoupper($this->request->get('_method', $this->query->get('_method','POST')));
Daniel@0 899 }
Daniel@0 900 }
Daniel@0 901 }
Daniel@0 902 return $this->method;
Daniel@0 903 }
Daniel@0 904 public function getRealMethod()
Daniel@0 905 {
Daniel@0 906 return strtoupper($this->server->get('REQUEST_METHOD','GET'));
Daniel@0 907 }
Daniel@0 908 public function getMimeType($format)
Daniel@0 909 {
Daniel@0 910 if (null === static::$formats) {
Daniel@0 911 static::initializeFormats();
Daniel@0 912 }
Daniel@0 913 return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
Daniel@0 914 }
Daniel@0 915 public function getFormat($mimeType)
Daniel@0 916 {
Daniel@0 917 if (false !== $pos = strpos($mimeType,';')) {
Daniel@0 918 $mimeType = substr($mimeType, 0, $pos);
Daniel@0 919 }
Daniel@0 920 if (null === static::$formats) {
Daniel@0 921 static::initializeFormats();
Daniel@0 922 }
Daniel@0 923 foreach (static::$formats as $format => $mimeTypes) {
Daniel@0 924 if (in_array($mimeType, (array) $mimeTypes)) {
Daniel@0 925 return $format;
Daniel@0 926 }
Daniel@0 927 }
Daniel@0 928 }
Daniel@0 929 public function setFormat($format, $mimeTypes)
Daniel@0 930 {
Daniel@0 931 if (null === static::$formats) {
Daniel@0 932 static::initializeFormats();
Daniel@0 933 }
Daniel@0 934 static::$formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
Daniel@0 935 }
Daniel@0 936 public function getRequestFormat($default ='html')
Daniel@0 937 {
Daniel@0 938 if (null === $this->format) {
Daniel@0 939 $this->format = $this->get('_format', $default);
Daniel@0 940 }
Daniel@0 941 return $this->format;
Daniel@0 942 }
Daniel@0 943 public function setRequestFormat($format)
Daniel@0 944 {
Daniel@0 945 $this->format = $format;
Daniel@0 946 }
Daniel@0 947 public function getContentType()
Daniel@0 948 {
Daniel@0 949 return $this->getFormat($this->headers->get('CONTENT_TYPE'));
Daniel@0 950 }
Daniel@0 951 public function setDefaultLocale($locale)
Daniel@0 952 {
Daniel@0 953 $this->defaultLocale = $locale;
Daniel@0 954 if (null === $this->locale) {
Daniel@0 955 $this->setPhpDefaultLocale($locale);
Daniel@0 956 }
Daniel@0 957 }
Daniel@0 958 public function getDefaultLocale()
Daniel@0 959 {
Daniel@0 960 return $this->defaultLocale;
Daniel@0 961 }
Daniel@0 962 public function setLocale($locale)
Daniel@0 963 {
Daniel@0 964 $this->setPhpDefaultLocale($this->locale = $locale);
Daniel@0 965 }
Daniel@0 966 public function getLocale()
Daniel@0 967 {
Daniel@0 968 return null === $this->locale ? $this->defaultLocale : $this->locale;
Daniel@0 969 }
Daniel@0 970 public function isMethod($method)
Daniel@0 971 {
Daniel@0 972 return $this->getMethod() === strtoupper($method);
Daniel@0 973 }
Daniel@0 974 public function isMethodSafe()
Daniel@0 975 {
Daniel@0 976 return in_array($this->getMethod(), array('GET','HEAD'));
Daniel@0 977 }
Daniel@0 978 public function getContent($asResource = false)
Daniel@0 979 {
Daniel@0 980 if (false === $this->content || (true === $asResource && null !== $this->content)) {
Daniel@0 981 throw new \LogicException('getContent() can only be called once when using the resource return type.');
Daniel@0 982 }
Daniel@0 983 if (true === $asResource) {
Daniel@0 984 $this->content = false;
Daniel@0 985 return fopen('php://input','rb');
Daniel@0 986 }
Daniel@0 987 if (null === $this->content) {
Daniel@0 988 $this->content = file_get_contents('php://input');
Daniel@0 989 }
Daniel@0 990 return $this->content;
Daniel@0 991 }
Daniel@0 992 public function getETags()
Daniel@0 993 {
Daniel@0 994 return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
Daniel@0 995 }
Daniel@0 996 public function isNoCache()
Daniel@0 997 {
Daniel@0 998 return $this->headers->hasCacheControlDirective('no-cache') ||'no-cache'== $this->headers->get('Pragma');
Daniel@0 999 }
Daniel@0 1000 public function getPreferredLanguage(array $locales = null)
Daniel@0 1001 {
Daniel@0 1002 $preferredLanguages = $this->getLanguages();
Daniel@0 1003 if (empty($locales)) {
Daniel@0 1004 return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
Daniel@0 1005 }
Daniel@0 1006 if (!$preferredLanguages) {
Daniel@0 1007 return $locales[0];
Daniel@0 1008 }
Daniel@0 1009 $extendedPreferredLanguages = array();
Daniel@0 1010 foreach ($preferredLanguages as $language) {
Daniel@0 1011 $extendedPreferredLanguages[] = $language;
Daniel@0 1012 if (false !== $position = strpos($language,'_')) {
Daniel@0 1013 $superLanguage = substr($language, 0, $position);
Daniel@0 1014 if (!in_array($superLanguage, $preferredLanguages)) {
Daniel@0 1015 $extendedPreferredLanguages[] = $superLanguage;
Daniel@0 1016 }
Daniel@0 1017 }
Daniel@0 1018 }
Daniel@0 1019 $preferredLanguages = array_values(array_intersect($extendedPreferredLanguages, $locales));
Daniel@0 1020 return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
Daniel@0 1021 }
Daniel@0 1022 public function getLanguages()
Daniel@0 1023 {
Daniel@0 1024 if (null !== $this->languages) {
Daniel@0 1025 return $this->languages;
Daniel@0 1026 }
Daniel@0 1027 $languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
Daniel@0 1028 $this->languages = array();
Daniel@0 1029 foreach (array_keys($languages) as $lang) {
Daniel@0 1030 if (strstr($lang,'-')) {
Daniel@0 1031 $codes = explode('-', $lang);
Daniel@0 1032 if ($codes[0] =='i') {
Daniel@0 1033 if (count($codes) > 1) {
Daniel@0 1034 $lang = $codes[1];
Daniel@0 1035 }
Daniel@0 1036 } else {
Daniel@0 1037 for ($i = 0, $max = count($codes); $i < $max; $i++) {
Daniel@0 1038 if ($i == 0) {
Daniel@0 1039 $lang = strtolower($codes[0]);
Daniel@0 1040 } else {
Daniel@0 1041 $lang .='_'.strtoupper($codes[$i]);
Daniel@0 1042 }
Daniel@0 1043 }
Daniel@0 1044 }
Daniel@0 1045 }
Daniel@0 1046 $this->languages[] = $lang;
Daniel@0 1047 }
Daniel@0 1048 return $this->languages;
Daniel@0 1049 }
Daniel@0 1050 public function getCharsets()
Daniel@0 1051 {
Daniel@0 1052 if (null !== $this->charsets) {
Daniel@0 1053 return $this->charsets;
Daniel@0 1054 }
Daniel@0 1055 return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
Daniel@0 1056 }
Daniel@0 1057 public function getEncodings()
Daniel@0 1058 {
Daniel@0 1059 if (null !== $this->encodings) {
Daniel@0 1060 return $this->encodings;
Daniel@0 1061 }
Daniel@0 1062 return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all());
Daniel@0 1063 }
Daniel@0 1064 public function getAcceptableContentTypes()
Daniel@0 1065 {
Daniel@0 1066 if (null !== $this->acceptableContentTypes) {
Daniel@0 1067 return $this->acceptableContentTypes;
Daniel@0 1068 }
Daniel@0 1069 return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
Daniel@0 1070 }
Daniel@0 1071 public function isXmlHttpRequest()
Daniel@0 1072 {
Daniel@0 1073 return'XMLHttpRequest'== $this->headers->get('X-Requested-With');
Daniel@0 1074 }
Daniel@0 1075 protected function prepareRequestUri()
Daniel@0 1076 {
Daniel@0 1077 $requestUri ='';
Daniel@0 1078 if ($this->headers->has('X_ORIGINAL_URL')) {
Daniel@0 1079 $requestUri = $this->headers->get('X_ORIGINAL_URL');
Daniel@0 1080 $this->headers->remove('X_ORIGINAL_URL');
Daniel@0 1081 $this->server->remove('HTTP_X_ORIGINAL_URL');
Daniel@0 1082 $this->server->remove('UNENCODED_URL');
Daniel@0 1083 $this->server->remove('IIS_WasUrlRewritten');
Daniel@0 1084 } elseif ($this->headers->has('X_REWRITE_URL')) {
Daniel@0 1085 $requestUri = $this->headers->get('X_REWRITE_URL');
Daniel@0 1086 $this->headers->remove('X_REWRITE_URL');
Daniel@0 1087 } elseif ($this->server->get('IIS_WasUrlRewritten') =='1'&& $this->server->get('UNENCODED_URL') !='') {
Daniel@0 1088 $requestUri = $this->server->get('UNENCODED_URL');
Daniel@0 1089 $this->server->remove('UNENCODED_URL');
Daniel@0 1090 $this->server->remove('IIS_WasUrlRewritten');
Daniel@0 1091 } elseif ($this->server->has('REQUEST_URI')) {
Daniel@0 1092 $requestUri = $this->server->get('REQUEST_URI');
Daniel@0 1093 $schemeAndHttpHost = $this->getSchemeAndHttpHost();
Daniel@0 1094 if (strpos($requestUri, $schemeAndHttpHost) === 0) {
Daniel@0 1095 $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
Daniel@0 1096 }
Daniel@0 1097 } elseif ($this->server->has('ORIG_PATH_INFO')) {
Daniel@0 1098 $requestUri = $this->server->get('ORIG_PATH_INFO');
Daniel@0 1099 if (''!= $this->server->get('QUERY_STRING')) {
Daniel@0 1100 $requestUri .='?'.$this->server->get('QUERY_STRING');
Daniel@0 1101 }
Daniel@0 1102 $this->server->remove('ORIG_PATH_INFO');
Daniel@0 1103 }
Daniel@0 1104 $this->server->set('REQUEST_URI', $requestUri);
Daniel@0 1105 return $requestUri;
Daniel@0 1106 }
Daniel@0 1107 protected function prepareBaseUrl()
Daniel@0 1108 {
Daniel@0 1109 $filename = basename($this->server->get('SCRIPT_FILENAME'));
Daniel@0 1110 if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
Daniel@0 1111 $baseUrl = $this->server->get('SCRIPT_NAME');
Daniel@0 1112 } elseif (basename($this->server->get('PHP_SELF')) === $filename) {
Daniel@0 1113 $baseUrl = $this->server->get('PHP_SELF');
Daniel@0 1114 } elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
Daniel@0 1115 $baseUrl = $this->server->get('ORIG_SCRIPT_NAME'); } else {
Daniel@0 1116 $path = $this->server->get('PHP_SELF','');
Daniel@0 1117 $file = $this->server->get('SCRIPT_FILENAME','');
Daniel@0 1118 $segs = explode('/', trim($file,'/'));
Daniel@0 1119 $segs = array_reverse($segs);
Daniel@0 1120 $index = 0;
Daniel@0 1121 $last = count($segs);
Daniel@0 1122 $baseUrl ='';
Daniel@0 1123 do {
Daniel@0 1124 $seg = $segs[$index];
Daniel@0 1125 $baseUrl ='/'.$seg.$baseUrl;
Daniel@0 1126 ++$index;
Daniel@0 1127 } while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
Daniel@0 1128 }
Daniel@0 1129 $requestUri = $this->getRequestUri();
Daniel@0 1130 if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
Daniel@0 1131 return $prefix;
Daniel@0 1132 }
Daniel@0 1133 if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl).'/')) {
Daniel@0 1134 return rtrim($prefix,'/');
Daniel@0 1135 }
Daniel@0 1136 $truncatedRequestUri = $requestUri;
Daniel@0 1137 if (false !== $pos = strpos($requestUri,'?')) {
Daniel@0 1138 $truncatedRequestUri = substr($requestUri, 0, $pos);
Daniel@0 1139 }
Daniel@0 1140 $basename = basename($baseUrl);
Daniel@0 1141 if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
Daniel@0 1142 return'';
Daniel@0 1143 }
Daniel@0 1144 if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && $pos !== 0) {
Daniel@0 1145 $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
Daniel@0 1146 }
Daniel@0 1147 return rtrim($baseUrl,'/');
Daniel@0 1148 }
Daniel@0 1149 protected function prepareBasePath()
Daniel@0 1150 {
Daniel@0 1151 $filename = basename($this->server->get('SCRIPT_FILENAME'));
Daniel@0 1152 $baseUrl = $this->getBaseUrl();
Daniel@0 1153 if (empty($baseUrl)) {
Daniel@0 1154 return'';
Daniel@0 1155 }
Daniel@0 1156 if (basename($baseUrl) === $filename) {
Daniel@0 1157 $basePath = dirname($baseUrl);
Daniel@0 1158 } else {
Daniel@0 1159 $basePath = $baseUrl;
Daniel@0 1160 }
Daniel@0 1161 if ('\\'=== DIRECTORY_SEPARATOR) {
Daniel@0 1162 $basePath = str_replace('\\','/', $basePath);
Daniel@0 1163 }
Daniel@0 1164 return rtrim($basePath,'/');
Daniel@0 1165 }
Daniel@0 1166 protected function preparePathInfo()
Daniel@0 1167 {
Daniel@0 1168 $baseUrl = $this->getBaseUrl();
Daniel@0 1169 if (null === ($requestUri = $this->getRequestUri())) {
Daniel@0 1170 return'/';
Daniel@0 1171 }
Daniel@0 1172 $pathInfo ='/';
Daniel@0 1173 if ($pos = strpos($requestUri,'?')) {
Daniel@0 1174 $requestUri = substr($requestUri, 0, $pos);
Daniel@0 1175 }
Daniel@0 1176 if (null !== $baseUrl && false === $pathInfo = substr($requestUri, strlen($baseUrl))) {
Daniel@0 1177 return'/';
Daniel@0 1178 } elseif (null === $baseUrl) {
Daniel@0 1179 return $requestUri;
Daniel@0 1180 }
Daniel@0 1181 return (string) $pathInfo;
Daniel@0 1182 }
Daniel@0 1183 protected static function initializeFormats()
Daniel@0 1184 {
Daniel@0 1185 static::$formats = array('html'=> array('text/html','application/xhtml+xml'),'txt'=> array('text/plain'),'js'=> array('application/javascript','application/x-javascript','text/javascript'),'css'=> array('text/css'),'json'=> array('application/json','application/x-json'),'xml'=> array('text/xml','application/xml','application/x-xml'),'rdf'=> array('application/rdf+xml'),'atom'=> array('application/atom+xml'),'rss'=> array('application/rss+xml'),
Daniel@0 1186 );
Daniel@0 1187 }
Daniel@0 1188 private function setPhpDefaultLocale($locale)
Daniel@0 1189 {
Daniel@0 1190 try {
Daniel@0 1191 if (class_exists('Locale', false)) {
Daniel@0 1192 \Locale::setDefault($locale);
Daniel@0 1193 }
Daniel@0 1194 } catch (\Exception $e) {
Daniel@0 1195 }
Daniel@0 1196 }
Daniel@0 1197 private function getUrlencodedPrefix($string, $prefix)
Daniel@0 1198 {
Daniel@0 1199 if (0 !== strpos(rawurldecode($string), $prefix)) {
Daniel@0 1200 return false;
Daniel@0 1201 }
Daniel@0 1202 $len = strlen($prefix);
Daniel@0 1203 if (preg_match("#^(%[[:xdigit:]]{2}|.){{$len}}#", $string, $match)) {
Daniel@0 1204 return $match[0];
Daniel@0 1205 }
Daniel@0 1206 return false;
Daniel@0 1207 }
Daniel@0 1208 private static function createRequestFromFactory(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
Daniel@0 1209 {
Daniel@0 1210 if (self::$requestFactory) {
Daniel@0 1211 $request = call_user_func(self::$requestFactory, $query, $request, $attributes, $cookies, $files, $server, $content);
Daniel@0 1212 if (!$request instanceof Request) {
Daniel@0 1213 throw new \LogicException('The Request factory must return an instance of Symfony\Component\HttpFoundation\Request.');
Daniel@0 1214 }
Daniel@0 1215 return $request;
Daniel@0 1216 }
Daniel@0 1217 return new static($query, $request, $attributes, $cookies, $files, $server, $content);
Daniel@0 1218 }
Daniel@0 1219 }
Daniel@0 1220 }
Daniel@0 1221 namespace Symfony\Component\HttpFoundation
Daniel@0 1222 {
Daniel@0 1223 class Response
Daniel@0 1224 {
Daniel@0 1225 const HTTP_CONTINUE = 100;
Daniel@0 1226 const HTTP_SWITCHING_PROTOCOLS = 101;
Daniel@0 1227 const HTTP_PROCESSING = 102; const HTTP_OK = 200;
Daniel@0 1228 const HTTP_CREATED = 201;
Daniel@0 1229 const HTTP_ACCEPTED = 202;
Daniel@0 1230 const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
Daniel@0 1231 const HTTP_NO_CONTENT = 204;
Daniel@0 1232 const HTTP_RESET_CONTENT = 205;
Daniel@0 1233 const HTTP_PARTIAL_CONTENT = 206;
Daniel@0 1234 const HTTP_MULTI_STATUS = 207; const HTTP_ALREADY_REPORTED = 208; const HTTP_IM_USED = 226; const HTTP_MULTIPLE_CHOICES = 300;
Daniel@0 1235 const HTTP_MOVED_PERMANENTLY = 301;
Daniel@0 1236 const HTTP_FOUND = 302;
Daniel@0 1237 const HTTP_SEE_OTHER = 303;
Daniel@0 1238 const HTTP_NOT_MODIFIED = 304;
Daniel@0 1239 const HTTP_USE_PROXY = 305;
Daniel@0 1240 const HTTP_RESERVED = 306;
Daniel@0 1241 const HTTP_TEMPORARY_REDIRECT = 307;
Daniel@0 1242 const HTTP_PERMANENTLY_REDIRECT = 308; const HTTP_BAD_REQUEST = 400;
Daniel@0 1243 const HTTP_UNAUTHORIZED = 401;
Daniel@0 1244 const HTTP_PAYMENT_REQUIRED = 402;
Daniel@0 1245 const HTTP_FORBIDDEN = 403;
Daniel@0 1246 const HTTP_NOT_FOUND = 404;
Daniel@0 1247 const HTTP_METHOD_NOT_ALLOWED = 405;
Daniel@0 1248 const HTTP_NOT_ACCEPTABLE = 406;
Daniel@0 1249 const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
Daniel@0 1250 const HTTP_REQUEST_TIMEOUT = 408;
Daniel@0 1251 const HTTP_CONFLICT = 409;
Daniel@0 1252 const HTTP_GONE = 410;
Daniel@0 1253 const HTTP_LENGTH_REQUIRED = 411;
Daniel@0 1254 const HTTP_PRECONDITION_FAILED = 412;
Daniel@0 1255 const HTTP_REQUEST_ENTITY_TOO_LARGE = 413;
Daniel@0 1256 const HTTP_REQUEST_URI_TOO_LONG = 414;
Daniel@0 1257 const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
Daniel@0 1258 const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
Daniel@0 1259 const HTTP_EXPECTATION_FAILED = 417;
Daniel@0 1260 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;
Daniel@0 1261 const HTTP_NOT_IMPLEMENTED = 501;
Daniel@0 1262 const HTTP_BAD_GATEWAY = 502;
Daniel@0 1263 const HTTP_SERVICE_UNAVAILABLE = 503;
Daniel@0 1264 const HTTP_GATEWAY_TIMEOUT = 504;
Daniel@0 1265 const HTTP_VERSION_NOT_SUPPORTED = 505;
Daniel@0 1266 const HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; const HTTP_INSUFFICIENT_STORAGE = 507; const HTTP_LOOP_DETECTED = 508; const HTTP_NOT_EXTENDED = 510; const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511;
Daniel@0 1267 public $headers;
Daniel@0 1268 protected $content;
Daniel@0 1269 protected $version;
Daniel@0 1270 protected $statusCode;
Daniel@0 1271 protected $statusText;
Daniel@0 1272 protected $charset;
Daniel@0 1273 public static $statusTexts = array(
Daniel@0 1274 100 =>'Continue',
Daniel@0 1275 101 =>'Switching Protocols',
Daniel@0 1276 102 =>'Processing', 200 =>'OK',
Daniel@0 1277 201 =>'Created',
Daniel@0 1278 202 =>'Accepted',
Daniel@0 1279 203 =>'Non-Authoritative Information',
Daniel@0 1280 204 =>'No Content',
Daniel@0 1281 205 =>'Reset Content',
Daniel@0 1282 206 =>'Partial Content',
Daniel@0 1283 207 =>'Multi-Status', 208 =>'Already Reported', 226 =>'IM Used', 300 =>'Multiple Choices',
Daniel@0 1284 301 =>'Moved Permanently',
Daniel@0 1285 302 =>'Found',
Daniel@0 1286 303 =>'See Other',
Daniel@0 1287 304 =>'Not Modified',
Daniel@0 1288 305 =>'Use Proxy',
Daniel@0 1289 306 =>'Reserved',
Daniel@0 1290 307 =>'Temporary Redirect',
Daniel@0 1291 308 =>'Permanent Redirect', 400 =>'Bad Request',
Daniel@0 1292 401 =>'Unauthorized',
Daniel@0 1293 402 =>'Payment Required',
Daniel@0 1294 403 =>'Forbidden',
Daniel@0 1295 404 =>'Not Found',
Daniel@0 1296 405 =>'Method Not Allowed',
Daniel@0 1297 406 =>'Not Acceptable',
Daniel@0 1298 407 =>'Proxy Authentication Required',
Daniel@0 1299 408 =>'Request Timeout',
Daniel@0 1300 409 =>'Conflict',
Daniel@0 1301 410 =>'Gone',
Daniel@0 1302 411 =>'Length Required',
Daniel@0 1303 412 =>'Precondition Failed',
Daniel@0 1304 413 =>'Request Entity Too Large',
Daniel@0 1305 414 =>'Request-URI Too Long',
Daniel@0 1306 415 =>'Unsupported Media Type',
Daniel@0 1307 416 =>'Requested Range Not Satisfiable',
Daniel@0 1308 417 =>'Expectation Failed',
Daniel@0 1309 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',
Daniel@0 1310 501 =>'Not Implemented',
Daniel@0 1311 502 =>'Bad Gateway',
Daniel@0 1312 503 =>'Service Unavailable',
Daniel@0 1313 504 =>'Gateway Timeout',
Daniel@0 1314 505 =>'HTTP Version Not Supported',
Daniel@0 1315 506 =>'Variant Also Negotiates (Experimental)', 507 =>'Insufficient Storage', 508 =>'Loop Detected', 510 =>'Not Extended', 511 =>'Network Authentication Required', );
Daniel@0 1316 public function __construct($content ='', $status = 200, $headers = array())
Daniel@0 1317 {
Daniel@0 1318 $this->headers = new ResponseHeaderBag($headers);
Daniel@0 1319 $this->setContent($content);
Daniel@0 1320 $this->setStatusCode($status);
Daniel@0 1321 $this->setProtocolVersion('1.0');
Daniel@0 1322 if (!$this->headers->has('Date')) {
Daniel@0 1323 $this->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
Daniel@0 1324 }
Daniel@0 1325 }
Daniel@0 1326 public static function create($content ='', $status = 200, $headers = array())
Daniel@0 1327 {
Daniel@0 1328 return new static($content, $status, $headers);
Daniel@0 1329 }
Daniel@0 1330 public function __toString()
Daniel@0 1331 {
Daniel@0 1332 return
Daniel@0 1333 sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
Daniel@0 1334 $this->headers."\r\n".
Daniel@0 1335 $this->getContent();
Daniel@0 1336 }
Daniel@0 1337 public function __clone()
Daniel@0 1338 {
Daniel@0 1339 $this->headers = clone $this->headers;
Daniel@0 1340 }
Daniel@0 1341 public function prepare(Request $request)
Daniel@0 1342 {
Daniel@0 1343 $headers = $this->headers;
Daniel@0 1344 if ($this->isInformational() || $this->isEmpty()) {
Daniel@0 1345 $this->setContent(null);
Daniel@0 1346 $headers->remove('Content-Type');
Daniel@0 1347 $headers->remove('Content-Length');
Daniel@0 1348 } else {
Daniel@0 1349 if (!$headers->has('Content-Type')) {
Daniel@0 1350 $format = $request->getRequestFormat();
Daniel@0 1351 if (null !== $format && $mimeType = $request->getMimeType($format)) {
Daniel@0 1352 $headers->set('Content-Type', $mimeType);
Daniel@0 1353 }
Daniel@0 1354 }
Daniel@0 1355 $charset = $this->charset ?:'UTF-8';
Daniel@0 1356 if (!$headers->has('Content-Type')) {
Daniel@0 1357 $headers->set('Content-Type','text/html; charset='.$charset);
Daniel@0 1358 } elseif (0 === stripos($headers->get('Content-Type'),'text/') && false === stripos($headers->get('Content-Type'),'charset')) {
Daniel@0 1359 $headers->set('Content-Type', $headers->get('Content-Type').'; charset='.$charset);
Daniel@0 1360 }
Daniel@0 1361 if ($headers->has('Transfer-Encoding')) {
Daniel@0 1362 $headers->remove('Content-Length');
Daniel@0 1363 }
Daniel@0 1364 if ($request->isMethod('HEAD')) {
Daniel@0 1365 $length = $headers->get('Content-Length');
Daniel@0 1366 $this->setContent(null);
Daniel@0 1367 if ($length) {
Daniel@0 1368 $headers->set('Content-Length', $length);
Daniel@0 1369 }
Daniel@0 1370 }
Daniel@0 1371 }
Daniel@0 1372 if ('HTTP/1.0'!= $request->server->get('SERVER_PROTOCOL')) {
Daniel@0 1373 $this->setProtocolVersion('1.1');
Daniel@0 1374 }
Daniel@0 1375 if ('1.0'== $this->getProtocolVersion() &&'no-cache'== $this->headers->get('Cache-Control')) {
Daniel@0 1376 $this->headers->set('pragma','no-cache');
Daniel@0 1377 $this->headers->set('expires', -1);
Daniel@0 1378 }
Daniel@0 1379 $this->ensureIEOverSSLCompatibility($request);
Daniel@0 1380 return $this;
Daniel@0 1381 }
Daniel@0 1382 public function sendHeaders()
Daniel@0 1383 {
Daniel@0 1384 if (headers_sent()) {
Daniel@0 1385 return $this;
Daniel@0 1386 }
Daniel@0 1387 header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
Daniel@0 1388 foreach ($this->headers->allPreserveCase() as $name => $values) {
Daniel@0 1389 foreach ($values as $value) {
Daniel@0 1390 header($name.': '.$value, false, $this->statusCode);
Daniel@0 1391 }
Daniel@0 1392 }
Daniel@0 1393 foreach ($this->headers->getCookies() as $cookie) {
Daniel@0 1394 setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
Daniel@0 1395 }
Daniel@0 1396 return $this;
Daniel@0 1397 }
Daniel@0 1398 public function sendContent()
Daniel@0 1399 {
Daniel@0 1400 echo $this->content;
Daniel@0 1401 return $this;
Daniel@0 1402 }
Daniel@0 1403 public function send()
Daniel@0 1404 {
Daniel@0 1405 $this->sendHeaders();
Daniel@0 1406 $this->sendContent();
Daniel@0 1407 if (function_exists('fastcgi_finish_request')) {
Daniel@0 1408 fastcgi_finish_request();
Daniel@0 1409 } elseif ('cli'!== PHP_SAPI) {
Daniel@0 1410 static::closeOutputBuffers(0, true);
Daniel@0 1411 }
Daniel@0 1412 return $this;
Daniel@0 1413 }
Daniel@0 1414 public function setContent($content)
Daniel@0 1415 {
Daniel@0 1416 if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content,'__toString'))) {
Daniel@0 1417 throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
Daniel@0 1418 }
Daniel@0 1419 $this->content = (string) $content;
Daniel@0 1420 return $this;
Daniel@0 1421 }
Daniel@0 1422 public function getContent()
Daniel@0 1423 {
Daniel@0 1424 return $this->content;
Daniel@0 1425 }
Daniel@0 1426 public function setProtocolVersion($version)
Daniel@0 1427 {
Daniel@0 1428 $this->version = $version;
Daniel@0 1429 return $this;
Daniel@0 1430 }
Daniel@0 1431 public function getProtocolVersion()
Daniel@0 1432 {
Daniel@0 1433 return $this->version;
Daniel@0 1434 }
Daniel@0 1435 public function setStatusCode($code, $text = null)
Daniel@0 1436 {
Daniel@0 1437 $this->statusCode = $code = (int) $code;
Daniel@0 1438 if ($this->isInvalid()) {
Daniel@0 1439 throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
Daniel@0 1440 }
Daniel@0 1441 if (null === $text) {
Daniel@0 1442 $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] :'';
Daniel@0 1443 return $this;
Daniel@0 1444 }
Daniel@0 1445 if (false === $text) {
Daniel@0 1446 $this->statusText ='';
Daniel@0 1447 return $this;
Daniel@0 1448 }
Daniel@0 1449 $this->statusText = $text;
Daniel@0 1450 return $this;
Daniel@0 1451 }
Daniel@0 1452 public function getStatusCode()
Daniel@0 1453 {
Daniel@0 1454 return $this->statusCode;
Daniel@0 1455 }
Daniel@0 1456 public function setCharset($charset)
Daniel@0 1457 {
Daniel@0 1458 $this->charset = $charset;
Daniel@0 1459 return $this;
Daniel@0 1460 }
Daniel@0 1461 public function getCharset()
Daniel@0 1462 {
Daniel@0 1463 return $this->charset;
Daniel@0 1464 }
Daniel@0 1465 public function isCacheable()
Daniel@0 1466 {
Daniel@0 1467 if (!in_array($this->statusCode, array(200, 203, 300, 301, 302, 404, 410))) {
Daniel@0 1468 return false;
Daniel@0 1469 }
Daniel@0 1470 if ($this->headers->hasCacheControlDirective('no-store') || $this->headers->getCacheControlDirective('private')) {
Daniel@0 1471 return false;
Daniel@0 1472 }
Daniel@0 1473 return $this->isValidateable() || $this->isFresh();
Daniel@0 1474 }
Daniel@0 1475 public function isFresh()
Daniel@0 1476 {
Daniel@0 1477 return $this->getTtl() > 0;
Daniel@0 1478 }
Daniel@0 1479 public function isValidateable()
Daniel@0 1480 {
Daniel@0 1481 return $this->headers->has('Last-Modified') || $this->headers->has('ETag');
Daniel@0 1482 }
Daniel@0 1483 public function setPrivate()
Daniel@0 1484 {
Daniel@0 1485 $this->headers->removeCacheControlDirective('public');
Daniel@0 1486 $this->headers->addCacheControlDirective('private');
Daniel@0 1487 return $this;
Daniel@0 1488 }
Daniel@0 1489 public function setPublic()
Daniel@0 1490 {
Daniel@0 1491 $this->headers->addCacheControlDirective('public');
Daniel@0 1492 $this->headers->removeCacheControlDirective('private');
Daniel@0 1493 return $this;
Daniel@0 1494 }
Daniel@0 1495 public function mustRevalidate()
Daniel@0 1496 {
Daniel@0 1497 return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->has('proxy-revalidate');
Daniel@0 1498 }
Daniel@0 1499 public function getDate()
Daniel@0 1500 {
Daniel@0 1501 return $this->headers->getDate('Date', new \DateTime());
Daniel@0 1502 }
Daniel@0 1503 public function setDate(\DateTime $date)
Daniel@0 1504 {
Daniel@0 1505 $date->setTimezone(new \DateTimeZone('UTC'));
Daniel@0 1506 $this->headers->set('Date', $date->format('D, d M Y H:i:s').' GMT');
Daniel@0 1507 return $this;
Daniel@0 1508 }
Daniel@0 1509 public function getAge()
Daniel@0 1510 {
Daniel@0 1511 if (null !== $age = $this->headers->get('Age')) {
Daniel@0 1512 return (int) $age;
Daniel@0 1513 }
Daniel@0 1514 return max(time() - $this->getDate()->format('U'), 0);
Daniel@0 1515 }
Daniel@0 1516 public function expire()
Daniel@0 1517 {
Daniel@0 1518 if ($this->isFresh()) {
Daniel@0 1519 $this->headers->set('Age', $this->getMaxAge());
Daniel@0 1520 }
Daniel@0 1521 return $this;
Daniel@0 1522 }
Daniel@0 1523 public function getExpires()
Daniel@0 1524 {
Daniel@0 1525 try {
Daniel@0 1526 return $this->headers->getDate('Expires');
Daniel@0 1527 } catch (\RuntimeException $e) {
Daniel@0 1528 return \DateTime::createFromFormat(DATE_RFC2822,'Sat, 01 Jan 00 00:00:00 +0000');
Daniel@0 1529 }
Daniel@0 1530 }
Daniel@0 1531 public function setExpires(\DateTime $date = null)
Daniel@0 1532 {
Daniel@0 1533 if (null === $date) {
Daniel@0 1534 $this->headers->remove('Expires');
Daniel@0 1535 } else {
Daniel@0 1536 $date = clone $date;
Daniel@0 1537 $date->setTimezone(new \DateTimeZone('UTC'));
Daniel@0 1538 $this->headers->set('Expires', $date->format('D, d M Y H:i:s').' GMT');
Daniel@0 1539 }
Daniel@0 1540 return $this;
Daniel@0 1541 }
Daniel@0 1542 public function getMaxAge()
Daniel@0 1543 {
Daniel@0 1544 if ($this->headers->hasCacheControlDirective('s-maxage')) {
Daniel@0 1545 return (int) $this->headers->getCacheControlDirective('s-maxage');
Daniel@0 1546 }
Daniel@0 1547 if ($this->headers->hasCacheControlDirective('max-age')) {
Daniel@0 1548 return (int) $this->headers->getCacheControlDirective('max-age');
Daniel@0 1549 }
Daniel@0 1550 if (null !== $this->getExpires()) {
Daniel@0 1551 return $this->getExpires()->format('U') - $this->getDate()->format('U');
Daniel@0 1552 }
Daniel@0 1553 }
Daniel@0 1554 public function setMaxAge($value)
Daniel@0 1555 {
Daniel@0 1556 $this->headers->addCacheControlDirective('max-age', $value);
Daniel@0 1557 return $this;
Daniel@0 1558 }
Daniel@0 1559 public function setSharedMaxAge($value)
Daniel@0 1560 {
Daniel@0 1561 $this->setPublic();
Daniel@0 1562 $this->headers->addCacheControlDirective('s-maxage', $value);
Daniel@0 1563 return $this;
Daniel@0 1564 }
Daniel@0 1565 public function getTtl()
Daniel@0 1566 {
Daniel@0 1567 if (null !== $maxAge = $this->getMaxAge()) {
Daniel@0 1568 return $maxAge - $this->getAge();
Daniel@0 1569 }
Daniel@0 1570 }
Daniel@0 1571 public function setTtl($seconds)
Daniel@0 1572 {
Daniel@0 1573 $this->setSharedMaxAge($this->getAge() + $seconds);
Daniel@0 1574 return $this;
Daniel@0 1575 }
Daniel@0 1576 public function setClientTtl($seconds)
Daniel@0 1577 {
Daniel@0 1578 $this->setMaxAge($this->getAge() + $seconds);
Daniel@0 1579 return $this;
Daniel@0 1580 }
Daniel@0 1581 public function getLastModified()
Daniel@0 1582 {
Daniel@0 1583 return $this->headers->getDate('Last-Modified');
Daniel@0 1584 }
Daniel@0 1585 public function setLastModified(\DateTime $date = null)
Daniel@0 1586 {
Daniel@0 1587 if (null === $date) {
Daniel@0 1588 $this->headers->remove('Last-Modified');
Daniel@0 1589 } else {
Daniel@0 1590 $date = clone $date;
Daniel@0 1591 $date->setTimezone(new \DateTimeZone('UTC'));
Daniel@0 1592 $this->headers->set('Last-Modified', $date->format('D, d M Y H:i:s').' GMT');
Daniel@0 1593 }
Daniel@0 1594 return $this;
Daniel@0 1595 }
Daniel@0 1596 public function getEtag()
Daniel@0 1597 {
Daniel@0 1598 return $this->headers->get('ETag');
Daniel@0 1599 }
Daniel@0 1600 public function setEtag($etag = null, $weak = false)
Daniel@0 1601 {
Daniel@0 1602 if (null === $etag) {
Daniel@0 1603 $this->headers->remove('Etag');
Daniel@0 1604 } else {
Daniel@0 1605 if (0 !== strpos($etag,'"')) {
Daniel@0 1606 $etag ='"'.$etag.'"';
Daniel@0 1607 }
Daniel@0 1608 $this->headers->set('ETag', (true === $weak ?'W/':'').$etag);
Daniel@0 1609 }
Daniel@0 1610 return $this;
Daniel@0 1611 }
Daniel@0 1612 public function setCache(array $options)
Daniel@0 1613 {
Daniel@0 1614 if ($diff = array_diff(array_keys($options), array('etag','last_modified','max_age','s_maxage','private','public'))) {
Daniel@0 1615 throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
Daniel@0 1616 }
Daniel@0 1617 if (isset($options['etag'])) {
Daniel@0 1618 $this->setEtag($options['etag']);
Daniel@0 1619 }
Daniel@0 1620 if (isset($options['last_modified'])) {
Daniel@0 1621 $this->setLastModified($options['last_modified']);
Daniel@0 1622 }
Daniel@0 1623 if (isset($options['max_age'])) {
Daniel@0 1624 $this->setMaxAge($options['max_age']);
Daniel@0 1625 }
Daniel@0 1626 if (isset($options['s_maxage'])) {
Daniel@0 1627 $this->setSharedMaxAge($options['s_maxage']);
Daniel@0 1628 }
Daniel@0 1629 if (isset($options['public'])) {
Daniel@0 1630 if ($options['public']) {
Daniel@0 1631 $this->setPublic();
Daniel@0 1632 } else {
Daniel@0 1633 $this->setPrivate();
Daniel@0 1634 }
Daniel@0 1635 }
Daniel@0 1636 if (isset($options['private'])) {
Daniel@0 1637 if ($options['private']) {
Daniel@0 1638 $this->setPrivate();
Daniel@0 1639 } else {
Daniel@0 1640 $this->setPublic();
Daniel@0 1641 }
Daniel@0 1642 }
Daniel@0 1643 return $this;
Daniel@0 1644 }
Daniel@0 1645 public function setNotModified()
Daniel@0 1646 {
Daniel@0 1647 $this->setStatusCode(304);
Daniel@0 1648 $this->setContent(null);
Daniel@0 1649 foreach (array('Allow','Content-Encoding','Content-Language','Content-Length','Content-MD5','Content-Type','Last-Modified') as $header) {
Daniel@0 1650 $this->headers->remove($header);
Daniel@0 1651 }
Daniel@0 1652 return $this;
Daniel@0 1653 }
Daniel@0 1654 public function hasVary()
Daniel@0 1655 {
Daniel@0 1656 return null !== $this->headers->get('Vary');
Daniel@0 1657 }
Daniel@0 1658 public function getVary()
Daniel@0 1659 {
Daniel@0 1660 if (!$vary = $this->headers->get('Vary', null, false)) {
Daniel@0 1661 return array();
Daniel@0 1662 }
Daniel@0 1663 $ret = array();
Daniel@0 1664 foreach ($vary as $item) {
Daniel@0 1665 $ret = array_merge($ret, preg_split('/[\s,]+/', $item));
Daniel@0 1666 }
Daniel@0 1667 return $ret;
Daniel@0 1668 }
Daniel@0 1669 public function setVary($headers, $replace = true)
Daniel@0 1670 {
Daniel@0 1671 $this->headers->set('Vary', $headers, $replace);
Daniel@0 1672 return $this;
Daniel@0 1673 }
Daniel@0 1674 public function isNotModified(Request $request)
Daniel@0 1675 {
Daniel@0 1676 if (!$request->isMethodSafe()) {
Daniel@0 1677 return false;
Daniel@0 1678 }
Daniel@0 1679 $notModified = false;
Daniel@0 1680 $lastModified = $this->headers->get('Last-Modified');
Daniel@0 1681 $modifiedSince = $request->headers->get('If-Modified-Since');
Daniel@0 1682 if ($etags = $request->getEtags()) {
Daniel@0 1683 $notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags);
Daniel@0 1684 }
Daniel@0 1685 if ($modifiedSince && $lastModified) {
Daniel@0 1686 $notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified);
Daniel@0 1687 }
Daniel@0 1688 if ($notModified) {
Daniel@0 1689 $this->setNotModified();
Daniel@0 1690 }
Daniel@0 1691 return $notModified;
Daniel@0 1692 }
Daniel@0 1693 public function isInvalid()
Daniel@0 1694 {
Daniel@0 1695 return $this->statusCode < 100 || $this->statusCode >= 600;
Daniel@0 1696 }
Daniel@0 1697 public function isInformational()
Daniel@0 1698 {
Daniel@0 1699 return $this->statusCode >= 100 && $this->statusCode < 200;
Daniel@0 1700 }
Daniel@0 1701 public function isSuccessful()
Daniel@0 1702 {
Daniel@0 1703 return $this->statusCode >= 200 && $this->statusCode < 300;
Daniel@0 1704 }
Daniel@0 1705 public function isRedirection()
Daniel@0 1706 {
Daniel@0 1707 return $this->statusCode >= 300 && $this->statusCode < 400;
Daniel@0 1708 }
Daniel@0 1709 public function isClientError()
Daniel@0 1710 {
Daniel@0 1711 return $this->statusCode >= 400 && $this->statusCode < 500;
Daniel@0 1712 }
Daniel@0 1713 public function isServerError()
Daniel@0 1714 {
Daniel@0 1715 return $this->statusCode >= 500 && $this->statusCode < 600;
Daniel@0 1716 }
Daniel@0 1717 public function isOk()
Daniel@0 1718 {
Daniel@0 1719 return 200 === $this->statusCode;
Daniel@0 1720 }
Daniel@0 1721 public function isForbidden()
Daniel@0 1722 {
Daniel@0 1723 return 403 === $this->statusCode;
Daniel@0 1724 }
Daniel@0 1725 public function isNotFound()
Daniel@0 1726 {
Daniel@0 1727 return 404 === $this->statusCode;
Daniel@0 1728 }
Daniel@0 1729 public function isRedirect($location = null)
Daniel@0 1730 {
Daniel@0 1731 return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
Daniel@0 1732 }
Daniel@0 1733 public function isEmpty()
Daniel@0 1734 {
Daniel@0 1735 return in_array($this->statusCode, array(204, 304));
Daniel@0 1736 }
Daniel@0 1737 public static function closeOutputBuffers($targetLevel, $flush)
Daniel@0 1738 {
Daniel@0 1739 $status = ob_get_status(true);
Daniel@0 1740 $level = count($status);
Daniel@0 1741 while ($level-- > $targetLevel
Daniel@0 1742 && (!empty($status[$level]['del'])
Daniel@0 1743 || (isset($status[$level]['flags'])
Daniel@0 1744 && ($status[$level]['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE)
Daniel@0 1745 && ($status[$level]['flags'] & ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE))
Daniel@0 1746 )
Daniel@0 1747 )
Daniel@0 1748 ) {
Daniel@0 1749 if ($flush) {
Daniel@0 1750 ob_end_flush();
Daniel@0 1751 } else {
Daniel@0 1752 ob_end_clean();
Daniel@0 1753 }
Daniel@0 1754 }
Daniel@0 1755 }
Daniel@0 1756 protected function ensureIEOverSSLCompatibility(Request $request)
Daniel@0 1757 {
Daniel@0 1758 if (false !== stripos($this->headers->get('Content-Disposition'),'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
Daniel@0 1759 if (intval(preg_replace("/(MSIE )(.*?);/","$2", $match[0])) < 9) {
Daniel@0 1760 $this->headers->remove('Cache-Control');
Daniel@0 1761 }
Daniel@0 1762 }
Daniel@0 1763 }
Daniel@0 1764 }
Daniel@0 1765 }
Daniel@0 1766 namespace Symfony\Component\HttpFoundation
Daniel@0 1767 {
Daniel@0 1768 class ResponseHeaderBag extends HeaderBag
Daniel@0 1769 {
Daniel@0 1770 const COOKIES_FLAT ='flat';
Daniel@0 1771 const COOKIES_ARRAY ='array';
Daniel@0 1772 const DISPOSITION_ATTACHMENT ='attachment';
Daniel@0 1773 const DISPOSITION_INLINE ='inline';
Daniel@0 1774 protected $computedCacheControl = array();
Daniel@0 1775 protected $cookies = array();
Daniel@0 1776 protected $headerNames = array();
Daniel@0 1777 public function __construct(array $headers = array())
Daniel@0 1778 {
Daniel@0 1779 parent::__construct($headers);
Daniel@0 1780 if (!isset($this->headers['cache-control'])) {
Daniel@0 1781 $this->set('Cache-Control','');
Daniel@0 1782 }
Daniel@0 1783 }
Daniel@0 1784 public function __toString()
Daniel@0 1785 {
Daniel@0 1786 $cookies ='';
Daniel@0 1787 foreach ($this->getCookies() as $cookie) {
Daniel@0 1788 $cookies .='Set-Cookie: '.$cookie."\r\n";
Daniel@0 1789 }
Daniel@0 1790 ksort($this->headerNames);
Daniel@0 1791 return parent::__toString().$cookies;
Daniel@0 1792 }
Daniel@0 1793 public function allPreserveCase()
Daniel@0 1794 {
Daniel@0 1795 return array_combine($this->headerNames, $this->headers);
Daniel@0 1796 }
Daniel@0 1797 public function replace(array $headers = array())
Daniel@0 1798 {
Daniel@0 1799 $this->headerNames = array();
Daniel@0 1800 parent::replace($headers);
Daniel@0 1801 if (!isset($this->headers['cache-control'])) {
Daniel@0 1802 $this->set('Cache-Control','');
Daniel@0 1803 }
Daniel@0 1804 }
Daniel@0 1805 public function set($key, $values, $replace = true)
Daniel@0 1806 {
Daniel@0 1807 parent::set($key, $values, $replace);
Daniel@0 1808 $uniqueKey = strtr(strtolower($key),'_','-');
Daniel@0 1809 $this->headerNames[$uniqueKey] = $key;
Daniel@0 1810 if (in_array($uniqueKey, array('cache-control','etag','last-modified','expires'))) {
Daniel@0 1811 $computed = $this->computeCacheControlValue();
Daniel@0 1812 $this->headers['cache-control'] = array($computed);
Daniel@0 1813 $this->headerNames['cache-control'] ='Cache-Control';
Daniel@0 1814 $this->computedCacheControl = $this->parseCacheControl($computed);
Daniel@0 1815 }
Daniel@0 1816 }
Daniel@0 1817 public function remove($key)
Daniel@0 1818 {
Daniel@0 1819 parent::remove($key);
Daniel@0 1820 $uniqueKey = strtr(strtolower($key),'_','-');
Daniel@0 1821 unset($this->headerNames[$uniqueKey]);
Daniel@0 1822 if ('cache-control'=== $uniqueKey) {
Daniel@0 1823 $this->computedCacheControl = array();
Daniel@0 1824 }
Daniel@0 1825 }
Daniel@0 1826 public function hasCacheControlDirective($key)
Daniel@0 1827 {
Daniel@0 1828 return array_key_exists($key, $this->computedCacheControl);
Daniel@0 1829 }
Daniel@0 1830 public function getCacheControlDirective($key)
Daniel@0 1831 {
Daniel@0 1832 return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
Daniel@0 1833 }
Daniel@0 1834 public function setCookie(Cookie $cookie)
Daniel@0 1835 {
Daniel@0 1836 $this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
Daniel@0 1837 }
Daniel@0 1838 public function removeCookie($name, $path ='/', $domain = null)
Daniel@0 1839 {
Daniel@0 1840 if (null === $path) {
Daniel@0 1841 $path ='/';
Daniel@0 1842 }
Daniel@0 1843 unset($this->cookies[$domain][$path][$name]);
Daniel@0 1844 if (empty($this->cookies[$domain][$path])) {
Daniel@0 1845 unset($this->cookies[$domain][$path]);
Daniel@0 1846 if (empty($this->cookies[$domain])) {
Daniel@0 1847 unset($this->cookies[$domain]);
Daniel@0 1848 }
Daniel@0 1849 }
Daniel@0 1850 }
Daniel@0 1851 public function getCookies($format = self::COOKIES_FLAT)
Daniel@0 1852 {
Daniel@0 1853 if (!in_array($format, array(self::COOKIES_FLAT, self::COOKIES_ARRAY))) {
Daniel@0 1854 throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', array(self::COOKIES_FLAT, self::COOKIES_ARRAY))));
Daniel@0 1855 }
Daniel@0 1856 if (self::COOKIES_ARRAY === $format) {
Daniel@0 1857 return $this->cookies;
Daniel@0 1858 }
Daniel@0 1859 $flattenedCookies = array();
Daniel@0 1860 foreach ($this->cookies as $path) {
Daniel@0 1861 foreach ($path as $cookies) {
Daniel@0 1862 foreach ($cookies as $cookie) {
Daniel@0 1863 $flattenedCookies[] = $cookie;
Daniel@0 1864 }
Daniel@0 1865 }
Daniel@0 1866 }
Daniel@0 1867 return $flattenedCookies;
Daniel@0 1868 }
Daniel@0 1869 public function clearCookie($name, $path ='/', $domain = null)
Daniel@0 1870 {
Daniel@0 1871 $this->setCookie(new Cookie($name, null, 1, $path, $domain));
Daniel@0 1872 }
Daniel@0 1873 public function makeDisposition($disposition, $filename, $filenameFallback ='')
Daniel@0 1874 {
Daniel@0 1875 if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) {
Daniel@0 1876 throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
Daniel@0 1877 }
Daniel@0 1878 if (''== $filenameFallback) {
Daniel@0 1879 $filenameFallback = $filename;
Daniel@0 1880 }
Daniel@0 1881 if (!preg_match('/^[\x20-\x7e]*$/', $filenameFallback)) {
Daniel@0 1882 throw new \InvalidArgumentException('The filename fallback must only contain ASCII characters.');
Daniel@0 1883 }
Daniel@0 1884 if (false !== strpos($filenameFallback,'%')) {
Daniel@0 1885 throw new \InvalidArgumentException('The filename fallback cannot contain the "%" character.');
Daniel@0 1886 }
Daniel@0 1887 if (false !== strpos($filename,'/') || false !== strpos($filename,'\\') || false !== strpos($filenameFallback,'/') || false !== strpos($filenameFallback,'\\')) {
Daniel@0 1888 throw new \InvalidArgumentException('The filename and the fallback cannot contain the "/" and "\\" characters.');
Daniel@0 1889 }
Daniel@0 1890 $output = sprintf('%s; filename="%s"', $disposition, str_replace('"','\\"', $filenameFallback));
Daniel@0 1891 if ($filename !== $filenameFallback) {
Daniel@0 1892 $output .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
Daniel@0 1893 }
Daniel@0 1894 return $output;
Daniel@0 1895 }
Daniel@0 1896 protected function computeCacheControlValue()
Daniel@0 1897 {
Daniel@0 1898 if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
Daniel@0 1899 return'no-cache';
Daniel@0 1900 }
Daniel@0 1901 if (!$this->cacheControl) {
Daniel@0 1902 return'private, must-revalidate';
Daniel@0 1903 }
Daniel@0 1904 $header = $this->getCacheControlHeader();
Daniel@0 1905 if (isset($this->cacheControl['public']) || isset($this->cacheControl['private'])) {
Daniel@0 1906 return $header;
Daniel@0 1907 }
Daniel@0 1908 if (!isset($this->cacheControl['s-maxage'])) {
Daniel@0 1909 return $header.', private';
Daniel@0 1910 }
Daniel@0 1911 return $header;
Daniel@0 1912 }
Daniel@0 1913 }
Daniel@0 1914 }
Daniel@0 1915 namespace Symfony\Component\DependencyInjection
Daniel@0 1916 {
Daniel@0 1917 interface ContainerAwareInterface
Daniel@0 1918 {
Daniel@0 1919 public function setContainer(ContainerInterface $container = null);
Daniel@0 1920 }
Daniel@0 1921 }
Daniel@0 1922 namespace Symfony\Component\DependencyInjection
Daniel@0 1923 {
Daniel@0 1924 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Daniel@0 1925 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
Daniel@0 1926 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
Daniel@0 1927 interface ContainerInterface
Daniel@0 1928 {
Daniel@0 1929 const EXCEPTION_ON_INVALID_REFERENCE = 1;
Daniel@0 1930 const NULL_ON_INVALID_REFERENCE = 2;
Daniel@0 1931 const IGNORE_ON_INVALID_REFERENCE = 3;
Daniel@0 1932 const SCOPE_CONTAINER ='container';
Daniel@0 1933 const SCOPE_PROTOTYPE ='prototype';
Daniel@0 1934 public function set($id, $service, $scope = self::SCOPE_CONTAINER);
Daniel@0 1935 public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
Daniel@0 1936 public function has($id);
Daniel@0 1937 public function getParameter($name);
Daniel@0 1938 public function hasParameter($name);
Daniel@0 1939 public function setParameter($name, $value);
Daniel@0 1940 public function enterScope($name);
Daniel@0 1941 public function leaveScope($name);
Daniel@0 1942 public function addScope(ScopeInterface $scope);
Daniel@0 1943 public function hasScope($name);
Daniel@0 1944 public function isScopeActive($name);
Daniel@0 1945 }
Daniel@0 1946 }
Daniel@0 1947 namespace Symfony\Component\DependencyInjection
Daniel@0 1948 {
Daniel@0 1949 interface IntrospectableContainerInterface extends ContainerInterface
Daniel@0 1950 {
Daniel@0 1951 public function initialized($id);
Daniel@0 1952 }
Daniel@0 1953 }
Daniel@0 1954 namespace Symfony\Component\DependencyInjection
Daniel@0 1955 {
Daniel@0 1956 use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
Daniel@0 1957 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Daniel@0 1958 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
Daniel@0 1959 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
Daniel@0 1960 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
Daniel@0 1961 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
Daniel@0 1962 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
Daniel@0 1963 use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
Daniel@0 1964 class Container implements IntrospectableContainerInterface
Daniel@0 1965 {
Daniel@0 1966 protected $parameterBag;
Daniel@0 1967 protected $services = array();
Daniel@0 1968 protected $methodMap = array();
Daniel@0 1969 protected $aliases = array();
Daniel@0 1970 protected $scopes = array();
Daniel@0 1971 protected $scopeChildren = array();
Daniel@0 1972 protected $scopedServices = array();
Daniel@0 1973 protected $scopeStacks = array();
Daniel@0 1974 protected $loading = array();
Daniel@0 1975 public function __construct(ParameterBagInterface $parameterBag = null)
Daniel@0 1976 {
Daniel@0 1977 $this->parameterBag = $parameterBag ?: new ParameterBag();
Daniel@0 1978 $this->set('service_container', $this);
Daniel@0 1979 }
Daniel@0 1980 public function compile()
Daniel@0 1981 {
Daniel@0 1982 $this->parameterBag->resolve();
Daniel@0 1983 $this->parameterBag = new FrozenParameterBag($this->parameterBag->all());
Daniel@0 1984 }
Daniel@0 1985 public function isFrozen()
Daniel@0 1986 {
Daniel@0 1987 return $this->parameterBag instanceof FrozenParameterBag;
Daniel@0 1988 }
Daniel@0 1989 public function getParameterBag()
Daniel@0 1990 {
Daniel@0 1991 return $this->parameterBag;
Daniel@0 1992 }
Daniel@0 1993 public function getParameter($name)
Daniel@0 1994 {
Daniel@0 1995 return $this->parameterBag->get($name);
Daniel@0 1996 }
Daniel@0 1997 public function hasParameter($name)
Daniel@0 1998 {
Daniel@0 1999 return $this->parameterBag->has($name);
Daniel@0 2000 }
Daniel@0 2001 public function setParameter($name, $value)
Daniel@0 2002 {
Daniel@0 2003 $this->parameterBag->set($name, $value);
Daniel@0 2004 }
Daniel@0 2005 public function set($id, $service, $scope = self::SCOPE_CONTAINER)
Daniel@0 2006 {
Daniel@0 2007 if (self::SCOPE_PROTOTYPE === $scope) {
Daniel@0 2008 throw new InvalidArgumentException(sprintf('You cannot set service "%s" of scope "prototype".', $id));
Daniel@0 2009 }
Daniel@0 2010 $id = strtolower($id);
Daniel@0 2011 if ('service_container'=== $id) {
Daniel@0 2012 return;
Daniel@0 2013 }
Daniel@0 2014 if (self::SCOPE_CONTAINER !== $scope) {
Daniel@0 2015 if (!isset($this->scopedServices[$scope])) {
Daniel@0 2016 throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
Daniel@0 2017 }
Daniel@0 2018 $this->scopedServices[$scope][$id] = $service;
Daniel@0 2019 }
Daniel@0 2020 $this->services[$id] = $service;
Daniel@0 2021 if (method_exists($this, $method ='synchronize'.strtr($id, array('_'=>'','.'=>'_','\\'=>'_')).'Service')) {
Daniel@0 2022 $this->$method();
Daniel@0 2023 }
Daniel@0 2024 if (self::SCOPE_CONTAINER !== $scope && null === $service) {
Daniel@0 2025 unset($this->scopedServices[$scope][$id]);
Daniel@0 2026 }
Daniel@0 2027 if (null === $service) {
Daniel@0 2028 unset($this->services[$id]);
Daniel@0 2029 }
Daniel@0 2030 }
Daniel@0 2031 public function has($id)
Daniel@0 2032 {
Daniel@0 2033 $id = strtolower($id);
Daniel@0 2034 if ('service_container'=== $id) {
Daniel@0 2035 return true;
Daniel@0 2036 }
Daniel@0 2037 return isset($this->services[$id])
Daniel@0 2038 || array_key_exists($id, $this->services)
Daniel@0 2039 || isset($this->aliases[$id])
Daniel@0 2040 || method_exists($this,'get'.strtr($id, array('_'=>'','.'=>'_','\\'=>'_')).'Service')
Daniel@0 2041 ;
Daniel@0 2042 }
Daniel@0 2043 public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
Daniel@0 2044 {
Daniel@0 2045 foreach (array(false, true) as $strtolower) {
Daniel@0 2046 if ($strtolower) {
Daniel@0 2047 $id = strtolower($id);
Daniel@0 2048 }
Daniel@0 2049 if ('service_container'=== $id) {
Daniel@0 2050 return $this;
Daniel@0 2051 }
Daniel@0 2052 if (isset($this->aliases[$id])) {
Daniel@0 2053 $id = $this->aliases[$id];
Daniel@0 2054 }
Daniel@0 2055 if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
Daniel@0 2056 return $this->services[$id];
Daniel@0 2057 }
Daniel@0 2058 }
Daniel@0 2059 if (isset($this->loading[$id])) {
Daniel@0 2060 throw new ServiceCircularReferenceException($id, array_keys($this->loading));
Daniel@0 2061 }
Daniel@0 2062 if (isset($this->methodMap[$id])) {
Daniel@0 2063 $method = $this->methodMap[$id];
Daniel@0 2064 } elseif (method_exists($this, $method ='get'.strtr($id, array('_'=>'','.'=>'_','\\'=>'_')).'Service')) {
Daniel@0 2065 } else {
Daniel@0 2066 if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
Daniel@0 2067 if (!$id) {
Daniel@0 2068 throw new ServiceNotFoundException($id);
Daniel@0 2069 }
Daniel@0 2070 $alternatives = array();
Daniel@0 2071 foreach (array_keys($this->services) as $key) {
Daniel@0 2072 $lev = levenshtein($id, $key);
Daniel@0 2073 if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
Daniel@0 2074 $alternatives[] = $key;
Daniel@0 2075 }
Daniel@0 2076 }
Daniel@0 2077 throw new ServiceNotFoundException($id, null, null, $alternatives);
Daniel@0 2078 }
Daniel@0 2079 return;
Daniel@0 2080 }
Daniel@0 2081 $this->loading[$id] = true;
Daniel@0 2082 try {
Daniel@0 2083 $service = $this->$method();
Daniel@0 2084 } catch (\Exception $e) {
Daniel@0 2085 unset($this->loading[$id]);
Daniel@0 2086 if (array_key_exists($id, $this->services)) {
Daniel@0 2087 unset($this->services[$id]);
Daniel@0 2088 }
Daniel@0 2089 if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
Daniel@0 2090 return;
Daniel@0 2091 }
Daniel@0 2092 throw $e;
Daniel@0 2093 }
Daniel@0 2094 unset($this->loading[$id]);
Daniel@0 2095 return $service;
Daniel@0 2096 }
Daniel@0 2097 public function initialized($id)
Daniel@0 2098 {
Daniel@0 2099 $id = strtolower($id);
Daniel@0 2100 if ('service_container'=== $id) {
Daniel@0 2101 return true;
Daniel@0 2102 }
Daniel@0 2103 if (isset($this->aliases[$id])) {
Daniel@0 2104 $id = $this->aliases[$id];
Daniel@0 2105 }
Daniel@0 2106 return isset($this->services[$id]) || array_key_exists($id, $this->services);
Daniel@0 2107 }
Daniel@0 2108 public function getServiceIds()
Daniel@0 2109 {
Daniel@0 2110 $ids = array();
Daniel@0 2111 $r = new \ReflectionClass($this);
Daniel@0 2112 foreach ($r->getMethods() as $method) {
Daniel@0 2113 if (preg_match('/^get(.+)Service$/', $method->name, $match)) {
Daniel@0 2114 $ids[] = self::underscore($match[1]);
Daniel@0 2115 }
Daniel@0 2116 }
Daniel@0 2117 $ids[] ='service_container';
Daniel@0 2118 return array_unique(array_merge($ids, array_keys($this->services)));
Daniel@0 2119 }
Daniel@0 2120 public function enterScope($name)
Daniel@0 2121 {
Daniel@0 2122 if (!isset($this->scopes[$name])) {
Daniel@0 2123 throw new InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
Daniel@0 2124 }
Daniel@0 2125 if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
Daniel@0 2126 throw new RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
Daniel@0 2127 }
Daniel@0 2128 if (isset($this->scopedServices[$name])) {
Daniel@0 2129 $services = array($this->services, $name => $this->scopedServices[$name]);
Daniel@0 2130 unset($this->scopedServices[$name]);
Daniel@0 2131 foreach ($this->scopeChildren[$name] as $child) {
Daniel@0 2132 if (isset($this->scopedServices[$child])) {
Daniel@0 2133 $services[$child] = $this->scopedServices[$child];
Daniel@0 2134 unset($this->scopedServices[$child]);
Daniel@0 2135 }
Daniel@0 2136 }
Daniel@0 2137 $this->services = call_user_func_array('array_diff_key', $services);
Daniel@0 2138 array_shift($services);
Daniel@0 2139 if (!isset($this->scopeStacks[$name])) {
Daniel@0 2140 $this->scopeStacks[$name] = new \SplStack();
Daniel@0 2141 }
Daniel@0 2142 $this->scopeStacks[$name]->push($services);
Daniel@0 2143 }
Daniel@0 2144 $this->scopedServices[$name] = array();
Daniel@0 2145 }
Daniel@0 2146 public function leaveScope($name)
Daniel@0 2147 {
Daniel@0 2148 if (!isset($this->scopedServices[$name])) {
Daniel@0 2149 throw new InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
Daniel@0 2150 }
Daniel@0 2151 $services = array($this->services, $this->scopedServices[$name]);
Daniel@0 2152 unset($this->scopedServices[$name]);
Daniel@0 2153 foreach ($this->scopeChildren[$name] as $child) {
Daniel@0 2154 if (!isset($this->scopedServices[$child])) {
Daniel@0 2155 continue;
Daniel@0 2156 }
Daniel@0 2157 $services[] = $this->scopedServices[$child];
Daniel@0 2158 unset($this->scopedServices[$child]);
Daniel@0 2159 }
Daniel@0 2160 $this->services = call_user_func_array('array_diff_key', $services);
Daniel@0 2161 if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
Daniel@0 2162 $services = $this->scopeStacks[$name]->pop();
Daniel@0 2163 $this->scopedServices += $services;
Daniel@0 2164 foreach ($services as $array) {
Daniel@0 2165 foreach ($array as $id => $service) {
Daniel@0 2166 $this->set($id, $service, $name);
Daniel@0 2167 }
Daniel@0 2168 }
Daniel@0 2169 }
Daniel@0 2170 }
Daniel@0 2171 public function addScope(ScopeInterface $scope)
Daniel@0 2172 {
Daniel@0 2173 $name = $scope->getName();
Daniel@0 2174 $parentScope = $scope->getParentName();
Daniel@0 2175 if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
Daniel@0 2176 throw new InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
Daniel@0 2177 }
Daniel@0 2178 if (isset($this->scopes[$name])) {
Daniel@0 2179 throw new InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
Daniel@0 2180 }
Daniel@0 2181 if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
Daniel@0 2182 throw new InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
Daniel@0 2183 }
Daniel@0 2184 $this->scopes[$name] = $parentScope;
Daniel@0 2185 $this->scopeChildren[$name] = array();
Daniel@0 2186 while ($parentScope !== self::SCOPE_CONTAINER) {
Daniel@0 2187 $this->scopeChildren[$parentScope][] = $name;
Daniel@0 2188 $parentScope = $this->scopes[$parentScope];
Daniel@0 2189 }
Daniel@0 2190 }
Daniel@0 2191 public function hasScope($name)
Daniel@0 2192 {
Daniel@0 2193 return isset($this->scopes[$name]);
Daniel@0 2194 }
Daniel@0 2195 public function isScopeActive($name)
Daniel@0 2196 {
Daniel@0 2197 return isset($this->scopedServices[$name]);
Daniel@0 2198 }
Daniel@0 2199 public static function camelize($id)
Daniel@0 2200 {
Daniel@0 2201 return strtr(ucwords(strtr($id, array('_'=>' ','.'=>'_ ','\\'=>'_ '))), array(' '=>''));
Daniel@0 2202 }
Daniel@0 2203 public static function underscore($id)
Daniel@0 2204 {
Daniel@0 2205 return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/','/([a-z\d])([A-Z])/'), array('\\1_\\2','\\1_\\2'), strtr($id,'_','.')));
Daniel@0 2206 }
Daniel@0 2207 }
Daniel@0 2208 }
Daniel@0 2209 namespace Symfony\Component\HttpKernel
Daniel@0 2210 {
Daniel@0 2211 use Symfony\Component\HttpFoundation\Request;
Daniel@0 2212 use Symfony\Component\HttpFoundation\Response;
Daniel@0 2213 interface HttpKernelInterface
Daniel@0 2214 {
Daniel@0 2215 const MASTER_REQUEST = 1;
Daniel@0 2216 const SUB_REQUEST = 2;
Daniel@0 2217 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
Daniel@0 2218 }
Daniel@0 2219 }
Daniel@0 2220 namespace Symfony\Component\HttpKernel
Daniel@0 2221 {
Daniel@0 2222 use Symfony\Component\DependencyInjection\ContainerInterface;
Daniel@0 2223 use Symfony\Component\HttpKernel\Bundle\BundleInterface;
Daniel@0 2224 use Symfony\Component\Config\Loader\LoaderInterface;
Daniel@0 2225 interface KernelInterface extends HttpKernelInterface, \Serializable
Daniel@0 2226 {
Daniel@0 2227 public function registerBundles();
Daniel@0 2228 public function registerContainerConfiguration(LoaderInterface $loader);
Daniel@0 2229 public function boot();
Daniel@0 2230 public function shutdown();
Daniel@0 2231 public function getBundles();
Daniel@0 2232 public function isClassInActiveBundle($class);
Daniel@0 2233 public function getBundle($name, $first = true);
Daniel@0 2234 public function locateResource($name, $dir = null, $first = true);
Daniel@0 2235 public function getName();
Daniel@0 2236 public function getEnvironment();
Daniel@0 2237 public function isDebug();
Daniel@0 2238 public function getRootDir();
Daniel@0 2239 public function getContainer();
Daniel@0 2240 public function getStartTime();
Daniel@0 2241 public function getCacheDir();
Daniel@0 2242 public function getLogDir();
Daniel@0 2243 public function getCharset();
Daniel@0 2244 }
Daniel@0 2245 }
Daniel@0 2246 namespace Symfony\Component\HttpKernel
Daniel@0 2247 {
Daniel@0 2248 use Symfony\Component\HttpFoundation\Request;
Daniel@0 2249 use Symfony\Component\HttpFoundation\Response;
Daniel@0 2250 interface TerminableInterface
Daniel@0 2251 {
Daniel@0 2252 public function terminate(Request $request, Response $response);
Daniel@0 2253 }
Daniel@0 2254 }
Daniel@0 2255 namespace Symfony\Component\HttpKernel
Daniel@0 2256 {
Daniel@0 2257 use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
Daniel@0 2258 use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
Daniel@0 2259 use Symfony\Component\DependencyInjection\ContainerInterface;
Daniel@0 2260 use Symfony\Component\DependencyInjection\ContainerBuilder;
Daniel@0 2261 use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
Daniel@0 2262 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
Daniel@0 2263 use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Daniel@0 2264 use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Daniel@0 2265 use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
Daniel@0 2266 use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
Daniel@0 2267 use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
Daniel@0 2268 use Symfony\Component\HttpFoundation\Request;
Daniel@0 2269 use Symfony\Component\HttpFoundation\Response;
Daniel@0 2270 use Symfony\Component\HttpKernel\Bundle\BundleInterface;
Daniel@0 2271 use Symfony\Component\HttpKernel\Config\EnvParametersResource;
Daniel@0 2272 use Symfony\Component\HttpKernel\Config\FileLocator;
Daniel@0 2273 use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
Daniel@0 2274 use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
Daniel@0 2275 use Symfony\Component\Config\Loader\LoaderResolver;
Daniel@0 2276 use Symfony\Component\Config\Loader\DelegatingLoader;
Daniel@0 2277 use Symfony\Component\Config\ConfigCache;
Daniel@0 2278 use Symfony\Component\ClassLoader\ClassCollectionLoader;
Daniel@0 2279 abstract class Kernel implements KernelInterface, TerminableInterface
Daniel@0 2280 {
Daniel@0 2281 protected $bundles = array();
Daniel@0 2282 protected $bundleMap;
Daniel@0 2283 protected $container;
Daniel@0 2284 protected $rootDir;
Daniel@0 2285 protected $environment;
Daniel@0 2286 protected $debug;
Daniel@0 2287 protected $booted = false;
Daniel@0 2288 protected $name;
Daniel@0 2289 protected $startTime;
Daniel@0 2290 protected $loadClassCache;
Daniel@0 2291 const VERSION ='2.5.10';
Daniel@0 2292 const VERSION_ID ='20510';
Daniel@0 2293 const MAJOR_VERSION ='2';
Daniel@0 2294 const MINOR_VERSION ='5';
Daniel@0 2295 const RELEASE_VERSION ='10';
Daniel@0 2296 const EXTRA_VERSION ='';
Daniel@0 2297 public function __construct($environment, $debug)
Daniel@0 2298 {
Daniel@0 2299 $this->environment = $environment;
Daniel@0 2300 $this->debug = (bool) $debug;
Daniel@0 2301 $this->rootDir = $this->getRootDir();
Daniel@0 2302 $this->name = $this->getName();
Daniel@0 2303 if ($this->debug) {
Daniel@0 2304 $this->startTime = microtime(true);
Daniel@0 2305 }
Daniel@0 2306 $this->init();
Daniel@0 2307 }
Daniel@0 2308 public function init()
Daniel@0 2309 {
Daniel@0 2310 }
Daniel@0 2311 public function __clone()
Daniel@0 2312 {
Daniel@0 2313 if ($this->debug) {
Daniel@0 2314 $this->startTime = microtime(true);
Daniel@0 2315 }
Daniel@0 2316 $this->booted = false;
Daniel@0 2317 $this->container = null;
Daniel@0 2318 }
Daniel@0 2319 public function boot()
Daniel@0 2320 {
Daniel@0 2321 if (true === $this->booted) {
Daniel@0 2322 return;
Daniel@0 2323 }
Daniel@0 2324 if ($this->loadClassCache) {
Daniel@0 2325 $this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
Daniel@0 2326 }
Daniel@0 2327 $this->initializeBundles();
Daniel@0 2328 $this->initializeContainer();
Daniel@0 2329 foreach ($this->getBundles() as $bundle) {
Daniel@0 2330 $bundle->setContainer($this->container);
Daniel@0 2331 $bundle->boot();
Daniel@0 2332 }
Daniel@0 2333 $this->booted = true;
Daniel@0 2334 }
Daniel@0 2335 public function terminate(Request $request, Response $response)
Daniel@0 2336 {
Daniel@0 2337 if (false === $this->booted) {
Daniel@0 2338 return;
Daniel@0 2339 }
Daniel@0 2340 if ($this->getHttpKernel() instanceof TerminableInterface) {
Daniel@0 2341 $this->getHttpKernel()->terminate($request, $response);
Daniel@0 2342 }
Daniel@0 2343 }
Daniel@0 2344 public function shutdown()
Daniel@0 2345 {
Daniel@0 2346 if (false === $this->booted) {
Daniel@0 2347 return;
Daniel@0 2348 }
Daniel@0 2349 $this->booted = false;
Daniel@0 2350 foreach ($this->getBundles() as $bundle) {
Daniel@0 2351 $bundle->shutdown();
Daniel@0 2352 $bundle->setContainer(null);
Daniel@0 2353 }
Daniel@0 2354 $this->container = null;
Daniel@0 2355 }
Daniel@0 2356 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
Daniel@0 2357 {
Daniel@0 2358 if (false === $this->booted) {
Daniel@0 2359 $this->boot();
Daniel@0 2360 }
Daniel@0 2361 return $this->getHttpKernel()->handle($request, $type, $catch);
Daniel@0 2362 }
Daniel@0 2363 protected function getHttpKernel()
Daniel@0 2364 {
Daniel@0 2365 return $this->container->get('http_kernel');
Daniel@0 2366 }
Daniel@0 2367 public function getBundles()
Daniel@0 2368 {
Daniel@0 2369 return $this->bundles;
Daniel@0 2370 }
Daniel@0 2371 public function isClassInActiveBundle($class)
Daniel@0 2372 {
Daniel@0 2373 foreach ($this->getBundles() as $bundle) {
Daniel@0 2374 if (0 === strpos($class, $bundle->getNamespace())) {
Daniel@0 2375 return true;
Daniel@0 2376 }
Daniel@0 2377 }
Daniel@0 2378 return false;
Daniel@0 2379 }
Daniel@0 2380 public function getBundle($name, $first = true)
Daniel@0 2381 {
Daniel@0 2382 if (!isset($this->bundleMap[$name])) {
Daniel@0 2383 throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your %s.php file?', $name, get_class($this)));
Daniel@0 2384 }
Daniel@0 2385 if (true === $first) {
Daniel@0 2386 return $this->bundleMap[$name][0];
Daniel@0 2387 }
Daniel@0 2388 return $this->bundleMap[$name];
Daniel@0 2389 }
Daniel@0 2390 public function locateResource($name, $dir = null, $first = true)
Daniel@0 2391 {
Daniel@0 2392 if ('@'!== $name[0]) {
Daniel@0 2393 throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
Daniel@0 2394 }
Daniel@0 2395 if (false !== strpos($name,'..')) {
Daniel@0 2396 throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
Daniel@0 2397 }
Daniel@0 2398 $bundleName = substr($name, 1);
Daniel@0 2399 $path ='';
Daniel@0 2400 if (false !== strpos($bundleName,'/')) {
Daniel@0 2401 list($bundleName, $path) = explode('/', $bundleName, 2);
Daniel@0 2402 }
Daniel@0 2403 $isResource = 0 === strpos($path,'Resources') && null !== $dir;
Daniel@0 2404 $overridePath = substr($path, 9);
Daniel@0 2405 $resourceBundle = null;
Daniel@0 2406 $bundles = $this->getBundle($bundleName, false);
Daniel@0 2407 $files = array();
Daniel@0 2408 foreach ($bundles as $bundle) {
Daniel@0 2409 if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
Daniel@0 2410 if (null !== $resourceBundle) {
Daniel@0 2411 throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
Daniel@0 2412 $file,
Daniel@0 2413 $resourceBundle,
Daniel@0 2414 $dir.'/'.$bundles[0]->getName().$overridePath
Daniel@0 2415 ));
Daniel@0 2416 }
Daniel@0 2417 if ($first) {
Daniel@0 2418 return $file;
Daniel@0 2419 }
Daniel@0 2420 $files[] = $file;
Daniel@0 2421 }
Daniel@0 2422 if (file_exists($file = $bundle->getPath().'/'.$path)) {
Daniel@0 2423 if ($first && !$isResource) {
Daniel@0 2424 return $file;
Daniel@0 2425 }
Daniel@0 2426 $files[] = $file;
Daniel@0 2427 $resourceBundle = $bundle->getName();
Daniel@0 2428 }
Daniel@0 2429 }
Daniel@0 2430 if (count($files) > 0) {
Daniel@0 2431 return $first && $isResource ? $files[0] : $files;
Daniel@0 2432 }
Daniel@0 2433 throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
Daniel@0 2434 }
Daniel@0 2435 public function getName()
Daniel@0 2436 {
Daniel@0 2437 if (null === $this->name) {
Daniel@0 2438 $this->name = preg_replace('/[^a-zA-Z0-9_]+/','', basename($this->rootDir));
Daniel@0 2439 }
Daniel@0 2440 return $this->name;
Daniel@0 2441 }
Daniel@0 2442 public function getEnvironment()
Daniel@0 2443 {
Daniel@0 2444 return $this->environment;
Daniel@0 2445 }
Daniel@0 2446 public function isDebug()
Daniel@0 2447 {
Daniel@0 2448 return $this->debug;
Daniel@0 2449 }
Daniel@0 2450 public function getRootDir()
Daniel@0 2451 {
Daniel@0 2452 if (null === $this->rootDir) {
Daniel@0 2453 $r = new \ReflectionObject($this);
Daniel@0 2454 $this->rootDir = str_replace('\\','/', dirname($r->getFileName()));
Daniel@0 2455 }
Daniel@0 2456 return $this->rootDir;
Daniel@0 2457 }
Daniel@0 2458 public function getContainer()
Daniel@0 2459 {
Daniel@0 2460 return $this->container;
Daniel@0 2461 }
Daniel@0 2462 public function loadClassCache($name ='classes', $extension ='.php')
Daniel@0 2463 {
Daniel@0 2464 $this->loadClassCache = array($name, $extension);
Daniel@0 2465 }
Daniel@0 2466 public function setClassCache(array $classes)
Daniel@0 2467 {
Daniel@0 2468 file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
Daniel@0 2469 }
Daniel@0 2470 public function getStartTime()
Daniel@0 2471 {
Daniel@0 2472 return $this->debug ? $this->startTime : -INF;
Daniel@0 2473 }
Daniel@0 2474 public function getCacheDir()
Daniel@0 2475 {
Daniel@0 2476 return $this->rootDir.'/cache/'.$this->environment;
Daniel@0 2477 }
Daniel@0 2478 public function getLogDir()
Daniel@0 2479 {
Daniel@0 2480 return $this->rootDir.'/logs';
Daniel@0 2481 }
Daniel@0 2482 public function getCharset()
Daniel@0 2483 {
Daniel@0 2484 return'UTF-8';
Daniel@0 2485 }
Daniel@0 2486 protected function doLoadClassCache($name, $extension)
Daniel@0 2487 {
Daniel@0 2488 if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
Daniel@0 2489 ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
Daniel@0 2490 }
Daniel@0 2491 }
Daniel@0 2492 protected function initializeBundles()
Daniel@0 2493 {
Daniel@0 2494 $this->bundles = array();
Daniel@0 2495 $topMostBundles = array();
Daniel@0 2496 $directChildren = array();
Daniel@0 2497 foreach ($this->registerBundles() as $bundle) {
Daniel@0 2498 $name = $bundle->getName();
Daniel@0 2499 if (isset($this->bundles[$name])) {
Daniel@0 2500 throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
Daniel@0 2501 }
Daniel@0 2502 $this->bundles[$name] = $bundle;
Daniel@0 2503 if ($parentName = $bundle->getParent()) {
Daniel@0 2504 if (isset($directChildren[$parentName])) {
Daniel@0 2505 throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
Daniel@0 2506 }
Daniel@0 2507 if ($parentName == $name) {
Daniel@0 2508 throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
Daniel@0 2509 }
Daniel@0 2510 $directChildren[$parentName] = $name;
Daniel@0 2511 } else {
Daniel@0 2512 $topMostBundles[$name] = $bundle;
Daniel@0 2513 }
Daniel@0 2514 }
Daniel@0 2515 if (!empty($directChildren) && count($diff = array_diff_key($directChildren, $this->bundles))) {
Daniel@0 2516 $diff = array_keys($diff);
Daniel@0 2517 throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
Daniel@0 2518 }
Daniel@0 2519 $this->bundleMap = array();
Daniel@0 2520 foreach ($topMostBundles as $name => $bundle) {
Daniel@0 2521 $bundleMap = array($bundle);
Daniel@0 2522 $hierarchy = array($name);
Daniel@0 2523 while (isset($directChildren[$name])) {
Daniel@0 2524 $name = $directChildren[$name];
Daniel@0 2525 array_unshift($bundleMap, $this->bundles[$name]);
Daniel@0 2526 $hierarchy[] = $name;
Daniel@0 2527 }
Daniel@0 2528 foreach ($hierarchy as $bundle) {
Daniel@0 2529 $this->bundleMap[$bundle] = $bundleMap;
Daniel@0 2530 array_pop($bundleMap);
Daniel@0 2531 }
Daniel@0 2532 }
Daniel@0 2533 }
Daniel@0 2534 protected function getContainerClass()
Daniel@0 2535 {
Daniel@0 2536 return $this->name.ucfirst($this->environment).($this->debug ?'Debug':'').'ProjectContainer';
Daniel@0 2537 }
Daniel@0 2538 protected function getContainerBaseClass()
Daniel@0 2539 {
Daniel@0 2540 return'Container';
Daniel@0 2541 }
Daniel@0 2542 protected function initializeContainer()
Daniel@0 2543 {
Daniel@0 2544 $class = $this->getContainerClass();
Daniel@0 2545 $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
Daniel@0 2546 $fresh = true;
Daniel@0 2547 if (!$cache->isFresh()) {
Daniel@0 2548 $container = $this->buildContainer();
Daniel@0 2549 $container->compile();
Daniel@0 2550 $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
Daniel@0 2551 $fresh = false;
Daniel@0 2552 }
Daniel@0 2553 require_once $cache;
Daniel@0 2554 $this->container = new $class();
Daniel@0 2555 $this->container->set('kernel', $this);
Daniel@0 2556 if (!$fresh && $this->container->has('cache_warmer')) {
Daniel@0 2557 $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
Daniel@0 2558 }
Daniel@0 2559 }
Daniel@0 2560 protected function getKernelParameters()
Daniel@0 2561 {
Daniel@0 2562 $bundles = array();
Daniel@0 2563 foreach ($this->bundles as $name => $bundle) {
Daniel@0 2564 $bundles[$name] = get_class($bundle);
Daniel@0 2565 }
Daniel@0 2566 return array_merge(
Daniel@0 2567 array('kernel.root_dir'=> realpath($this->rootDir) ?: $this->rootDir,'kernel.environment'=> $this->environment,'kernel.debug'=> $this->debug,'kernel.name'=> $this->name,'kernel.cache_dir'=> realpath($this->getCacheDir()) ?: $this->getCacheDir(),'kernel.logs_dir'=> realpath($this->getLogDir()) ?: $this->getLogDir(),'kernel.bundles'=> $bundles,'kernel.charset'=> $this->getCharset(),'kernel.container_class'=> $this->getContainerClass(),
Daniel@0 2568 ),
Daniel@0 2569 $this->getEnvParameters()
Daniel@0 2570 );
Daniel@0 2571 }
Daniel@0 2572 protected function getEnvParameters()
Daniel@0 2573 {
Daniel@0 2574 $parameters = array();
Daniel@0 2575 foreach ($_SERVER as $key => $value) {
Daniel@0 2576 if (0 === strpos($key,'SYMFONY__')) {
Daniel@0 2577 $parameters[strtolower(str_replace('__','.', substr($key, 9)))] = $value;
Daniel@0 2578 }
Daniel@0 2579 }
Daniel@0 2580 return $parameters;
Daniel@0 2581 }
Daniel@0 2582 protected function buildContainer()
Daniel@0 2583 {
Daniel@0 2584 foreach (array('cache'=> $this->getCacheDir(),'logs'=> $this->getLogDir()) as $name => $dir) {
Daniel@0 2585 if (!is_dir($dir)) {
Daniel@0 2586 if (false === @mkdir($dir, 0777, true)) {
Daniel@0 2587 throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
Daniel@0 2588 }
Daniel@0 2589 } elseif (!is_writable($dir)) {
Daniel@0 2590 throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
Daniel@0 2591 }
Daniel@0 2592 }
Daniel@0 2593 $container = $this->getContainerBuilder();
Daniel@0 2594 $container->addObjectResource($this);
Daniel@0 2595 $this->prepareContainer($container);
Daniel@0 2596 if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
Daniel@0 2597 $container->merge($cont);
Daniel@0 2598 }
Daniel@0 2599 $container->addCompilerPass(new AddClassesToCachePass($this));
Daniel@0 2600 $container->addResource(new EnvParametersResource('SYMFONY__'));
Daniel@0 2601 return $container;
Daniel@0 2602 }
Daniel@0 2603 protected function prepareContainer(ContainerBuilder $container)
Daniel@0 2604 {
Daniel@0 2605 $extensions = array();
Daniel@0 2606 foreach ($this->bundles as $bundle) {
Daniel@0 2607 if ($extension = $bundle->getContainerExtension()) {
Daniel@0 2608 $container->registerExtension($extension);
Daniel@0 2609 $extensions[] = $extension->getAlias();
Daniel@0 2610 }
Daniel@0 2611 if ($this->debug) {
Daniel@0 2612 $container->addObjectResource($bundle);
Daniel@0 2613 }
Daniel@0 2614 }
Daniel@0 2615 foreach ($this->bundles as $bundle) {
Daniel@0 2616 $bundle->build($container);
Daniel@0 2617 }
Daniel@0 2618 $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
Daniel@0 2619 }
Daniel@0 2620 protected function getContainerBuilder()
Daniel@0 2621 {
Daniel@0 2622 $container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
Daniel@0 2623 if (class_exists('ProxyManager\Configuration')) {
Daniel@0 2624 $container->setProxyInstantiator(new RuntimeInstantiator());
Daniel@0 2625 }
Daniel@0 2626 return $container;
Daniel@0 2627 }
Daniel@0 2628 protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
Daniel@0 2629 {
Daniel@0 2630 $dumper = new PhpDumper($container);
Daniel@0 2631 if (class_exists('ProxyManager\Configuration')) {
Daniel@0 2632 $dumper->setProxyDumper(new ProxyDumper());
Daniel@0 2633 }
Daniel@0 2634 $content = $dumper->dump(array('class'=> $class,'base_class'=> $baseClass,'file'=> (string) $cache));
Daniel@0 2635 if (!$this->debug) {
Daniel@0 2636 $content = static::stripComments($content);
Daniel@0 2637 }
Daniel@0 2638 $cache->write($content, $container->getResources());
Daniel@0 2639 }
Daniel@0 2640 protected function getContainerLoader(ContainerInterface $container)
Daniel@0 2641 {
Daniel@0 2642 $locator = new FileLocator($this);
Daniel@0 2643 $resolver = new LoaderResolver(array(
Daniel@0 2644 new XmlFileLoader($container, $locator),
Daniel@0 2645 new YamlFileLoader($container, $locator),
Daniel@0 2646 new IniFileLoader($container, $locator),
Daniel@0 2647 new PhpFileLoader($container, $locator),
Daniel@0 2648 new ClosureLoader($container),
Daniel@0 2649 ));
Daniel@0 2650 return new DelegatingLoader($resolver);
Daniel@0 2651 }
Daniel@0 2652 public static function stripComments($source)
Daniel@0 2653 {
Daniel@0 2654 if (!function_exists('token_get_all')) {
Daniel@0 2655 return $source;
Daniel@0 2656 }
Daniel@0 2657 $rawChunk ='';
Daniel@0 2658 $output ='';
Daniel@0 2659 $tokens = token_get_all($source);
Daniel@0 2660 $ignoreSpace = false;
Daniel@0 2661 for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
Daniel@0 2662 if (is_string($token)) {
Daniel@0 2663 $rawChunk .= $token;
Daniel@0 2664 } elseif (T_START_HEREDOC === $token[0]) {
Daniel@0 2665 $output .= $rawChunk.$token[1];
Daniel@0 2666 do {
Daniel@0 2667 $token = next($tokens);
Daniel@0 2668 $output .= $token[1];
Daniel@0 2669 } while ($token[0] !== T_END_HEREDOC);
Daniel@0 2670 $rawChunk ='';
Daniel@0 2671 } elseif (T_WHITESPACE === $token[0]) {
Daniel@0 2672 if ($ignoreSpace) {
Daniel@0 2673 $ignoreSpace = false;
Daniel@0 2674 continue;
Daniel@0 2675 }
Daniel@0 2676 $rawChunk .= preg_replace(array('/\n{2,}/S'),"\n", $token[1]);
Daniel@0 2677 } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
Daniel@0 2678 $ignoreSpace = true;
Daniel@0 2679 } else {
Daniel@0 2680 $rawChunk .= $token[1];
Daniel@0 2681 if (T_OPEN_TAG === $token[0]) {
Daniel@0 2682 $ignoreSpace = true;
Daniel@0 2683 }
Daniel@0 2684 }
Daniel@0 2685 }
Daniel@0 2686 $output .= $rawChunk;
Daniel@0 2687 return $output;
Daniel@0 2688 }
Daniel@0 2689 public function serialize()
Daniel@0 2690 {
Daniel@0 2691 return serialize(array($this->environment, $this->debug));
Daniel@0 2692 }
Daniel@0 2693 public function unserialize($data)
Daniel@0 2694 {
Daniel@0 2695 list($environment, $debug) = unserialize($data);
Daniel@0 2696 $this->__construct($environment, $debug);
Daniel@0 2697 }
Daniel@0 2698 }
Daniel@0 2699 }
Daniel@0 2700 namespace Symfony\Component\ClassLoader
Daniel@0 2701 {
Daniel@0 2702 class ApcClassLoader
Daniel@0 2703 {
Daniel@0 2704 private $prefix;
Daniel@0 2705 protected $decorated;
Daniel@0 2706 public function __construct($prefix, $decorated)
Daniel@0 2707 {
Daniel@0 2708 if (!extension_loaded('apc')) {
Daniel@0 2709 throw new \RuntimeException('Unable to use ApcClassLoader as APC is not enabled.');
Daniel@0 2710 }
Daniel@0 2711 if (!method_exists($decorated,'findFile')) {
Daniel@0 2712 throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
Daniel@0 2713 }
Daniel@0 2714 $this->prefix = $prefix;
Daniel@0 2715 $this->decorated = $decorated;
Daniel@0 2716 }
Daniel@0 2717 public function register($prepend = false)
Daniel@0 2718 {
Daniel@0 2719 spl_autoload_register(array($this,'loadClass'), true, $prepend);
Daniel@0 2720 }
Daniel@0 2721 public function unregister()
Daniel@0 2722 {
Daniel@0 2723 spl_autoload_unregister(array($this,'loadClass'));
Daniel@0 2724 }
Daniel@0 2725 public function loadClass($class)
Daniel@0 2726 {
Daniel@0 2727 if ($file = $this->findFile($class)) {
Daniel@0 2728 require $file;
Daniel@0 2729 return true;
Daniel@0 2730 }
Daniel@0 2731 }
Daniel@0 2732 public function findFile($class)
Daniel@0 2733 {
Daniel@0 2734 if (false === $file = apc_fetch($this->prefix.$class)) {
Daniel@0 2735 apc_store($this->prefix.$class, $file = $this->decorated->findFile($class));
Daniel@0 2736 }
Daniel@0 2737 return $file;
Daniel@0 2738 }
Daniel@0 2739 public function __call($method, $args)
Daniel@0 2740 {
Daniel@0 2741 return call_user_func_array(array($this->decorated, $method), $args);
Daniel@0 2742 }
Daniel@0 2743 }
Daniel@0 2744 }
Daniel@0 2745 namespace Symfony\Component\HttpKernel\Bundle
Daniel@0 2746 {
Daniel@0 2747 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
Daniel@0 2748 use Symfony\Component\DependencyInjection\ContainerBuilder;
Daniel@0 2749 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
Daniel@0 2750 interface BundleInterface extends ContainerAwareInterface
Daniel@0 2751 {
Daniel@0 2752 public function boot();
Daniel@0 2753 public function shutdown();
Daniel@0 2754 public function build(ContainerBuilder $container);
Daniel@0 2755 public function getContainerExtension();
Daniel@0 2756 public function getParent();
Daniel@0 2757 public function getName();
Daniel@0 2758 public function getNamespace();
Daniel@0 2759 public function getPath();
Daniel@0 2760 }
Daniel@0 2761 }
Daniel@0 2762 namespace Symfony\Component\DependencyInjection
Daniel@0 2763 {
Daniel@0 2764 abstract class ContainerAware implements ContainerAwareInterface
Daniel@0 2765 {
Daniel@0 2766 protected $container;
Daniel@0 2767 public function setContainer(ContainerInterface $container = null)
Daniel@0 2768 {
Daniel@0 2769 $this->container = $container;
Daniel@0 2770 }
Daniel@0 2771 }
Daniel@0 2772 }
Daniel@0 2773 namespace Symfony\Component\HttpKernel\Bundle
Daniel@0 2774 {
Daniel@0 2775 use Symfony\Component\DependencyInjection\ContainerAware;
Daniel@0 2776 use Symfony\Component\DependencyInjection\ContainerBuilder;
Daniel@0 2777 use Symfony\Component\DependencyInjection\Container;
Daniel@0 2778 use Symfony\Component\Console\Application;
Daniel@0 2779 use Symfony\Component\Finder\Finder;
Daniel@0 2780 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
Daniel@0 2781 abstract class Bundle extends ContainerAware implements BundleInterface
Daniel@0 2782 {
Daniel@0 2783 protected $name;
Daniel@0 2784 protected $extension;
Daniel@0 2785 protected $path;
Daniel@0 2786 public function boot()
Daniel@0 2787 {
Daniel@0 2788 }
Daniel@0 2789 public function shutdown()
Daniel@0 2790 {
Daniel@0 2791 }
Daniel@0 2792 public function build(ContainerBuilder $container)
Daniel@0 2793 {
Daniel@0 2794 }
Daniel@0 2795 public function getContainerExtension()
Daniel@0 2796 {
Daniel@0 2797 if (null === $this->extension) {
Daniel@0 2798 $basename = preg_replace('/Bundle$/','', $this->getName());
Daniel@0 2799 $class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
Daniel@0 2800 if (class_exists($class)) {
Daniel@0 2801 $extension = new $class();
Daniel@0 2802 $expectedAlias = Container::underscore($basename);
Daniel@0 2803 if ($expectedAlias != $extension->getAlias()) {
Daniel@0 2804 throw new \LogicException(sprintf('The extension alias for the default extension of a '.'bundle must be the underscored version of the '.'bundle name ("%s" instead of "%s")',
Daniel@0 2805 $expectedAlias, $extension->getAlias()
Daniel@0 2806 ));
Daniel@0 2807 }
Daniel@0 2808 $this->extension = $extension;
Daniel@0 2809 } else {
Daniel@0 2810 $this->extension = false;
Daniel@0 2811 }
Daniel@0 2812 }
Daniel@0 2813 if ($this->extension) {
Daniel@0 2814 return $this->extension;
Daniel@0 2815 }
Daniel@0 2816 }
Daniel@0 2817 public function getNamespace()
Daniel@0 2818 {
Daniel@0 2819 $class = get_class($this);
Daniel@0 2820 return substr($class, 0, strrpos($class,'\\'));
Daniel@0 2821 }
Daniel@0 2822 public function getPath()
Daniel@0 2823 {
Daniel@0 2824 if (null === $this->path) {
Daniel@0 2825 $reflected = new \ReflectionObject($this);
Daniel@0 2826 $this->path = dirname($reflected->getFileName());
Daniel@0 2827 }
Daniel@0 2828 return $this->path;
Daniel@0 2829 }
Daniel@0 2830 public function getParent()
Daniel@0 2831 {
Daniel@0 2832 }
Daniel@0 2833 final public function getName()
Daniel@0 2834 {
Daniel@0 2835 if (null !== $this->name) {
Daniel@0 2836 return $this->name;
Daniel@0 2837 }
Daniel@0 2838 $name = get_class($this);
Daniel@0 2839 $pos = strrpos($name,'\\');
Daniel@0 2840 return $this->name = false === $pos ? $name : substr($name, $pos + 1);
Daniel@0 2841 }
Daniel@0 2842 public function registerCommands(Application $application)
Daniel@0 2843 {
Daniel@0 2844 if (!is_dir($dir = $this->getPath().'/Command')) {
Daniel@0 2845 return;
Daniel@0 2846 }
Daniel@0 2847 $finder = new Finder();
Daniel@0 2848 $finder->files()->name('*Command.php')->in($dir);
Daniel@0 2849 $prefix = $this->getNamespace().'\\Command';
Daniel@0 2850 foreach ($finder as $file) {
Daniel@0 2851 $ns = $prefix;
Daniel@0 2852 if ($relativePath = $file->getRelativePath()) {
Daniel@0 2853 $ns .='\\'.strtr($relativePath,'/','\\');
Daniel@0 2854 }
Daniel@0 2855 $class = $ns.'\\'.$file->getBasename('.php');
Daniel@0 2856 if ($this->container) {
Daniel@0 2857 $alias ='console.command.'.strtolower(str_replace('\\','_', $class));
Daniel@0 2858 if ($this->container->has($alias)) {
Daniel@0 2859 continue;
Daniel@0 2860 }
Daniel@0 2861 }
Daniel@0 2862 $r = new \ReflectionClass($class);
Daniel@0 2863 if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
Daniel@0 2864 $application->add($r->newInstance());
Daniel@0 2865 }
Daniel@0 2866 }
Daniel@0 2867 }
Daniel@0 2868 }
Daniel@0 2869 }
Daniel@0 2870 namespace Symfony\Component\Config
Daniel@0 2871 {
Daniel@0 2872 use Symfony\Component\Config\Resource\ResourceInterface;
Daniel@0 2873 use Symfony\Component\Filesystem\Exception\IOException;
Daniel@0 2874 use Symfony\Component\Filesystem\Filesystem;
Daniel@0 2875 class ConfigCache
Daniel@0 2876 {
Daniel@0 2877 private $debug;
Daniel@0 2878 private $file;
Daniel@0 2879 public function __construct($file, $debug)
Daniel@0 2880 {
Daniel@0 2881 $this->file = $file;
Daniel@0 2882 $this->debug = (bool) $debug;
Daniel@0 2883 }
Daniel@0 2884 public function __toString()
Daniel@0 2885 {
Daniel@0 2886 return $this->file;
Daniel@0 2887 }
Daniel@0 2888 public function isFresh()
Daniel@0 2889 {
Daniel@0 2890 if (!is_file($this->file)) {
Daniel@0 2891 return false;
Daniel@0 2892 }
Daniel@0 2893 if (!$this->debug) {
Daniel@0 2894 return true;
Daniel@0 2895 }
Daniel@0 2896 $metadata = $this->getMetaFile();
Daniel@0 2897 if (!is_file($metadata)) {
Daniel@0 2898 return false;
Daniel@0 2899 }
Daniel@0 2900 $time = filemtime($this->file);
Daniel@0 2901 $meta = unserialize(file_get_contents($metadata));
Daniel@0 2902 foreach ($meta as $resource) {
Daniel@0 2903 if (!$resource->isFresh($time)) {
Daniel@0 2904 return false;
Daniel@0 2905 }
Daniel@0 2906 }
Daniel@0 2907 return true;
Daniel@0 2908 }
Daniel@0 2909 public function write($content, array $metadata = null)
Daniel@0 2910 {
Daniel@0 2911 $mode = 0666;
Daniel@0 2912 $umask = umask();
Daniel@0 2913 $filesystem = new Filesystem();
Daniel@0 2914 $filesystem->dumpFile($this->file, $content, null);
Daniel@0 2915 try {
Daniel@0 2916 $filesystem->chmod($this->file, $mode, $umask);
Daniel@0 2917 } catch (IOException $e) {
Daniel@0 2918 }
Daniel@0 2919 if (null !== $metadata && true === $this->debug) {
Daniel@0 2920 $filesystem->dumpFile($this->getMetaFile(), serialize($metadata), null);
Daniel@0 2921 try {
Daniel@0 2922 $filesystem->chmod($this->getMetaFile(), $mode, $umask);
Daniel@0 2923 } catch (IOException $e) {
Daniel@0 2924 }
Daniel@0 2925 }
Daniel@0 2926 }
Daniel@0 2927 private function getMetaFile()
Daniel@0 2928 {
Daniel@0 2929 return $this->file.'.meta';
Daniel@0 2930 }
Daniel@0 2931 }
Daniel@0 2932 }
Daniel@0 2933 namespace Symfony\Component\HttpKernel
Daniel@0 2934 {
Daniel@0 2935 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
Daniel@0 2936 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Daniel@0 2937 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
Daniel@0 2938 use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
Daniel@0 2939 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
Daniel@0 2940 use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
Daniel@0 2941 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
Daniel@0 2942 use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
Daniel@0 2943 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
Daniel@0 2944 use Symfony\Component\HttpKernel\Event\PostResponseEvent;
Daniel@0 2945 use Symfony\Component\HttpFoundation\Request;
Daniel@0 2946 use Symfony\Component\HttpFoundation\RequestStack;
Daniel@0 2947 use Symfony\Component\HttpFoundation\Response;
Daniel@0 2948 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Daniel@0 2949 class HttpKernel implements HttpKernelInterface, TerminableInterface
Daniel@0 2950 {
Daniel@0 2951 protected $dispatcher;
Daniel@0 2952 protected $resolver;
Daniel@0 2953 protected $requestStack;
Daniel@0 2954 public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver, RequestStack $requestStack = null)
Daniel@0 2955 {
Daniel@0 2956 $this->dispatcher = $dispatcher;
Daniel@0 2957 $this->resolver = $resolver;
Daniel@0 2958 $this->requestStack = $requestStack ?: new RequestStack();
Daniel@0 2959 }
Daniel@0 2960 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
Daniel@0 2961 {
Daniel@0 2962 try {
Daniel@0 2963 return $this->handleRaw($request, $type);
Daniel@0 2964 } catch (\Exception $e) {
Daniel@0 2965 if (false === $catch) {
Daniel@0 2966 $this->finishRequest($request, $type);
Daniel@0 2967 throw $e;
Daniel@0 2968 }
Daniel@0 2969 return $this->handleException($e, $request, $type);
Daniel@0 2970 }
Daniel@0 2971 }
Daniel@0 2972 public function terminate(Request $request, Response $response)
Daniel@0 2973 {
Daniel@0 2974 $this->dispatcher->dispatch(KernelEvents::TERMINATE, new PostResponseEvent($this, $request, $response));
Daniel@0 2975 }
Daniel@0 2976 public function terminateWithException(\Exception $exception)
Daniel@0 2977 {
Daniel@0 2978 if (!$request = $this->requestStack->getMasterRequest()) {
Daniel@0 2979 throw new \LogicException('Request stack is empty', 0, $exception);
Daniel@0 2980 }
Daniel@0 2981 $response = $this->handleException($exception, $request, self::MASTER_REQUEST);
Daniel@0 2982 $response->sendHeaders();
Daniel@0 2983 $response->sendContent();
Daniel@0 2984 $this->terminate($request, $response);
Daniel@0 2985 }
Daniel@0 2986 private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
Daniel@0 2987 {
Daniel@0 2988 $this->requestStack->push($request);
Daniel@0 2989 $event = new GetResponseEvent($this, $request, $type);
Daniel@0 2990 $this->dispatcher->dispatch(KernelEvents::REQUEST, $event);
Daniel@0 2991 if ($event->hasResponse()) {
Daniel@0 2992 return $this->filterResponse($event->getResponse(), $request, $type);
Daniel@0 2993 }
Daniel@0 2994 if (false === $controller = $this->resolver->getController($request)) {
Daniel@0 2995 throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". Maybe you forgot to add the matching route in your routing configuration?', $request->getPathInfo()));
Daniel@0 2996 }
Daniel@0 2997 $event = new FilterControllerEvent($this, $controller, $request, $type);
Daniel@0 2998 $this->dispatcher->dispatch(KernelEvents::CONTROLLER, $event);
Daniel@0 2999 $controller = $event->getController();
Daniel@0 3000 $arguments = $this->resolver->getArguments($request, $controller);
Daniel@0 3001 $response = call_user_func_array($controller, $arguments);
Daniel@0 3002 if (!$response instanceof Response) {
Daniel@0 3003 $event = new GetResponseForControllerResultEvent($this, $request, $type, $response);
Daniel@0 3004 $this->dispatcher->dispatch(KernelEvents::VIEW, $event);
Daniel@0 3005 if ($event->hasResponse()) {
Daniel@0 3006 $response = $event->getResponse();
Daniel@0 3007 }
Daniel@0 3008 if (!$response instanceof Response) {
Daniel@0 3009 $msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));
Daniel@0 3010 if (null === $response) {
Daniel@0 3011 $msg .=' Did you forget to add a return statement somewhere in your controller?';
Daniel@0 3012 }
Daniel@0 3013 throw new \LogicException($msg);
Daniel@0 3014 }
Daniel@0 3015 }
Daniel@0 3016 return $this->filterResponse($response, $request, $type);
Daniel@0 3017 }
Daniel@0 3018 private function filterResponse(Response $response, Request $request, $type)
Daniel@0 3019 {
Daniel@0 3020 $event = new FilterResponseEvent($this, $request, $type, $response);
Daniel@0 3021 $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
Daniel@0 3022 $this->finishRequest($request, $type);
Daniel@0 3023 return $event->getResponse();
Daniel@0 3024 }
Daniel@0 3025 private function finishRequest(Request $request, $type)
Daniel@0 3026 {
Daniel@0 3027 $this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type));
Daniel@0 3028 $this->requestStack->pop();
Daniel@0 3029 }
Daniel@0 3030 private function handleException(\Exception $e, $request, $type)
Daniel@0 3031 {
Daniel@0 3032 $event = new GetResponseForExceptionEvent($this, $request, $type, $e);
Daniel@0 3033 $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
Daniel@0 3034 $e = $event->getException();
Daniel@0 3035 if (!$event->hasResponse()) {
Daniel@0 3036 $this->finishRequest($request, $type);
Daniel@0 3037 throw $e;
Daniel@0 3038 }
Daniel@0 3039 $response = $event->getResponse();
Daniel@0 3040 if ($response->headers->has('X-Status-Code')) {
Daniel@0 3041 $response->setStatusCode($response->headers->get('X-Status-Code'));
Daniel@0 3042 $response->headers->remove('X-Status-Code');
Daniel@0 3043 } elseif (!$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
Daniel@0 3044 if ($e instanceof HttpExceptionInterface) {
Daniel@0 3045 $response->setStatusCode($e->getStatusCode());
Daniel@0 3046 $response->headers->add($e->getHeaders());
Daniel@0 3047 } else {
Daniel@0 3048 $response->setStatusCode(500);
Daniel@0 3049 }
Daniel@0 3050 }
Daniel@0 3051 try {
Daniel@0 3052 return $this->filterResponse($response, $request, $type);
Daniel@0 3053 } catch (\Exception $e) {
Daniel@0 3054 return $response;
Daniel@0 3055 }
Daniel@0 3056 }
Daniel@0 3057 private function varToString($var)
Daniel@0 3058 {
Daniel@0 3059 if (is_object($var)) {
Daniel@0 3060 return sprintf('Object(%s)', get_class($var));
Daniel@0 3061 }
Daniel@0 3062 if (is_array($var)) {
Daniel@0 3063 $a = array();
Daniel@0 3064 foreach ($var as $k => $v) {
Daniel@0 3065 $a[] = sprintf('%s => %s', $k, $this->varToString($v));
Daniel@0 3066 }
Daniel@0 3067 return sprintf("Array(%s)", implode(', ', $a));
Daniel@0 3068 }
Daniel@0 3069 if (is_resource($var)) {
Daniel@0 3070 return sprintf('Resource(%s)', get_resource_type($var));
Daniel@0 3071 }
Daniel@0 3072 if (null === $var) {
Daniel@0 3073 return'null';
Daniel@0 3074 }
Daniel@0 3075 if (false === $var) {
Daniel@0 3076 return'false';
Daniel@0 3077 }
Daniel@0 3078 if (true === $var) {
Daniel@0 3079 return'true';
Daniel@0 3080 }
Daniel@0 3081 return (string) $var;
Daniel@0 3082 }
Daniel@0 3083 }
Daniel@0 3084 }
Daniel@0 3085 namespace Symfony\Component\HttpKernel\DependencyInjection
Daniel@0 3086 {
Daniel@0 3087 use Symfony\Component\HttpFoundation\Request;
Daniel@0 3088 use Symfony\Component\HttpFoundation\RequestStack;
Daniel@0 3089 use Symfony\Component\HttpKernel\HttpKernelInterface;
Daniel@0 3090 use Symfony\Component\HttpKernel\HttpKernel;
Daniel@0 3091 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
Daniel@0 3092 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Daniel@0 3093 use Symfony\Component\DependencyInjection\ContainerInterface;
Daniel@0 3094 use Symfony\Component\DependencyInjection\Scope;
Daniel@0 3095 class ContainerAwareHttpKernel extends HttpKernel
Daniel@0 3096 {
Daniel@0 3097 protected $container;
Daniel@0 3098 public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver, RequestStack $requestStack = null)
Daniel@0 3099 {
Daniel@0 3100 parent::__construct($dispatcher, $controllerResolver, $requestStack);
Daniel@0 3101 $this->container = $container;
Daniel@0 3102 if (!$container->hasScope('request')) {
Daniel@0 3103 $container->addScope(new Scope('request'));
Daniel@0 3104 }
Daniel@0 3105 }
Daniel@0 3106 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
Daniel@0 3107 {
Daniel@0 3108 $request->headers->set('X-Php-Ob-Level', ob_get_level());
Daniel@0 3109 $this->container->enterScope('request');
Daniel@0 3110 $this->container->set('request', $request,'request');
Daniel@0 3111 try {
Daniel@0 3112 $response = parent::handle($request, $type, $catch);
Daniel@0 3113 } catch (\Exception $e) {
Daniel@0 3114 $this->container->set('request', null,'request');
Daniel@0 3115 $this->container->leaveScope('request');
Daniel@0 3116 throw $e;
Daniel@0 3117 }
Daniel@0 3118 $this->container->set('request', null,'request');
Daniel@0 3119 $this->container->leaveScope('request');
Daniel@0 3120 return $response;
Daniel@0 3121 }
Daniel@0 3122 }
Daniel@0 3123 }
Daniel@0 3124
Daniel@0 3125 namespace { return $loader; }
Daniel@0 3126