1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Core\Service;
13:
14: /**
15: * Null Service Provider object
16: *
17: * This provider will be used whenever there is no provider defined
18: * for the service name requested. This will allow service consumers
19: * to avoid handling the condition of a service not being available.
20: *
21: * Any calls to service methods will return NULL.
22: *
23: * Any read of service properties will return null, and any check for
24: * isset() will return false.
25: *
26: * @category Xoops\Core\Service\NullProvider
27: * @package Xoops\Core
28: * @author Richard Griffith <richard@geekwright.com>
29: * @copyright 2013-2015 The XOOPS Project https://github.com/XOOPS/XoopsCore
30: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
31: * @version Release: 1.0
32: * @link http://xoops.org
33: * @since 2.6.0
34: */
35: class NullProvider extends Provider
36: {
37: /** @var Response - a 'null' response object returned for any method calls */
38: private $response = null;
39:
40: /**
41: * __construct
42: *
43: * @param Manager $manager Manager instance
44: * @param string $service service name (case sensitive)
45: */
46: public function __construct(Manager $manager, $service)
47: {
48: $this->response = new Response();
49: $this->response->setSuccess(false)->addErrorMessage(sprintf("No provider installed for %s", $service));
50: parent::__construct($manager, $service);
51: }
52:
53: /**
54: * isAvailable - indicate the (lack of) availability of an actual provider
55: *
56: * @return boolean false to indicate no provider is available
57: */
58: public function isAvailable()
59: {
60: return false;
61: }
62:
63: /**
64: * Any property writes will go here
65: *
66: * @param string $name not used
67: * @param mixed $value not used
68: *
69: * @return void
70: */
71: public function __set($name, $value)
72: {
73: }
74:
75: /**
76: * Any property reads will go here and return null
77: *
78: * @param string $name not used
79: *
80: * @return null
81: */
82: public function __get($name)
83: {
84: return null;
85: }
86:
87: /**
88: * Any isset() or empty() on a property will go here and return false
89: *
90: * @param string $name not used
91: *
92: * @return false
93: */
94: public function __isset($name)
95: {
96: return false;
97: }
98:
99: /**
100: * Any property unset() will go here
101: *
102: * @param string $name not used
103: *
104: * @return void
105: */
106: public function __unset($name)
107: {
108: }
109:
110: /**
111: * All non-static methods go here and will return null response
112: *
113: * @param string $name not used
114: * @param mixed $arguments not used
115: *
116: * @return Response Response
117: */
118: public function __call($name, $arguments)
119: {
120: return $this->response;
121: }
122:
123: /**
124: * All static methods go here and will return null response
125: *
126: * @param string $name not used
127: * @param mixed $arguments not used
128: *
129: * @return Response Response
130: */
131: public static function __callStatic($name, $arguments)
132: {
133: $response = new Response();
134: $response->setSuccess(false)->addErrorMessage(sprintf("No provider installed for %s", get_called_class()));
135: return $response;
136: }
137: }
138: