bootstrap.php.cache 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. <?php
  2. namespace Symfony\Component\HttpFoundation
  3. {
  4. class ParameterBag implements \IteratorAggregate, \Countable
  5. {
  6. protected $parameters;
  7. public function __construct(array $parameters = array())
  8. {
  9. $this->parameters = $parameters;
  10. }
  11. public function all()
  12. {
  13. return $this->parameters;
  14. }
  15. public function keys()
  16. {
  17. return array_keys($this->parameters);
  18. }
  19. public function replace(array $parameters = array())
  20. {
  21. $this->parameters = $parameters;
  22. }
  23. public function add(array $parameters = array())
  24. {
  25. $this->parameters = array_replace($this->parameters, $parameters);
  26. }
  27. public function get($key, $default = null, $deep = false)
  28. {
  29. if ($deep) {
  30. @trigger_error('Using paths to find deeper items in '.__METHOD__.' is deprecated since version 2.8 and will be removed in 3.0. Filter the returned value in your own code instead.', E_USER_DEPRECATED);
  31. }
  32. if (!$deep || false === $pos = strpos($key,'[')) {
  33. return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
  34. }
  35. $root = substr($key, 0, $pos);
  36. if (!array_key_exists($root, $this->parameters)) {
  37. return $default;
  38. }
  39. $value = $this->parameters[$root];
  40. $currentKey = null;
  41. for ($i = $pos, $c = strlen($key); $i < $c; ++$i) {
  42. $char = $key[$i];
  43. if ('['=== $char) {
  44. if (null !== $currentKey) {
  45. throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
  46. }
  47. $currentKey ='';
  48. } elseif (']'=== $char) {
  49. if (null === $currentKey) {
  50. throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
  51. }
  52. if (!is_array($value) || !array_key_exists($currentKey, $value)) {
  53. return $default;
  54. }
  55. $value = $value[$currentKey];
  56. $currentKey = null;
  57. } else {
  58. if (null === $currentKey) {
  59. throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
  60. }
  61. $currentKey .= $char;
  62. }
  63. }
  64. if (null !== $currentKey) {
  65. throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
  66. }
  67. return $value;
  68. }
  69. public function set($key, $value)
  70. {
  71. $this->parameters[$key] = $value;
  72. }
  73. public function has($key)
  74. {
  75. return array_key_exists($key, $this->parameters);
  76. }
  77. public function remove($key)
  78. {
  79. unset($this->parameters[$key]);
  80. }
  81. public function getAlpha($key, $default ='', $deep = false)
  82. {
  83. return preg_replace('/[^[:alpha:]]/','', $this->get($key, $default, $deep));
  84. }
  85. public function getAlnum($key, $default ='', $deep = false)
  86. {
  87. return preg_replace('/[^[:alnum:]]/','', $this->get($key, $default, $deep));
  88. }
  89. public function getDigits($key, $default ='', $deep = false)
  90. {
  91. return str_replace(array('-','+'),'', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT, array(), $deep));
  92. }
  93. public function getInt($key, $default = 0, $deep = false)
  94. {
  95. return (int) $this->get($key, $default, $deep);
  96. }
  97. public function getBoolean($key, $default = false, $deep = false)
  98. {
  99. return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN, array(), $deep);
  100. }
  101. public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = array(), $deep = false)
  102. {
  103. static $filters = null;
  104. if (null === $filters) {
  105. foreach (filter_list() as $tmp) {
  106. $filters[filter_id($tmp)] = 1;
  107. }
  108. }
  109. if (is_bool($filter) || !isset($filters[$filter]) || is_array($deep)) {
  110. @trigger_error('Passing the $deep boolean as 3rd argument to the '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Remove it altogether as the $deep argument will be removed in 3.0.', E_USER_DEPRECATED);
  111. $tmp = $deep;
  112. $deep = $filter;
  113. $filter = $options;
  114. $options = $tmp;
  115. }
  116. $value = $this->get($key, $default, $deep);
  117. if (!is_array($options) && $options) {
  118. $options = array('flags'=> $options);
  119. }
  120. if (is_array($value) && !isset($options['flags'])) {
  121. $options['flags'] = FILTER_REQUIRE_ARRAY;
  122. }
  123. return filter_var($value, $filter, $options);
  124. }
  125. public function getIterator()
  126. {
  127. return new \ArrayIterator($this->parameters);
  128. }
  129. public function count()
  130. {
  131. return count($this->parameters);
  132. }
  133. }
  134. }
  135. namespace Symfony\Component\HttpFoundation
  136. {
  137. class HeaderBag implements \IteratorAggregate, \Countable
  138. {
  139. protected $headers = array();
  140. protected $cacheControl = array();
  141. public function __construct(array $headers = array())
  142. {
  143. foreach ($headers as $key => $values) {
  144. $this->set($key, $values);
  145. }
  146. }
  147. public function __toString()
  148. {
  149. if (!$this->headers) {
  150. return'';
  151. }
  152. $max = max(array_map('strlen', array_keys($this->headers))) + 1;
  153. $content ='';
  154. ksort($this->headers);
  155. foreach ($this->headers as $name => $values) {
  156. $name = implode('-', array_map('ucfirst', explode('-', $name)));
  157. foreach ($values as $value) {
  158. $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
  159. }
  160. }
  161. return $content;
  162. }
  163. public function all()
  164. {
  165. return $this->headers;
  166. }
  167. public function keys()
  168. {
  169. return array_keys($this->headers);
  170. }
  171. public function replace(array $headers = array())
  172. {
  173. $this->headers = array();
  174. $this->add($headers);
  175. }
  176. public function add(array $headers)
  177. {
  178. foreach ($headers as $key => $values) {
  179. $this->set($key, $values);
  180. }
  181. }
  182. public function get($key, $default = null, $first = true)
  183. {
  184. $key = str_replace('_','-', strtolower($key));
  185. if (!array_key_exists($key, $this->headers)) {
  186. if (null === $default) {
  187. return $first ? null : array();
  188. }
  189. return $first ? $default : array($default);
  190. }
  191. if ($first) {
  192. return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
  193. }
  194. return $this->headers[$key];
  195. }
  196. public function set($key, $values, $replace = true)
  197. {
  198. $key = str_replace('_','-', strtolower($key));
  199. $values = array_values((array) $values);
  200. if (true === $replace || !isset($this->headers[$key])) {
  201. $this->headers[$key] = $values;
  202. } else {
  203. $this->headers[$key] = array_merge($this->headers[$key], $values);
  204. }
  205. if ('cache-control'=== $key) {
  206. $this->cacheControl = $this->parseCacheControl($values[0]);
  207. }
  208. }
  209. public function has($key)
  210. {
  211. return array_key_exists(str_replace('_','-', strtolower($key)), $this->headers);
  212. }
  213. public function contains($key, $value)
  214. {
  215. return in_array($value, $this->get($key, null, false));
  216. }
  217. public function remove($key)
  218. {
  219. $key = str_replace('_','-', strtolower($key));
  220. unset($this->headers[$key]);
  221. if ('cache-control'=== $key) {
  222. $this->cacheControl = array();
  223. }
  224. }
  225. public function getDate($key, \DateTime $default = null)
  226. {
  227. if (null === $value = $this->get($key)) {
  228. return $default;
  229. }
  230. if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
  231. throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
  232. }
  233. return $date;
  234. }
  235. public function addCacheControlDirective($key, $value = true)
  236. {
  237. $this->cacheControl[$key] = $value;
  238. $this->set('Cache-Control', $this->getCacheControlHeader());
  239. }
  240. public function hasCacheControlDirective($key)
  241. {
  242. return array_key_exists($key, $this->cacheControl);
  243. }
  244. public function getCacheControlDirective($key)
  245. {
  246. return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
  247. }
  248. public function removeCacheControlDirective($key)
  249. {
  250. unset($this->cacheControl[$key]);
  251. $this->set('Cache-Control', $this->getCacheControlHeader());
  252. }
  253. public function getIterator()
  254. {
  255. return new \ArrayIterator($this->headers);
  256. }
  257. public function count()
  258. {
  259. return count($this->headers);
  260. }
  261. protected function getCacheControlHeader()
  262. {
  263. $parts = array();
  264. ksort($this->cacheControl);
  265. foreach ($this->cacheControl as $key => $value) {
  266. if (true === $value) {
  267. $parts[] = $key;
  268. } else {
  269. if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
  270. $value ='"'.$value.'"';
  271. }
  272. $parts[] = "$key=$value";
  273. }
  274. }
  275. return implode(', ', $parts);
  276. }
  277. protected function parseCacheControl($header)
  278. {
  279. $cacheControl = array();
  280. preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
  281. foreach ($matches as $match) {
  282. $cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
  283. }
  284. return $cacheControl;
  285. }
  286. }
  287. }
  288. namespace Symfony\Component\HttpFoundation
  289. {
  290. use Symfony\Component\HttpFoundation\File\UploadedFile;
  291. class FileBag extends ParameterBag
  292. {
  293. private static $fileKeys = array('error','name','size','tmp_name','type');
  294. public function __construct(array $parameters = array())
  295. {
  296. $this->replace($parameters);
  297. }
  298. public function replace(array $files = array())
  299. {
  300. $this->parameters = array();
  301. $this->add($files);
  302. }
  303. public function set($key, $value)
  304. {
  305. if (!is_array($value) && !$value instanceof UploadedFile) {
  306. throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
  307. }
  308. parent::set($key, $this->convertFileInformation($value));
  309. }
  310. public function add(array $files = array())
  311. {
  312. foreach ($files as $key => $file) {
  313. $this->set($key, $file);
  314. }
  315. }
  316. protected function convertFileInformation($file)
  317. {
  318. if ($file instanceof UploadedFile) {
  319. return $file;
  320. }
  321. $file = $this->fixPhpFilesArray($file);
  322. if (is_array($file)) {
  323. $keys = array_keys($file);
  324. sort($keys);
  325. if ($keys == self::$fileKeys) {
  326. if (UPLOAD_ERR_NO_FILE == $file['error']) {
  327. $file = null;
  328. } else {
  329. $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
  330. }
  331. } else {
  332. $file = array_map(array($this,'convertFileInformation'), $file);
  333. }
  334. }
  335. return $file;
  336. }
  337. protected function fixPhpFilesArray($data)
  338. {
  339. if (!is_array($data)) {
  340. return $data;
  341. }
  342. $keys = array_keys($data);
  343. sort($keys);
  344. if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
  345. return $data;
  346. }
  347. $files = $data;
  348. foreach (self::$fileKeys as $k) {
  349. unset($files[$k]);
  350. }
  351. foreach ($data['name'] as $key => $name) {
  352. $files[$key] = $this->fixPhpFilesArray(array('error'=> $data['error'][$key],'name'=> $name,'type'=> $data['type'][$key],'tmp_name'=> $data['tmp_name'][$key],'size'=> $data['size'][$key],
  353. ));
  354. }
  355. return $files;
  356. }
  357. }
  358. }
  359. namespace Symfony\Component\HttpFoundation
  360. {
  361. class ServerBag extends ParameterBag
  362. {
  363. public function getHeaders()
  364. {
  365. $headers = array();
  366. $contentHeaders = array('CONTENT_LENGTH'=> true,'CONTENT_MD5'=> true,'CONTENT_TYPE'=> true);
  367. foreach ($this->parameters as $key => $value) {
  368. if (0 === strpos($key,'HTTP_')) {
  369. $headers[substr($key, 5)] = $value;
  370. }
  371. elseif (isset($contentHeaders[$key])) {
  372. $headers[$key] = $value;
  373. }
  374. }
  375. if (isset($this->parameters['PHP_AUTH_USER'])) {
  376. $headers['PHP_AUTH_USER'] = $this->parameters['PHP_AUTH_USER'];
  377. $headers['PHP_AUTH_PW'] = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] :'';
  378. } else {
  379. $authorizationHeader = null;
  380. if (isset($this->parameters['HTTP_AUTHORIZATION'])) {
  381. $authorizationHeader = $this->parameters['HTTP_AUTHORIZATION'];
  382. } elseif (isset($this->parameters['REDIRECT_HTTP_AUTHORIZATION'])) {
  383. $authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION'];
  384. }
  385. if (null !== $authorizationHeader) {
  386. if (0 === stripos($authorizationHeader,'basic ')) {
  387. $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)), 2);
  388. if (count($exploded) == 2) {
  389. list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
  390. }
  391. } elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader,'digest '))) {
  392. $headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
  393. $this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
  394. } elseif (0 === stripos($authorizationHeader,'bearer ')) {
  395. $headers['AUTHORIZATION'] = $authorizationHeader;
  396. }
  397. }
  398. }
  399. if (isset($headers['AUTHORIZATION'])) {
  400. return $headers;
  401. }
  402. if (isset($headers['PHP_AUTH_USER'])) {
  403. $headers['AUTHORIZATION'] ='Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
  404. } elseif (isset($headers['PHP_AUTH_DIGEST'])) {
  405. $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
  406. }
  407. return $headers;
  408. }
  409. }
  410. }
  411. namespace Symfony\Component\HttpFoundation
  412. {
  413. use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
  414. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  415. class Request
  416. {
  417. const HEADER_FORWARDED ='forwarded';
  418. const HEADER_CLIENT_IP ='client_ip';
  419. const HEADER_CLIENT_HOST ='client_host';
  420. const HEADER_CLIENT_PROTO ='client_proto';
  421. const HEADER_CLIENT_PORT ='client_port';
  422. const METHOD_HEAD ='HEAD';
  423. const METHOD_GET ='GET';
  424. const METHOD_POST ='POST';
  425. const METHOD_PUT ='PUT';
  426. const METHOD_PATCH ='PATCH';
  427. const METHOD_DELETE ='DELETE';
  428. const METHOD_PURGE ='PURGE';
  429. const METHOD_OPTIONS ='OPTIONS';
  430. const METHOD_TRACE ='TRACE';
  431. const METHOD_CONNECT ='CONNECT';
  432. protected static $trustedProxies = array();
  433. protected static $trustedHostPatterns = array();
  434. protected static $trustedHosts = array();
  435. protected static $trustedHeaders = array(
  436. self::HEADER_FORWARDED =>'FORWARDED',
  437. self::HEADER_CLIENT_IP =>'X_FORWARDED_FOR',
  438. self::HEADER_CLIENT_HOST =>'X_FORWARDED_HOST',
  439. self::HEADER_CLIENT_PROTO =>'X_FORWARDED_PROTO',
  440. self::HEADER_CLIENT_PORT =>'X_FORWARDED_PORT',
  441. );
  442. protected static $httpMethodParameterOverride = false;
  443. public $attributes;
  444. public $request;
  445. public $query;
  446. public $server;
  447. public $files;
  448. public $cookies;
  449. public $headers;
  450. protected $content;
  451. protected $languages;
  452. protected $charsets;
  453. protected $encodings;
  454. protected $acceptableContentTypes;
  455. protected $pathInfo;
  456. protected $requestUri;
  457. protected $baseUrl;
  458. protected $basePath;
  459. protected $method;
  460. protected $format;
  461. protected $session;
  462. protected $locale;
  463. protected $defaultLocale ='en';
  464. protected static $formats;
  465. protected static $requestFactory;
  466. public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  467. {
  468. $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
  469. }
  470. public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  471. {
  472. $this->request = new ParameterBag($request);
  473. $this->query = new ParameterBag($query);
  474. $this->attributes = new ParameterBag($attributes);
  475. $this->cookies = new ParameterBag($cookies);
  476. $this->files = new FileBag($files);
  477. $this->server = new ServerBag($server);
  478. $this->headers = new HeaderBag($this->server->getHeaders());
  479. $this->content = $content;
  480. $this->languages = null;
  481. $this->charsets = null;
  482. $this->encodings = null;
  483. $this->acceptableContentTypes = null;
  484. $this->pathInfo = null;
  485. $this->requestUri = null;
  486. $this->baseUrl = null;
  487. $this->basePath = null;
  488. $this->method = null;
  489. $this->format = null;
  490. }
  491. public static function createFromGlobals()
  492. {
  493. $server = $_SERVER;
  494. if ('cli-server'=== PHP_SAPI) {
  495. if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) {
  496. $server['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH'];
  497. }
  498. if (array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
  499. $server['CONTENT_TYPE'] = $_SERVER['HTTP_CONTENT_TYPE'];
  500. }
  501. }
  502. $request = self::createRequestFromFactory($_GET, $_POST, array(), $_COOKIE, $_FILES, $server);
  503. if (0 === strpos($request->headers->get('CONTENT_TYPE'),'application/x-www-form-urlencoded')
  504. && in_array(strtoupper($request->server->get('REQUEST_METHOD','GET')), array('PUT','DELETE','PATCH'))
  505. ) {
  506. parse_str($request->getContent(), $data);
  507. $request->request = new ParameterBag($data);
  508. }
  509. return $request;
  510. }
  511. public static function create($uri, $method ='GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null)
  512. {
  513. $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(),
  514. ), $server);
  515. $server['PATH_INFO'] ='';
  516. $server['REQUEST_METHOD'] = strtoupper($method);
  517. $components = parse_url($uri);
  518. if (isset($components['host'])) {
  519. $server['SERVER_NAME'] = $components['host'];
  520. $server['HTTP_HOST'] = $components['host'];
  521. }
  522. if (isset($components['scheme'])) {
  523. if ('https'=== $components['scheme']) {
  524. $server['HTTPS'] ='on';
  525. $server['SERVER_PORT'] = 443;
  526. } else {
  527. unset($server['HTTPS']);
  528. $server['SERVER_PORT'] = 80;
  529. }
  530. }
  531. if (isset($components['port'])) {
  532. $server['SERVER_PORT'] = $components['port'];
  533. $server['HTTP_HOST'] = $server['HTTP_HOST'].':'.$components['port'];
  534. }
  535. if (isset($components['user'])) {
  536. $server['PHP_AUTH_USER'] = $components['user'];
  537. }
  538. if (isset($components['pass'])) {
  539. $server['PHP_AUTH_PW'] = $components['pass'];
  540. }
  541. if (!isset($components['path'])) {
  542. $components['path'] ='/';
  543. }
  544. switch (strtoupper($method)) {
  545. case'POST':
  546. case'PUT':
  547. case'DELETE':
  548. if (!isset($server['CONTENT_TYPE'])) {
  549. $server['CONTENT_TYPE'] ='application/x-www-form-urlencoded';
  550. }
  551. case'PATCH':
  552. $request = $parameters;
  553. $query = array();
  554. break;
  555. default:
  556. $request = array();
  557. $query = $parameters;
  558. break;
  559. }
  560. $queryString ='';
  561. if (isset($components['query'])) {
  562. parse_str(html_entity_decode($components['query']), $qs);
  563. if ($query) {
  564. $query = array_replace($qs, $query);
  565. $queryString = http_build_query($query,'','&');
  566. } else {
  567. $query = $qs;
  568. $queryString = $components['query'];
  569. }
  570. } elseif ($query) {
  571. $queryString = http_build_query($query,'','&');
  572. }
  573. $server['REQUEST_URI'] = $components['path'].(''!== $queryString ?'?'.$queryString :'');
  574. $server['QUERY_STRING'] = $queryString;
  575. return self::createRequestFromFactory($query, $request, array(), $cookies, $files, $server, $content);
  576. }
  577. public static function setFactory($callable)
  578. {
  579. self::$requestFactory = $callable;
  580. }
  581. public function duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
  582. {
  583. $dup = clone $this;
  584. if ($query !== null) {
  585. $dup->query = new ParameterBag($query);
  586. }
  587. if ($request !== null) {
  588. $dup->request = new ParameterBag($request);
  589. }
  590. if ($attributes !== null) {
  591. $dup->attributes = new ParameterBag($attributes);
  592. }
  593. if ($cookies !== null) {
  594. $dup->cookies = new ParameterBag($cookies);
  595. }
  596. if ($files !== null) {
  597. $dup->files = new FileBag($files);
  598. }
  599. if ($server !== null) {
  600. $dup->server = new ServerBag($server);
  601. $dup->headers = new HeaderBag($dup->server->getHeaders());
  602. }
  603. $dup->languages = null;
  604. $dup->charsets = null;
  605. $dup->encodings = null;
  606. $dup->acceptableContentTypes = null;
  607. $dup->pathInfo = null;
  608. $dup->requestUri = null;
  609. $dup->baseUrl = null;
  610. $dup->basePath = null;
  611. $dup->method = null;
  612. $dup->format = null;
  613. if (!$dup->get('_format') && $this->get('_format')) {
  614. $dup->attributes->set('_format', $this->get('_format'));
  615. }
  616. if (!$dup->getRequestFormat(null)) {
  617. $dup->setRequestFormat($this->getRequestFormat(null));
  618. }
  619. return $dup;
  620. }
  621. public function __clone()
  622. {
  623. $this->query = clone $this->query;
  624. $this->request = clone $this->request;
  625. $this->attributes = clone $this->attributes;
  626. $this->cookies = clone $this->cookies;
  627. $this->files = clone $this->files;
  628. $this->server = clone $this->server;
  629. $this->headers = clone $this->headers;
  630. }
  631. public function __toString()
  632. {
  633. try {
  634. $content = $this->getContent();
  635. } catch (\LogicException $e) {
  636. return trigger_error($e, E_USER_ERROR);
  637. }
  638. return
  639. sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
  640. $this->headers."\r\n".
  641. $content;
  642. }
  643. public function overrideGlobals()
  644. {
  645. $this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null,'&')));
  646. $_GET = $this->query->all();
  647. $_POST = $this->request->all();
  648. $_SERVER = $this->server->all();
  649. $_COOKIE = $this->cookies->all();
  650. foreach ($this->headers->all() as $key => $value) {
  651. $key = strtoupper(str_replace('-','_', $key));
  652. if (in_array($key, array('CONTENT_TYPE','CONTENT_LENGTH'))) {
  653. $_SERVER[$key] = implode(', ', $value);
  654. } else {
  655. $_SERVER['HTTP_'.$key] = implode(', ', $value);
  656. }
  657. }
  658. $request = array('g'=> $_GET,'p'=> $_POST,'c'=> $_COOKIE);
  659. $requestOrder = ini_get('request_order') ?: ini_get('variables_order');
  660. $requestOrder = preg_replace('#[^cgp]#','', strtolower($requestOrder)) ?:'gp';
  661. $_REQUEST = array();
  662. foreach (str_split($requestOrder) as $order) {
  663. $_REQUEST = array_merge($_REQUEST, $request[$order]);
  664. }
  665. }
  666. public static function setTrustedProxies(array $proxies)
  667. {
  668. self::$trustedProxies = $proxies;
  669. }
  670. public static function getTrustedProxies()
  671. {
  672. return self::$trustedProxies;
  673. }
  674. public static function setTrustedHosts(array $hostPatterns)
  675. {
  676. self::$trustedHostPatterns = array_map(function ($hostPattern) {
  677. return sprintf('#%s#i', $hostPattern);
  678. }, $hostPatterns);
  679. self::$trustedHosts = array();
  680. }
  681. public static function getTrustedHosts()
  682. {
  683. return self::$trustedHostPatterns;
  684. }
  685. public static function setTrustedHeaderName($key, $value)
  686. {
  687. if (!array_key_exists($key, self::$trustedHeaders)) {
  688. throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
  689. }
  690. self::$trustedHeaders[$key] = $value;
  691. }
  692. public static function getTrustedHeaderName($key)
  693. {
  694. if (!array_key_exists($key, self::$trustedHeaders)) {
  695. throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
  696. }
  697. return self::$trustedHeaders[$key];
  698. }
  699. public static function normalizeQueryString($qs)
  700. {
  701. if (''== $qs) {
  702. return'';
  703. }
  704. $parts = array();
  705. $order = array();
  706. foreach (explode('&', $qs) as $param) {
  707. if (''=== $param ||'='=== $param[0]) {
  708. continue;
  709. }
  710. $keyValuePair = explode('=', $param, 2);
  711. $parts[] = isset($keyValuePair[1]) ?
  712. rawurlencode(urldecode($keyValuePair[0])).'='.rawurlencode(urldecode($keyValuePair[1])) :
  713. rawurlencode(urldecode($keyValuePair[0]));
  714. $order[] = urldecode($keyValuePair[0]);
  715. }
  716. array_multisort($order, SORT_ASC, $parts);
  717. return implode('&', $parts);
  718. }
  719. public static function enableHttpMethodParameterOverride()
  720. {
  721. self::$httpMethodParameterOverride = true;
  722. }
  723. public static function getHttpMethodParameterOverride()
  724. {
  725. return self::$httpMethodParameterOverride;
  726. }
  727. public function get($key, $default = null, $deep = false)
  728. {
  729. if ($deep) {
  730. @trigger_error('Using paths to find deeper items in '.__METHOD__.' is deprecated since version 2.8 and will be removed in 3.0. Filter the returned value in your own code instead.', E_USER_DEPRECATED);
  731. }
  732. if ($this !== $result = $this->query->get($key, $this, $deep)) {
  733. return $result;
  734. }
  735. if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
  736. return $result;
  737. }
  738. if ($this !== $result = $this->request->get($key, $this, $deep)) {
  739. return $result;
  740. }
  741. return $default;
  742. }
  743. public function getSession()
  744. {
  745. return $this->session;
  746. }
  747. public function hasPreviousSession()
  748. {
  749. return $this->hasSession() && $this->cookies->has($this->session->getName());
  750. }
  751. public function hasSession()
  752. {
  753. return null !== $this->session;
  754. }
  755. public function setSession(SessionInterface $session)
  756. {
  757. $this->session = $session;
  758. }
  759. public function getClientIps()
  760. {
  761. $clientIps = array();
  762. $ip = $this->server->get('REMOTE_ADDR');
  763. if (!$this->isFromTrustedProxy()) {
  764. return array($ip);
  765. }
  766. $hasTrustedForwardedHeader = self::$trustedHeaders[self::HEADER_FORWARDED] && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED]);
  767. $hasTrustedClientIpHeader = self::$trustedHeaders[self::HEADER_CLIENT_IP] && $this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP]);
  768. if ($hasTrustedForwardedHeader) {
  769. $forwardedHeader = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]);
  770. preg_match_all('{(for)=("?\[?)([a-z0-9\.:_\-/]*)}', $forwardedHeader, $matches);
  771. $forwardedClientIps = $matches[3];
  772. $forwardedClientIps = $this->normalizeAndFilterClientIps($forwardedClientIps, $ip);
  773. $clientIps = $forwardedClientIps;
  774. }
  775. if ($hasTrustedClientIpHeader) {
  776. $xForwardedForClientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
  777. $xForwardedForClientIps = $this->normalizeAndFilterClientIps($xForwardedForClientIps, $ip);
  778. $clientIps = $xForwardedForClientIps;
  779. }
  780. if ($hasTrustedForwardedHeader && $hasTrustedClientIpHeader && $forwardedClientIps !== $xForwardedForClientIps) {
  781. throw new ConflictingHeadersException('The request has both a trusted Forwarded header and a trusted Client IP header, conflicting with each other with regards to the originating IP addresses of the request. This is the result of a misconfiguration. You should either configure your proxy only to send one of these headers, or configure Symfony to distrust one of them.');
  782. }
  783. if (!$hasTrustedForwardedHeader && !$hasTrustedClientIpHeader) {
  784. return $this->normalizeAndFilterClientIps(array(), $ip);
  785. }
  786. return $clientIps;
  787. }
  788. public function getClientIp()
  789. {
  790. $ipAddresses = $this->getClientIps();
  791. return $ipAddresses[0];
  792. }
  793. public function getScriptName()
  794. {
  795. return $this->server->get('SCRIPT_NAME', $this->server->get('ORIG_SCRIPT_NAME',''));
  796. }
  797. public function getPathInfo()
  798. {
  799. if (null === $this->pathInfo) {
  800. $this->pathInfo = $this->preparePathInfo();
  801. }
  802. return $this->pathInfo;
  803. }
  804. public function getBasePath()
  805. {
  806. if (null === $this->basePath) {
  807. $this->basePath = $this->prepareBasePath();
  808. }
  809. return $this->basePath;
  810. }
  811. public function getBaseUrl()
  812. {
  813. if (null === $this->baseUrl) {
  814. $this->baseUrl = $this->prepareBaseUrl();
  815. }
  816. return $this->baseUrl;
  817. }
  818. public function getScheme()
  819. {
  820. return $this->isSecure() ?'https':'http';
  821. }
  822. public function getPort()
  823. {
  824. if ($this->isFromTrustedProxy()) {
  825. if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && $port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT])) {
  826. return $port;
  827. }
  828. if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] &&'https'=== $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO],'http')) {
  829. return 443;
  830. }
  831. }
  832. if ($host = $this->headers->get('HOST')) {
  833. if ($host[0] ==='[') {
  834. $pos = strpos($host,':', strrpos($host,']'));
  835. } else {
  836. $pos = strrpos($host,':');
  837. }
  838. if (false !== $pos) {
  839. return (int) substr($host, $pos + 1);
  840. }
  841. return'https'=== $this->getScheme() ? 443 : 80;
  842. }
  843. return $this->server->get('SERVER_PORT');
  844. }
  845. public function getUser()
  846. {
  847. return $this->headers->get('PHP_AUTH_USER');
  848. }
  849. public function getPassword()
  850. {
  851. return $this->headers->get('PHP_AUTH_PW');
  852. }
  853. public function getUserInfo()
  854. {
  855. $userinfo = $this->getUser();
  856. $pass = $this->getPassword();
  857. if (''!= $pass) {
  858. $userinfo .= ":$pass";
  859. }
  860. return $userinfo;
  861. }
  862. public function getHttpHost()
  863. {
  864. $scheme = $this->getScheme();
  865. $port = $this->getPort();
  866. if (('http'== $scheme && $port == 80) || ('https'== $scheme && $port == 443)) {
  867. return $this->getHost();
  868. }
  869. return $this->getHost().':'.$port;
  870. }
  871. public function getRequestUri()
  872. {
  873. if (null === $this->requestUri) {
  874. $this->requestUri = $this->prepareRequestUri();
  875. }
  876. return $this->requestUri;
  877. }
  878. public function getSchemeAndHttpHost()
  879. {
  880. return $this->getScheme().'://'.$this->getHttpHost();
  881. }
  882. public function getUri()
  883. {
  884. if (null !== $qs = $this->getQueryString()) {
  885. $qs ='?'.$qs;
  886. }
  887. return $this->getSchemeAndHttpHost().$this->getBaseUrl().$this->getPathInfo().$qs;
  888. }
  889. public function getUriForPath($path)
  890. {
  891. return $this->getSchemeAndHttpHost().$this->getBaseUrl().$path;
  892. }
  893. public function getRelativeUriForPath($path)
  894. {
  895. if (!isset($path[0]) ||'/'!== $path[0]) {
  896. return $path;
  897. }
  898. if ($path === $basePath = $this->getPathInfo()) {
  899. return'';
  900. }
  901. $sourceDirs = explode('/', isset($basePath[0]) &&'/'=== $basePath[0] ? substr($basePath, 1) : $basePath);
  902. $targetDirs = explode('/', isset($path[0]) &&'/'=== $path[0] ? substr($path, 1) : $path);
  903. array_pop($sourceDirs);
  904. $targetFile = array_pop($targetDirs);
  905. foreach ($sourceDirs as $i => $dir) {
  906. if (isset($targetDirs[$i]) && $dir === $targetDirs[$i]) {
  907. unset($sourceDirs[$i], $targetDirs[$i]);
  908. } else {
  909. break;
  910. }
  911. }
  912. $targetDirs[] = $targetFile;
  913. $path = str_repeat('../', count($sourceDirs)).implode('/', $targetDirs);
  914. return !isset($path[0]) ||'/'=== $path[0]
  915. || false !== ($colonPos = strpos($path,':')) && ($colonPos < ($slashPos = strpos($path,'/')) || false === $slashPos)
  916. ? "./$path" : $path;
  917. }
  918. public function getQueryString()
  919. {
  920. $qs = static::normalizeQueryString($this->server->get('QUERY_STRING'));
  921. return''=== $qs ? null : $qs;
  922. }
  923. public function isSecure()
  924. {
  925. if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && $proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO])) {
  926. return in_array(strtolower(current(explode(',', $proto))), array('https','on','ssl','1'));
  927. }
  928. $https = $this->server->get('HTTPS');
  929. return !empty($https) &&'off'!== strtolower($https);
  930. }
  931. public function getHost()
  932. {
  933. if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && $host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST])) {
  934. $elements = explode(',', $host);
  935. $host = $elements[count($elements) - 1];
  936. } elseif (!$host = $this->headers->get('HOST')) {
  937. if (!$host = $this->server->get('SERVER_NAME')) {
  938. $host = $this->server->get('SERVER_ADDR','');
  939. }
  940. }
  941. $host = strtolower(preg_replace('/:\d+$/','', trim($host)));
  942. if ($host &&''!== preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/','', $host)) {
  943. throw new \UnexpectedValueException(sprintf('Invalid Host "%s"', $host));
  944. }
  945. if (count(self::$trustedHostPatterns) > 0) {
  946. if (in_array($host, self::$trustedHosts)) {
  947. return $host;
  948. }
  949. foreach (self::$trustedHostPatterns as $pattern) {
  950. if (preg_match($pattern, $host)) {
  951. self::$trustedHosts[] = $host;
  952. return $host;
  953. }
  954. }
  955. throw new \UnexpectedValueException(sprintf('Untrusted Host "%s"', $host));
  956. }
  957. return $host;
  958. }
  959. public function setMethod($method)
  960. {
  961. $this->method = null;
  962. $this->server->set('REQUEST_METHOD', $method);
  963. }
  964. public function getMethod()
  965. {
  966. if (null === $this->method) {
  967. $this->method = strtoupper($this->server->get('REQUEST_METHOD','GET'));
  968. if ('POST'=== $this->method) {
  969. if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
  970. $this->method = strtoupper($method);
  971. } elseif (self::$httpMethodParameterOverride) {
  972. $this->method = strtoupper($this->request->get('_method', $this->query->get('_method','POST')));
  973. }
  974. }
  975. }
  976. return $this->method;
  977. }
  978. public function getRealMethod()
  979. {
  980. return strtoupper($this->server->get('REQUEST_METHOD','GET'));
  981. }
  982. public function getMimeType($format)
  983. {
  984. if (null === static::$formats) {
  985. static::initializeFormats();
  986. }
  987. return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
  988. }
  989. public function getFormat($mimeType)
  990. {
  991. $canonicalMimeType = null;
  992. if (false !== $pos = strpos($mimeType,';')) {
  993. $canonicalMimeType = substr($mimeType, 0, $pos);
  994. }
  995. if (null === static::$formats) {
  996. static::initializeFormats();
  997. }
  998. foreach (static::$formats as $format => $mimeTypes) {
  999. if (in_array($mimeType, (array) $mimeTypes)) {
  1000. return $format;
  1001. }
  1002. if (null !== $canonicalMimeType && in_array($canonicalMimeType, (array) $mimeTypes)) {
  1003. return $format;
  1004. }
  1005. }
  1006. }
  1007. public function setFormat($format, $mimeTypes)
  1008. {
  1009. if (null === static::$formats) {
  1010. static::initializeFormats();
  1011. }
  1012. static::$formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
  1013. }
  1014. public function getRequestFormat($default ='html')
  1015. {
  1016. if (null === $this->format) {
  1017. $this->format = $this->get('_format', $default);
  1018. }
  1019. return $this->format;
  1020. }
  1021. public function setRequestFormat($format)
  1022. {
  1023. $this->format = $format;
  1024. }
  1025. public function getContentType()
  1026. {
  1027. return $this->getFormat($this->headers->get('CONTENT_TYPE'));
  1028. }
  1029. public function setDefaultLocale($locale)
  1030. {
  1031. $this->defaultLocale = $locale;
  1032. if (null === $this->locale) {
  1033. $this->setPhpDefaultLocale($locale);
  1034. }
  1035. }
  1036. public function getDefaultLocale()
  1037. {
  1038. return $this->defaultLocale;
  1039. }
  1040. public function setLocale($locale)
  1041. {
  1042. $this->setPhpDefaultLocale($this->locale = $locale);
  1043. }
  1044. public function getLocale()
  1045. {
  1046. return null === $this->locale ? $this->defaultLocale : $this->locale;
  1047. }
  1048. public function isMethod($method)
  1049. {
  1050. return $this->getMethod() === strtoupper($method);
  1051. }
  1052. public function isMethodSafe()
  1053. {
  1054. return in_array($this->getMethod(), array('GET','HEAD','OPTIONS','TRACE'));
  1055. }
  1056. public function getContent($asResource = false)
  1057. {
  1058. $currentContentIsResource = is_resource($this->content);
  1059. if (PHP_VERSION_ID < 50600 && false === $this->content) {
  1060. throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
  1061. }
  1062. if (true === $asResource) {
  1063. if ($currentContentIsResource) {
  1064. rewind($this->content);
  1065. return $this->content;
  1066. }
  1067. if (is_string($this->content)) {
  1068. $resource = fopen('php://temp','r+');
  1069. fwrite($resource, $this->content);
  1070. rewind($resource);
  1071. return $resource;
  1072. }
  1073. $this->content = false;
  1074. return fopen('php://input','rb');
  1075. }
  1076. if ($currentContentIsResource) {
  1077. rewind($this->content);
  1078. return stream_get_contents($this->content);
  1079. }
  1080. if (null === $this->content || false === $this->content) {
  1081. $this->content = file_get_contents('php://input');
  1082. }
  1083. return $this->content;
  1084. }
  1085. public function getETags()
  1086. {
  1087. return preg_split('/\s*,\s*/', $this->headers->get('if_none_match'), null, PREG_SPLIT_NO_EMPTY);
  1088. }
  1089. public function isNoCache()
  1090. {
  1091. return $this->headers->hasCacheControlDirective('no-cache') ||'no-cache'== $this->headers->get('Pragma');
  1092. }
  1093. public function getPreferredLanguage(array $locales = null)
  1094. {
  1095. $preferredLanguages = $this->getLanguages();
  1096. if (empty($locales)) {
  1097. return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
  1098. }
  1099. if (!$preferredLanguages) {
  1100. return $locales[0];
  1101. }
  1102. $extendedPreferredLanguages = array();
  1103. foreach ($preferredLanguages as $language) {
  1104. $extendedPreferredLanguages[] = $language;
  1105. if (false !== $position = strpos($language,'_')) {
  1106. $superLanguage = substr($language, 0, $position);
  1107. if (!in_array($superLanguage, $preferredLanguages)) {
  1108. $extendedPreferredLanguages[] = $superLanguage;
  1109. }
  1110. }
  1111. }
  1112. $preferredLanguages = array_values(array_intersect($extendedPreferredLanguages, $locales));
  1113. return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
  1114. }
  1115. public function getLanguages()
  1116. {
  1117. if (null !== $this->languages) {
  1118. return $this->languages;
  1119. }
  1120. $languages = AcceptHeader::fromString($this->headers->get('Accept-Language'))->all();
  1121. $this->languages = array();
  1122. foreach ($languages as $lang => $acceptHeaderItem) {
  1123. if (false !== strpos($lang,'-')) {
  1124. $codes = explode('-', $lang);
  1125. if ('i'=== $codes[0]) {
  1126. if (count($codes) > 1) {
  1127. $lang = $codes[1];
  1128. }
  1129. } else {
  1130. for ($i = 0, $max = count($codes); $i < $max; ++$i) {
  1131. if ($i === 0) {
  1132. $lang = strtolower($codes[0]);
  1133. } else {
  1134. $lang .='_'.strtoupper($codes[$i]);
  1135. }
  1136. }
  1137. }
  1138. }
  1139. $this->languages[] = $lang;
  1140. }
  1141. return $this->languages;
  1142. }
  1143. public function getCharsets()
  1144. {
  1145. if (null !== $this->charsets) {
  1146. return $this->charsets;
  1147. }
  1148. return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all());
  1149. }
  1150. public function getEncodings()
  1151. {
  1152. if (null !== $this->encodings) {
  1153. return $this->encodings;
  1154. }
  1155. return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all());
  1156. }
  1157. public function getAcceptableContentTypes()
  1158. {
  1159. if (null !== $this->acceptableContentTypes) {
  1160. return $this->acceptableContentTypes;
  1161. }
  1162. return $this->acceptableContentTypes = array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all());
  1163. }
  1164. public function isXmlHttpRequest()
  1165. {
  1166. return'XMLHttpRequest'== $this->headers->get('X-Requested-With');
  1167. }
  1168. protected function prepareRequestUri()
  1169. {
  1170. $requestUri ='';
  1171. if ($this->headers->has('X_ORIGINAL_URL')) {
  1172. $requestUri = $this->headers->get('X_ORIGINAL_URL');
  1173. $this->headers->remove('X_ORIGINAL_URL');
  1174. $this->server->remove('HTTP_X_ORIGINAL_URL');
  1175. $this->server->remove('UNENCODED_URL');
  1176. $this->server->remove('IIS_WasUrlRewritten');
  1177. } elseif ($this->headers->has('X_REWRITE_URL')) {
  1178. $requestUri = $this->headers->get('X_REWRITE_URL');
  1179. $this->headers->remove('X_REWRITE_URL');
  1180. } elseif ($this->server->get('IIS_WasUrlRewritten') =='1'&& $this->server->get('UNENCODED_URL') !='') {
  1181. $requestUri = $this->server->get('UNENCODED_URL');
  1182. $this->server->remove('UNENCODED_URL');
  1183. $this->server->remove('IIS_WasUrlRewritten');
  1184. } elseif ($this->server->has('REQUEST_URI')) {
  1185. $requestUri = $this->server->get('REQUEST_URI');
  1186. $schemeAndHttpHost = $this->getSchemeAndHttpHost();
  1187. if (strpos($requestUri, $schemeAndHttpHost) === 0) {
  1188. $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
  1189. }
  1190. } elseif ($this->server->has('ORIG_PATH_INFO')) {
  1191. $requestUri = $this->server->get('ORIG_PATH_INFO');
  1192. if (''!= $this->server->get('QUERY_STRING')) {
  1193. $requestUri .='?'.$this->server->get('QUERY_STRING');
  1194. }
  1195. $this->server->remove('ORIG_PATH_INFO');
  1196. }
  1197. $this->server->set('REQUEST_URI', $requestUri);
  1198. return $requestUri;
  1199. }
  1200. protected function prepareBaseUrl()
  1201. {
  1202. $filename = basename($this->server->get('SCRIPT_FILENAME'));
  1203. if (basename($this->server->get('SCRIPT_NAME')) === $filename) {
  1204. $baseUrl = $this->server->get('SCRIPT_NAME');
  1205. } elseif (basename($this->server->get('PHP_SELF')) === $filename) {
  1206. $baseUrl = $this->server->get('PHP_SELF');
  1207. } elseif (basename($this->server->get('ORIG_SCRIPT_NAME')) === $filename) {
  1208. $baseUrl = $this->server->get('ORIG_SCRIPT_NAME'); } else {
  1209. $path = $this->server->get('PHP_SELF','');
  1210. $file = $this->server->get('SCRIPT_FILENAME','');
  1211. $segs = explode('/', trim($file,'/'));
  1212. $segs = array_reverse($segs);
  1213. $index = 0;
  1214. $last = count($segs);
  1215. $baseUrl ='';
  1216. do {
  1217. $seg = $segs[$index];
  1218. $baseUrl ='/'.$seg.$baseUrl;
  1219. ++$index;
  1220. } while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
  1221. }
  1222. $requestUri = $this->getRequestUri();
  1223. if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
  1224. return $prefix;
  1225. }
  1226. if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, rtrim(dirname($baseUrl),'/'.DIRECTORY_SEPARATOR).'/')) {
  1227. return rtrim($prefix,'/'.DIRECTORY_SEPARATOR);
  1228. }
  1229. $truncatedRequestUri = $requestUri;
  1230. if (false !== $pos = strpos($requestUri,'?')) {
  1231. $truncatedRequestUri = substr($requestUri, 0, $pos);
  1232. }
  1233. $basename = basename($baseUrl);
  1234. if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
  1235. return'';
  1236. }
  1237. if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && $pos !== 0) {
  1238. $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
  1239. }
  1240. return rtrim($baseUrl,'/'.DIRECTORY_SEPARATOR);
  1241. }
  1242. protected function prepareBasePath()
  1243. {
  1244. $filename = basename($this->server->get('SCRIPT_FILENAME'));
  1245. $baseUrl = $this->getBaseUrl();
  1246. if (empty($baseUrl)) {
  1247. return'';
  1248. }
  1249. if (basename($baseUrl) === $filename) {
  1250. $basePath = dirname($baseUrl);
  1251. } else {
  1252. $basePath = $baseUrl;
  1253. }
  1254. if ('\\'=== DIRECTORY_SEPARATOR) {
  1255. $basePath = str_replace('\\','/', $basePath);
  1256. }
  1257. return rtrim($basePath,'/');
  1258. }
  1259. protected function preparePathInfo()
  1260. {
  1261. $baseUrl = $this->getBaseUrl();
  1262. if (null === ($requestUri = $this->getRequestUri())) {
  1263. return'/';
  1264. }
  1265. if ($pos = strpos($requestUri,'?')) {
  1266. $requestUri = substr($requestUri, 0, $pos);
  1267. }
  1268. $pathInfo = substr($requestUri, strlen($baseUrl));
  1269. if (null !== $baseUrl && (false === $pathInfo ||''=== $pathInfo)) {
  1270. return'/';
  1271. } elseif (null === $baseUrl) {
  1272. return $requestUri;
  1273. }
  1274. return (string) $pathInfo;
  1275. }
  1276. protected static function initializeFormats()
  1277. {
  1278. 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'),'form'=> array('application/x-www-form-urlencoded'),
  1279. );
  1280. }
  1281. private function setPhpDefaultLocale($locale)
  1282. {
  1283. try {
  1284. if (class_exists('Locale', false)) {
  1285. \Locale::setDefault($locale);
  1286. }
  1287. } catch (\Exception $e) {
  1288. }
  1289. }
  1290. private function getUrlencodedPrefix($string, $prefix)
  1291. {
  1292. if (0 !== strpos(rawurldecode($string), $prefix)) {
  1293. return false;
  1294. }
  1295. $len = strlen($prefix);
  1296. if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $len), $string, $match)) {
  1297. return $match[0];
  1298. }
  1299. return false;
  1300. }
  1301. private static function createRequestFromFactory(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
  1302. {
  1303. if (self::$requestFactory) {
  1304. $request = call_user_func(self::$requestFactory, $query, $request, $attributes, $cookies, $files, $server, $content);
  1305. if (!$request instanceof self) {
  1306. throw new \LogicException('The Request factory must return an instance of Symfony\Component\HttpFoundation\Request.');
  1307. }
  1308. return $request;
  1309. }
  1310. return new static($query, $request, $attributes, $cookies, $files, $server, $content);
  1311. }
  1312. private function isFromTrustedProxy()
  1313. {
  1314. return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
  1315. }
  1316. private function normalizeAndFilterClientIps(array $clientIps, $ip)
  1317. {
  1318. $clientIps[] = $ip; $firstTrustedIp = null;
  1319. foreach ($clientIps as $key => $clientIp) {
  1320. if (preg_match('{((?:\d+\.){3}\d+)\:\d+}', $clientIp, $match)) {
  1321. $clientIps[$key] = $clientIp = $match[1];
  1322. }
  1323. if (!filter_var($clientIp, FILTER_VALIDATE_IP)) {
  1324. unset($clientIps[$key]);
  1325. continue;
  1326. }
  1327. if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
  1328. unset($clientIps[$key]);
  1329. if (null === $firstTrustedIp) {
  1330. $firstTrustedIp = $clientIp;
  1331. }
  1332. }
  1333. }
  1334. return $clientIps ? array_reverse($clientIps) : array($firstTrustedIp);
  1335. }
  1336. }
  1337. }
  1338. namespace Symfony\Component\HttpKernel
  1339. {
  1340. use Symfony\Component\HttpFoundation\Request;
  1341. use Symfony\Component\HttpFoundation\Response;
  1342. interface HttpKernelInterface
  1343. {
  1344. const MASTER_REQUEST = 1;
  1345. const SUB_REQUEST = 2;
  1346. public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
  1347. }
  1348. }
  1349. namespace Symfony\Component\HttpKernel
  1350. {
  1351. use Symfony\Component\DependencyInjection\ContainerInterface;
  1352. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  1353. use Symfony\Component\Config\Loader\LoaderInterface;
  1354. interface KernelInterface extends HttpKernelInterface, \Serializable
  1355. {
  1356. public function registerBundles();
  1357. public function registerContainerConfiguration(LoaderInterface $loader);
  1358. public function boot();
  1359. public function shutdown();
  1360. public function getBundles();
  1361. public function isClassInActiveBundle($class);
  1362. public function getBundle($name, $first = true);
  1363. public function locateResource($name, $dir = null, $first = true);
  1364. public function getName();
  1365. public function getEnvironment();
  1366. public function isDebug();
  1367. public function getRootDir();
  1368. public function getContainer();
  1369. public function getStartTime();
  1370. public function getCacheDir();
  1371. public function getLogDir();
  1372. public function getCharset();
  1373. }
  1374. }
  1375. namespace Symfony\Component\HttpKernel
  1376. {
  1377. use Symfony\Component\HttpFoundation\Request;
  1378. use Symfony\Component\HttpFoundation\Response;
  1379. interface TerminableInterface
  1380. {
  1381. public function terminate(Request $request, Response $response);
  1382. }
  1383. }
  1384. namespace Symfony\Component\HttpKernel
  1385. {
  1386. use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
  1387. use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
  1388. use Symfony\Component\DependencyInjection\ContainerInterface;
  1389. use Symfony\Component\DependencyInjection\ContainerBuilder;
  1390. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  1391. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  1392. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  1393. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  1394. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  1395. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  1396. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  1397. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  1398. use Symfony\Component\HttpFoundation\Request;
  1399. use Symfony\Component\HttpFoundation\Response;
  1400. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  1401. use Symfony\Component\HttpKernel\Config\EnvParametersResource;
  1402. use Symfony\Component\HttpKernel\Config\FileLocator;
  1403. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  1404. use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
  1405. use Symfony\Component\Config\Loader\LoaderResolver;
  1406. use Symfony\Component\Config\Loader\DelegatingLoader;
  1407. use Symfony\Component\Config\ConfigCache;
  1408. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  1409. abstract class Kernel implements KernelInterface, TerminableInterface
  1410. {
  1411. protected $bundles = array();
  1412. protected $bundleMap;
  1413. protected $container;
  1414. protected $rootDir;
  1415. protected $environment;
  1416. protected $debug;
  1417. protected $booted = false;
  1418. protected $name;
  1419. protected $startTime;
  1420. protected $loadClassCache;
  1421. const VERSION ='2.8.11';
  1422. const VERSION_ID = 20811;
  1423. const MAJOR_VERSION = 2;
  1424. const MINOR_VERSION = 8;
  1425. const RELEASE_VERSION = 11;
  1426. const EXTRA_VERSION ='';
  1427. const END_OF_MAINTENANCE ='11/2018';
  1428. const END_OF_LIFE ='11/2019';
  1429. public function __construct($environment, $debug)
  1430. {
  1431. $this->environment = $environment;
  1432. $this->debug = (bool) $debug;
  1433. $this->rootDir = $this->getRootDir();
  1434. $this->name = $this->getName();
  1435. if ($this->debug) {
  1436. $this->startTime = microtime(true);
  1437. }
  1438. $defClass = new \ReflectionMethod($this,'init');
  1439. $defClass = $defClass->getDeclaringClass()->name;
  1440. if (__CLASS__ !== $defClass) {
  1441. @trigger_error(sprintf('Calling the %s::init() method is deprecated since version 2.3 and will be removed in 3.0. Move your logic to the constructor method instead.', $defClass), E_USER_DEPRECATED);
  1442. $this->init();
  1443. }
  1444. }
  1445. public function init()
  1446. {
  1447. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Move your logic to the constructor method instead.', E_USER_DEPRECATED);
  1448. }
  1449. public function __clone()
  1450. {
  1451. if ($this->debug) {
  1452. $this->startTime = microtime(true);
  1453. }
  1454. $this->booted = false;
  1455. $this->container = null;
  1456. }
  1457. public function boot()
  1458. {
  1459. if (true === $this->booted) {
  1460. return;
  1461. }
  1462. if ($this->loadClassCache) {
  1463. $this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
  1464. }
  1465. $this->initializeBundles();
  1466. $this->initializeContainer();
  1467. foreach ($this->getBundles() as $bundle) {
  1468. $bundle->setContainer($this->container);
  1469. $bundle->boot();
  1470. }
  1471. $this->booted = true;
  1472. }
  1473. public function terminate(Request $request, Response $response)
  1474. {
  1475. if (false === $this->booted) {
  1476. return;
  1477. }
  1478. if ($this->getHttpKernel() instanceof TerminableInterface) {
  1479. $this->getHttpKernel()->terminate($request, $response);
  1480. }
  1481. }
  1482. public function shutdown()
  1483. {
  1484. if (false === $this->booted) {
  1485. return;
  1486. }
  1487. $this->booted = false;
  1488. foreach ($this->getBundles() as $bundle) {
  1489. $bundle->shutdown();
  1490. $bundle->setContainer(null);
  1491. }
  1492. $this->container = null;
  1493. }
  1494. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  1495. {
  1496. if (false === $this->booted) {
  1497. $this->boot();
  1498. }
  1499. return $this->getHttpKernel()->handle($request, $type, $catch);
  1500. }
  1501. protected function getHttpKernel()
  1502. {
  1503. return $this->container->get('http_kernel');
  1504. }
  1505. public function getBundles()
  1506. {
  1507. return $this->bundles;
  1508. }
  1509. public function isClassInActiveBundle($class)
  1510. {
  1511. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in version 3.0.', E_USER_DEPRECATED);
  1512. foreach ($this->getBundles() as $bundle) {
  1513. if (0 === strpos($class, $bundle->getNamespace())) {
  1514. return true;
  1515. }
  1516. }
  1517. return false;
  1518. }
  1519. public function getBundle($name, $first = true)
  1520. {
  1521. if (!isset($this->bundleMap[$name])) {
  1522. 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)));
  1523. }
  1524. if (true === $first) {
  1525. return $this->bundleMap[$name][0];
  1526. }
  1527. return $this->bundleMap[$name];
  1528. }
  1529. public function locateResource($name, $dir = null, $first = true)
  1530. {
  1531. if ('@'!== $name[0]) {
  1532. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  1533. }
  1534. if (false !== strpos($name,'..')) {
  1535. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  1536. }
  1537. $bundleName = substr($name, 1);
  1538. $path ='';
  1539. if (false !== strpos($bundleName,'/')) {
  1540. list($bundleName, $path) = explode('/', $bundleName, 2);
  1541. }
  1542. $isResource = 0 === strpos($path,'Resources') && null !== $dir;
  1543. $overridePath = substr($path, 9);
  1544. $resourceBundle = null;
  1545. $bundles = $this->getBundle($bundleName, false);
  1546. $files = array();
  1547. foreach ($bundles as $bundle) {
  1548. if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
  1549. if (null !== $resourceBundle) {
  1550. 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.',
  1551. $file,
  1552. $resourceBundle,
  1553. $dir.'/'.$bundles[0]->getName().$overridePath
  1554. ));
  1555. }
  1556. if ($first) {
  1557. return $file;
  1558. }
  1559. $files[] = $file;
  1560. }
  1561. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  1562. if ($first && !$isResource) {
  1563. return $file;
  1564. }
  1565. $files[] = $file;
  1566. $resourceBundle = $bundle->getName();
  1567. }
  1568. }
  1569. if (count($files) > 0) {
  1570. return $first && $isResource ? $files[0] : $files;
  1571. }
  1572. throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
  1573. }
  1574. public function getName()
  1575. {
  1576. if (null === $this->name) {
  1577. $this->name = preg_replace('/[^a-zA-Z0-9_]+/','', basename($this->rootDir));
  1578. }
  1579. return $this->name;
  1580. }
  1581. public function getEnvironment()
  1582. {
  1583. return $this->environment;
  1584. }
  1585. public function isDebug()
  1586. {
  1587. return $this->debug;
  1588. }
  1589. public function getRootDir()
  1590. {
  1591. if (null === $this->rootDir) {
  1592. $r = new \ReflectionObject($this);
  1593. $this->rootDir = dirname($r->getFileName());
  1594. }
  1595. return $this->rootDir;
  1596. }
  1597. public function getContainer()
  1598. {
  1599. return $this->container;
  1600. }
  1601. public function loadClassCache($name ='classes', $extension ='.php')
  1602. {
  1603. $this->loadClassCache = array($name, $extension);
  1604. }
  1605. public function setClassCache(array $classes)
  1606. {
  1607. file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
  1608. }
  1609. public function getStartTime()
  1610. {
  1611. return $this->debug ? $this->startTime : -INF;
  1612. }
  1613. public function getCacheDir()
  1614. {
  1615. return $this->rootDir.'/cache/'.$this->environment;
  1616. }
  1617. public function getLogDir()
  1618. {
  1619. return $this->rootDir.'/logs';
  1620. }
  1621. public function getCharset()
  1622. {
  1623. return'UTF-8';
  1624. }
  1625. protected function doLoadClassCache($name, $extension)
  1626. {
  1627. if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
  1628. ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
  1629. }
  1630. }
  1631. protected function initializeBundles()
  1632. {
  1633. $this->bundles = array();
  1634. $topMostBundles = array();
  1635. $directChildren = array();
  1636. foreach ($this->registerBundles() as $bundle) {
  1637. $name = $bundle->getName();
  1638. if (isset($this->bundles[$name])) {
  1639. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  1640. }
  1641. $this->bundles[$name] = $bundle;
  1642. if ($parentName = $bundle->getParent()) {
  1643. if (isset($directChildren[$parentName])) {
  1644. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  1645. }
  1646. if ($parentName == $name) {
  1647. throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
  1648. }
  1649. $directChildren[$parentName] = $name;
  1650. } else {
  1651. $topMostBundles[$name] = $bundle;
  1652. }
  1653. }
  1654. if (!empty($directChildren) && count($diff = array_diff_key($directChildren, $this->bundles))) {
  1655. $diff = array_keys($diff);
  1656. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  1657. }
  1658. $this->bundleMap = array();
  1659. foreach ($topMostBundles as $name => $bundle) {
  1660. $bundleMap = array($bundle);
  1661. $hierarchy = array($name);
  1662. while (isset($directChildren[$name])) {
  1663. $name = $directChildren[$name];
  1664. array_unshift($bundleMap, $this->bundles[$name]);
  1665. $hierarchy[] = $name;
  1666. }
  1667. foreach ($hierarchy as $hierarchyBundle) {
  1668. $this->bundleMap[$hierarchyBundle] = $bundleMap;
  1669. array_pop($bundleMap);
  1670. }
  1671. }
  1672. }
  1673. protected function getContainerClass()
  1674. {
  1675. return $this->name.ucfirst($this->environment).($this->debug ?'Debug':'').'ProjectContainer';
  1676. }
  1677. protected function getContainerBaseClass()
  1678. {
  1679. return'Container';
  1680. }
  1681. protected function initializeContainer()
  1682. {
  1683. $class = $this->getContainerClass();
  1684. $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
  1685. $fresh = true;
  1686. if (!$cache->isFresh()) {
  1687. $container = $this->buildContainer();
  1688. $container->compile();
  1689. $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
  1690. $fresh = false;
  1691. }
  1692. require_once $cache->getPath();
  1693. $this->container = new $class();
  1694. $this->container->set('kernel', $this);
  1695. if (!$fresh && $this->container->has('cache_warmer')) {
  1696. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  1697. }
  1698. }
  1699. protected function getKernelParameters()
  1700. {
  1701. $bundles = array();
  1702. foreach ($this->bundles as $name => $bundle) {
  1703. $bundles[$name] = get_class($bundle);
  1704. }
  1705. return array_merge(
  1706. 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(),
  1707. ),
  1708. $this->getEnvParameters()
  1709. );
  1710. }
  1711. protected function getEnvParameters()
  1712. {
  1713. $parameters = array();
  1714. foreach ($_SERVER as $key => $value) {
  1715. if (0 === strpos($key,'SYMFONY__')) {
  1716. $parameters[strtolower(str_replace('__','.', substr($key, 9)))] = $value;
  1717. }
  1718. }
  1719. return $parameters;
  1720. }
  1721. protected function buildContainer()
  1722. {
  1723. foreach (array('cache'=> $this->getCacheDir(),'logs'=> $this->getLogDir()) as $name => $dir) {
  1724. if (!is_dir($dir)) {
  1725. if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
  1726. throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
  1727. }
  1728. } elseif (!is_writable($dir)) {
  1729. throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  1730. }
  1731. }
  1732. $container = $this->getContainerBuilder();
  1733. $container->addObjectResource($this);
  1734. $this->prepareContainer($container);
  1735. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  1736. $container->merge($cont);
  1737. }
  1738. $container->addCompilerPass(new AddClassesToCachePass($this));
  1739. $container->addResource(new EnvParametersResource('SYMFONY__'));
  1740. return $container;
  1741. }
  1742. protected function prepareContainer(ContainerBuilder $container)
  1743. {
  1744. $extensions = array();
  1745. foreach ($this->bundles as $bundle) {
  1746. if ($extension = $bundle->getContainerExtension()) {
  1747. $container->registerExtension($extension);
  1748. $extensions[] = $extension->getAlias();
  1749. }
  1750. if ($this->debug) {
  1751. $container->addObjectResource($bundle);
  1752. }
  1753. }
  1754. foreach ($this->bundles as $bundle) {
  1755. $bundle->build($container);
  1756. }
  1757. $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  1758. }
  1759. protected function getContainerBuilder()
  1760. {
  1761. $container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  1762. if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
  1763. $container->setProxyInstantiator(new RuntimeInstantiator());
  1764. }
  1765. return $container;
  1766. }
  1767. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
  1768. {
  1769. $dumper = new PhpDumper($container);
  1770. if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) {
  1771. $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath())));
  1772. }
  1773. $content = $dumper->dump(array('class'=> $class,'base_class'=> $baseClass,'file'=> $cache->getPath(),'debug'=> $this->debug));
  1774. $cache->write($content, $container->getResources());
  1775. }
  1776. protected function getContainerLoader(ContainerInterface $container)
  1777. {
  1778. $locator = new FileLocator($this);
  1779. $resolver = new LoaderResolver(array(
  1780. new XmlFileLoader($container, $locator),
  1781. new YamlFileLoader($container, $locator),
  1782. new IniFileLoader($container, $locator),
  1783. new PhpFileLoader($container, $locator),
  1784. new DirectoryLoader($container, $locator),
  1785. new ClosureLoader($container),
  1786. ));
  1787. return new DelegatingLoader($resolver);
  1788. }
  1789. public static function stripComments($source)
  1790. {
  1791. if (!function_exists('token_get_all')) {
  1792. return $source;
  1793. }
  1794. $rawChunk ='';
  1795. $output ='';
  1796. $tokens = token_get_all($source);
  1797. $ignoreSpace = false;
  1798. for ($i = 0; isset($tokens[$i]); ++$i) {
  1799. $token = $tokens[$i];
  1800. if (!isset($token[1]) ||'b"'=== $token) {
  1801. $rawChunk .= $token;
  1802. } elseif (T_START_HEREDOC === $token[0]) {
  1803. $output .= $rawChunk.$token[1];
  1804. do {
  1805. $token = $tokens[++$i];
  1806. $output .= isset($token[1]) &&'b"'!== $token ? $token[1] : $token;
  1807. } while ($token[0] !== T_END_HEREDOC);
  1808. $rawChunk ='';
  1809. } elseif (T_WHITESPACE === $token[0]) {
  1810. if ($ignoreSpace) {
  1811. $ignoreSpace = false;
  1812. continue;
  1813. }
  1814. $rawChunk .= preg_replace(array('/\n{2,}/S'),"\n", $token[1]);
  1815. } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  1816. $ignoreSpace = true;
  1817. } else {
  1818. $rawChunk .= $token[1];
  1819. if (T_OPEN_TAG === $token[0]) {
  1820. $ignoreSpace = true;
  1821. }
  1822. }
  1823. }
  1824. $output .= $rawChunk;
  1825. if (PHP_VERSION_ID >= 70000) {
  1826. unset($tokens, $rawChunk);
  1827. gc_mem_caches();
  1828. }
  1829. return $output;
  1830. }
  1831. public function serialize()
  1832. {
  1833. return serialize(array($this->environment, $this->debug));
  1834. }
  1835. public function unserialize($data)
  1836. {
  1837. list($environment, $debug) = unserialize($data);
  1838. $this->__construct($environment, $debug);
  1839. }
  1840. }
  1841. }
  1842. namespace Symfony\Component\ClassLoader
  1843. {
  1844. class ApcClassLoader
  1845. {
  1846. private $prefix;
  1847. protected $decorated;
  1848. public function __construct($prefix, $decorated)
  1849. {
  1850. if (!function_exists('apcu_fetch')) {
  1851. throw new \RuntimeException('Unable to use ApcClassLoader as APC is not installed.');
  1852. }
  1853. if (!method_exists($decorated,'findFile')) {
  1854. throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
  1855. }
  1856. $this->prefix = $prefix;
  1857. $this->decorated = $decorated;
  1858. }
  1859. public function register($prepend = false)
  1860. {
  1861. spl_autoload_register(array($this,'loadClass'), true, $prepend);
  1862. }
  1863. public function unregister()
  1864. {
  1865. spl_autoload_unregister(array($this,'loadClass'));
  1866. }
  1867. public function loadClass($class)
  1868. {
  1869. if ($file = $this->findFile($class)) {
  1870. require $file;
  1871. return true;
  1872. }
  1873. }
  1874. public function findFile($class)
  1875. {
  1876. $file = apcu_fetch($this->prefix.$class, $success);
  1877. if (!$success) {
  1878. apcu_store($this->prefix.$class, $file = $this->decorated->findFile($class) ?: null);
  1879. }
  1880. return $file;
  1881. }
  1882. public function __call($method, $args)
  1883. {
  1884. return call_user_func_array(array($this->decorated, $method), $args);
  1885. }
  1886. }
  1887. }