westdc-core/Westdc/Service/ServiceFactory.php

48 lines
1.1 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2014/11/4
* Time: 10:39
*/
namespace Westdc\Service;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\AbstractFactoryInterface;
class ServiceFactory implements AbstractFactoryInterface{
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$serviceAgentDir = __DIR__ . "/ServiceAgent";
if(is_dir($serviceAgentDir))
{
if(false != ($handle = opendir($serviceAgentDir)))
{
while(false !== ($file = readdir($handle)))
{
if(substr($file,0,strlen($file)-4) == (string)$requestedName) {
return true;
}
}
}
}
return false;
}
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$serviceName = __NAMESPACE__ . "\\ServiceAgent\\" . $requestedName;
$service = new $serviceName;
$service->name = $requestedName;
return $service;
}
}