명령에 대한 di.xml을 사용하여 Object Manager 인수 대체를 이해합니다
-
28-09-2020 - |
문제
"Nofollow"> Object Manager 인수 교체 튜토리얼을 수행합니다.가능한 di.xml 중 하나는
처럼 보입니다.<type name="Pulsestorm\TutorialObjectManagerArguments\Model\Example">
<arguments>
<argument name="scaler1" xsi:type="string">bar</argument>
</arguments>
</type>
.
모델 Example
의 클래스의 생성자를 의미하는 것은 $scaler1
가있는 인수 bar
의 인수의 값을 대체합니다.
명령은
처럼 보입니다.<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="testbedCommand" xsi:type="object">Pulsestorm\TutorialObjectManagerArguments\Command\Testbed</item>
</argument>
</arguments>
</type>
.
CommandList
의 생성자 인수 (배열 형식 인) commands
(배열 유형)에 1 개의 새 항목을 추가합니다.
i testbedCommand
이름을 모듈의 모든 이름으로 사용하지 않습니다.
사용법은 무엇입니까?그것은 독특해야합니까?
해결책
항목 이름은 Magento \ Framework \ Console \ commandList에서 사용되지 않습니다. 이 클래스를 살펴보면 값만 사용되거나 배열 키도 사용할 수 있습니다.
모듈에서 동일한 유형과 동일한 인수 항목 이름으로 정의한 경우 :
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="testbedCommand" xsi:type="object">Your\Module\Command\Testbed</item>
</argument>
</arguments>
</type>
.
및 모듈은 pulsestorm \ tutorialObjectManagerArguments 후에 이동합니다. 그런 다음 값을 얻을 인수로 다음을 가져옵니다.
<argument name="commands" xsi:type="array">
<item name="testbedCommand" xsi:type="object">Your\Module\Command\Testbed</item>
</argument>
. 제휴하지 않습니다 magento.stackexchange