VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/14.2-configuration-api

⇱ Configuration API | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Configuration API

Purpose and Scope

This document provides a technical reference for accessing and manipulating configuration data in Maho through the Configuration API. It covers the Mage_Core_Model_Config class and related methods for reading configuration values at different scopes (global, website, store), understanding the configuration caching system, and utilizing the environment override and attribute-based observer systems.

For information about the overall configuration system architecture, including XML file structure and loading process, see Configuration System.


Configuration Access Overview

The Configuration API provides both static facade methods via the Mage class and direct access through the configuration model. All configuration data follows a hierarchical path notation using forward slashes (e.g., section/group/field).

Primary Access Methods

The diagram below illustrates the relationship between the static Mage facade, the application model, and the underlying configuration model.

Title: Configuration Access Flow


Sources: app/Mage.php78 app/Mage.php277-280 app/code/core/Mage/Core/Model/Config.php13-14


Reading Configuration Values

Store-Scoped Configuration

The most common pattern for retrieving configuration values uses Mage::getStoreConfig(), which respects the configuration scope hierarchy.

Method Signature:


Parameters:

  • $path: Configuration path in format section/group/field.
  • $store: Store ID, store code, store model, or null for current store. app/Mage.php277-280

Implementation Details: This method proxies the request to the application model's store object. app/Mage.php279

Typed Configuration Accessors

Maho provides specialized static methods in the Mage class to retrieve configuration values cast to specific PHP types.

MethodReturn TypeImplementation
getStoreConfigAsInt($path, $store)int(int) self::getStoreConfig($path, $store)
getStoreConfigAsFloat($path, $store)float(float) self::getStoreConfig($path, $store)
getStoreConfigFlag($path, $store)boolEvaluates value as boolean flag

Sources: app/Mage.php285-313

Boolean Flags

The getStoreConfigFlag method is used for settings that represent "Yes/No" options. It handles string representations like 'false', '0', and empty strings, converting them to boolean false.

Sources: app/Mage.php305-313


Configuration Hierarchy and Scope

Configuration values follow a cascading priority system across multiple scopes. Values in more specific scopes override those in broader scopes.

Title: Configuration Scope Resolution


Sources: app/code/core/Mage/Core/Model/Config.php89-95 app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php28-46

Environment Variable Overrides

Maho allows overriding configuration values using environment variables. This is handled by Mage_Core_Helper_EnvironmentConfigLoader. app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php11-12

Environment variables follow a specific naming convention: MAHO_CONFIG__<SCOPE>__<PATH>

Where <SCOPE> can be:

And <PATH> is the configuration path with __ as a separator (e.g., GENERAL__STORE_INFORMATION__NAME). app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php34-35

Example:

  • MAHO_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME=default
  • MAHO_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__NAME=website
  • MAHO_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME=store_german

The overrideEnvironment() method parses these variables and injects them into the configuration object. app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php47-73

Sources: app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php11-17 app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php28-46 app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php47-73


Direct Configuration Model Access

For advanced use cases, access the configuration model Mage_Core_Model_Config directly via Mage::getConfig(). app/Mage.php78

XML Node Access

The configuration is stored internally as a Maho\Simplexml\Config object. You can access raw XML nodes using the getNode() method.


Class Name Resolution

The configuration model resolves grouped class names (e.g., core/config) into actual PHP class names. It maintains internal caches for these resolutions.

MethodPurpose
getModelClassName($modelClass)Resolves model class names
getBlockClassName($blockClass)Resolves block class names

Sources: app/code/core/Mage/Core/Model/Config.php112-123


Attribute-Based Configuration (Maho Extensions)

Maho utilizes PHP 8 attributes to simplify configuration, particularly for Event Observers. This replaces the need for extensive config.xml observer definitions.

Observer Attribute

The #[Maho\Config\Observer] attribute allows registering methods as event observers directly in the PHP class.

Parameters:

  • event: Event name (e.g., catalog_product_save_after).
  • area: Scope (e.g., global, frontend, adminhtml).
  • type: model (new instance) or singleton (shared instance).
  • id: Optional unique identifier for the observer.

Example Implementations:

Sources: app/code/core/Mage/CatalogInventory/Model/Observer.php44-45 app/code/core/Maho/AdminActivityLog/Model/Observer.php48-49 app/code/core/Mage/GiftMessage/Model/Observer.php20-22 app/code/core/Mage/Weee/Model/Observer.php20-21 app/code/core/Mage/Catalog/Model/Product/Compare/Item.php164-165 app/code/core/Mage/Tag/Model/Tag.php194-195


Configuration Caching

Maho caches the merged XML configuration to avoid expensive disk I/O and XML merging on every request.

Cache Sections

Certain sections are cached with specific recursion levels to optimize retrieval. app/code/core/Mage/Core/Model/Config.php89-95

SectionRecursion Level
adminhtml0
crontab0
install0
stores1
websites1

Cache Tags

The configuration system uses the cache tag CONFIG. app/code/core/Mage/Core/Model/Config.php73


Implementation Details: Mage_Core_Model_Config

The Mage_Core_Model_Config class extends Mage_Core_Model_Config_Base and acts as the central repository for system settings. app/code/core/Mage/Core/Model/Config.php13-14

Key Properties

Initialization Flow

The init() method resets internal state and loads base configuration. app/code/core/Mage/Core/Model/Config.php272-278

Area-Specific Configuration

The Mage_Core_Model_App_Area class initializes area-specific parts, including configuration and events. app/code/core/Mage/Core/Model/App/Area.php72-83 app/code/core/Mage/Core/Model/App/Area.php97-103

Sources: app/code/core/Mage/Core/Model/Config.php13-14 app/code/core/Mage/Core/Model/Config.php107-116 app/code/core/Mage/Core/Model/Config.php272-278 app/code/core/Mage/Core/Model/App/Area.php72-103


API Summary Table

Class/MethodPurpose
Mage::getStoreConfig($path, $store)Main entry point for reading settings.
Mage::getConfig()Access the global configuration model.
Mage_Core_Model_Config::getNode($path)Access raw XML nodes.
Mage_Core_Model_Config::getOptions()Access directory paths and base options.
Mage_Core_Model_Config::getResourceModel()Access the resource model for DB operations.
Mage_Core_Helper_EnvironmentConfigLoader::overrideEnvironment()Overrides configuration values from environment variables.

Sources: app/Mage.php78 app/Mage.php277-280 app/code/core/Mage/Core/Model/Config.php234-240 app/code/core/Mage/Core/Model/Config.php248-250 app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php47-73