I am migrating fro ZF2 to Laminas. I used ServiceLocatorAwareInterface to get config into my entity classes:
<?php
namespace Application\Model;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class ServiceLocatorAwareEntity implements ServiceLocatorAwareInterface
{
protected $sm;
protected $config;
/**
* Set the service locator
*
* @param ServiceLocatorInterface $sm
*
* @return void
*/
public function setServiceLocator(ServiceLocatorInterface $sm)
{
$this->sm = $sm;
$this->config = $sm->get('Config');
}
/**
* Get the service locator
*
* @return ServiceLocator ServiceLocator instance
*/
public function getServiceLocator()
{
return $this->sm;
}
}
and the entity:
<?php
namespace Application\Entity;
use Application\Model\ServiceLocatorAwareEntity;
class Photo extends ServiceLocatorAwareEntity
{
public function getData()
{
return $this->config['photo'];
}
}
I am struggling with this in Laminas. How can it be done? This Photo entity is used as doctrine entity so i think it can’t have parametrized constructor.