2d2999e335dea9581426a80bce86e5800d73d7dd
[yaffs-website] / web / core / modules / system / tests / modules / session_test / src / Session / TestSessionHandlerProxy.php
1 <?php
2
3 namespace Drupal\session_test\Session;
4
5 /**
6  * Provides a test session handler proxy.
7  */
8 class TestSessionHandlerProxy implements \SessionHandlerInterface {
9
10   /**
11    * The decorated session handler.
12    *
13    * @var \SessionHandlerInterface
14    */
15   protected $sessionHandler;
16
17   /**
18    * An optional argument.
19    *
20    * @var mixed
21    */
22   protected $optionalArgument;
23
24   /**
25    * Constructs a new TestSessionHandlerProxy object.
26    *
27    * @param \SessionHandlerInterface $session_handler
28    *   The decorated session handler.
29    * @param mixed $optional_argument
30    *   (optional) An optional argument.
31    */
32   public function __construct(\SessionHandlerInterface $session_handler, $optional_argument = NULL) {
33     $this->sessionHandler = $session_handler;
34     $this->optionalArgument = $optional_argument;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function open($save_path, $name) {
41     $trace = \Drupal::service('session_test.session_handler_proxy_trace');
42     $trace[] = ['BEGIN', $this->optionalArgument, __FUNCTION__];
43     $result = $this->sessionHandler->open($save_path, $name);
44     $trace[] = ['END', $this->optionalArgument, __FUNCTION__];
45     return $result;
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function close() {
52     $trace = \Drupal::service('session_test.session_handler_proxy_trace');
53     $trace[] = ['BEGIN', $this->optionalArgument, __FUNCTION__];
54     $result = $this->sessionHandler->close();
55     $trace[] = ['END', $this->optionalArgument, __FUNCTION__];
56     return $result;
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function read($session_id) {
63     $trace = \Drupal::service('session_test.session_handler_proxy_trace');
64     $trace[] = ['BEGIN', $this->optionalArgument, __FUNCTION__, $session_id];
65     $result = $this->sessionHandler->read($session_id);
66     $trace[] = ['END', $this->optionalArgument, __FUNCTION__, $session_id];
67     return $result;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function write($session_id, $session_data) {
74     $trace = \Drupal::service('session_test.session_handler_proxy_trace');
75     $trace[] = ['BEGIN', $this->optionalArgument, __FUNCTION__, $session_id];
76     $result = $this->sessionHandler->write($session_id, $session_data);
77     $trace[] = ['END', $this->optionalArgument, __FUNCTION__, $session_id];
78     return $result;
79   }
80
81   /**
82    * {@inheritdoc}
83    */
84   public function destroy($session_id) {
85     return $this->sessionHandler->destroy($session_id);
86   }
87
88   /**
89    * {@inheritdoc}
90    */
91   public function gc($max_lifetime) {
92     return $this->sessionHandler->gc($max_lifetime);
93   }
94
95 }