setup:di:compile ignores third party type definition (Monolog)
-
06-02-2021 - |
سؤال
I have a DI configuration for a custom exception handler:
<type name="My\Logger\Handler\ExceptionHandler">
<arguments>
<argument name="formatter" xsi:type="object">My\Logger\Formatter\LogstashFormatterVirtual</argument>
</arguments>
</type>
<type name="Monolog\Formatter\LogstashFormatter">
<arguments>
<argument name="applicationName" xsi:type="string">Magento</argument>
</arguments>
</type>
This works fine in developer mode, but if I run bin/magento setup:di:compile
, I get the following error as soon as the exception handler would be instantiated:
Missing required argument $applicationName of Monolog\Formatter\LogstashFormatter.
How can I ensure that compilation includes the Monolog type?
المحلول
While I still do not understand why it does not work, I solved it by using a virtual type instead:
<type name="My\Logger\Handler\ExceptionHandler">
<arguments>
<argument name="formatter" xsi:type="object">My\Logger\Formatter\LogstashFormatterVirtual</argument>
</arguments>
</type>
<virtualType name="My\Logger\Formatter\LogstashFormatterVirtual" type="Monolog\Formatter\LogstashFormatter">
<arguments>
<argument name="applicationName" xsi:type="string">Magento</argument>
</arguments>
</virtualType>
نصائح أخرى
You may try virtual type instead of type in your XML file.
لا تنتمي إلى magento.stackexchange