我有这个服务:
<?php
namespace AppBundle'Services'facade;
use AppBundle'Support'Constants;
class ImageFacade extends AbstractFacade {
public function __construct('Doctrine'ORM'EntityManager $em) {
parent::__construct($em);
}
public function delete( $id ) {
return parent::deleteLine($id, (Constants::IMAGE_CLASS_NAME));
}
public function getDescription( $link ) {
$queryResult = $this->entityManager->getRepository(Constants::IMAGE_CLASS_NAME)->findBy( array('link' => $link ));
if ( count($queryResult) > 0 ) {
$image = $queryResult[0];
return $image->getDescription();
}
else {
return null;
}
}
}
我想从另一个服务使用它:
class ImageBn {
public function __construct() {
//get a reference to ImageFacade
}
}
我该怎么做?
感谢
您将ImageFacade作为依赖项添加到ImageBtn的构造函数中,并将其注册到您的服务配置文件中:
class ImageBn {
private $facade;
public function __construct(ImageFacade $facade) {
$this->facade = $facade;
}
}
在役。yml:
service.image_facade:
class: ...'ImageFacade
arguments: [@doctrine.orm.entity_manager]
service.image_button:
class: ...'ImageBn
arguments: [@service.image_facade]