The area is a logical component that organizes code for optimized request processing.
While the majority of the time we don't really have to code anything specific regarding areas, understanding them is key to understanding Magento.
The Magento\Framework\App\Area class AREA_* constants hint at the following areas:
const AREA_GLOBAL = 'global';
const AREA_FRONTEND = 'frontend';
const AREA_ADMINHTML = 'adminhtml';
const AREA_DOC = 'doc';
const AREA_CRONTAB = 'crontab';
const AREA_WEBAPI_REST = 'webapi_rest';
const AREA_WEBAPI_SOAP = 'webapi_soap';
By doing a lookup for the <argument name="areas" string across all of the <MAGENTO_DIR> di.xml files, we can see that five of these areas have been explicitly added to the areas argument of the Magento\Framework\App\AreaList class:
- adminhtml via <MAGENTOI_DIR>/module-backend/etc/di.xml
- webapi_rest via <MAGENTOI_DIR>/module-webapi/etc/di.xml
- webapi_soap via <MAGENTOI_DIR>/magento/module-webapi/etc/di.xml
- frontend via <MAGENTOI_DIR>/magento/module-store/etc/di.xml
- crontab via <MAGENTOI_DIR>/magento/module-cron/etc/di.xml
The default area is frontend, as defined by the default argument under module-
store/etc/di.xml. The global area is used as a fallback for files that are absent in the adminhtml and frontend areas.
Let's take a closer look at the <MAGENTO_DIR>/module-webapi/etc/di.xml file:
<type name="Magento\Framework\App\AreaList">
<arguments>
<argument name="areas" xsi:type="array">
<item name="webapi_rest" xsi:type="array">
<item name="frontName" xsi:type="string">rest</item>
</item>
<item name="webapi_soap" xsi:type="array">
<item name="frontName" xsi:type="string">soap</item>
</item>
</argument>
</arguments>
</type>