PageRenderTime 64ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/domainconnect-cp/vendor/laravel/framework/src/Illuminate/Http/RedirectResponse.php

https://bitbucket.org/vlad-h/cloudfest
PHP | 238 lines | 111 code | 32 blank | 95 comment | 6 complexity | ccb50b7bfc34763a54f541ac68fed274 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT
  1. <?php
  2. namespace Illuminate\Http;
  3. use BadMethodCallException;
  4. use Illuminate\Support\Str;
  5. use Illuminate\Support\MessageBag;
  6. use Illuminate\Support\ViewErrorBag;
  7. use Illuminate\Support\Traits\Macroable;
  8. use Illuminate\Session\Store as SessionStore;
  9. use Illuminate\Contracts\Support\MessageProvider;
  10. use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
  11. use Symfony\Component\HttpFoundation\RedirectResponse as BaseRedirectResponse;
  12. class RedirectResponse extends BaseRedirectResponse
  13. {
  14. use ResponseTrait, Macroable {
  15. Macroable::__call as macroCall;
  16. }
  17. /**
  18. * The request instance.
  19. *
  20. * @var \Illuminate\Http\Request
  21. */
  22. protected $request;
  23. /**
  24. * The session store implementation.
  25. *
  26. * @var \Illuminate\Session\Store
  27. */
  28. protected $session;
  29. /**
  30. * Flash a piece of data to the session.
  31. *
  32. * @param string|array $key
  33. * @param mixed $value
  34. * @return \Illuminate\Http\RedirectResponse
  35. */
  36. public function with($key, $value = null)
  37. {
  38. $key = is_array($key) ? $key : [$key => $value];
  39. foreach ($key as $k => $v) {
  40. $this->session->flash($k, $v);
  41. }
  42. return $this;
  43. }
  44. /**
  45. * Add multiple cookies to the response.
  46. *
  47. * @param array $cookies
  48. * @return $this
  49. */
  50. public function withCookies(array $cookies)
  51. {
  52. foreach ($cookies as $cookie) {
  53. $this->headers->setCookie($cookie);
  54. }
  55. return $this;
  56. }
  57. /**
  58. * Flash an array of input to the session.
  59. *
  60. * @param array $input
  61. * @return $this
  62. */
  63. public function withInput(array $input = null)
  64. {
  65. $this->session->flashInput($this->removeFilesFromInput(
  66. ! is_null($input) ? $input : $this->request->input()
  67. ));
  68. return $this;
  69. }
  70. /**
  71. * Remove all uploaded files form the given input array.
  72. *
  73. * @param array $input
  74. * @return array
  75. */
  76. protected function removeFilesFromInput(array $input)
  77. {
  78. foreach ($input as $key => $value) {
  79. if (is_array($value)) {
  80. $input[$key] = $this->removeFilesFromInput($value);
  81. }
  82. if ($value instanceof SymfonyUploadedFile) {
  83. unset($input[$key]);
  84. }
  85. }
  86. return $input;
  87. }
  88. /**
  89. * Flash an array of input to the session.
  90. *
  91. * @return $this
  92. */
  93. public function onlyInput()
  94. {
  95. return $this->withInput($this->request->only(func_get_args()));
  96. }
  97. /**
  98. * Flash an array of input to the session.
  99. *
  100. * @return \Illuminate\Http\RedirectResponse
  101. */
  102. public function exceptInput()
  103. {
  104. return $this->withInput($this->request->except(func_get_args()));
  105. }
  106. /**
  107. * Flash a container of errors to the session.
  108. *
  109. * @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider
  110. * @param string $key
  111. * @return $this
  112. */
  113. public function withErrors($provider, $key = 'default')
  114. {
  115. $value = $this->parseErrors($provider);
  116. $errors = $this->session->get('errors', new ViewErrorBag);
  117. if (! $errors instanceof ViewErrorBag) {
  118. $errors = new ViewErrorBag;
  119. }
  120. $this->session->flash(
  121. 'errors', $errors->put($key, $value)
  122. );
  123. return $this;
  124. }
  125. /**
  126. * Parse the given errors into an appropriate value.
  127. *
  128. * @param \Illuminate\Contracts\Support\MessageProvider|array|string $provider
  129. * @return \Illuminate\Support\MessageBag
  130. */
  131. protected function parseErrors($provider)
  132. {
  133. if ($provider instanceof MessageProvider) {
  134. return $provider->getMessageBag();
  135. }
  136. return new MessageBag((array) $provider);
  137. }
  138. /**
  139. * Get the original response content.
  140. *
  141. * @return null
  142. */
  143. public function getOriginalContent()
  144. {
  145. //
  146. }
  147. /**
  148. * Get the request instance.
  149. *
  150. * @return \Illuminate\Http\Request|null
  151. */
  152. public function getRequest()
  153. {
  154. return $this->request;
  155. }
  156. /**
  157. * Set the request instance.
  158. *
  159. * @param \Illuminate\Http\Request $request
  160. * @return void
  161. */
  162. public function setRequest(Request $request)
  163. {
  164. $this->request = $request;
  165. }
  166. /**
  167. * Get the session store implementation.
  168. *
  169. * @return \Illuminate\Session\Store|null
  170. */
  171. public function getSession()
  172. {
  173. return $this->session;
  174. }
  175. /**
  176. * Set the session store implementation.
  177. *
  178. * @param \Illuminate\Session\Store $session
  179. * @return void
  180. */
  181. public function setSession(SessionStore $session)
  182. {
  183. $this->session = $session;
  184. }
  185. /**
  186. * Dynamically bind flash data in the session.
  187. *
  188. * @param string $method
  189. * @param array $parameters
  190. * @return $this
  191. *
  192. * @throws \BadMethodCallException
  193. */
  194. public function __call($method, $parameters)
  195. {
  196. if (static::hasMacro($method)) {
  197. return $this->macroCall($method, $parameters);
  198. }
  199. if (Str::startsWith($method, 'with')) {
  200. return $this->with(Str::snake(substr($method, 4)), $parameters[0]);
  201. }
  202. throw new BadMethodCallException(sprintf(
  203. 'Method %s::%s does not exist.', static::class, $method
  204. ));
  205. }
  206. }