Файловый менеджер - Редактировать - /var/www/html/php-http.zip
Ðазад
PK ! ���e e * discovery/src/HttpAsyncClientDiscovery.phpnu �[��� <?php namespace Http\Discovery; use Http\Client\HttpAsyncClient; use Http\Discovery\Exception\DiscoveryFailedException; /** * Finds an HTTP Asynchronous Client. * * @author Joel Wurtz <joel.wurtz@gmail.com> */ final class HttpAsyncClientDiscovery extends ClassDiscovery { /** * Finds an HTTP Async Client. * * @return HttpAsyncClient * * @throws Exception\NotFoundException */ public static function find() { try { $asyncClient = static::findOneByType(HttpAsyncClient::class); } catch (DiscoveryFailedException $e) { throw new NotFoundException('No HTTPlug async clients found. Make sure to install a package providing "php-http/async-client-implementation". Example: "php-http/guzzle6-adapter".', 0, $e); } return static::instantiateClass($asyncClient); } } PK ! ���3> > discovery/src/ClassDiscovery.phpnu �[��� <?php namespace Http\Discovery; use Http\Discovery\Exception\ClassInstantiationFailedException; use Http\Discovery\Exception\DiscoveryFailedException; use Http\Discovery\Exception\NoCandidateFoundException; use Http\Discovery\Exception\StrategyUnavailableException; use Http\Discovery\Strategy\DiscoveryStrategy; /** * Registry that based find results on class existence. * * @author David de Boer <david@ddeboer.nl> * @author Márk Sági-Kazár <mark.sagikazar@gmail.com> * @author Tobias Nyholm <tobias.nyholm@gmail.com> */ abstract class ClassDiscovery { /** * A list of strategies to find classes. * * @var DiscoveryStrategy[] */ private static $strategies = [ Strategy\GeneratedDiscoveryStrategy::class, Strategy\CommonClassesStrategy::class, Strategy\CommonPsr17ClassesStrategy::class, Strategy\PuliBetaStrategy::class, ]; private static $deprecatedStrategies = [ Strategy\PuliBetaStrategy::class => true, ]; /** * Discovery cache to make the second time we use discovery faster. * * @var array */ private static $cache = []; /** * Finds a class. * * @param string $type * * @return string|\Closure * * @throws DiscoveryFailedException */ protected static function findOneByType($type) { // Look in the cache if (null !== ($class = self::getFromCache($type))) { return $class; } static $skipStrategy; $skipStrategy ?? $skipStrategy = self::safeClassExists(Strategy\GeneratedDiscoveryStrategy::class) ? false : Strategy\GeneratedDiscoveryStrategy::class; $exceptions = []; foreach (self::$strategies as $strategy) { if ($skipStrategy === $strategy) { continue; } try { $candidates = $strategy::getCandidates($type); } catch (StrategyUnavailableException $e) { if (!isset(self::$deprecatedStrategies[$strategy])) { $exceptions[] = $e; } continue; } foreach ($candidates as $candidate) { if (isset($candidate['condition'])) { if (!self::evaluateCondition($candidate['condition'])) { continue; } } // save the result for later use self::storeInCache($type, $candidate); return $candidate['class']; } $exceptions[] = new NoCandidateFoundException($strategy, $candidates); } throw DiscoveryFailedException::create($exceptions); } /** * Get a value from cache. * * @param string $type * * @return string|null */ private static function getFromCache($type) { if (!isset(self::$cache[$type])) { return; } $candidate = self::$cache[$type]; if (isset($candidate['condition'])) { if (!self::evaluateCondition($candidate['condition'])) { return; } } return $candidate['class']; } /** * Store a value in cache. * * @param string $type * @param string $class */ private static function storeInCache($type, $class) { self::$cache[$type] = $class; } /** * Set new strategies and clear the cache. * * @param string[] $strategies list of fully qualified class names that implement DiscoveryStrategy */ public static function setStrategies(array $strategies) { self::$strategies = $strategies; self::clearCache(); } /** * Returns the currently configured discovery strategies as fully qualified class names. * * @return string[] */ public static function getStrategies(): iterable { return self::$strategies; } /** * Append a strategy at the end of the strategy queue. * * @param string $strategy Fully qualified class name of a DiscoveryStrategy */ public static function appendStrategy($strategy) { self::$strategies[] = $strategy; self::clearCache(); } /** * Prepend a strategy at the beginning of the strategy queue. * * @param string $strategy Fully qualified class name to a DiscoveryStrategy */ public static function prependStrategy($strategy) { array_unshift(self::$strategies, $strategy); self::clearCache(); } public static function clearCache() { self::$cache = []; } /** * Evaluates conditions to boolean. * * @return bool */ protected static function evaluateCondition($condition) { if (is_string($condition)) { // Should be extended for functions, extensions??? return self::safeClassExists($condition); } if (is_callable($condition)) { return (bool) $condition(); } if (is_bool($condition)) { return $condition; } if (is_array($condition)) { foreach ($condition as $c) { if (false === static::evaluateCondition($c)) { // Immediately stop execution if the condition is false return false; } } return true; } return false; } /** * Get an instance of the $class. * * @param string|\Closure $class a FQCN of a class or a closure that instantiate the class * * @return object * * @throws ClassInstantiationFailedException */ protected static function instantiateClass($class) { try { if (is_string($class)) { return new $class(); } if (is_callable($class)) { return $class(); } } catch (\Exception $e) { throw new ClassInstantiationFailedException('Unexpected exception when instantiating class.', 0, $e); } throw new ClassInstantiationFailedException('Could not instantiate class because parameter is neither a callable nor a string'); } /** * We need a "safe" version of PHP's "class_exists" because Magento has a bug * (or they call it a "feature"). Magento is throwing an exception if you do class_exists() * on a class that ends with "Factory" and if that file does not exits. * * This function catches all potential exceptions and makes sure to always return a boolean. * * @param string $class * * @return bool */ public static function safeClassExists($class) { try { return class_exists($class) || interface_exists($class); } catch (\Exception $e) { return false; } } } PK ! ҞG�� � discovery/src/Exception.phpnu �[��� <?php namespace Http\Discovery; /** * An interface implemented by all discovery related exceptions. * * @author Tobias Nyholm <tobias.nyholm@gmail.com> */ interface Exception extends \Throwable { } PK ! �4�{I {I ! discovery/src/Composer/Plugin.phpnu �[��� <?php namespace Http\Discovery\Composer; use Composer\Composer; use Composer\DependencyResolver\Pool; use Composer\EventDispatcher\EventSubscriberInterface; use Composer\Factory; use Composer\Installer; use Composer\IO\IOInterface; use Composer\Json\JsonFile; use Composer\Json\JsonManipulator; use Composer\Package\Locker; use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionSelector; use Composer\Plugin\PluginInterface; use Composer\Repository\InstalledRepositoryInterface; use Composer\Repository\RepositorySet; use Composer\Script\Event; use Composer\Script\ScriptEvents; use Composer\Util\Filesystem; use Http\Discovery\ClassDiscovery; /** * Auto-installs missing implementations. * * When a dependency requires both this package and one of the supported `*-implementation` * virtual packages, this plugin will auto-install a well-known implementation if none is * found. The plugin will first look at already installed packages and figure out the * preferred implementation to install based on the below stickyness rules (or on the first * listed implementation if no rules match.) * * Don't miss updating src/Strategy/Common*Strategy.php when adding a new supported package. * * @author Nicolas Grekas <p@tchwork.com> * * @internal */ class Plugin implements PluginInterface, EventSubscriberInterface { /** * Describes, for every supported virtual implementation, which packages * provide said implementation and which extra dependencies each package * requires to provide the implementation. */ private const PROVIDE_RULES = [ 'php-http/async-client-implementation' => [ 'symfony/http-client:>=6.3' => ['guzzlehttp/promises', 'psr/http-factory-implementation', 'php-http/httplug'], 'symfony/http-client' => ['guzzlehttp/promises', 'php-http/message-factory', 'psr/http-factory-implementation', 'php-http/httplug'], 'php-http/guzzle7-adapter' => [], 'php-http/guzzle6-adapter' => [], 'php-http/curl-client' => [], 'php-http/react-adapter' => [], ], 'php-http/client-implementation' => [ 'symfony/http-client:>=6.3' => ['psr/http-factory-implementation', 'php-http/httplug'], 'symfony/http-client' => ['php-http/message-factory', 'psr/http-factory-implementation', 'php-http/httplug'], 'php-http/guzzle7-adapter' => [], 'php-http/guzzle6-adapter' => [], 'php-http/cakephp-adapter' => [], 'php-http/curl-client' => [], 'php-http/react-adapter' => [], 'php-http/buzz-adapter' => [], 'php-http/artax-adapter' => [], 'kriswallsmith/buzz:^1' => [], ], 'psr/http-client-implementation' => [ 'symfony/http-client' => ['psr/http-factory-implementation', 'psr/http-client'], 'guzzlehttp/guzzle' => [], 'kriswallsmith/buzz:^1' => [], ], 'psr/http-message-implementation' => [ 'php-http/discovery' => ['psr/http-factory-implementation'], ], 'psr/http-factory-implementation' => [ 'nyholm/psr7' => [], 'guzzlehttp/psr7:>=2' => [], 'slim/psr7' => [], 'laminas/laminas-diactoros' => [], 'phalcon/cphalcon:^4' => [], 'http-interop/http-factory-guzzle' => [], 'http-interop/http-factory-diactoros' => [], 'http-interop/http-factory-slim' => [], 'httpsoft/http-message' => [], ], ]; /** * Describes which package should be preferred on the left side * depending on which one is already installed on the right side. */ private const STICKYNESS_RULES = [ 'symfony/http-client' => 'symfony/framework-bundle', 'php-http/guzzle7-adapter' => 'guzzlehttp/guzzle:^7', 'php-http/guzzle6-adapter' => 'guzzlehttp/guzzle:^6', 'php-http/guzzle5-adapter' => 'guzzlehttp/guzzle:^5', 'php-http/cakephp-adapter' => 'cakephp/cakephp', 'php-http/react-adapter' => 'react/event-loop', 'php-http/buzz-adapter' => 'kriswallsmith/buzz:^0.15.1', 'php-http/artax-adapter' => 'amphp/artax:^3', 'http-interop/http-factory-guzzle' => 'guzzlehttp/psr7:^1', 'http-interop/http-factory-slim' => 'slim/slim:^3', ]; private const INTERFACE_MAP = [ 'php-http/async-client-implementation' => [ 'Http\Client\HttpAsyncClient', ], 'php-http/client-implementation' => [ 'Http\Client\HttpClient', ], 'psr/http-client-implementation' => [ 'Psr\Http\Client\ClientInterface', ], 'psr/http-factory-implementation' => [ 'Psr\Http\Message\RequestFactoryInterface', 'Psr\Http\Message\ResponseFactoryInterface', 'Psr\Http\Message\ServerRequestFactoryInterface', 'Psr\Http\Message\StreamFactoryInterface', 'Psr\Http\Message\UploadedFileFactoryInterface', 'Psr\Http\Message\UriFactoryInterface', ], ]; public static function getSubscribedEvents(): array { return [ ScriptEvents::PRE_AUTOLOAD_DUMP => 'preAutoloadDump', ScriptEvents::POST_UPDATE_CMD => 'postUpdate', ]; } public function activate(Composer $composer, IOInterface $io): void { } public function deactivate(Composer $composer, IOInterface $io) { } public function uninstall(Composer $composer, IOInterface $io) { } public function postUpdate(Event $event) { $composer = $event->getComposer(); $repo = $composer->getRepositoryManager()->getLocalRepository(); $requires = [ $composer->getPackage()->getRequires(), $composer->getPackage()->getDevRequires(), ]; $pinnedAbstractions = []; $pinned = $composer->getPackage()->getExtra()['discovery'] ?? []; foreach (self::INTERFACE_MAP as $abstraction => $interfaces) { foreach (isset($pinned[$abstraction]) ? [] : $interfaces as $interface) { if (!isset($pinned[$interface])) { continue 2; } } $pinnedAbstractions[$abstraction] = true; } $missingRequires = $this->getMissingRequires($repo, $requires, 'project' === $composer->getPackage()->getType(), $pinnedAbstractions); $missingRequires = [ 'require' => array_fill_keys(array_merge([], ...array_values($missingRequires[0])), '*'), 'require-dev' => array_fill_keys(array_merge([], ...array_values($missingRequires[1])), '*'), 'remove' => array_fill_keys(array_merge([], ...array_values($missingRequires[2])), '*'), ]; if (!$missingRequires = array_filter($missingRequires)) { return; } $composerJsonContents = file_get_contents(Factory::getComposerFile()); $this->updateComposerJson($missingRequires, $composer->getConfig()->get('sort-packages')); $installer = null; // Find the composer installer, hack borrowed from symfony/flex foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT) as $trace) { if (isset($trace['object']) && $trace['object'] instanceof Installer) { $installer = $trace['object']; break; } } if (!$installer) { return; } $event->stopPropagation(); $dispatcher = $composer->getEventDispatcher(); $disableScripts = !method_exists($dispatcher, 'setRunScripts') || !((array) $dispatcher)["\0*\0runScripts"]; $composer = Factory::create($event->getIO(), null, false, $disableScripts); /** @var Installer $installer */ $installer = clone $installer; if (method_exists($installer, 'setAudit')) { $trace['object']->setAudit(false); } // we need a clone of the installer to preserve its configuration state but with our own service objects $installer->__construct( $event->getIO(), $composer->getConfig(), $composer->getPackage(), $composer->getDownloadManager(), $composer->getRepositoryManager(), $composer->getLocker(), $composer->getInstallationManager(), $composer->getEventDispatcher(), $composer->getAutoloadGenerator() ); if (method_exists($installer, 'setPlatformRequirementFilter')) { $installer->setPlatformRequirementFilter(((array) $trace['object'])["\0*\0platformRequirementFilter"]); } if (0 !== $installer->run()) { file_put_contents(Factory::getComposerFile(), $composerJsonContents); return; } $versionSelector = new VersionSelector(ClassDiscovery::safeClassExists(RepositorySet::class) ? new RepositorySet() : new Pool()); $updateComposerJson = false; foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) { foreach (['require', 'require-dev'] as $key) { if (!isset($missingRequires[$key][$package->getName()])) { continue; } $updateComposerJson = true; $missingRequires[$key][$package->getName()] = $versionSelector->findRecommendedRequireVersion($package); } } if ($updateComposerJson) { $this->updateComposerJson($missingRequires, $composer->getConfig()->get('sort-packages')); $this->updateComposerLock($composer, $event->getIO()); } } public function getMissingRequires(InstalledRepositoryInterface $repo, array $requires, bool $isProject, array $pinnedAbstractions): array { $allPackages = []; $devPackages = method_exists($repo, 'getDevPackageNames') ? array_fill_keys($repo->getDevPackageNames(), true) : []; // One must require "php-http/discovery" // to opt-in for auto-installation of virtual package implementations if (!isset($requires[0]['php-http/discovery'])) { $requires = [[], []]; } foreach ($repo->getPackages() as $package) { $allPackages[$package->getName()] = true; if (1 < \count($names = $package->getNames(false))) { $allPackages += array_fill_keys($names, false); if (isset($devPackages[$package->getName()])) { $devPackages += $names; } } if (isset($package->getRequires()['php-http/discovery'])) { $requires[(int) isset($devPackages[$package->getName()])] += $package->getRequires(); } } $missingRequires = [[], [], []]; $versionParser = new VersionParser(); if (ClassDiscovery::safeClassExists(\Phalcon\Http\Message\RequestFactory::class, false)) { $missingRequires[0]['psr/http-factory-implementation'] = []; $missingRequires[1]['psr/http-factory-implementation'] = []; } foreach ($requires as $dev => $rules) { $abstractions = []; $rules = array_intersect_key(self::PROVIDE_RULES, $rules); while ($rules) { $abstraction = key($rules); if (isset($pinnedAbstractions[$abstraction])) { unset($rules[$abstraction]); continue; } $abstractions[] = $abstraction; foreach (array_shift($rules) as $candidate => $deps) { [$candidate, $version] = explode(':', $candidate, 2) + [1 => null]; if (!isset($allPackages[$candidate])) { continue; } if (null !== $version && !$repo->findPackage($candidate, $versionParser->parseConstraints($version))) { continue; } if ($isProject && !$dev && isset($devPackages[$candidate])) { $missingRequires[0][$abstraction] = [$candidate]; $missingRequires[2][$abstraction] = [$candidate]; } else { $missingRequires[$dev][$abstraction] = []; } foreach ($deps as $dep) { if (isset(self::PROVIDE_RULES[$dep])) { $rules[$dep] = self::PROVIDE_RULES[$dep]; } elseif (!isset($allPackages[$dep])) { $missingRequires[$dev][$abstraction][] = $dep; } elseif ($isProject && !$dev && isset($devPackages[$dep])) { $missingRequires[0][$abstraction][] = $dep; $missingRequires[2][$abstraction][] = $dep; } } break; } } while ($abstractions) { $abstraction = array_shift($abstractions); if (isset($missingRequires[$dev][$abstraction])) { continue; } $candidates = self::PROVIDE_RULES[$abstraction]; foreach ($candidates as $candidate => $deps) { [$candidate, $version] = explode(':', $candidate, 2) + [1 => null]; if (null !== $version && !$repo->findPackage($candidate, $versionParser->parseConstraints($version))) { continue; } if (isset($allPackages[$candidate]) && (!$isProject || $dev || !isset($devPackages[$candidate]))) { continue 2; } } foreach (array_intersect_key(self::STICKYNESS_RULES, $candidates) as $candidate => $stickyRule) { [$stickyName, $stickyVersion] = explode(':', $stickyRule, 2) + [1 => null]; if (!isset($allPackages[$stickyName]) || ($isProject && !$dev && isset($devPackages[$stickyName]))) { continue; } if (null !== $stickyVersion && !$repo->findPackage($stickyName, $versionParser->parseConstraints($stickyVersion))) { continue; } $candidates = [$candidate => $candidates[$candidate]]; break; } $dep = key($candidates); [$dep] = explode(':', $dep, 2); $missingRequires[$dev][$abstraction] = [$dep]; if ($isProject && !$dev && isset($devPackages[$dep])) { $missingRequires[2][$abstraction][] = $dep; } } } $missingRequires[1] = array_diff_key($missingRequires[1], $missingRequires[0]); return $missingRequires; } public function preAutoloadDump(Event $event) { $filesystem = new Filesystem(); // Double realpath() on purpose, see https://bugs.php.net/72738 $vendorDir = $filesystem->normalizePath(realpath(realpath($event->getComposer()->getConfig()->get('vendor-dir')))); $filesystem->ensureDirectoryExists($vendorDir.'/composer'); $pinned = $event->getComposer()->getPackage()->getExtra()['discovery'] ?? []; $candidates = []; $allInterfaces = array_merge(...array_values(self::INTERFACE_MAP)); foreach ($pinned as $abstraction => $class) { if (isset(self::INTERFACE_MAP[$abstraction])) { $interfaces = self::INTERFACE_MAP[$abstraction]; } elseif (false !== $k = array_search($abstraction, $allInterfaces, true)) { $interfaces = [$allInterfaces[$k]]; } else { throw new \UnexpectedValueException(sprintf('Invalid "extra.discovery" pinned in composer.json: "%s" is not one of ["%s"].', $abstraction, implode('", "', array_keys(self::INTERFACE_MAP)))); } foreach ($interfaces as $interface) { $candidates[] = sprintf("case %s: return [['class' => %s]];\n", var_export($interface, true), var_export($class, true)); } } $file = $vendorDir.'/composer/GeneratedDiscoveryStrategy.php'; if (!$candidates) { if (file_exists($file)) { unlink($file); } return; } $candidates = implode(' ', $candidates); $code = <<<EOPHP <?php namespace Http\Discovery\Strategy; class GeneratedDiscoveryStrategy implements DiscoveryStrategy { public static function getCandidates(\$type) { switch (\$type) { $candidates default: return []; } } } EOPHP ; if (!file_exists($file) || $code !== file_get_contents($file)) { file_put_contents($file, $code); } $rootPackage = $event->getComposer()->getPackage(); $autoload = $rootPackage->getAutoload(); $autoload['classmap'][] = $vendorDir.'/composer/GeneratedDiscoveryStrategy.php'; $rootPackage->setAutoload($autoload); } private function updateComposerJson(array $missingRequires, bool $sortPackages) { $file = Factory::getComposerFile(); $contents = file_get_contents($file); $manipulator = new JsonManipulator($contents); foreach ($missingRequires as $key => $packages) { foreach ($packages as $package => $constraint) { if ('remove' === $key) { $manipulator->removeSubNode('require-dev', $package); } else { $manipulator->addLink($key, $package, $constraint, $sortPackages); } } } file_put_contents($file, $manipulator->getContents()); } private function updateComposerLock(Composer $composer, IOInterface $io) { $lock = substr(Factory::getComposerFile(), 0, -4).'lock'; $composerJson = file_get_contents(Factory::getComposerFile()); $lockFile = new JsonFile($lock, null, $io); $locker = ClassDiscovery::safeClassExists(RepositorySet::class) ? new Locker($io, $lockFile, $composer->getInstallationManager(), $composerJson) : new Locker($io, $lockFile, $composer->getRepositoryManager(), $composer->getInstallationManager(), $composerJson); $lockData = $locker->getLockData(); $lockData['content-hash'] = Locker::getContentHash($composerJson); $lockFile->write($lockData); } } PK ! �)�� '