php - ZF2 domain specific object -
i have fetch entity object, based on given domain of application. based on entity, other services handle requests.
is there way store static object or that? or should inject other services, should store way?
thanks help
-- edit --
now have following service factory return wantend entity. have problem, in case of default domain, no entity exists , application crashes because can't return null value in factory. how can solve that?
namespace client\factory; use zend\servicemanager\factoryinterface; use zend\servicemanager\servicelocatorinterface; class clientfactory implements factoryinterface { /** * @param \zend\servicemanager\servicelocatorinterface $servicelocator * @return \client\entity\client */ public function createservice(servicelocatorinterface $servicelocator) { /* @var $clientservice \client\service\clientserviceinterface */ $clientservice = $servicelocator->get('client\service\client'); $baseurl = $servicelocator->get('request')->geturi()->gethost(); // client.mydomain.com returns client entity // www.mydomain.com doesn't return client entity return $clientservice->getclientbybaseurl($baseurl); } }
Comments
Post a Comment