2016-09-08 3 views
0

실 리우스 양식을위한 자체 공장을 만들려고합니다.실 리우스 - FactoryInterface를 내 공장에 주입하는 방법

실리아스 구성 요소를 검색하면 어떻게하는지 발견했습니다. 내가 Sylius의 FactoryInterface을 주입하는 방법을 찾을 수없는

class CommentFactory implements CommentFactoryInterface 
{ 
/** 
* @var FactoryInterface 
*/ 
private $factory; 

/** 
* @param FactoryInterface $factory 
*/ 
public function __construct(FactoryInterface $factory) 
{ 
    $this->factory = $factory; 
} 

/** 
* {@inheritDoc} 
*/ 
public function createNew() 
{ 
    return $this->factory->createNew(); 
} 

public function createWithPost($postId) 
{ 
    $comment = $this->createNew(); 
    $comment->setPost($postId); 

    return $comment; 
} 
} 

:

여기 내 공장입니다.

나는 서비스를 검색 할 수 php app/console debug:container | grep factory을 실행하지만 표시되지 않습니다 :(

어떤 제안? 지금까지 내가 당신이 서비스 선언에 문제가 이해되는

답변

2

가. 들어 I 권리?

오전 위에서 제공 한 클래스는 서비스로 등록해야하며 기본 서비스로 장식됩니다.이 서비스는 xml에 decorates 속성이 추가로 포함 된

<service id="app.custom_factory.comment" class="App\Factory\CommentFactory" decorates="app.factory.comment"> 
     <argument type="service" id="app.custom_factory.comment.inner" /> 
    </service> 

서비스 장식에 대한 추가 정보는 in symfony documentation입니다. 그러나 Sylius 문서에서는 how to inject your custom factory to controller 정보를 찾을 수 있습니다.

+0

좋아 보인다, 아프지 만 내일 어떻게 노력하는지 :) 감사합니다 lchrusciel –

+0

완벽하게 작동합니다. 고마워요 @ lchrusciel –

관련 문제