I have a base plugin which accepts blockName(String) as a parameter.
Based on that value I have created three virtual type plugins and used them.
Below are the codes.
di.xml
<virtualType name="Vendor\ModuleName\Plugin\FirstPlugin"
type="Vendor\ModuleName\Plugin\BasePlugin">
<arguments>
<argument name="blockName" xsi:type="string">dummyone</argument>
</arguments>
</virtualType>
<virtualType name="Vendor\ModuleName\Plugin\SecondPlugin"
type="Vendor\ModuleName\Plugin\BasePlugin">
<arguments>
<argument name="blockName" xsi:type="string">dummytwo</argument>
</arguments>
</virtualType>
<virtualType name="Vendor\ModuleName\Plugin\ThirdPlugin"
type="Vendor\ModuleName\Plugin\BasePlugin">
<arguments>
<argument name="blockName" xsi:type="string">dummy</argument>
</arguments>
</virtualType>
<type name="Some\Core\Class">
<plugin name="Vendor_ModuleName::FirstPlugin"
type="Vendor\ModuleName\Plugin\FirstPlugin" sortOrder="1"/>
</type>
<type name="Some\Other\Core\Class">
<plugin name="Vendor_ModuleName::SecondPlugin"
type="Vendor\ModuleName\Plugin\SecondPlugin" sortOrder="1"/>
</type>
<type name="Some\Another\Core\Class">
<plugin name="Vendor_ModuleName::ThirdPlugin"
type="Vendor\ModuleName\Plugin\ThirdPlugin" sortOrder="1"/>
</type>
BasePlugin.php
class BasePlugin
{
public $blockNames = [];
public $layout;
public $resultJsonFactory;
public function __construct(JsonFactory $resultJsonFactory, Layout $layout, string $blockName)
{
$this->resultJsonFactory = $resultJsonFactory;
$this->layout = $layout->getLayout();
$this->blockNames [] = $blockName;
}
public function afterExecute($subject, $result)
{
//After plugin code.
}
The code is executing as expected, in the front end there are no errors. The Base plugin code is being execute every time with the correct constructor parameters for the three virtual plugins.
But when I run setup:di:compile, I am getting the error stating Plugin class Vendor\ModuleName\Plugin\FirstPlugin doesn't exist.
Why is that happening? Is there something wrong in my way of declaring the virtual types?
Any help is appreciated.