bootstrap.php.cache 85 KB

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