What are all the allowed `xsi:type` values in the xml's from Magento2
I've found all types by checking <xs:extension base="argumentType"
in *.xsd files.
lib/internal/Magento/Framework/Data/etc/argument/types.xsd
, these are base types:
- "array"
- "string"
- "boolean"
- "object"
- "configurableObject"
- "number"
- "null"
lib/internal/Magento/Framework/ObjectManager/etc/config.xsd
, can be found in di.xml files:
- "object"
- "init_parameter"
- "const"
lib/internal/Magento/Framework/View/Layout/etc/elements.xsd
, can be found in layout *.xml files:
- "options"
- "url"
- "helper"
Magento/Ui/etc/ui_components.xsd
, can be found in UI components' *.xml files:
- "constant"
- "url"
According to my researches, here is what I've found:
The argument interpreter is created in the lib\internal\Magento\Framework\App\ObjectManagerFactory.php
:
protected function createArgumentInterpreter(
\Magento\Framework\Stdlib\BooleanUtils $booleanUtils
) {
$constInterpreter = new \Magento\Framework\Data\Argument\Interpreter\Constant();
$result = new \Magento\Framework\Data\Argument\Interpreter\Composite(
[
'boolean' => new \Magento\Framework\Data\Argument\Interpreter\Boolean($booleanUtils),
'string' => new \Magento\Framework\Data\Argument\Interpreter\StringUtils($booleanUtils),
'number' => new \Magento\Framework\Data\Argument\Interpreter\Number(),
'null' => new \Magento\Framework\Data\Argument\Interpreter\NullType(),
'object' => new \Magento\Framework\Data\Argument\Interpreter\DataObject($booleanUtils),
'const' => $constInterpreter,
'init_parameter' => new \Magento\Framework\App\Arguments\ArgumentInterpreter($constInterpreter),
],
\Magento\Framework\ObjectManager\Config\Reader\Dom::TYPE_ATTRIBUTE
);
// Add interpreters that reference the composite
$result->addInterpreter('array', new \Magento\Framework\Data\Argument\Interpreter\ArrayType($result));
return $result;
}
In this code, you can clearly see that different interpreters are used based on the type attribute of the argument \Magento\Framework\ObjectManager\Config\Reader\Dom::TYPE_ATTRIBUTE
:
- boolean =>
\Magento\Framework\Data\Argument\Interpreter\Boolean
- string =>
\Magento\Framework\Data\Argument\Interpreter\StringUtils
- number =>
\Magento\Framework\Data\Argument\Interpreter\Number
- null =>
\Magento\Framework\Data\Argument\Interpreter\NullType
- object =>
\Magento\Framework\Data\Argument\Interpreter\DataObject
- const =>
\Magento\Framework\Data\Argument\Interpreter\Constant
- init_parameter =>
\Magento\Framework\App\Arguments\ArgumentInterpreter
(note that this one takes the\Magento\Framework\Data\Argument\Interpreter\Constant
as parameter and not the constructor parameter)
Also an extra interpreter is added on the fly to handle array types:
- array =>
\Magento\Framework\Data\Argument\Interpreter\ArrayType
Note: it seems like the init_parameter
type is only used in the app\code\Magento\Store\etc\di.xml
to initiate some constants:
<argument name="xFrameOpt" xsi:type="init_parameter">Magento\Framework\App\Response\XFrameOptPlugin::DEPLOYMENT_CONFIG_X_FRAME_OPT</argument>
...
<argument name="isCustomEntryPoint" xsi:type="init_parameter">Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM</argument>
...
<argument name="runMode" xsi:type="init_parameter">Magento\Store\Model\StoreManager::PARAM_RUN_TYPE</argument>
<argument name="scopeCode" xsi:type="init_parameter">Magento\Store\Model\StoreManager::PARAM_RUN_CODE</argument>