Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ServiceFactory.php

class ServiceFactory

WebDriver\ServiceFactory class

A service factory

@package WebDriver

Hierarchy

  • class \WebDriver\ServiceFactory

Expanded class hierarchy of ServiceFactory

1 file declares its use of ServiceFactory
SauceRest.php in vendor/lullabot/php-webdriver/lib/WebDriver/SauceLabs/SauceRest.php

File

vendor/lullabot/php-webdriver/lib/WebDriver/ServiceFactory.php, line 21

Namespace

WebDriver
View source
class ServiceFactory {
    
    /**
     * singleton
     *
     * @var \WebDriver\ServiceFactory
     */
    private static $instance;
    
    /**
     * @var array
     */
    protected $services;
    
    /**
     * @var array
     */
    protected $serviceClasses;
    
    /**
     * Private constructor
     */
    private function __construct() {
        $this->services = array();
        $this->serviceClasses = array(
            'service.curl' => '\\WebDriver\\Service\\CurlService',
        );
    }
    
    /**
     * Get singleton instance
     *
     * @return \WebDriver\ServiceFactory
     */
    public static function getInstance() {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    
    /**
     * Get service
     *
     * @param string $serviceName Name of service
     *
     * @return object
     */
    public function getService($serviceName) {
        if (!isset($this->services[$serviceName])) {
            $className = $this->serviceClasses[$serviceName];
            $this->services[$serviceName] = new $className();
        }
        return $this->services[$serviceName];
    }
    
    /**
     * Set service
     *
     * @param string $serviceName Name of service
     * @param object $service     Service instance
     */
    public function setService($serviceName, $service) {
        $this->services[$serviceName] = $service;
    }
    
    /**
     * Override default service class
     *
     * @param string $serviceName Name of service
     * @param string $className   Name of service class
     */
    public function setServiceClass($serviceName, $className) {
        if (substr($className, 0, 1) !== '\\') {
            $className = '\\' . $className;
        }
        $this->serviceClasses[$serviceName] = $className;
        $this->services[$serviceName] = null;
    }

}

Members

Title Sort descending Modifiers Object type Summary
ServiceFactory::$instance private static property singleton
ServiceFactory::$serviceClasses protected property
ServiceFactory::$services protected property
ServiceFactory::getInstance public static function Get singleton instance
ServiceFactory::getService public function Get service
ServiceFactory::setService public function Set service
ServiceFactory::setServiceClass public function Override default service class
ServiceFactory::__construct private function Private constructor

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal