| 1 | <?php |
||
| 12 | class SessionCookieJar extends GuzzleCookieJar |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * The Magister cookie creator service. |
||
| 16 | * |
||
| 17 | * @var \Magister\Services\Cookie\CookieJar |
||
| 18 | */ |
||
| 19 | protected $cookie; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Create a new session cookie jar instance. |
||
| 23 | * |
||
| 24 | * @param \Magister\Services\Cookie\CookieJar $cookie |
||
| 25 | * @param bool $strict |
||
| 26 | * @param array $cookies |
||
| 27 | */ |
||
| 28 | public function __construct(CookieJar $cookie, $strict = false, $cookies = []) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Save cookies to the client's session. |
||
| 39 | * |
||
| 40 | * @param \GuzzleHttp\Cookie\SetCookie $cookie |
||
| 41 | * |
||
| 42 | * @return bool |
||
| 43 | */ |
||
| 44 | public function setCookie(SetCookie $cookie) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Load the contents of the client's session into the data array. |
||
| 59 | * |
||
| 60 | * @param array $cookies |
||
| 61 | * |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | protected function load($cookies) |
||
| 76 | } |
||
| 77 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: