Hello,
Consider the following Service.php file. Such files are created in EspoCRM when creating new entities:
What is the proper syntax for to set and access Di aware things? Suppose I want to access $this->language inside some method of this class. Do I override the parent constructor, if so, what is the proper syntax? Or do I do something this?
Consider the following Service.php file. Such files are created in EspoCRM when creating new entities:
PHP Code:
<?php
namespace Espo\Custom\Services;
class NoticeOfViolation extends \Espo\Core\Templates\Services\Base
{
}
What is the proper syntax for to set and access Di aware things? Suppose I want to access $this->language inside some method of this class. Do I override the parent constructor, if so, what is the proper syntax? Or do I do something this?
PHP Code:
<?php
namespace Espo\Custom\Services;
use Espo\Core\{
Di,
Templates\Services\Base as BaseService
};
/**
* @internal This class should not be removed as it's used by custom entities.
* @extends BaseService<\Espo\Custom\Entities\NoticeOfViolation>
*/
class NoticeOfViolation extends BaseService implements
Di\FileManagerAware,
Di\DataManagerAware,
Di\LanguageAware
{
use Di\FileManagerSetter;
use Di\DataManagerSetter;
use Di\LanguageSetter;
public function myMethod() {
$this->language->translateOption($value, $field,$scope);
}
}
Comment