PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / vendor / stripe / stripe-php / lib / Service / AbstractServiceFactory.php

AbstractServiceFactory.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at vendor/stripe/stripe-php/lib/Service/AbstractServiceFactory.php

60 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Stripe\Service;
4
5 /**
6 * Abstract base class for all service factories used to expose service
7 * instances through {@link \Stripe\StripeClient}.
8 *
9 * Service factories serve two purposes:
10 *
11 * 1. Expose properties for all services through the `__get()` magic method.
12 * 2. Lazily initialize each service instance the first time the property for
13 * a given service is used.
14 */
15 abstract class AbstractServiceFactory
16 {
17 /** @var \Stripe\StripeClientInterface */
18 private $client;
19
20 /** @var array<string, AbstractService|AbstractServiceFactory> */
21 private $services;
22
23 /**
24 * @param \Stripe\StripeClientInterface $client
25 */
26 public function __construct($client)
27 {
28 $this->client = $client;
29 $this->services = [];
30 }
31
32 /**
33 * @param string $name
34 *
35 * @return null|string
36 */
37 abstract protected function getServiceClass($name);
38
39 /**
40 * @param string $name
41 *
42 * @return null|AbstractService|AbstractServiceFactory
43 */
44 public function __get($name)
45 {
46 $serviceClass = $this->getServiceClass($name);
47 if (null !== $serviceClass) {
48 if (!\array_key_exists($name, $this->services)) {
49 $this->services[$name] = new $serviceClass($this->client);
50 }
51
52 return $this->services[$name];
53 }
54
55 \trigger_error('Undefined property: ' . static::class . '::$' . $name);
56
57 return null;
58 }
59 }
60