PluginProbe
ManageWP Worker / 4.9.29
ManageWP Worker v4.9.29
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Worker / RequestStack.php

RequestStack.php in ManageWP Worker 4.9.29, at src/MWP/Worker/RequestStack.php

90 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <contact@managewp.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_Worker_RequestStack
12 {
13 /**
14 * @var MWP_Worker_Request[]
15 */
16 private $requests = array();
17
18 /**
19 * Pushes a Request on the stack.
20 *
21 * This method should generally not be called directly as the stack
22 * management should be taken care of by the application itself.
23 */
24 public function push(MWP_Worker_Request $request)
25 {
26 $this->requests[] = $request;
27 }
28
29 /**
30 * Pops the current request from the stack.
31 *
32 * This operation lets the current request go out of scope.
33 *
34 * This method should generally not be called directly as the stack
35 * management should be taken care of by the application itself.
36 *
37 * @return MWP_Worker_Request|null
38 */
39 public function pop()
40 {
41 if (!$this->requests) {
42 return null;
43 }
44
45 return array_pop($this->requests);
46 }
47
48 /**
49 * @return MWP_Worker_Request|null
50 */
51 public function getCurrentRequest()
52 {
53 $lastRequest = end($this->requests);
54
55 return $lastRequest ? $lastRequest : null;
56 }
57
58 /**
59 * Gets the master Request.
60 *
61 * @return MWP_Worker_Request|null
62 */
63 public function getMasterRequest()
64 {
65 if (!$this->requests) {
66 return null;
67 }
68
69 return $this->requests[0];
70 }
71
72 /**
73 * Returns the parent request of the current.
74 *
75 * If current Request is the master request, it returns null.
76 *
77 * @return MWP_Worker_Request|null
78 */
79 public function getParentRequest()
80 {
81 $pos = count($this->requests) - 2;
82
83 if (!isset($this->requests[$pos])) {
84 return null;
85 }
86
87 return $this->requests[$pos];
88 }
89 }
90