bootstrap.php.cache 101 KB

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