Info.php 826 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Devtool;
  12. use Hyperf\Devtool\Adapter\AbstractAdapter;
  13. use Psr\Container\ContainerInterface;
  14. class Info
  15. {
  16. public function __construct(private ContainerInterface $container)
  17. {
  18. }
  19. public function get(string $key): ?AbstractAdapter
  20. {
  21. if (! $this->has($key)) {
  22. return null;
  23. }
  24. $class = __NAMESPACE__ . '\\Adapter\\' . ucfirst($key);
  25. return $this->container->get($class);
  26. }
  27. public function has(string $key): bool
  28. {
  29. return class_exists(__NAMESPACE__ . '\\Adapter\\' . ucfirst($key));
  30. }
  31. }