Pristine upstream, unpacked from the official wordpress.org tarball. https://wordpress.org/wordpress-7.1.1.tar.gz sha1 2a9d68474e8703aa3a66f80427b325e0941b6a1e (published by wordpress.org) sha256 3996fee13448ef12e07e9f0c77db2f655ffa1b7cde71c80a4965d3bf1fb956b3 This branch carries nothing but upstream releases, one commit each, and is never edited. It is the other side of the git-subtree merge that brings security releases into SiriusPress/wordpress/ — see SiriusPress/docs/upstream-merges.md.
77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace WordPress\AiClientDependencies\Http\Discovery\Strategy;
|
|
|
|
use WordPress\AiClientDependencies\Http\Discovery\ClassDiscovery;
|
|
use WordPress\AiClientDependencies\Http\Discovery\Exception\PuliUnavailableException;
|
|
use WordPress\AiClientDependencies\Puli\Discovery\Api\Discovery;
|
|
use WordPress\AiClientDependencies\Puli\GeneratedPuliFactory;
|
|
/**
|
|
* Find candidates using Puli.
|
|
*
|
|
* @internal
|
|
*
|
|
* @final
|
|
*
|
|
* @author David de Boer <david@ddeboer.nl>
|
|
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
|
|
*/
|
|
class PuliBetaStrategy implements DiscoveryStrategy
|
|
{
|
|
/**
|
|
* @var GeneratedPuliFactory
|
|
*/
|
|
protected static $puliFactory;
|
|
/**
|
|
* @var Discovery
|
|
*/
|
|
protected static $puliDiscovery;
|
|
/**
|
|
* @return GeneratedPuliFactory
|
|
*
|
|
* @throws PuliUnavailableException
|
|
*/
|
|
private static function getPuliFactory()
|
|
{
|
|
if (null === self::$puliFactory) {
|
|
if (!defined('PULI_FACTORY_CLASS')) {
|
|
throw new PuliUnavailableException('Puli Factory is not available');
|
|
}
|
|
$puliFactoryClass = PULI_FACTORY_CLASS;
|
|
if (!ClassDiscovery::safeClassExists($puliFactoryClass)) {
|
|
throw new PuliUnavailableException('Puli Factory class does not exist');
|
|
}
|
|
self::$puliFactory = new $puliFactoryClass();
|
|
}
|
|
return self::$puliFactory;
|
|
}
|
|
/**
|
|
* Returns the Puli discovery layer.
|
|
*
|
|
* @return Discovery
|
|
*
|
|
* @throws PuliUnavailableException
|
|
*/
|
|
private static function getPuliDiscovery()
|
|
{
|
|
if (!isset(self::$puliDiscovery)) {
|
|
$factory = self::getPuliFactory();
|
|
$repository = $factory->createRepository();
|
|
self::$puliDiscovery = $factory->createDiscovery($repository);
|
|
}
|
|
return self::$puliDiscovery;
|
|
}
|
|
public static function getCandidates($type)
|
|
{
|
|
$returnData = [];
|
|
$bindings = self::getPuliDiscovery()->findBindings($type);
|
|
foreach ($bindings as $binding) {
|
|
$condition = \true;
|
|
if ($binding->hasParameterValue('depends')) {
|
|
$condition = $binding->getParameterValue('depends');
|
|
}
|
|
$returnData[] = ['class' => $binding->getClassName(), 'condition' => $condition];
|
|
}
|
|
return $returnData;
|
|
}
|
|
}
|