mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
Applied fixes from StyleCI
This commit is contained in:
committed by
StyleCI Bot
parent
3663603b80
commit
fe1f144ec3
@@ -27,21 +27,21 @@ class ServiceLocator implements ServiceLocatorInterface
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->services = array();
|
||||
$this->services = array();
|
||||
$this->instantiated = array();
|
||||
$this->shared = array();
|
||||
$this->shared = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a service with specific interface.
|
||||
*
|
||||
* @param string $interface
|
||||
* @param string $interface
|
||||
* @param string|object $service
|
||||
* @param bool $share
|
||||
* @param bool $share
|
||||
*/
|
||||
public function add($interface, $service, $share = true)
|
||||
{
|
||||
/**
|
||||
/*
|
||||
* When you add a service, you should register it
|
||||
* with its interface or with a string that you can use
|
||||
* in the future even if you will change the service implementation.
|
||||
@@ -51,7 +51,7 @@ class ServiceLocator implements ServiceLocatorInterface
|
||||
$this->instantiated[$interface] = $service;
|
||||
}
|
||||
$this->services[$interface] = (is_object($service) ? get_class($service) : $service);
|
||||
$this->shared[$interface] = $share;
|
||||
$this->shared[$interface] = $share;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ class ServiceLocator implements ServiceLocatorInterface
|
||||
*/
|
||||
public function has($interface)
|
||||
{
|
||||
return (isset($this->services[$interface]) || isset($this->instantiated[$interface]));
|
||||
return isset($this->services[$interface]) || isset($this->instantiated[$interface]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +101,7 @@ class ServiceLocator implements ServiceLocatorInterface
|
||||
if ($this->shared[$interface]) {
|
||||
$this->instantiated[$interface] = $object;
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ namespace DesignPatterns\More\ServiceLocator\Tests;
|
||||
use DesignPatterns\More\ServiceLocator\DatabaseService;
|
||||
use DesignPatterns\More\ServiceLocator\LogService;
|
||||
use DesignPatterns\More\ServiceLocator\ServiceLocator;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class ServiceLocatorTest extends TestCase
|
||||
{
|
||||
@@ -26,8 +26,8 @@ class ServiceLocatorTest extends TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->serviceLocator = new ServiceLocator();
|
||||
$this->logService = new LogService();
|
||||
$this->serviceLocator = new ServiceLocator();
|
||||
$this->logService = new LogService();
|
||||
$this->databaseService = new DatabaseService();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user