<commit_before><?php

namespace Behat\Mink;

use Behat\Mink\Driver\DriverInterface,
    Behat\Mink\Selector\SelectorsHandler;

/*
 * This file is part of the Behat\Mink.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Mink.
 *
 * @author      <NAME> <<EMAIL>>
 */
class Mink
{
    private $selectorsHandler;
    private $defaultDriverName;
    private $currentDriverName;
    private $drivers = array();

    /**
     * Initializes mink.
     *
     * @param   Behat\Mink\Selector\SelectorsHandler    $selectorsHandler
     */
    public function __construct(SelectorsHandler $selectorsHandler = null)
    {
        if (null === $selectorsHandler) {
            $selectorsHandler = new SelectorsHandler();
        }

        $this->selectorsHandler = $selectorsHandler;
    }

    /**
     * Stops all started drivers.
     */
    public function __destruct()
    {
        foreach ($this->drivers as $driver) {
            if ($driver->isStarted()) {
                $driver->stop();
            }
        }
    }

    /**
     * Registers new driver.
     *
     * @param   string                              $name       driver alias name
     * @param   Behat\Mink\Driver\DriverInterface   $driver     driver instance
     * @param   Boolean                             $isDefault  should this driver be the default one?
     */
    public function registerDriver($name, DriverInterface $driver, $isDefault = false)
    {
        $name = strtolower($name);

        $this->drivers[$name] = $driver;

        if ($isDefault) {
            $this->defaultDriverName = $name;
        }
    }

    /**
     * Switches mink to specific driver.
     *
     * @param   string  $name   driver alias name
     */
    public function switchToDriver($name)
    {
        $name = strtolower($name);

        if (!isset($this->drivers[$name])) {
            throw new \InvalidArgumentException(sprintf('Driver "%s" is not registered.', $name));
        }

        if (null !== $this->currentDriverName && $name === $this->currentDriverName) {
            return;
        }

        $this->currentDriverName = $name;
    }

    /**
     * Switches mink to default driver.
     */
    public function switchToDefaultDriver()
    {
        if (null === $this->defaultDriverName) {
            throw new \RuntimeException('Default driver is not defined.');
        }

        $this->switchToDriver($this->defaultDriverName);
    }

    /**
     * Resets driver (between tests for example).
     */
    public function resetDriver()
    {
        $this->getDriver()->reset();
    }

    /**
     * Returns mink session, initialized with current (or default) driver.
     *
     * @return  Behat\Mink\Session
     */
    public function getSession()
    {
        static $session;

        if (null === $session || $session->getDriver() !== $this->getDriver()) {
            $session = new Session($this->getDriver(), $this->selectorsHandler);
        }

        return $session;
    }

    /**
     * Returns current (or default) driver.
     *
     * @return  Behat\Mink\Driver\DriverInterface
     */
    private function getDriver()
    {
        if (null === $this->currentDriverName) {
            $this->switchToDefaultDriver();
        }

        if (!$this->drivers[$this->currentDriverName]->isStarted()) {<commit_msg>added ability to stop drivers explicitly<commit_after><?php

namespace Behat\Mink;

use Behat\Mink\Driver\DriverInterface,
    Behat\Mink\Selector\SelectorsHandler;

/*
 * This file is part of the Behat\Mink.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Mink.
 *
 * @author      <NAME> <<EMAIL>>
 */
class Mink
{
    private $selectorsHandler;
    private $defaultDriverName;
    private $currentDriverName;
    private $drivers = array();

    /**
     * Initializes mink.
     *
     * @param   Behat\Mink\Selector\SelectorsHandler    $selectorsHandler
     */
    public function __construct(SelectorsHandler $selectorsHandler = null)
    {
        if (null === $selectorsHandler) {
            $selectorsHandler = new SelectorsHandler();
        }

        $this->selectorsHandler = $selectorsHandler;
    }

    /**
     * Stops all started drivers.
     */
    public function __destruct()
    {
        $this->stopDrivers();
    }

    /**
     * Registers new driver.
     *
     * @param   string                              $name       driver alias name
     * @param   Behat\Mink\Driver\DriverInterface   $driver     driver instance
     * @param   Boolean                             $isDefault  should this driver be the default one?
     */
    public function registerDriver($name, DriverInterface $driver, $isDefault = false)
    {
        $name = strtolower($name);

        $this->drivers[$name] = $driver;

        if ($isDefault) {
            $this->defaultDriverName = $name;
        }
    }

    /**
     * Switches mink to specific driver.
     *
     * @param   string  $name   driver alias name
     */
    public function switchToDriver($name)
    {
        $name = strtolower($name);

        if (!isset($this->drivers[$name])) {
            throw new \InvalidArgumentException(sprintf('Driver "%s" is not registered.', $name));
        }

        if (null !== $this->currentDriverName && $name === $this->currentDriverName) {
            return;
        }

        $this->currentDriverName = $name;
    }

    /**
     * Switches mink to default driver.
     */
    public function switchToDefaultDriver()
    {
        if (null === $this->defaultDriverName) {
            throw new \RuntimeException('Default driver is not defined.');
        }

        $this->switchToDriver($this->defaultDriverName);
    }

    /**
     * Resets driver (between tests for example).
     */
    public function resetDriver()
    {
        $this->getDriver()->reset();
    }

    /**
     * Stop all started drivers. 
     */
    public function stopDrivers()
    {
        foreach ($this->drivers as $driver) {
            if ($driver->isStarted()) {
                $driver->stop();
            }
        }
    }

    /**
     * Returns mink session, initialized with current (or default) driver.
     *
     * @return  Behat\Mink\Session
     */
    public function getSession()
    {
        static $session;

        if (null === $session || $session->getDriver() !== $this->getDriver()) {
            $session = new Session($this->getDriver(), $this->selectorsHandler);
        }

        return $session;
    }

    /**
     * Returns current (or default) driver.
     *
     * @return  Behat\Mink\Driver\DriverInterface
     */
    private function getDriver()
    {
        if (null === $this->currentDriverName) {
            $this->switchToDefaultDriver();
        }

        if (!$this->drivers[$this->currentDriverName]->isStarted()) {
{'fraction_non_alphanumeric': 0.12760193897918448, 'fraction_numerical': 0.0, 'mean_word_length': 1.9787685774946921, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5251361', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1942, 'n_words': 467}