1<?php
2
3namespace Facebook\WebDriver\Firefox;
4
5use Facebook\WebDriver\Remote\Service\DriverService;
6
7class FirefoxDriverService extends DriverService
8{
9    /**
10     * @var string Name of the environment variable storing the path to the driver binary
11     */
12    const WEBDRIVER_FIREFOX_DRIVER = 'WEBDRIVER_FIREFOX_DRIVER';
13    /**
14     * @var string Default executable used when no other is provided
15     * @internal
16     */
17    const DEFAULT_EXECUTABLE = 'geckodriver';
18
19    /**
20     * @return static
21     */
22    public static function createDefaultService()
23    {
24        $pathToExecutable = getenv(static::WEBDRIVER_FIREFOX_DRIVER);
25        if ($pathToExecutable === false || $pathToExecutable === '') {
26            $pathToExecutable = static::DEFAULT_EXECUTABLE;
27        }
28
29        $port = 9515; // TODO: Get another free port if the default port is used.
30        $args = ['-p=' . $port];
31
32        return new static($pathToExecutable, $port, $args);
33    }
34}
35