I am trying to create a "service" in my module's di.xml
file for a third-party vendor object.
I tried to configure it like this:
<type name="League\Flysystem\MountManager">
<arguments>
<argument name="filesystems" xsi:type="array">
<item name="orders_storage" xsi:type="object">oneup_flysystem_orders_storage_filesystem</item>
<item name="tmp_storage" xsi:type="object">oneup_flysystem_tmp_storage_filesystem</item>
</argument>
</arguments>
</type>
But anytime I would run setup:di:compile
and inject this service into my class, Magento throws an exception, because the arguments that I defined did not get passed to the factory that creates the object, so the code does a fallback and injects the ObjectManager
as the first argument to the constructor.
I was able to get around this issue by creating a dummy class inside my module that does nothing but extend the class I want to override, like this:
<?php
namespace Renegade\FileStorage\Manager;
use League\Flysystem\MountManager as BaseMountManager;
/**
* Class MountManager
*
* @package Renegade\FileStorage\Manager
*/
class MountManager extends BaseMountManager
{
}
Then creating a preference node for the class in di.xml:
<preference for="League\Flysystem\MountManager"
type="Renegade\FileStorage\Manager\MountManager"/>
And finally changing my type from:
<type name="League\Flysystem\MountManager">
To:
<type name="Renegade\FileStorage\Manager\MountManager">
From what I can tell, doesn't seem to work on objects that are outside of the Magento application. If that's not the case, can someone tell me how to accomplish this without my workaround?