PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / libraries / http / discovery / Strategy / PuliBetaStrategy.php

PuliBetaStrategy.php in DecaLog 4.4.0, at includes/libraries/http/discovery/Strategy/PuliBetaStrategy.php

91 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Http\Discovery\Strategy;
4
5 use Http\Discovery\ClassDiscovery;
6 use Http\Discovery\Exception\PuliUnavailableException;
7 use Puli\Discovery\Api\Discovery;
8 use Puli\GeneratedPuliFactory;
9
10 /**
11 * Find candidates using Puli.
12 *
13 * @internal
14 *
15 * @final
16 *
17 * @author David de Boer <david@ddeboer.nl>
18 * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
19 */
20 class PuliBetaStrategy implements DiscoveryStrategy
21 {
22 /**
23 * @var GeneratedPuliFactory
24 */
25 protected static $puliFactory;
26
27 /**
28 * @var Discovery
29 */
30 protected static $puliDiscovery;
31
32 /**
33 * @return GeneratedPuliFactory
34 *
35 * @throws PuliUnavailableException
36 */
37 private static function getPuliFactory()
38 {
39 if (null === self::$puliFactory) {
40 if (!defined('PULI_FACTORY_CLASS')) {
41 throw new PuliUnavailableException('Puli Factory is not available');
42 }
43
44 $puliFactoryClass = PULI_FACTORY_CLASS;
45
46 if (!ClassDiscovery::safeClassExists($puliFactoryClass)) {
47 throw new PuliUnavailableException('Puli Factory class does not exist');
48 }
49
50 self::$puliFactory = new $puliFactoryClass();
51 }
52
53 return self::$puliFactory;
54 }
55
56 /**
57 * Returns the Puli discovery layer.
58 *
59 * @return Discovery
60 *
61 * @throws PuliUnavailableException
62 */
63 private static function getPuliDiscovery()
64 {
65 if (!isset(self::$puliDiscovery)) {
66 $factory = self::getPuliFactory();
67 $repository = $factory->createRepository();
68
69 self::$puliDiscovery = $factory->createDiscovery($repository);
70 }
71
72 return self::$puliDiscovery;
73 }
74
75 public static function getCandidates($type)
76 {
77 $returnData = [];
78 $bindings = self::getPuliDiscovery()->findBindings($type);
79
80 foreach ($bindings as $binding) {
81 $condition = true;
82 if ($binding->hasParameterValue('depends')) {
83 $condition = $binding->getParameterValue('depends');
84 }
85 $returnData[] = ['class' => $binding->getClassName(), 'condition' => $condition];
86 }
87
88 return $returnData;
89 }
90 }
91