bootstrap.php.cache 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361
  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) {
  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\HttpFoundation
  1339. {
  1340. class Response
  1341. {
  1342. const HTTP_CONTINUE = 100;
  1343. const HTTP_SWITCHING_PROTOCOLS = 101;
  1344. const HTTP_PROCESSING = 102; const HTTP_OK = 200;
  1345. const HTTP_CREATED = 201;
  1346. const HTTP_ACCEPTED = 202;
  1347. const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
  1348. const HTTP_NO_CONTENT = 204;
  1349. const HTTP_RESET_CONTENT = 205;
  1350. const HTTP_PARTIAL_CONTENT = 206;
  1351. const HTTP_MULTI_STATUS = 207; const HTTP_ALREADY_REPORTED = 208; const HTTP_IM_USED = 226; const HTTP_MULTIPLE_CHOICES = 300;
  1352. const HTTP_MOVED_PERMANENTLY = 301;
  1353. const HTTP_FOUND = 302;
  1354. const HTTP_SEE_OTHER = 303;
  1355. const HTTP_NOT_MODIFIED = 304;
  1356. const HTTP_USE_PROXY = 305;
  1357. const HTTP_RESERVED = 306;
  1358. const HTTP_TEMPORARY_REDIRECT = 307;
  1359. const HTTP_PERMANENTLY_REDIRECT = 308; const HTTP_BAD_REQUEST = 400;
  1360. const HTTP_UNAUTHORIZED = 401;
  1361. const HTTP_PAYMENT_REQUIRED = 402;
  1362. const HTTP_FORBIDDEN = 403;
  1363. const HTTP_NOT_FOUND = 404;
  1364. const HTTP_METHOD_NOT_ALLOWED = 405;
  1365. const HTTP_NOT_ACCEPTABLE = 406;
  1366. const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
  1367. const HTTP_REQUEST_TIMEOUT = 408;
  1368. const HTTP_CONFLICT = 409;
  1369. const HTTP_GONE = 410;
  1370. const HTTP_LENGTH_REQUIRED = 411;
  1371. const HTTP_PRECONDITION_FAILED = 412;
  1372. const HTTP_REQUEST_ENTITY_TOO_LARGE = 413;
  1373. const HTTP_REQUEST_URI_TOO_LONG = 414;
  1374. const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
  1375. const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
  1376. const HTTP_EXPECTATION_FAILED = 417;
  1377. const HTTP_I_AM_A_TEAPOT = 418; const HTTP_MISDIRECTED_REQUEST = 421; const HTTP_UNPROCESSABLE_ENTITY = 422; const HTTP_LOCKED = 423; const HTTP_FAILED_DEPENDENCY = 424; const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; const HTTP_UPGRADE_REQUIRED = 426; const HTTP_PRECONDITION_REQUIRED = 428; const HTTP_TOO_MANY_REQUESTS = 429; const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451;
  1378. const HTTP_INTERNAL_SERVER_ERROR = 500;
  1379. const HTTP_NOT_IMPLEMENTED = 501;
  1380. const HTTP_BAD_GATEWAY = 502;
  1381. const HTTP_SERVICE_UNAVAILABLE = 503;
  1382. const HTTP_GATEWAY_TIMEOUT = 504;
  1383. const HTTP_VERSION_NOT_SUPPORTED = 505;
  1384. 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;
  1385. public $headers;
  1386. protected $content;
  1387. protected $version;
  1388. protected $statusCode;
  1389. protected $statusText;
  1390. protected $charset;
  1391. public static $statusTexts = array(
  1392. 100 =>'Continue',
  1393. 101 =>'Switching Protocols',
  1394. 102 =>'Processing', 200 =>'OK',
  1395. 201 =>'Created',
  1396. 202 =>'Accepted',
  1397. 203 =>'Non-Authoritative Information',
  1398. 204 =>'No Content',
  1399. 205 =>'Reset Content',
  1400. 206 =>'Partial Content',
  1401. 207 =>'Multi-Status', 208 =>'Already Reported', 226 =>'IM Used', 300 =>'Multiple Choices',
  1402. 301 =>'Moved Permanently',
  1403. 302 =>'Found',
  1404. 303 =>'See Other',
  1405. 304 =>'Not Modified',
  1406. 305 =>'Use Proxy',
  1407. 307 =>'Temporary Redirect',
  1408. 308 =>'Permanent Redirect', 400 =>'Bad Request',
  1409. 401 =>'Unauthorized',
  1410. 402 =>'Payment Required',
  1411. 403 =>'Forbidden',
  1412. 404 =>'Not Found',
  1413. 405 =>'Method Not Allowed',
  1414. 406 =>'Not Acceptable',
  1415. 407 =>'Proxy Authentication Required',
  1416. 408 =>'Request Timeout',
  1417. 409 =>'Conflict',
  1418. 410 =>'Gone',
  1419. 411 =>'Length Required',
  1420. 412 =>'Precondition Failed',
  1421. 413 =>'Payload Too Large',
  1422. 414 =>'URI Too Long',
  1423. 415 =>'Unsupported Media Type',
  1424. 416 =>'Range Not Satisfiable',
  1425. 417 =>'Expectation Failed',
  1426. 418 =>'I\'m a teapot', 421 =>'Misdirected Request', 422 =>'Unprocessable Entity', 423 =>'Locked', 424 =>'Failed Dependency', 425 =>'Reserved for WebDAV advanced collections expired proposal', 426 =>'Upgrade Required', 428 =>'Precondition Required', 429 =>'Too Many Requests', 431 =>'Request Header Fields Too Large', 451 =>'Unavailable For Legal Reasons', 500 =>'Internal Server Error',
  1427. 501 =>'Not Implemented',
  1428. 502 =>'Bad Gateway',
  1429. 503 =>'Service Unavailable',
  1430. 504 =>'Gateway Timeout',
  1431. 505 =>'HTTP Version Not Supported',
  1432. 506 =>'Variant Also Negotiates (Experimental)', 507 =>'Insufficient Storage', 508 =>'Loop Detected', 510 =>'Not Extended', 511 =>'Network Authentication Required', );
  1433. public function __construct($content ='', $status = 200, $headers = array())
  1434. {
  1435. $this->headers = new ResponseHeaderBag($headers);
  1436. $this->setContent($content);
  1437. $this->setStatusCode($status);
  1438. $this->setProtocolVersion('1.0');
  1439. }
  1440. public static function create($content ='', $status = 200, $headers = array())
  1441. {
  1442. return new static($content, $status, $headers);
  1443. }
  1444. public function __toString()
  1445. {
  1446. return
  1447. sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
  1448. $this->headers."\r\n".
  1449. $this->getContent();
  1450. }
  1451. public function __clone()
  1452. {
  1453. $this->headers = clone $this->headers;
  1454. }
  1455. public function prepare(Request $request)
  1456. {
  1457. $headers = $this->headers;
  1458. if ($this->isInformational() || $this->isEmpty()) {
  1459. $this->setContent(null);
  1460. $headers->remove('Content-Type');
  1461. $headers->remove('Content-Length');
  1462. } else {
  1463. if (!$headers->has('Content-Type')) {
  1464. $format = $request->getRequestFormat();
  1465. if (null !== $format && $mimeType = $request->getMimeType($format)) {
  1466. $headers->set('Content-Type', $mimeType);
  1467. }
  1468. }
  1469. $charset = $this->charset ?:'UTF-8';
  1470. if (!$headers->has('Content-Type')) {
  1471. $headers->set('Content-Type','text/html; charset='.$charset);
  1472. } elseif (0 === stripos($headers->get('Content-Type'),'text/') && false === stripos($headers->get('Content-Type'),'charset')) {
  1473. $headers->set('Content-Type', $headers->get('Content-Type').'; charset='.$charset);
  1474. }
  1475. if ($headers->has('Transfer-Encoding')) {
  1476. $headers->remove('Content-Length');
  1477. }
  1478. if ($request->isMethod('HEAD')) {
  1479. $length = $headers->get('Content-Length');
  1480. $this->setContent(null);
  1481. if ($length) {
  1482. $headers->set('Content-Length', $length);
  1483. }
  1484. }
  1485. }
  1486. if ('HTTP/1.0'!= $request->server->get('SERVER_PROTOCOL')) {
  1487. $this->setProtocolVersion('1.1');
  1488. }
  1489. if ('1.0'== $this->getProtocolVersion() &&'no-cache'== $this->headers->get('Cache-Control')) {
  1490. $this->headers->set('pragma','no-cache');
  1491. $this->headers->set('expires', -1);
  1492. }
  1493. $this->ensureIEOverSSLCompatibility($request);
  1494. return $this;
  1495. }
  1496. public function sendHeaders()
  1497. {
  1498. if (headers_sent()) {
  1499. return $this;
  1500. }
  1501. if (!$this->headers->has('Date')) {
  1502. $this->setDate(\DateTime::createFromFormat('U', time()));
  1503. }
  1504. foreach ($this->headers->allPreserveCase() as $name => $values) {
  1505. foreach ($values as $value) {
  1506. header($name.': '.$value, false, $this->statusCode);
  1507. }
  1508. }
  1509. header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
  1510. foreach ($this->headers->getCookies() as $cookie) {
  1511. setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
  1512. }
  1513. return $this;
  1514. }
  1515. public function sendContent()
  1516. {
  1517. echo $this->content;
  1518. return $this;
  1519. }
  1520. public function send()
  1521. {
  1522. $this->sendHeaders();
  1523. $this->sendContent();
  1524. if (function_exists('fastcgi_finish_request')) {
  1525. fastcgi_finish_request();
  1526. } elseif ('cli'!== PHP_SAPI) {
  1527. static::closeOutputBuffers(0, true);
  1528. }
  1529. return $this;
  1530. }
  1531. public function setContent($content)
  1532. {
  1533. if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content,'__toString'))) {
  1534. throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
  1535. }
  1536. $this->content = (string) $content;
  1537. return $this;
  1538. }
  1539. public function getContent()
  1540. {
  1541. return $this->content;
  1542. }
  1543. public function setProtocolVersion($version)
  1544. {
  1545. $this->version = $version;
  1546. return $this;
  1547. }
  1548. public function getProtocolVersion()
  1549. {
  1550. return $this->version;
  1551. }
  1552. public function setStatusCode($code, $text = null)
  1553. {
  1554. $this->statusCode = $code = (int) $code;
  1555. if ($this->isInvalid()) {
  1556. throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
  1557. }
  1558. if (null === $text) {
  1559. $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] :'unknown status';
  1560. return $this;
  1561. }
  1562. if (false === $text) {
  1563. $this->statusText ='';
  1564. return $this;
  1565. }
  1566. $this->statusText = $text;
  1567. return $this;
  1568. }
  1569. public function getStatusCode()
  1570. {
  1571. return $this->statusCode;
  1572. }
  1573. public function setCharset($charset)
  1574. {
  1575. $this->charset = $charset;
  1576. return $this;
  1577. }
  1578. public function getCharset()
  1579. {
  1580. return $this->charset;
  1581. }
  1582. public function isCacheable()
  1583. {
  1584. if (!in_array($this->statusCode, array(200, 203, 300, 301, 302, 404, 410))) {
  1585. return false;
  1586. }
  1587. if ($this->headers->hasCacheControlDirective('no-store') || $this->headers->getCacheControlDirective('private')) {
  1588. return false;
  1589. }
  1590. return $this->isValidateable() || $this->isFresh();
  1591. }
  1592. public function isFresh()
  1593. {
  1594. return $this->getTtl() > 0;
  1595. }
  1596. public function isValidateable()
  1597. {
  1598. return $this->headers->has('Last-Modified') || $this->headers->has('ETag');
  1599. }
  1600. public function setPrivate()
  1601. {
  1602. $this->headers->removeCacheControlDirective('public');
  1603. $this->headers->addCacheControlDirective('private');
  1604. return $this;
  1605. }
  1606. public function setPublic()
  1607. {
  1608. $this->headers->addCacheControlDirective('public');
  1609. $this->headers->removeCacheControlDirective('private');
  1610. return $this;
  1611. }
  1612. public function mustRevalidate()
  1613. {
  1614. return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->hasCacheControlDirective('proxy-revalidate');
  1615. }
  1616. public function getDate()
  1617. {
  1618. if (!$this->headers->has('Date')) {
  1619. $this->setDate(\DateTime::createFromFormat('U', time()));
  1620. }
  1621. return $this->headers->getDate('Date');
  1622. }
  1623. public function setDate(\DateTime $date)
  1624. {
  1625. $date->setTimezone(new \DateTimeZone('UTC'));
  1626. $this->headers->set('Date', $date->format('D, d M Y H:i:s').' GMT');
  1627. return $this;
  1628. }
  1629. public function getAge()
  1630. {
  1631. if (null !== $age = $this->headers->get('Age')) {
  1632. return (int) $age;
  1633. }
  1634. return max(time() - $this->getDate()->format('U'), 0);
  1635. }
  1636. public function expire()
  1637. {
  1638. if ($this->isFresh()) {
  1639. $this->headers->set('Age', $this->getMaxAge());
  1640. }
  1641. return $this;
  1642. }
  1643. public function getExpires()
  1644. {
  1645. try {
  1646. return $this->headers->getDate('Expires');
  1647. } catch (\RuntimeException $e) {
  1648. return \DateTime::createFromFormat(DATE_RFC2822,'Sat, 01 Jan 00 00:00:00 +0000');
  1649. }
  1650. }
  1651. public function setExpires(\DateTime $date = null)
  1652. {
  1653. if (null === $date) {
  1654. $this->headers->remove('Expires');
  1655. } else {
  1656. $date = clone $date;
  1657. $date->setTimezone(new \DateTimeZone('UTC'));
  1658. $this->headers->set('Expires', $date->format('D, d M Y H:i:s').' GMT');
  1659. }
  1660. return $this;
  1661. }
  1662. public function getMaxAge()
  1663. {
  1664. if ($this->headers->hasCacheControlDirective('s-maxage')) {
  1665. return (int) $this->headers->getCacheControlDirective('s-maxage');
  1666. }
  1667. if ($this->headers->hasCacheControlDirective('max-age')) {
  1668. return (int) $this->headers->getCacheControlDirective('max-age');
  1669. }
  1670. if (null !== $this->getExpires()) {
  1671. return $this->getExpires()->format('U') - $this->getDate()->format('U');
  1672. }
  1673. }
  1674. public function setMaxAge($value)
  1675. {
  1676. $this->headers->addCacheControlDirective('max-age', $value);
  1677. return $this;
  1678. }
  1679. public function setSharedMaxAge($value)
  1680. {
  1681. $this->setPublic();
  1682. $this->headers->addCacheControlDirective('s-maxage', $value);
  1683. return $this;
  1684. }
  1685. public function getTtl()
  1686. {
  1687. if (null !== $maxAge = $this->getMaxAge()) {
  1688. return $maxAge - $this->getAge();
  1689. }
  1690. }
  1691. public function setTtl($seconds)
  1692. {
  1693. $this->setSharedMaxAge($this->getAge() + $seconds);
  1694. return $this;
  1695. }
  1696. public function setClientTtl($seconds)
  1697. {
  1698. $this->setMaxAge($this->getAge() + $seconds);
  1699. return $this;
  1700. }
  1701. public function getLastModified()
  1702. {
  1703. return $this->headers->getDate('Last-Modified');
  1704. }
  1705. public function setLastModified(\DateTime $date = null)
  1706. {
  1707. if (null === $date) {
  1708. $this->headers->remove('Last-Modified');
  1709. } else {
  1710. $date = clone $date;
  1711. $date->setTimezone(new \DateTimeZone('UTC'));
  1712. $this->headers->set('Last-Modified', $date->format('D, d M Y H:i:s').' GMT');
  1713. }
  1714. return $this;
  1715. }
  1716. public function getEtag()
  1717. {
  1718. return $this->headers->get('ETag');
  1719. }
  1720. public function setEtag($etag = null, $weak = false)
  1721. {
  1722. if (null === $etag) {
  1723. $this->headers->remove('Etag');
  1724. } else {
  1725. if (0 !== strpos($etag,'"')) {
  1726. $etag ='"'.$etag.'"';
  1727. }
  1728. $this->headers->set('ETag', (true === $weak ?'W/':'').$etag);
  1729. }
  1730. return $this;
  1731. }
  1732. public function setCache(array $options)
  1733. {
  1734. if ($diff = array_diff(array_keys($options), array('etag','last_modified','max_age','s_maxage','private','public'))) {
  1735. throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
  1736. }
  1737. if (isset($options['etag'])) {
  1738. $this->setEtag($options['etag']);
  1739. }
  1740. if (isset($options['last_modified'])) {
  1741. $this->setLastModified($options['last_modified']);
  1742. }
  1743. if (isset($options['max_age'])) {
  1744. $this->setMaxAge($options['max_age']);
  1745. }
  1746. if (isset($options['s_maxage'])) {
  1747. $this->setSharedMaxAge($options['s_maxage']);
  1748. }
  1749. if (isset($options['public'])) {
  1750. if ($options['public']) {
  1751. $this->setPublic();
  1752. } else {
  1753. $this->setPrivate();
  1754. }
  1755. }
  1756. if (isset($options['private'])) {
  1757. if ($options['private']) {
  1758. $this->setPrivate();
  1759. } else {
  1760. $this->setPublic();
  1761. }
  1762. }
  1763. return $this;
  1764. }
  1765. public function setNotModified()
  1766. {
  1767. $this->setStatusCode(304);
  1768. $this->setContent(null);
  1769. foreach (array('Allow','Content-Encoding','Content-Language','Content-Length','Content-MD5','Content-Type','Last-Modified') as $header) {
  1770. $this->headers->remove($header);
  1771. }
  1772. return $this;
  1773. }
  1774. public function hasVary()
  1775. {
  1776. return null !== $this->headers->get('Vary');
  1777. }
  1778. public function getVary()
  1779. {
  1780. if (!$vary = $this->headers->get('Vary', null, false)) {
  1781. return array();
  1782. }
  1783. $ret = array();
  1784. foreach ($vary as $item) {
  1785. $ret = array_merge($ret, preg_split('/[\s,]+/', $item));
  1786. }
  1787. return $ret;
  1788. }
  1789. public function setVary($headers, $replace = true)
  1790. {
  1791. $this->headers->set('Vary', $headers, $replace);
  1792. return $this;
  1793. }
  1794. public function isNotModified(Request $request)
  1795. {
  1796. if (!$request->isMethodSafe()) {
  1797. return false;
  1798. }
  1799. $notModified = false;
  1800. $lastModified = $this->headers->get('Last-Modified');
  1801. $modifiedSince = $request->headers->get('If-Modified-Since');
  1802. if ($etags = $request->getETags()) {
  1803. $notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags);
  1804. }
  1805. if ($modifiedSince && $lastModified) {
  1806. $notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified);
  1807. }
  1808. if ($notModified) {
  1809. $this->setNotModified();
  1810. }
  1811. return $notModified;
  1812. }
  1813. public function isInvalid()
  1814. {
  1815. return $this->statusCode < 100 || $this->statusCode >= 600;
  1816. }
  1817. public function isInformational()
  1818. {
  1819. return $this->statusCode >= 100 && $this->statusCode < 200;
  1820. }
  1821. public function isSuccessful()
  1822. {
  1823. return $this->statusCode >= 200 && $this->statusCode < 300;
  1824. }
  1825. public function isRedirection()
  1826. {
  1827. return $this->statusCode >= 300 && $this->statusCode < 400;
  1828. }
  1829. public function isClientError()
  1830. {
  1831. return $this->statusCode >= 400 && $this->statusCode < 500;
  1832. }
  1833. public function isServerError()
  1834. {
  1835. return $this->statusCode >= 500 && $this->statusCode < 600;
  1836. }
  1837. public function isOk()
  1838. {
  1839. return 200 === $this->statusCode;
  1840. }
  1841. public function isForbidden()
  1842. {
  1843. return 403 === $this->statusCode;
  1844. }
  1845. public function isNotFound()
  1846. {
  1847. return 404 === $this->statusCode;
  1848. }
  1849. public function isRedirect($location = null)
  1850. {
  1851. return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
  1852. }
  1853. public function isEmpty()
  1854. {
  1855. return in_array($this->statusCode, array(204, 304));
  1856. }
  1857. public static function closeOutputBuffers($targetLevel, $flush)
  1858. {
  1859. $status = ob_get_status(true);
  1860. $level = count($status);
  1861. $flags = defined('PHP_OUTPUT_HANDLER_REMOVABLE') ? PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE) : -1;
  1862. while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || $flags === ($s['flags'] & $flags) : $s['del'])) {
  1863. if ($flush) {
  1864. ob_end_flush();
  1865. } else {
  1866. ob_end_clean();
  1867. }
  1868. }
  1869. }
  1870. protected function ensureIEOverSSLCompatibility(Request $request)
  1871. {
  1872. if (false !== stripos($this->headers->get('Content-Disposition'),'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
  1873. if ((int) preg_replace('/(MSIE )(.*?);/','$2', $match[0]) < 9) {
  1874. $this->headers->remove('Cache-Control');
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. namespace Symfony\Component\HttpFoundation
  1881. {
  1882. class ResponseHeaderBag extends HeaderBag
  1883. {
  1884. const COOKIES_FLAT ='flat';
  1885. const COOKIES_ARRAY ='array';
  1886. const DISPOSITION_ATTACHMENT ='attachment';
  1887. const DISPOSITION_INLINE ='inline';
  1888. protected $computedCacheControl = array();
  1889. protected $cookies = array();
  1890. protected $headerNames = array();
  1891. public function __construct(array $headers = array())
  1892. {
  1893. parent::__construct($headers);
  1894. if (!isset($this->headers['cache-control'])) {
  1895. $this->set('Cache-Control','');
  1896. }
  1897. }
  1898. public function __toString()
  1899. {
  1900. $cookies ='';
  1901. foreach ($this->getCookies() as $cookie) {
  1902. $cookies .='Set-Cookie: '.$cookie."\r\n";
  1903. }
  1904. ksort($this->headerNames);
  1905. return parent::__toString().$cookies;
  1906. }
  1907. public function allPreserveCase()
  1908. {
  1909. return array_combine($this->headerNames, $this->headers);
  1910. }
  1911. public function replace(array $headers = array())
  1912. {
  1913. $this->headerNames = array();
  1914. parent::replace($headers);
  1915. if (!isset($this->headers['cache-control'])) {
  1916. $this->set('Cache-Control','');
  1917. }
  1918. }
  1919. public function set($key, $values, $replace = true)
  1920. {
  1921. parent::set($key, $values, $replace);
  1922. $uniqueKey = str_replace('_','-', strtolower($key));
  1923. $this->headerNames[$uniqueKey] = $key;
  1924. if (in_array($uniqueKey, array('cache-control','etag','last-modified','expires'))) {
  1925. $computed = $this->computeCacheControlValue();
  1926. $this->headers['cache-control'] = array($computed);
  1927. $this->headerNames['cache-control'] ='Cache-Control';
  1928. $this->computedCacheControl = $this->parseCacheControl($computed);
  1929. }
  1930. }
  1931. public function remove($key)
  1932. {
  1933. parent::remove($key);
  1934. $uniqueKey = str_replace('_','-', strtolower($key));
  1935. unset($this->headerNames[$uniqueKey]);
  1936. if ('cache-control'=== $uniqueKey) {
  1937. $this->computedCacheControl = array();
  1938. }
  1939. }
  1940. public function hasCacheControlDirective($key)
  1941. {
  1942. return array_key_exists($key, $this->computedCacheControl);
  1943. }
  1944. public function getCacheControlDirective($key)
  1945. {
  1946. return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
  1947. }
  1948. public function setCookie(Cookie $cookie)
  1949. {
  1950. $this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
  1951. }
  1952. public function removeCookie($name, $path ='/', $domain = null)
  1953. {
  1954. if (null === $path) {
  1955. $path ='/';
  1956. }
  1957. unset($this->cookies[$domain][$path][$name]);
  1958. if (empty($this->cookies[$domain][$path])) {
  1959. unset($this->cookies[$domain][$path]);
  1960. if (empty($this->cookies[$domain])) {
  1961. unset($this->cookies[$domain]);
  1962. }
  1963. }
  1964. }
  1965. public function getCookies($format = self::COOKIES_FLAT)
  1966. {
  1967. if (!in_array($format, array(self::COOKIES_FLAT, self::COOKIES_ARRAY))) {
  1968. throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', array(self::COOKIES_FLAT, self::COOKIES_ARRAY))));
  1969. }
  1970. if (self::COOKIES_ARRAY === $format) {
  1971. return $this->cookies;
  1972. }
  1973. $flattenedCookies = array();
  1974. foreach ($this->cookies as $path) {
  1975. foreach ($path as $cookies) {
  1976. foreach ($cookies as $cookie) {
  1977. $flattenedCookies[] = $cookie;
  1978. }
  1979. }
  1980. }
  1981. return $flattenedCookies;
  1982. }
  1983. public function clearCookie($name, $path ='/', $domain = null, $secure = false, $httpOnly = true)
  1984. {
  1985. $this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly));
  1986. }
  1987. public function makeDisposition($disposition, $filename, $filenameFallback ='')
  1988. {
  1989. if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) {
  1990. throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
  1991. }
  1992. if (''== $filenameFallback) {
  1993. $filenameFallback = $filename;
  1994. }
  1995. if (!preg_match('/^[\x20-\x7e]*$/', $filenameFallback)) {
  1996. throw new \InvalidArgumentException('The filename fallback must only contain ASCII characters.');
  1997. }
  1998. if (false !== strpos($filenameFallback,'%')) {
  1999. throw new \InvalidArgumentException('The filename fallback cannot contain the "%" character.');
  2000. }
  2001. if (false !== strpos($filename,'/') || false !== strpos($filename,'\\') || false !== strpos($filenameFallback,'/') || false !== strpos($filenameFallback,'\\')) {
  2002. throw new \InvalidArgumentException('The filename and the fallback cannot contain the "/" and "\\" characters.');
  2003. }
  2004. $output = sprintf('%s; filename="%s"', $disposition, str_replace('"','\\"', $filenameFallback));
  2005. if ($filename !== $filenameFallback) {
  2006. $output .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
  2007. }
  2008. return $output;
  2009. }
  2010. protected function computeCacheControlValue()
  2011. {
  2012. if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
  2013. return'no-cache';
  2014. }
  2015. if (!$this->cacheControl) {
  2016. return'private, must-revalidate';
  2017. }
  2018. $header = $this->getCacheControlHeader();
  2019. if (isset($this->cacheControl['public']) || isset($this->cacheControl['private'])) {
  2020. return $header;
  2021. }
  2022. if (!isset($this->cacheControl['s-maxage'])) {
  2023. return $header.', private';
  2024. }
  2025. return $header;
  2026. }
  2027. }
  2028. }
  2029. namespace Symfony\Component\DependencyInjection
  2030. {
  2031. interface ContainerAwareInterface
  2032. {
  2033. public function setContainer(ContainerInterface $container = null);
  2034. }
  2035. }
  2036. namespace Symfony\Component\DependencyInjection
  2037. {
  2038. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  2039. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  2040. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  2041. interface ContainerInterface
  2042. {
  2043. const EXCEPTION_ON_INVALID_REFERENCE = 1;
  2044. const NULL_ON_INVALID_REFERENCE = 2;
  2045. const IGNORE_ON_INVALID_REFERENCE = 3;
  2046. const SCOPE_CONTAINER ='container';
  2047. const SCOPE_PROTOTYPE ='prototype';
  2048. public function set($id, $service, $scope = self::SCOPE_CONTAINER);
  2049. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
  2050. public function has($id);
  2051. public function getParameter($name);
  2052. public function hasParameter($name);
  2053. public function setParameter($name, $value);
  2054. public function enterScope($name);
  2055. public function leaveScope($name);
  2056. public function addScope(ScopeInterface $scope);
  2057. public function hasScope($name);
  2058. public function isScopeActive($name);
  2059. }
  2060. }
  2061. namespace Symfony\Component\DependencyInjection
  2062. {
  2063. interface IntrospectableContainerInterface extends ContainerInterface
  2064. {
  2065. public function initialized($id);
  2066. }
  2067. }
  2068. namespace Symfony\Component\DependencyInjection
  2069. {
  2070. interface ResettableContainerInterface extends ContainerInterface
  2071. {
  2072. public function reset();
  2073. }
  2074. }
  2075. namespace Symfony\Component\DependencyInjection
  2076. {
  2077. use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
  2078. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  2079. use Symfony\Component\DependencyInjection\Exception\LogicException;
  2080. use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  2081. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  2082. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  2083. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  2084. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  2085. use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
  2086. class Container implements IntrospectableContainerInterface, ResettableContainerInterface
  2087. {
  2088. protected $parameterBag;
  2089. protected $services = array();
  2090. protected $methodMap = array();
  2091. protected $aliases = array();
  2092. protected $scopes = array();
  2093. protected $scopeChildren = array();
  2094. protected $scopedServices = array();
  2095. protected $scopeStacks = array();
  2096. protected $loading = array();
  2097. private $underscoreMap = array('_'=>'','.'=>'_','\\'=>'_');
  2098. public function __construct(ParameterBagInterface $parameterBag = null)
  2099. {
  2100. $this->parameterBag = $parameterBag ?: new ParameterBag();
  2101. }
  2102. public function compile()
  2103. {
  2104. $this->parameterBag->resolve();
  2105. $this->parameterBag = new FrozenParameterBag($this->parameterBag->all());
  2106. }
  2107. public function isFrozen()
  2108. {
  2109. return $this->parameterBag instanceof FrozenParameterBag;
  2110. }
  2111. public function getParameterBag()
  2112. {
  2113. return $this->parameterBag;
  2114. }
  2115. public function getParameter($name)
  2116. {
  2117. return $this->parameterBag->get($name);
  2118. }
  2119. public function hasParameter($name)
  2120. {
  2121. return $this->parameterBag->has($name);
  2122. }
  2123. public function setParameter($name, $value)
  2124. {
  2125. $this->parameterBag->set($name, $value);
  2126. }
  2127. public function set($id, $service, $scope = self::SCOPE_CONTAINER)
  2128. {
  2129. if (!in_array($scope, array('container','request')) || ('request'=== $scope &&'request'!== $id)) {
  2130. @trigger_error('The concept of container scopes is deprecated since version 2.8 and will be removed in 3.0. Omit the third parameter.', E_USER_DEPRECATED);
  2131. }
  2132. if (self::SCOPE_PROTOTYPE === $scope) {
  2133. throw new InvalidArgumentException(sprintf('You cannot set service "%s" of scope "prototype".', $id));
  2134. }
  2135. $id = strtolower($id);
  2136. if ('service_container'=== $id) {
  2137. return;
  2138. }
  2139. if (self::SCOPE_CONTAINER !== $scope) {
  2140. if (!isset($this->scopedServices[$scope])) {
  2141. throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
  2142. }
  2143. $this->scopedServices[$scope][$id] = $service;
  2144. }
  2145. if (isset($this->aliases[$id])) {
  2146. unset($this->aliases[$id]);
  2147. }
  2148. $this->services[$id] = $service;
  2149. if (method_exists($this, $method ='synchronize'.strtr($id, $this->underscoreMap).'Service')) {
  2150. $this->$method();
  2151. }
  2152. if (null === $service) {
  2153. if (self::SCOPE_CONTAINER !== $scope) {
  2154. unset($this->scopedServices[$scope][$id]);
  2155. }
  2156. unset($this->services[$id]);
  2157. }
  2158. }
  2159. public function has($id)
  2160. {
  2161. for ($i = 2;;) {
  2162. if ('service_container'=== $id
  2163. || isset($this->aliases[$id])
  2164. || isset($this->services[$id])
  2165. || array_key_exists($id, $this->services)
  2166. ) {
  2167. return true;
  2168. }
  2169. if (--$i && $id !== $lcId = strtolower($id)) {
  2170. $id = $lcId;
  2171. } else {
  2172. return method_exists($this,'get'.strtr($id, $this->underscoreMap).'Service');
  2173. }
  2174. }
  2175. }
  2176. public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
  2177. {
  2178. for ($i = 2;;) {
  2179. if ('service_container'=== $id) {
  2180. return $this;
  2181. }
  2182. if (isset($this->aliases[$id])) {
  2183. $id = $this->aliases[$id];
  2184. }
  2185. if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
  2186. return $this->services[$id];
  2187. }
  2188. if (isset($this->loading[$id])) {
  2189. throw new ServiceCircularReferenceException($id, array_keys($this->loading));
  2190. }
  2191. if (isset($this->methodMap[$id])) {
  2192. $method = $this->methodMap[$id];
  2193. } elseif (--$i && $id !== $lcId = strtolower($id)) {
  2194. $id = $lcId;
  2195. continue;
  2196. } elseif (method_exists($this, $method ='get'.strtr($id, $this->underscoreMap).'Service')) {
  2197. } else {
  2198. if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
  2199. if (!$id) {
  2200. throw new ServiceNotFoundException($id);
  2201. }
  2202. $alternatives = array();
  2203. foreach ($this->services as $key => $associatedService) {
  2204. $lev = levenshtein($id, $key);
  2205. if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
  2206. $alternatives[] = $key;
  2207. }
  2208. }
  2209. throw new ServiceNotFoundException($id, null, null, $alternatives);
  2210. }
  2211. return;
  2212. }
  2213. $this->loading[$id] = true;
  2214. try {
  2215. $service = $this->$method();
  2216. } catch (\Exception $e) {
  2217. unset($this->loading[$id]);
  2218. unset($this->services[$id]);
  2219. if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
  2220. return;
  2221. }
  2222. throw $e;
  2223. } catch (\Throwable $e) {
  2224. unset($this->loading[$id]);
  2225. unset($this->services[$id]);
  2226. throw $e;
  2227. }
  2228. unset($this->loading[$id]);
  2229. return $service;
  2230. }
  2231. }
  2232. public function initialized($id)
  2233. {
  2234. $id = strtolower($id);
  2235. if ('service_container'=== $id) {
  2236. return true;
  2237. }
  2238. if (isset($this->aliases[$id])) {
  2239. $id = $this->aliases[$id];
  2240. }
  2241. return isset($this->services[$id]) || array_key_exists($id, $this->services);
  2242. }
  2243. public function reset()
  2244. {
  2245. if (!empty($this->scopedServices)) {
  2246. throw new LogicException('Resetting the container is not allowed when a scope is active.');
  2247. }
  2248. $this->services = array();
  2249. }
  2250. public function getServiceIds()
  2251. {
  2252. $ids = array();
  2253. foreach (get_class_methods($this) as $method) {
  2254. if (preg_match('/^get(.+)Service$/', $method, $match)) {
  2255. $ids[] = self::underscore($match[1]);
  2256. }
  2257. }
  2258. $ids[] ='service_container';
  2259. return array_unique(array_merge($ids, array_keys($this->services)));
  2260. }
  2261. public function enterScope($name)
  2262. {
  2263. if ('request'!== $name) {
  2264. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  2265. }
  2266. if (!isset($this->scopes[$name])) {
  2267. throw new InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
  2268. }
  2269. if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
  2270. throw new RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
  2271. }
  2272. if (isset($this->scopedServices[$name])) {
  2273. $services = array($this->services, $name => $this->scopedServices[$name]);
  2274. unset($this->scopedServices[$name]);
  2275. foreach ($this->scopeChildren[$name] as $child) {
  2276. if (isset($this->scopedServices[$child])) {
  2277. $services[$child] = $this->scopedServices[$child];
  2278. unset($this->scopedServices[$child]);
  2279. }
  2280. }
  2281. $this->services = call_user_func_array('array_diff_key', $services);
  2282. array_shift($services);
  2283. if (!isset($this->scopeStacks[$name])) {
  2284. $this->scopeStacks[$name] = new \SplStack();
  2285. }
  2286. $this->scopeStacks[$name]->push($services);
  2287. }
  2288. $this->scopedServices[$name] = array();
  2289. }
  2290. public function leaveScope($name)
  2291. {
  2292. if ('request'!== $name) {
  2293. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  2294. }
  2295. if (!isset($this->scopedServices[$name])) {
  2296. throw new InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
  2297. }
  2298. $services = array($this->services, $this->scopedServices[$name]);
  2299. unset($this->scopedServices[$name]);
  2300. foreach ($this->scopeChildren[$name] as $child) {
  2301. if (isset($this->scopedServices[$child])) {
  2302. $services[] = $this->scopedServices[$child];
  2303. unset($this->scopedServices[$child]);
  2304. }
  2305. }
  2306. $this->services = call_user_func_array('array_diff_key', $services);
  2307. if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
  2308. $services = $this->scopeStacks[$name]->pop();
  2309. $this->scopedServices += $services;
  2310. if ($this->scopeStacks[$name]->isEmpty()) {
  2311. unset($this->scopeStacks[$name]);
  2312. }
  2313. foreach ($services as $array) {
  2314. foreach ($array as $id => $service) {
  2315. $this->set($id, $service, $name);
  2316. }
  2317. }
  2318. }
  2319. }
  2320. public function addScope(ScopeInterface $scope)
  2321. {
  2322. $name = $scope->getName();
  2323. $parentScope = $scope->getParentName();
  2324. if ('request'!== $name) {
  2325. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  2326. }
  2327. if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
  2328. throw new InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
  2329. }
  2330. if (isset($this->scopes[$name])) {
  2331. throw new InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
  2332. }
  2333. if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
  2334. throw new InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
  2335. }
  2336. $this->scopes[$name] = $parentScope;
  2337. $this->scopeChildren[$name] = array();
  2338. while ($parentScope !== self::SCOPE_CONTAINER) {
  2339. $this->scopeChildren[$parentScope][] = $name;
  2340. $parentScope = $this->scopes[$parentScope];
  2341. }
  2342. }
  2343. public function hasScope($name)
  2344. {
  2345. if ('request'!== $name) {
  2346. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  2347. }
  2348. return isset($this->scopes[$name]);
  2349. }
  2350. public function isScopeActive($name)
  2351. {
  2352. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  2353. return isset($this->scopedServices[$name]);
  2354. }
  2355. public static function camelize($id)
  2356. {
  2357. return strtr(ucwords(strtr($id, array('_'=>' ','.'=>'_ ','\\'=>'_ '))), array(' '=>''));
  2358. }
  2359. public static function underscore($id)
  2360. {
  2361. return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/','/([a-z\d])([A-Z])/'), array('\\1_\\2','\\1_\\2'), str_replace('_','.', $id)));
  2362. }
  2363. private function __clone()
  2364. {
  2365. }
  2366. }
  2367. }
  2368. namespace Symfony\Component\HttpKernel
  2369. {
  2370. use Symfony\Component\HttpFoundation\Request;
  2371. use Symfony\Component\HttpFoundation\Response;
  2372. interface HttpKernelInterface
  2373. {
  2374. const MASTER_REQUEST = 1;
  2375. const SUB_REQUEST = 2;
  2376. public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
  2377. }
  2378. }
  2379. namespace Symfony\Component\HttpKernel
  2380. {
  2381. use Symfony\Component\DependencyInjection\ContainerInterface;
  2382. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  2383. use Symfony\Component\Config\Loader\LoaderInterface;
  2384. interface KernelInterface extends HttpKernelInterface, \Serializable
  2385. {
  2386. public function registerBundles();
  2387. public function registerContainerConfiguration(LoaderInterface $loader);
  2388. public function boot();
  2389. public function shutdown();
  2390. public function getBundles();
  2391. public function isClassInActiveBundle($class);
  2392. public function getBundle($name, $first = true);
  2393. public function locateResource($name, $dir = null, $first = true);
  2394. public function getName();
  2395. public function getEnvironment();
  2396. public function isDebug();
  2397. public function getRootDir();
  2398. public function getContainer();
  2399. public function getStartTime();
  2400. public function getCacheDir();
  2401. public function getLogDir();
  2402. public function getCharset();
  2403. }
  2404. }
  2405. namespace Symfony\Component\HttpKernel
  2406. {
  2407. use Symfony\Component\HttpFoundation\Request;
  2408. use Symfony\Component\HttpFoundation\Response;
  2409. interface TerminableInterface
  2410. {
  2411. public function terminate(Request $request, Response $response);
  2412. }
  2413. }
  2414. namespace Symfony\Component\HttpKernel
  2415. {
  2416. use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
  2417. use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
  2418. use Symfony\Component\DependencyInjection\ContainerInterface;
  2419. use Symfony\Component\DependencyInjection\ContainerBuilder;
  2420. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  2421. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
  2422. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  2423. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  2424. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  2425. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  2426. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  2427. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  2428. use Symfony\Component\HttpFoundation\Request;
  2429. use Symfony\Component\HttpFoundation\Response;
  2430. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  2431. use Symfony\Component\HttpKernel\Config\EnvParametersResource;
  2432. use Symfony\Component\HttpKernel\Config\FileLocator;
  2433. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  2434. use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
  2435. use Symfony\Component\Config\Loader\LoaderResolver;
  2436. use Symfony\Component\Config\Loader\DelegatingLoader;
  2437. use Symfony\Component\Config\ConfigCache;
  2438. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  2439. abstract class Kernel implements KernelInterface, TerminableInterface
  2440. {
  2441. protected $bundles = array();
  2442. protected $bundleMap;
  2443. protected $container;
  2444. protected $rootDir;
  2445. protected $environment;
  2446. protected $debug;
  2447. protected $booted = false;
  2448. protected $name;
  2449. protected $startTime;
  2450. protected $loadClassCache;
  2451. const VERSION ='2.8.9';
  2452. const VERSION_ID = 20809;
  2453. const MAJOR_VERSION = 2;
  2454. const MINOR_VERSION = 8;
  2455. const RELEASE_VERSION = 9;
  2456. const EXTRA_VERSION ='';
  2457. const END_OF_MAINTENANCE ='11/2018';
  2458. const END_OF_LIFE ='11/2019';
  2459. public function __construct($environment, $debug)
  2460. {
  2461. $this->environment = $environment;
  2462. $this->debug = (bool) $debug;
  2463. $this->rootDir = $this->getRootDir();
  2464. $this->name = $this->getName();
  2465. if ($this->debug) {
  2466. $this->startTime = microtime(true);
  2467. }
  2468. $defClass = new \ReflectionMethod($this,'init');
  2469. $defClass = $defClass->getDeclaringClass()->name;
  2470. if (__CLASS__ !== $defClass) {
  2471. @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);
  2472. $this->init();
  2473. }
  2474. }
  2475. public function init()
  2476. {
  2477. @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);
  2478. }
  2479. public function __clone()
  2480. {
  2481. if ($this->debug) {
  2482. $this->startTime = microtime(true);
  2483. }
  2484. $this->booted = false;
  2485. $this->container = null;
  2486. }
  2487. public function boot()
  2488. {
  2489. if (true === $this->booted) {
  2490. return;
  2491. }
  2492. if ($this->loadClassCache) {
  2493. $this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
  2494. }
  2495. $this->initializeBundles();
  2496. $this->initializeContainer();
  2497. foreach ($this->getBundles() as $bundle) {
  2498. $bundle->setContainer($this->container);
  2499. $bundle->boot();
  2500. }
  2501. $this->booted = true;
  2502. }
  2503. public function terminate(Request $request, Response $response)
  2504. {
  2505. if (false === $this->booted) {
  2506. return;
  2507. }
  2508. if ($this->getHttpKernel() instanceof TerminableInterface) {
  2509. $this->getHttpKernel()->terminate($request, $response);
  2510. }
  2511. }
  2512. public function shutdown()
  2513. {
  2514. if (false === $this->booted) {
  2515. return;
  2516. }
  2517. $this->booted = false;
  2518. foreach ($this->getBundles() as $bundle) {
  2519. $bundle->shutdown();
  2520. $bundle->setContainer(null);
  2521. }
  2522. $this->container = null;
  2523. }
  2524. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  2525. {
  2526. if (false === $this->booted) {
  2527. $this->boot();
  2528. }
  2529. return $this->getHttpKernel()->handle($request, $type, $catch);
  2530. }
  2531. protected function getHttpKernel()
  2532. {
  2533. return $this->container->get('http_kernel');
  2534. }
  2535. public function getBundles()
  2536. {
  2537. return $this->bundles;
  2538. }
  2539. public function isClassInActiveBundle($class)
  2540. {
  2541. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in version 3.0.', E_USER_DEPRECATED);
  2542. foreach ($this->getBundles() as $bundle) {
  2543. if (0 === strpos($class, $bundle->getNamespace())) {
  2544. return true;
  2545. }
  2546. }
  2547. return false;
  2548. }
  2549. public function getBundle($name, $first = true)
  2550. {
  2551. if (!isset($this->bundleMap[$name])) {
  2552. 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)));
  2553. }
  2554. if (true === $first) {
  2555. return $this->bundleMap[$name][0];
  2556. }
  2557. return $this->bundleMap[$name];
  2558. }
  2559. public function locateResource($name, $dir = null, $first = true)
  2560. {
  2561. if ('@'!== $name[0]) {
  2562. throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
  2563. }
  2564. if (false !== strpos($name,'..')) {
  2565. throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
  2566. }
  2567. $bundleName = substr($name, 1);
  2568. $path ='';
  2569. if (false !== strpos($bundleName,'/')) {
  2570. list($bundleName, $path) = explode('/', $bundleName, 2);
  2571. }
  2572. $isResource = 0 === strpos($path,'Resources') && null !== $dir;
  2573. $overridePath = substr($path, 9);
  2574. $resourceBundle = null;
  2575. $bundles = $this->getBundle($bundleName, false);
  2576. $files = array();
  2577. foreach ($bundles as $bundle) {
  2578. if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
  2579. if (null !== $resourceBundle) {
  2580. 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.',
  2581. $file,
  2582. $resourceBundle,
  2583. $dir.'/'.$bundles[0]->getName().$overridePath
  2584. ));
  2585. }
  2586. if ($first) {
  2587. return $file;
  2588. }
  2589. $files[] = $file;
  2590. }
  2591. if (file_exists($file = $bundle->getPath().'/'.$path)) {
  2592. if ($first && !$isResource) {
  2593. return $file;
  2594. }
  2595. $files[] = $file;
  2596. $resourceBundle = $bundle->getName();
  2597. }
  2598. }
  2599. if (count($files) > 0) {
  2600. return $first && $isResource ? $files[0] : $files;
  2601. }
  2602. throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
  2603. }
  2604. public function getName()
  2605. {
  2606. if (null === $this->name) {
  2607. $this->name = preg_replace('/[^a-zA-Z0-9_]+/','', basename($this->rootDir));
  2608. }
  2609. return $this->name;
  2610. }
  2611. public function getEnvironment()
  2612. {
  2613. return $this->environment;
  2614. }
  2615. public function isDebug()
  2616. {
  2617. return $this->debug;
  2618. }
  2619. public function getRootDir()
  2620. {
  2621. if (null === $this->rootDir) {
  2622. $r = new \ReflectionObject($this);
  2623. $this->rootDir = dirname($r->getFileName());
  2624. }
  2625. return $this->rootDir;
  2626. }
  2627. public function getContainer()
  2628. {
  2629. return $this->container;
  2630. }
  2631. public function loadClassCache($name ='classes', $extension ='.php')
  2632. {
  2633. $this->loadClassCache = array($name, $extension);
  2634. }
  2635. public function setClassCache(array $classes)
  2636. {
  2637. file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
  2638. }
  2639. public function getStartTime()
  2640. {
  2641. return $this->debug ? $this->startTime : -INF;
  2642. }
  2643. public function getCacheDir()
  2644. {
  2645. return $this->rootDir.'/cache/'.$this->environment;
  2646. }
  2647. public function getLogDir()
  2648. {
  2649. return $this->rootDir.'/logs';
  2650. }
  2651. public function getCharset()
  2652. {
  2653. return'UTF-8';
  2654. }
  2655. protected function doLoadClassCache($name, $extension)
  2656. {
  2657. if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
  2658. ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
  2659. }
  2660. }
  2661. protected function initializeBundles()
  2662. {
  2663. $this->bundles = array();
  2664. $topMostBundles = array();
  2665. $directChildren = array();
  2666. foreach ($this->registerBundles() as $bundle) {
  2667. $name = $bundle->getName();
  2668. if (isset($this->bundles[$name])) {
  2669. throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
  2670. }
  2671. $this->bundles[$name] = $bundle;
  2672. if ($parentName = $bundle->getParent()) {
  2673. if (isset($directChildren[$parentName])) {
  2674. throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
  2675. }
  2676. if ($parentName == $name) {
  2677. throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
  2678. }
  2679. $directChildren[$parentName] = $name;
  2680. } else {
  2681. $topMostBundles[$name] = $bundle;
  2682. }
  2683. }
  2684. if (!empty($directChildren) && count($diff = array_diff_key($directChildren, $this->bundles))) {
  2685. $diff = array_keys($diff);
  2686. throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
  2687. }
  2688. $this->bundleMap = array();
  2689. foreach ($topMostBundles as $name => $bundle) {
  2690. $bundleMap = array($bundle);
  2691. $hierarchy = array($name);
  2692. while (isset($directChildren[$name])) {
  2693. $name = $directChildren[$name];
  2694. array_unshift($bundleMap, $this->bundles[$name]);
  2695. $hierarchy[] = $name;
  2696. }
  2697. foreach ($hierarchy as $bundle) {
  2698. $this->bundleMap[$bundle] = $bundleMap;
  2699. array_pop($bundleMap);
  2700. }
  2701. }
  2702. }
  2703. protected function getContainerClass()
  2704. {
  2705. return $this->name.ucfirst($this->environment).($this->debug ?'Debug':'').'ProjectContainer';
  2706. }
  2707. protected function getContainerBaseClass()
  2708. {
  2709. return'Container';
  2710. }
  2711. protected function initializeContainer()
  2712. {
  2713. $class = $this->getContainerClass();
  2714. $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
  2715. $fresh = true;
  2716. if (!$cache->isFresh()) {
  2717. $container = $this->buildContainer();
  2718. $container->compile();
  2719. $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
  2720. $fresh = false;
  2721. }
  2722. require_once $cache->getPath();
  2723. $this->container = new $class();
  2724. $this->container->set('kernel', $this);
  2725. if (!$fresh && $this->container->has('cache_warmer')) {
  2726. $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  2727. }
  2728. }
  2729. protected function getKernelParameters()
  2730. {
  2731. $bundles = array();
  2732. foreach ($this->bundles as $name => $bundle) {
  2733. $bundles[$name] = get_class($bundle);
  2734. }
  2735. return array_merge(
  2736. 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(),
  2737. ),
  2738. $this->getEnvParameters()
  2739. );
  2740. }
  2741. protected function getEnvParameters()
  2742. {
  2743. $parameters = array();
  2744. foreach ($_SERVER as $key => $value) {
  2745. if (0 === strpos($key,'SYMFONY__')) {
  2746. $parameters[strtolower(str_replace('__','.', substr($key, 9)))] = $value;
  2747. }
  2748. }
  2749. return $parameters;
  2750. }
  2751. protected function buildContainer()
  2752. {
  2753. foreach (array('cache'=> $this->getCacheDir(),'logs'=> $this->getLogDir()) as $name => $dir) {
  2754. if (!is_dir($dir)) {
  2755. if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
  2756. throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
  2757. }
  2758. } elseif (!is_writable($dir)) {
  2759. throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
  2760. }
  2761. }
  2762. $container = $this->getContainerBuilder();
  2763. $container->addObjectResource($this);
  2764. $this->prepareContainer($container);
  2765. if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  2766. $container->merge($cont);
  2767. }
  2768. $container->addCompilerPass(new AddClassesToCachePass($this));
  2769. $container->addResource(new EnvParametersResource('SYMFONY__'));
  2770. return $container;
  2771. }
  2772. protected function prepareContainer(ContainerBuilder $container)
  2773. {
  2774. $extensions = array();
  2775. foreach ($this->bundles as $bundle) {
  2776. if ($extension = $bundle->getContainerExtension()) {
  2777. $container->registerExtension($extension);
  2778. $extensions[] = $extension->getAlias();
  2779. }
  2780. if ($this->debug) {
  2781. $container->addObjectResource($bundle);
  2782. }
  2783. }
  2784. foreach ($this->bundles as $bundle) {
  2785. $bundle->build($container);
  2786. }
  2787. $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  2788. }
  2789. protected function getContainerBuilder()
  2790. {
  2791. $container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  2792. if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
  2793. $container->setProxyInstantiator(new RuntimeInstantiator());
  2794. }
  2795. return $container;
  2796. }
  2797. protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
  2798. {
  2799. $dumper = new PhpDumper($container);
  2800. if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) {
  2801. $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath())));
  2802. }
  2803. $content = $dumper->dump(array('class'=> $class,'base_class'=> $baseClass,'file'=> $cache->getPath(),'debug'=> $this->debug));
  2804. $cache->write($content, $container->getResources());
  2805. }
  2806. protected function getContainerLoader(ContainerInterface $container)
  2807. {
  2808. $locator = new FileLocator($this);
  2809. $resolver = new LoaderResolver(array(
  2810. new XmlFileLoader($container, $locator),
  2811. new YamlFileLoader($container, $locator),
  2812. new IniFileLoader($container, $locator),
  2813. new PhpFileLoader($container, $locator),
  2814. new DirectoryLoader($container, $locator),
  2815. new ClosureLoader($container),
  2816. ));
  2817. return new DelegatingLoader($resolver);
  2818. }
  2819. public static function stripComments($source)
  2820. {
  2821. if (!function_exists('token_get_all')) {
  2822. return $source;
  2823. }
  2824. $rawChunk ='';
  2825. $output ='';
  2826. $tokens = token_get_all($source);
  2827. $ignoreSpace = false;
  2828. for ($i = 0; isset($tokens[$i]); ++$i) {
  2829. $token = $tokens[$i];
  2830. if (!isset($token[1]) ||'b"'=== $token) {
  2831. $rawChunk .= $token;
  2832. } elseif (T_START_HEREDOC === $token[0]) {
  2833. $output .= $rawChunk.$token[1];
  2834. do {
  2835. $token = $tokens[++$i];
  2836. $output .= isset($token[1]) &&'b"'!== $token ? $token[1] : $token;
  2837. } while ($token[0] !== T_END_HEREDOC);
  2838. $rawChunk ='';
  2839. } elseif (T_WHITESPACE === $token[0]) {
  2840. if ($ignoreSpace) {
  2841. $ignoreSpace = false;
  2842. continue;
  2843. }
  2844. $rawChunk .= preg_replace(array('/\n{2,}/S'),"\n", $token[1]);
  2845. } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
  2846. $ignoreSpace = true;
  2847. } else {
  2848. $rawChunk .= $token[1];
  2849. if (T_OPEN_TAG === $token[0]) {
  2850. $ignoreSpace = true;
  2851. }
  2852. }
  2853. }
  2854. $output .= $rawChunk;
  2855. if (PHP_VERSION_ID >= 70000) {
  2856. unset($tokens, $rawChunk);
  2857. gc_mem_caches();
  2858. }
  2859. return $output;
  2860. }
  2861. public function serialize()
  2862. {
  2863. return serialize(array($this->environment, $this->debug));
  2864. }
  2865. public function unserialize($data)
  2866. {
  2867. list($environment, $debug) = unserialize($data);
  2868. $this->__construct($environment, $debug);
  2869. }
  2870. }
  2871. }
  2872. namespace Symfony\Component\ClassLoader
  2873. {
  2874. class ApcClassLoader
  2875. {
  2876. private $prefix;
  2877. protected $decorated;
  2878. public function __construct($prefix, $decorated)
  2879. {
  2880. if (!function_exists('apcu_fetch')) {
  2881. throw new \RuntimeException('Unable to use ApcClassLoader as APC is not installed.');
  2882. }
  2883. if (!method_exists($decorated,'findFile')) {
  2884. throw new \InvalidArgumentException('The class finder must implement a "findFile" method.');
  2885. }
  2886. $this->prefix = $prefix;
  2887. $this->decorated = $decorated;
  2888. }
  2889. public function register($prepend = false)
  2890. {
  2891. spl_autoload_register(array($this,'loadClass'), true, $prepend);
  2892. }
  2893. public function unregister()
  2894. {
  2895. spl_autoload_unregister(array($this,'loadClass'));
  2896. }
  2897. public function loadClass($class)
  2898. {
  2899. if ($file = $this->findFile($class)) {
  2900. require $file;
  2901. return true;
  2902. }
  2903. }
  2904. public function findFile($class)
  2905. {
  2906. $file = apcu_fetch($this->prefix.$class, $success);
  2907. if (!$success) {
  2908. apcu_store($this->prefix.$class, $file = $this->decorated->findFile($class) ?: null);
  2909. }
  2910. return $file;
  2911. }
  2912. public function __call($method, $args)
  2913. {
  2914. return call_user_func_array(array($this->decorated, $method), $args);
  2915. }
  2916. }
  2917. }
  2918. namespace Symfony\Component\HttpKernel\Bundle
  2919. {
  2920. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  2921. use Symfony\Component\DependencyInjection\ContainerBuilder;
  2922. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  2923. interface BundleInterface extends ContainerAwareInterface
  2924. {
  2925. public function boot();
  2926. public function shutdown();
  2927. public function build(ContainerBuilder $container);
  2928. public function getContainerExtension();
  2929. public function getParent();
  2930. public function getName();
  2931. public function getNamespace();
  2932. public function getPath();
  2933. }
  2934. }
  2935. namespace Symfony\Component\HttpKernel\Bundle
  2936. {
  2937. use Symfony\Component\DependencyInjection\ContainerInterface;
  2938. use Symfony\Component\DependencyInjection\ContainerBuilder;
  2939. use Symfony\Component\DependencyInjection\Container;
  2940. use Symfony\Component\Console\Application;
  2941. use Symfony\Component\Finder\Finder;
  2942. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  2943. abstract class Bundle implements BundleInterface
  2944. {
  2945. protected $container;
  2946. protected $name;
  2947. protected $extension;
  2948. protected $path;
  2949. public function boot()
  2950. {
  2951. }
  2952. public function shutdown()
  2953. {
  2954. }
  2955. public function build(ContainerBuilder $container)
  2956. {
  2957. }
  2958. public function setContainer(ContainerInterface $container = null)
  2959. {
  2960. $this->container = $container;
  2961. }
  2962. public function getContainerExtension()
  2963. {
  2964. if (null === $this->extension) {
  2965. $extension = $this->createContainerExtension();
  2966. if (null !== $extension) {
  2967. if (!$extension instanceof ExtensionInterface) {
  2968. throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_class($extension)));
  2969. }
  2970. $basename = preg_replace('/Bundle$/','', $this->getName());
  2971. $expectedAlias = Container::underscore($basename);
  2972. if ($expectedAlias != $extension->getAlias()) {
  2973. throw new \LogicException(sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.',
  2974. $expectedAlias, $extension->getAlias()
  2975. ));
  2976. }
  2977. $this->extension = $extension;
  2978. } else {
  2979. $this->extension = false;
  2980. }
  2981. }
  2982. if ($this->extension) {
  2983. return $this->extension;
  2984. }
  2985. }
  2986. public function getNamespace()
  2987. {
  2988. $class = get_class($this);
  2989. return substr($class, 0, strrpos($class,'\\'));
  2990. }
  2991. public function getPath()
  2992. {
  2993. if (null === $this->path) {
  2994. $reflected = new \ReflectionObject($this);
  2995. $this->path = dirname($reflected->getFileName());
  2996. }
  2997. return $this->path;
  2998. }
  2999. public function getParent()
  3000. {
  3001. }
  3002. final public function getName()
  3003. {
  3004. if (null !== $this->name) {
  3005. return $this->name;
  3006. }
  3007. $name = get_class($this);
  3008. $pos = strrpos($name,'\\');
  3009. return $this->name = false === $pos ? $name : substr($name, $pos + 1);
  3010. }
  3011. public function registerCommands(Application $application)
  3012. {
  3013. if (!is_dir($dir = $this->getPath().'/Command')) {
  3014. return;
  3015. }
  3016. if (!class_exists('Symfony\Component\Finder\Finder')) {
  3017. throw new \RuntimeException('You need the symfony/finder component to register bundle commands.');
  3018. }
  3019. $finder = new Finder();
  3020. $finder->files()->name('*Command.php')->in($dir);
  3021. $prefix = $this->getNamespace().'\\Command';
  3022. foreach ($finder as $file) {
  3023. $ns = $prefix;
  3024. if ($relativePath = $file->getRelativePath()) {
  3025. $ns .='\\'.str_replace('/','\\', $relativePath);
  3026. }
  3027. $class = $ns.'\\'.$file->getBasename('.php');
  3028. if ($this->container) {
  3029. $alias ='console.command.'.strtolower(str_replace('\\','_', $class));
  3030. if ($this->container->has($alias)) {
  3031. continue;
  3032. }
  3033. }
  3034. $r = new \ReflectionClass($class);
  3035. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
  3036. $application->add($r->newInstance());
  3037. }
  3038. }
  3039. }
  3040. protected function getContainerExtensionClass()
  3041. {
  3042. $basename = preg_replace('/Bundle$/','', $this->getName());
  3043. return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
  3044. }
  3045. protected function createContainerExtension()
  3046. {
  3047. if (class_exists($class = $this->getContainerExtensionClass())) {
  3048. return new $class();
  3049. }
  3050. }
  3051. }
  3052. }
  3053. namespace Symfony\Component\Config
  3054. {
  3055. use Symfony\Component\Config\Resource\ResourceInterface;
  3056. interface ConfigCacheInterface
  3057. {
  3058. public function getPath();
  3059. public function isFresh();
  3060. public function write($content, array $metadata = null);
  3061. }
  3062. }
  3063. namespace Symfony\Component\Config
  3064. {
  3065. use Symfony\Component\Config\Resource\ResourceInterface;
  3066. use Symfony\Component\Filesystem\Exception\IOException;
  3067. use Symfony\Component\Filesystem\Filesystem;
  3068. class ResourceCheckerConfigCache implements ConfigCacheInterface
  3069. {
  3070. private $file;
  3071. private $resourceCheckers;
  3072. public function __construct($file, array $resourceCheckers = array())
  3073. {
  3074. $this->file = $file;
  3075. $this->resourceCheckers = $resourceCheckers;
  3076. }
  3077. public function getPath()
  3078. {
  3079. return $this->file;
  3080. }
  3081. public function isFresh()
  3082. {
  3083. if (!is_file($this->file)) {
  3084. return false;
  3085. }
  3086. if (!$this->resourceCheckers) {
  3087. return true; }
  3088. $metadata = $this->getMetaFile();
  3089. if (!is_file($metadata)) {
  3090. return true;
  3091. }
  3092. $time = filemtime($this->file);
  3093. $meta = unserialize(file_get_contents($metadata));
  3094. foreach ($meta as $resource) {
  3095. foreach ($this->resourceCheckers as $checker) {
  3096. if (!$checker->supports($resource)) {
  3097. continue; }
  3098. if ($checker->isFresh($resource, $time)) {
  3099. break; }
  3100. return false; }
  3101. }
  3102. return true;
  3103. }
  3104. public function write($content, array $metadata = null)
  3105. {
  3106. $mode = 0666;
  3107. $umask = umask();
  3108. $filesystem = new Filesystem();
  3109. $filesystem->dumpFile($this->file, $content, null);
  3110. try {
  3111. $filesystem->chmod($this->file, $mode, $umask);
  3112. } catch (IOException $e) {
  3113. }
  3114. if (null !== $metadata) {
  3115. $filesystem->dumpFile($this->getMetaFile(), serialize($metadata), null);
  3116. try {
  3117. $filesystem->chmod($this->getMetaFile(), $mode, $umask);
  3118. } catch (IOException $e) {
  3119. }
  3120. }
  3121. }
  3122. private function getMetaFile()
  3123. {
  3124. return $this->file.'.meta';
  3125. }
  3126. }
  3127. }
  3128. namespace Symfony\Component\Config
  3129. {
  3130. use Symfony\Component\Config\Resource\BCResourceInterfaceChecker;
  3131. use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
  3132. class ConfigCache extends ResourceCheckerConfigCache
  3133. {
  3134. private $debug;
  3135. public function __construct($file, $debug)
  3136. {
  3137. parent::__construct($file, array(
  3138. new SelfCheckingResourceChecker(),
  3139. new BCResourceInterfaceChecker(),
  3140. ));
  3141. $this->debug = (bool) $debug;
  3142. }
  3143. public function __toString()
  3144. {
  3145. @trigger_error('ConfigCache::__toString() is deprecated since version 2.7 and will be removed in 3.0. Use the getPath() method instead.', E_USER_DEPRECATED);
  3146. return $this->getPath();
  3147. }
  3148. public function isFresh()
  3149. {
  3150. if (!$this->debug && is_file($this->getPath())) {
  3151. return true;
  3152. }
  3153. return parent::isFresh();
  3154. }
  3155. }
  3156. }
  3157. namespace Symfony\Component\HttpKernel
  3158. {
  3159. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  3160. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  3161. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  3162. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  3163. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  3164. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  3165. use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
  3166. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  3167. use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
  3168. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  3169. use Symfony\Component\HttpKernel\Event\PostResponseEvent;
  3170. use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
  3171. use Symfony\Component\HttpFoundation\Request;
  3172. use Symfony\Component\HttpFoundation\RequestStack;
  3173. use Symfony\Component\HttpFoundation\Response;
  3174. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  3175. class HttpKernel implements HttpKernelInterface, TerminableInterface
  3176. {
  3177. protected $dispatcher;
  3178. protected $resolver;
  3179. protected $requestStack;
  3180. public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver, RequestStack $requestStack = null)
  3181. {
  3182. $this->dispatcher = $dispatcher;
  3183. $this->resolver = $resolver;
  3184. $this->requestStack = $requestStack ?: new RequestStack();
  3185. }
  3186. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  3187. {
  3188. $request->headers->set('X-Php-Ob-Level', ob_get_level());
  3189. try {
  3190. return $this->handleRaw($request, $type);
  3191. } catch (\Exception $e) {
  3192. if ($e instanceof ConflictingHeadersException) {
  3193. $e = new BadRequestHttpException('The request headers contain conflicting information regarding the origin of this request.', $e);
  3194. }
  3195. if (false === $catch) {
  3196. $this->finishRequest($request, $type);
  3197. throw $e;
  3198. }
  3199. return $this->handleException($e, $request, $type);
  3200. }
  3201. }
  3202. public function terminate(Request $request, Response $response)
  3203. {
  3204. $this->dispatcher->dispatch(KernelEvents::TERMINATE, new PostResponseEvent($this, $request, $response));
  3205. }
  3206. public function terminateWithException(\Exception $exception)
  3207. {
  3208. if (!$request = $this->requestStack->getMasterRequest()) {
  3209. throw new \LogicException('Request stack is empty', 0, $exception);
  3210. }
  3211. $response = $this->handleException($exception, $request, self::MASTER_REQUEST);
  3212. $response->sendHeaders();
  3213. $response->sendContent();
  3214. $this->terminate($request, $response);
  3215. }
  3216. private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
  3217. {
  3218. $this->requestStack->push($request);
  3219. $event = new GetResponseEvent($this, $request, $type);
  3220. $this->dispatcher->dispatch(KernelEvents::REQUEST, $event);
  3221. if ($event->hasResponse()) {
  3222. return $this->filterResponse($event->getResponse(), $request, $type);
  3223. }
  3224. if (false === $controller = $this->resolver->getController($request)) {
  3225. throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". The route is wrongly configured.', $request->getPathInfo()));
  3226. }
  3227. $event = new FilterControllerEvent($this, $controller, $request, $type);
  3228. $this->dispatcher->dispatch(KernelEvents::CONTROLLER, $event);
  3229. $controller = $event->getController();
  3230. $arguments = $this->resolver->getArguments($request, $controller);
  3231. $response = call_user_func_array($controller, $arguments);
  3232. if (!$response instanceof Response) {
  3233. $event = new GetResponseForControllerResultEvent($this, $request, $type, $response);
  3234. $this->dispatcher->dispatch(KernelEvents::VIEW, $event);
  3235. if ($event->hasResponse()) {
  3236. $response = $event->getResponse();
  3237. }
  3238. if (!$response instanceof Response) {
  3239. $msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));
  3240. if (null === $response) {
  3241. $msg .=' Did you forget to add a return statement somewhere in your controller?';
  3242. }
  3243. throw new \LogicException($msg);
  3244. }
  3245. }
  3246. return $this->filterResponse($response, $request, $type);
  3247. }
  3248. private function filterResponse(Response $response, Request $request, $type)
  3249. {
  3250. $event = new FilterResponseEvent($this, $request, $type, $response);
  3251. $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
  3252. $this->finishRequest($request, $type);
  3253. return $event->getResponse();
  3254. }
  3255. private function finishRequest(Request $request, $type)
  3256. {
  3257. $this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type));
  3258. $this->requestStack->pop();
  3259. }
  3260. private function handleException(\Exception $e, $request, $type)
  3261. {
  3262. $event = new GetResponseForExceptionEvent($this, $request, $type, $e);
  3263. $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
  3264. $e = $event->getException();
  3265. if (!$event->hasResponse()) {
  3266. $this->finishRequest($request, $type);
  3267. throw $e;
  3268. }
  3269. $response = $event->getResponse();
  3270. if ($response->headers->has('X-Status-Code')) {
  3271. $response->setStatusCode($response->headers->get('X-Status-Code'));
  3272. $response->headers->remove('X-Status-Code');
  3273. } elseif (!$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
  3274. if ($e instanceof HttpExceptionInterface) {
  3275. $response->setStatusCode($e->getStatusCode());
  3276. $response->headers->add($e->getHeaders());
  3277. } else {
  3278. $response->setStatusCode(500);
  3279. }
  3280. }
  3281. try {
  3282. return $this->filterResponse($response, $request, $type);
  3283. } catch (\Exception $e) {
  3284. return $response;
  3285. }
  3286. }
  3287. private function varToString($var)
  3288. {
  3289. if (is_object($var)) {
  3290. return sprintf('Object(%s)', get_class($var));
  3291. }
  3292. if (is_array($var)) {
  3293. $a = array();
  3294. foreach ($var as $k => $v) {
  3295. $a[] = sprintf('%s => %s', $k, $this->varToString($v));
  3296. }
  3297. return sprintf('Array(%s)', implode(', ', $a));
  3298. }
  3299. if (is_resource($var)) {
  3300. return sprintf('Resource(%s)', get_resource_type($var));
  3301. }
  3302. if (null === $var) {
  3303. return'null';
  3304. }
  3305. if (false === $var) {
  3306. return'false';
  3307. }
  3308. if (true === $var) {
  3309. return'true';
  3310. }
  3311. return (string) $var;
  3312. }
  3313. }
  3314. }
  3315. namespace Symfony\Component\HttpKernel\DependencyInjection
  3316. {
  3317. use Symfony\Component\HttpFoundation\Request;
  3318. use Symfony\Component\HttpFoundation\RequestStack;
  3319. use Symfony\Component\HttpKernel\HttpKernelInterface;
  3320. use Symfony\Component\HttpKernel\HttpKernel;
  3321. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  3322. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  3323. use Symfony\Component\DependencyInjection\ContainerInterface;
  3324. use Symfony\Component\DependencyInjection\Scope;
  3325. class ContainerAwareHttpKernel extends HttpKernel
  3326. {
  3327. protected $container;
  3328. public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver, RequestStack $requestStack = null, $triggerDeprecation = true)
  3329. {
  3330. parent::__construct($dispatcher, $controllerResolver, $requestStack);
  3331. if ($triggerDeprecation) {
  3332. @trigger_error('The '.__CLASS__.' class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Component\HttpKernel\HttpKernel class instead.', E_USER_DEPRECATED);
  3333. }
  3334. $this->container = $container;
  3335. if (!$container->hasScope('request')) {
  3336. $container->addScope(new Scope('request'));
  3337. }
  3338. }
  3339. public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
  3340. {
  3341. $this->container->enterScope('request');
  3342. $this->container->set('request', $request,'request');
  3343. try {
  3344. $response = parent::handle($request, $type, $catch);
  3345. } catch (\Exception $e) {
  3346. $this->container->set('request', null,'request');
  3347. $this->container->leaveScope('request');
  3348. throw $e;
  3349. } catch (\Throwable $e) {
  3350. $this->container->set('request', null,'request');
  3351. $this->container->leaveScope('request');
  3352. throw $e;
  3353. }
  3354. $this->container->set('request', null,'request');
  3355. $this->container->leaveScope('request');
  3356. return $response;
  3357. }
  3358. }
  3359. }