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