diff options
author | Wolfy-J <[email protected]> | 2020-12-14 13:27:35 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2020-12-14 13:27:35 +0300 |
commit | 00b42663891713f142a6cc67bcccdc31353daeb2 (patch) | |
tree | 1c3966f18c15f3815e47cb065917b314be23472c /tests/src/Environment.php | |
parent | 8203dc4d76624f4fceddff49b8a1aba9d525fc73 (diff) |
- removed old RoadRunner code
- added new RR source code
Diffstat (limited to 'tests/src/Environment.php')
-rw-r--r-- | tests/src/Environment.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/src/Environment.php b/tests/src/Environment.php new file mode 100644 index 00000000..9b306063 --- /dev/null +++ b/tests/src/Environment.php @@ -0,0 +1,82 @@ +<?php + +/** + * High-performance PHP process supervisor and load balancer written in Go. + * + * @author Wolfy-J + */ + +declare(strict_types=1); + +namespace Spiral\RoadRunner; + +use Spiral\RoadRunner\Exception\EnvironmentException; + +class Environment implements EnvironmentInterface +{ + /** @var array */ + private array $env; + + /** + * @param array $env + */ + public function __construct(array $env) + { + $this->env = $env; + } + + /** + * Returns worker mode assigned to the PHP process. + * + * @return string + * @throws EnvironmentException + */ + public function getMode(): string + { + return $this->getValue('RR_MODE'); + } + + /** + * Address worker should be connected to (or pipes). + * + * @return string + * @throws EnvironmentException + */ + public function getRelayAddress(): string + { + return $this->getValue('RR_RELAY'); + } + + /** + * RPC address. + * + * @return string + * @throws EnvironmentException + */ + public function getRPCAddress(): string + { + return $this->getValue('RR_RPC'); + } + + /** + * @param string $name + * @return string + * @throws EnvironmentException + */ + private function getValue(string $name): string + { + if (!isset($this->env[$name])) { + throw new EnvironmentException(sprintf("Missing environment value `%s`", $name)); + } + + return (string) $this->env[$name]; + } + + /** + * @return EnvironmentInterface + */ + public static function fromGlobals(): EnvironmentInterface + { + return new static(array_merge($_SERVER, $_ENV)); + } +} |