PluginProbe
PayPlug for WooCommerce (Official) / 3.0.0
PayPlug for WooCommerce (Official) v3.0.0
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / src / Traits / ServiceGetter.php

ServiceGetter.php in PayPlug for WooCommerce (Official) 3.0.0, at src/Traits/ServiceGetter.php

61 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce\Traits;
4
5 trait ServiceGetter
6 {
7 private $configuration;
8 private $api;
9
10 /**
11 * @param $name
12 *
13 * @return object|null
14 */
15 public function get_service($name = '')
16 {
17 if (!is_string($name) || empty($name)) {
18 return null;
19 }
20
21 try {
22 $service_name = '\Payplug\PayplugWoocommerce\Service\\';
23 $service_name .= str_replace('_', '', ucwords($name, '_'));
24
25 if (!class_exists($service_name)) {
26 return null;
27 }
28 $service = new $service_name();
29 // $this->{$name} = new $service_name();
30 } catch (\Exception $e) {
31 return null;
32 }
33
34 return $service;
35 }
36
37 /**
38 * @return object|null
39 */
40 public function get_configuration()
41 {
42 $this->configuration = empty($this->configuration)
43 ? $this->get_service('configuration')
44 : $this->configuration;
45
46 return $this->configuration;
47 }
48
49 /**
50 * @return object|null
51 */
52 public function get_api()
53 {
54 $this->api = empty($this->api)
55 ? $this->get_service('api')
56 : $this->api;
57
58 return $this->api;
59 }
60 }
61