Skip to content

Commit

Permalink
Merge pull request #7 from elgentos/disable-in-development-mode
Browse files Browse the repository at this point in the history
Disable in development mode
  • Loading branch information
WouterSteen authored May 17, 2024
2 parents 85b20c8 + dc7d03a commit 9a92c5e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
File renamed without changes.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


IDE = phpstorm

.PHONY: all
all:

vendor/autoload.php:
composer install --prefer-dist --optimize-autoloader

.PHONY: tests
tests: vendor/autoload.php
php vendor/bin/phpunit

ide:
exec $(IDE) . &

4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"type": "magento2-module",
"license": "GPL-3.0",
"authors": [
{
"name": "Wouter Steenmeijer",
"email": "[email protected]"
},
{
"name": "Wouter Steenmeijer",
"email": "[email protected]"
Expand Down
6 changes: 3 additions & 3 deletions src/Api/ConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

interface ConfigurationInterface
{
public const CONFIG_RUMVISION_ENALBED = 'elgentos_rumvision/general/enabled',
CONFIG_RUMVISION_TRACKING_ID = 'elgentos_rumvision/general/tracking_id',
CONFIG_RUMVISION_HOST_NAME = 'elgentos_rumvision/general/hostname';
public const CONFIG_RUMVISION_ENABLED = 'elgentos_rumvision/general/enabled',
CONFIG_RUMVISION_TRACKING_ID = 'elgentos_rumvision/general/tracking_id',
CONFIG_RUMVISION_HOST_NAME = 'elgentos_rumvision/general/hostname';

public function isEnabled(int $storeId = null): bool;

Expand Down
29 changes: 22 additions & 7 deletions src/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,46 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\State;

class Config implements ConfigurationInterface
{
/**
* @param ScopeConfigInterface $config
* @param StoreManagerInterface $storeManager
*/
public function __construct(
private ScopeConfigInterface $config,
private StoreManagerInterface $storeManager,
private State $appState,
) {}

public function isEnabled(int $storeId = null): bool
{
return (bool)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId));
if ($this->appState->getMode() === State::MODE_DEVELOPER) {
// Don't run in developer mode
return false;
}

return (bool)$this->config->getValue(
self::CONFIG_RUMVISION_ENABLED,
ScopeInterface::SCOPE_STORE,
$this->getStoreId($storeId)
);
}

public function getTrackingId(int $storeId = null): string
{
return (string)$this->config->getValue(self::CONFIG_RUMVISION_TRACKING_ID, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId));
return (string)$this->config->getValue(
self::CONFIG_RUMVISION_TRACKING_ID,
ScopeInterface::SCOPE_STORE,
$this->getStoreId($storeId)
);
}

public function getHostName(int $storeId = null): string
{
return (string)$this->config->getValue(self::CONFIG_RUMVISION_HOST_NAME, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId));
return (string)$this->config->getValue(
self::CONFIG_RUMVISION_HOST_NAME,
ScopeInterface::SCOPE_STORE,
$this->getStoreId($storeId)
);
}

public function getStoreId(int $storeId = null) :int
Expand Down

0 comments on commit 9a92c5e

Please sign in to comment.