Created
May 13, 2015 20:35
-
-
Save tjlytle/5b5cc9df2555f8db6ad1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Zend\ServiceManager\AbstractFactoryInterface; | |
use Zend\ServiceManager\ServiceLocatorInterface; | |
class ClientFactory implements AbstractFactoryInterface | |
{ | |
protected $services = [ | |
'Nexmo\Sms', | |
'Nexmo\Voice', | |
'Nexmo\Developer', | |
'Nexmo\Verify', | |
'Nexmo\Insight' | |
]; | |
protected $config = []; | |
/** | |
* Determine if we can create a service with name | |
* | |
* @param ServiceLocatorInterface $serviceLocator | |
* @param $name | |
* @param $requestedName | |
* @return bool | |
*/ | |
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) | |
{ | |
if(!in_array($requestedName, $this->services)){ | |
return false; | |
} | |
if(empty($this->config) AND !$serviceLocator->has('config')){ | |
return false; | |
} | |
$this->config = $serviceLocator->get('config'); | |
if(!isset($this->config['nexmo'])){ | |
return false; | |
} | |
return true; | |
} | |
/** | |
* Create service with name | |
* | |
* @param ServiceLocatorInterface $serviceLocator | |
* @param $name | |
* @param $requestedName | |
* @return mixed | |
*/ | |
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) | |
{ | |
return new $requestedName($this->config['nexmo']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment