What is the use of "mapping" node in di.xml in Magento 2?
When you check Magento\Payment\Model\Checks\SpecificationFactory
of the construt
public function __construct(\Magento\Payment\Model\Checks\CompositeFactory $compositeFactory, array $mapping)
{
$this->compositeFactory = $compositeFactory;
$this->mapping = $mapping;
}
Second argument array $mapping
in the array you will get all your argument which you defined in di.xml
EDIT
from the construct
$this->mapping
you will find all of the objects in the array which you defined in di.xml
.
For example If you set <argument name="mappingtest" xsi:type="array">
then you need to define construct
as
public function __construct(
\Magento\Payment\Model\Checks\CompositeFactory $compositeFactory, array $mappingytest
) {
$this->compositeFactory = $compositeFactory;
$this->mapping = $mapping;
}
Here $mappingytest
The object manager injects the Magento\Core\Model\Url implementation class wherever there is a request for the Magento\Core\Model\UrlInterface in the global scope.
Multiple validation for different modules with filed.
<argument name="mapping" xsi:type="array">
<item name="country" xsi:type="object">Magento\Payment\Model\Checks\CanUseForCountry</item>
<item name="currency" xsi:type="object">Magento\Payment\Model\Checks\CanUseForCurrency</item>
<item name="checkout" xsi:type="object">Magento\Payment\Model\Checks\CanUseCheckout</item>
<item name="internal" xsi:type="object">Magento\Payment\Model\Checks\CanUseInternal</item>
<item name="total" xsi:type="object">Magento\Payment\Model\Checks\TotalMinMax</item>
<item name="zero_total" xsi:type="object">Magento\Payment\Model\Checks\ZeroTotal</item>
</argument>
Now check SpecificationFactory file for Business logic.
vendor/magento/module-payment/Model/Checks/SpecificationFactory.php
class SpecificationFactory
{
/**
* Composite Factory
*
* @var \Magento\Payment\Model\Checks\CompositeFactory
*/
protected $compositeFactory;
/**
* @var array
*/
protected $mapping;
/**
* Construct
*
* @param \Magento\Payment\Model\Checks\CompositeFactory $compositeFactory
* @param array $mapping
*/
public function __construct(\Magento\Payment\Model\Checks\CompositeFactory $compositeFactory, array $mapping)
{
$this->compositeFactory = $compositeFactory;
$this->mapping = $mapping;
}
/**
* Creates new instances of payment method models
*
* @param array $data
* @return Composite
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function create($data)
{
$specifications = array_intersect_key($this->mapping, array_flip((array)$data));
return $this->compositeFactory->create(['list' => $specifications]);
}
}
It validates the mapping data module wise.
$specifications = array_intersect_key($this->mapping, array_flip((array)$data));