3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace J7mbo\SeleniumGrid2Api; use J7mbo\SeleniumGrid2Api\Entity\CapabilityFactory, J7mbo\SeleniumGrid2Api\Entity\NodeFactory, GuzzleHttp\Client as HttpClient, GuzzleHttp\Message\Response; /** * Class SeleniumGrid2Api * * @package J7mbo\SeleniumGrid2Api */ class SeleniumGrid2Api { /** * @var int The timeout for the request */ const REQUEST_TIMEOUT = 5; /** * @var HttpClient */ protected $httpClient; /** * @var JsonValidator */ protected $jsonValidator; /** * @var CapabilityFactory */ protected $capabilityFactory; /** * @var NodeFactory */ protected $nodeFactory; /** * @constructor * * @param HttpClient $httpClient * @param JsonValidator $jsonValidator * @param CapabilityFactory $capabilityFactory * @param NodeFactory $nodeFactory */ public function __construct( HttpClient $httpClient, JsonValidator $jsonValidator, CapabilityFactory $capabilityFactory, NodeFactory $nodeFactory ) { $this->httpClient = $httpClient; $this->jsonValidator = $jsonValidator; $this->capabilityFactory = $capabilityFactory; $this->nodeFactory = $nodeFactory; } /** * Get a Node entity representing the running node * * @param string $host * @param int $port * * @throws NotFoundException * * @return Entity\Node */ public function getNode($host = 'localhost', $port = 5555) { $uri = sprintf('http://%s:%d', $host, $port); $request = $this->httpClient->createRequest('GET', sprintf(Endpoints::NODE_STATUS), $uri, [ 'timeout' => self::REQUEST_TIMEOUT ]); try { /** @var Response $response */ /** @noinspection PhpVoidFunctionResultUsedInspection */ $response = $this->httpClient->send($request); if (($status = $response->getStatusCode()) !== 200) { throw new NotFoundException(sprintf('Status code for: %s returned %d', $uri, $status)); } if ($this->jsonValidator->isJson($response->getBody())) { throw new NotFoundException(sprintf('Invalid json returned from: %s', $uri)); } $data = json_decode($response->getBody(), true); $capabilities = []; foreach($data['request']['capabilities'] as $capability) { if ($capability['seleniumProtocol'] === 'WebDriver') { $capabilities[] = $this->capabilityFactory->build( $capability['browsername'], $capability['maxInstances'], $capability['platform'] ); } } return $this->nodeFactory->build($capabilities, $host, $port); } catch (\Exception $e) { throw new NotFoundException($e->getMessage()); } } }
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/qh70Q on line 76
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/qh70Q on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/qh70Q on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qh70Q on line 3
Process exited with code 255.

preferences:
141.95 ms | 411 KiB | 5 Q