PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / symfony / service-contracts / ServiceSubscriberTrait.php

ServiceSubscriberTrait.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at vendor/symfony/service-contracts/ServiceSubscriberTrait.php

110 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Contracts\Service;
13
14 use Psr\Container\ContainerInterface;
15 use Symfony\Contracts\Service\Attribute\SubscribedService;
16
17 /**
18 * Implementation of ServiceSubscriberInterface that determines subscribed services from
19 * method return types. Service ids are available as "ClassName::methodName".
20 *
21 * @author Kevin Bond <[email protected]>
22 */
23 trait ServiceSubscriberTrait
24 {
25 /** @var ContainerInterface */
26 protected $container;
27
28 /**
29 * {@inheritdoc}
30 */
31 public static function getSubscribedServices(): array
32 {
33 $services = method_exists(get_parent_class(self::class) ?: '', __FUNCTION__) ? parent::getSubscribedServices() : [];
34 $attributeOptIn = false;
35
36 if (\PHP_VERSION_ID >= 80000) {
37 foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
38 if (self::class !== $method->getDeclaringClass()->name) {
39 continue;
40 }
41
42 if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) {
43 continue;
44 }
45
46 if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
47 throw new \LogicException(sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class, $method->name));
48 }
49
50 if (!$returnType = $method->getReturnType()) {
51 throw new \LogicException(sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class, $method->name, self::class));
52 }
53
54 $serviceId = $returnType instanceof \ReflectionNamedType ? $returnType->getName() : (string) $returnType;
55
56 if ($returnType->allowsNull()) {
57 $serviceId = '?'.$serviceId;
58 }
59
60 $services[$attribute->newInstance()->key ?? self::class.'::'.$method->name] = $serviceId;
61 $attributeOptIn = true;
62 }
63 }
64
65 if (!$attributeOptIn) {
66 foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
67 if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
68 continue;
69 }
70
71 if (self::class !== $method->getDeclaringClass()->name) {
72 continue;
73 }
74
75 if (!($returnType = $method->getReturnType()) instanceof \ReflectionNamedType) {
76 continue;
77 }
78
79 if ($returnType->isBuiltin()) {
80 continue;
81 }
82
83 if (\PHP_VERSION_ID >= 80000) {
84 trigger_deprecation('symfony/service-contracts', '2.5', 'Using "%s" in "%s" without using the "%s" attribute on any method is deprecated.', ServiceSubscriberTrait::class, self::class, SubscribedService::class);
85 }
86
87 $services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType);
88 }
89 }
90
91 return $services;
92 }
93
94 /**
95 * @required
96 *
97 * @return ContainerInterface|null
98 */
99 public function setContainer(ContainerInterface $container)
100 {
101 $this->container = $container;
102
103 if (method_exists(get_parent_class(self::class) ?: '', __FUNCTION__)) {
104 return parent::setContainer($container);
105 }
106
107 return null;
108 }
109 }
110