3 * Copyright 2012-2017 Anthon Pang. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @author Anthon Pang <apang@softwaredevelopment.ca>
25 * WebDriver\ServiceFactory class
31 final class ServiceFactory
36 * @var \WebDriver\ServiceFactory
38 private static $instance;
48 protected $serviceClasses;
53 private function __construct()
55 $this->services = array();
57 $this->serviceClasses = array(
58 'service.curl' => '\\WebDriver\\Service\\CurlService',
63 * Get singleton instance
65 * @return \WebDriver\ServiceFactory
67 public static function getInstance()
69 if (!self::$instance) {
70 self::$instance = new self;
73 return self::$instance;
79 * @param string $serviceName Name of service
83 public function getService($serviceName)
85 if (!isset($this->services[$serviceName])) {
86 $className = $this->serviceClasses[$serviceName];
88 $this->services[$serviceName] = new $className;
91 return $this->services[$serviceName];
97 * @param string $serviceName Name of service
98 * @param object $service Service instance
100 public function setService($serviceName, $service)
102 $this->services[$serviceName] = $service;
106 * Override default service class
108 * @param string $serviceName Name of service
109 * @param string $className Name of service class
111 public function setServiceClass($serviceName, $className)
113 if (substr($className, 0, 1) !== '\\') {
114 $className = '\\' . $className;
117 $this->serviceClasses[$serviceName] = $className;
118 $this->services[$serviceName] = null;