<service id="my_plugin.config" class="Dustin\ShopwareUtils\Core\Framework\Struct\Encapsulation">
<factory service="Dustin\ShopwareUtils\Core\System\SystemConfig\ConfigFactory" method="createConfig" />
<argument type="string">MyPlugin.config</argument>
<service><service id="My\Service">
<argument type="service" id="my_plugin.config" />
<service>use Dustin\ShopwareUtils\Core\Framework\Struct\Encapsulation;
class Service {
public function __construct(
private readonly Encapsulation $config
) {}
public function doSomething(): void {
// get a single config value
$configValue = $this->config->get('config_key');
// get an associative array of multiple config values
$configValues = $this->config->getList(['first_key', 'second_key']);
// check if a key exists
$has = $this->config->has('key');
// get all keys of a config
$keys = $this->config->getFields();
// Check if a config is empty
$isEmpty = $this->config->isEmpty();
// convert config to an array
$array = $this->config->toArray();
// iterate over all values
foreach($this->config as $key => $value) {
// do some fancy stuff
}
}
}<service id="my_plugin.config.per_sales_channel" class="Dustin\ShopwareUtils\Core\Framework\Struct\Encapsulation">
<factory service="Dustin\ShopwareUtils\Core\System\SystemConfig\ConfigFactory" method="createConfigPerSalesChannel" />
<argument type="string">MyPlugin.config</argument>
<service>
<service id="My\Service">
<argument type="service" id="my_plugin.config.per_sales_channel" />
<service>use Dustin\ShopwareUtils\Core\Framework\Struct\Encapsulation;
class Service {
public function __construct(
private readonly Encapsulation $configPerSalesChannel
) {}
public function doSomething(string $salesChannelId): void {
$config = $this->configPerSalesChannel->get($salesChannelId);
// continue with using the config object like shown above
}
}