bootstrap.php.cache 96 KB

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