PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | admin/helpers/src/platform/aware.php +168 -0 1.6.0 → 1.8.16 View file →
@@ -1,0 +1,168 @@
1 +<?php
2 +/**
3 + * @package VikBooking
4 + * @subpackage core
5 + * @author E4J s.r.l.
6 + * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 + * @link https://vikwp.com
9 + */
10 +
11 +// No direct access
12 +defined('ABSPATH') or die('No script kiddies please!');
13 +
14 +/**
15 + * Declares all the helper methods that may differ between every supported platform.
16 + *
17 + * @since 1.5
18 + */
19 +abstract class VBOPlatformAware implements VBOPlatformInterface
20 +{
21 + /**
22 + * The platform URI handler.
23 + *
24 + * @var VBOPlatformUriInterface
25 + */
26 + private $uri;
27 +
28 + /**
29 + * The platform mailer handler.
30 + *
31 + * @var VBOPlatformMailerInstance
32 + */
33 + private $mailer;
34 +
35 + /**
36 + * The event dispatcher handler.
37 + *
38 + * @var VBOPlatformDispatcherInstance
39 + */
40 + private $dispatcher;
41 +
42 + /**
43 + * Returns the URI helper instance.
44 + *
45 + * @return VBOPlatformUriInterface
46 + */
47 + public function getUri()
48 + {
49 + if (is_null($this->uri))
50 + {
51 + // lazy creation
52 + $this->uri = $this->createUri();
53 + }
54 +
55 + // make sure we have a valid instance
56 + if (!$this->uri instanceof VBOPlatformUriInterface)
57 + {
58 + if (is_object($this->uri))
59 + {
60 + // extract class name from object
61 + $t = get_class($this->uri);
62 + }
63 + else
64 + {
65 + // fetch the type of the property
66 + $t = gettype($this->uri);
67 + }
68 +
69 + // nope, throw a "Not acceptable" 406 error
70 + throw new UnexpectedValueException(sprintf('The [%s] object is not a valid URI instance', $t), 406);
71 + }
72 +
73 + return $this->uri;
74 + }
75 +
76 + /**
77 + * Returns the mail sender instance.
78 + *
79 + * @return VBOPlatformMailerInterface
80 + */
81 + public function getMailer()
82 + {
83 + if (is_null($this->mailer))
84 + {
85 + // lazy creation
86 + $this->mailer = $this->createMailer();
87 + }
88 +
89 + // make sure we have a valid instance
90 + if (!$this->mailer instanceof VBOPlatformMailerInterface)
91 + {
92 + if (is_object($this->mailer))
93 + {
94 + // extract class name from object
95 + $t = get_class($this->mailer);
96 + }
97 + else
98 + {
99 + // fetch the type of the property
100 + $t = gettype($this->mailer);
101 + }
102 +
103 + // nope, throw a "Not acceptable" 406 error
104 + throw new UnexpectedValueException(sprintf('The [%s] object is not a valid mailer instance', $t), 406);
105 + }
106 +
107 + return $this->mailer;
108 + }
109 +
110 + /**
111 + * Returns the event dispatcher instance.
112 + *
113 + * @return VBOPlatformDispatcherInterface
114 + *
115 + * @since 1.5.10
116 + */
117 + public function getDispatcher()
118 + {
119 + if (is_null($this->dispatcher))
120 + {
121 + // lazy creation
122 + $this->dispatcher = $this->createDispatcher();
123 + }
124 +
125 + // make sure we have a valid instance
126 + if (!$this->dispatcher instanceof VBOPlatformDispatcherInterface)
127 + {
128 + if (is_object($this->dispatcher))
129 + {
130 + // extract class name from object
131 + $t = get_class($this->dispatcher);
132 + }
133 + else
134 + {
135 + // fetch the type of the property
136 + $t = gettype($this->dispatcher);
137 + }
138 +
139 + // nope, throw a "Not acceptable" 406 error
140 + throw new UnexpectedValueException(sprintf('The [%s] object is not a valid dispatcher instance', $t), 406);
141 + }
142 +
143 + return $this->dispatcher;
144 + }
145 +
146 + /**
147 + * Creates a new URI helper instance.
148 + *
149 + * @return VBOPlatformUriInterface
150 + */
151 + abstract protected function createUri();
152 +
153 + /**
154 + * Creates a new mailer instance.
155 + *
156 + * @return VBOPlatformMailerInterface
157 + */
158 + abstract protected function createMailer();
159 +
160 + /**
161 + * Creates a new event dispatcher instance.
162 + *
163 + * @return VBOPlatformDispatcherInterface
164 + *
165 + * @since 1.5.10
166 + */
167 + abstract protected function createDispatcher();
168 +}