first commit
This commit is contained in:
64
modules/ps_metrics/src/Environment/AnalyticsEnv.php
Normal file
64
modules/ps_metrics/src/Environment/AnalyticsEnv.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Ps_metrics\Environment;
|
||||
|
||||
class AnalyticsEnv extends Env
|
||||
{
|
||||
/**
|
||||
* Url service analytics (prod and test)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $serviceUrl;
|
||||
|
||||
/**
|
||||
* AnalyticsEnv constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setServiceUrl($_ENV['ANALYTICS_API']);
|
||||
}
|
||||
|
||||
/**
|
||||
* getServiceUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceUrl()
|
||||
{
|
||||
return $this->serviceUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for serviceUrl
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setServiceUrl($url)
|
||||
{
|
||||
$this->serviceUrl = $url;
|
||||
}
|
||||
}
|
||||
65
modules/ps_metrics/src/Environment/CacheEnv.php
Normal file
65
modules/ps_metrics/src/Environment/CacheEnv.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Ps_metrics\Environment;
|
||||
|
||||
class CacheEnv extends Env
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cacheEnv = '';
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$activeCache = getenv('ACTIVE_CACHE');
|
||||
if ($activeCache) {
|
||||
$this->setCacheEnv($activeCache);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getCacheEnv
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getCacheEnv()
|
||||
{
|
||||
return ('false' === $this->cacheEnv) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for CacheEnv
|
||||
*
|
||||
* @param string $cacheActive
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setCacheEnv($cacheActive)
|
||||
{
|
||||
$this->cacheEnv = $cacheActive;
|
||||
}
|
||||
}
|
||||
98
modules/ps_metrics/src/Environment/Env.php
Normal file
98
modules/ps_metrics/src/Environment/Env.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Ps_metrics\Environment;
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
class Env
|
||||
{
|
||||
const MODULE_NAME = 'ps_metrics';
|
||||
|
||||
/**
|
||||
* Const that define all environment possible to use.
|
||||
* Top of the list are taken in first if they exist in the project.
|
||||
* eg: If .env.test is present in the module it will be loaded, if not present
|
||||
* we try to load the next one etc ...
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const FILE_ENV_LIST = [
|
||||
'test' => '.env.test',
|
||||
'prod' => '.env',
|
||||
];
|
||||
|
||||
/**
|
||||
* Environment name: can be 'prod' or 'test'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Environment mode: can be 'live' or 'sandbox'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mode;
|
||||
|
||||
/**
|
||||
* Env constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
foreach (self::FILE_ENV_LIST as $env => $fileName) {
|
||||
if (!file_exists(_PS_MODULE_DIR_ . self::MODULE_NAME . '/' . $fileName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$dotenv = Dotenv::create(_PS_MODULE_DIR_ . self::MODULE_NAME . '/', $fileName);
|
||||
$dotenv->load();
|
||||
|
||||
$this->setName($env);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* setName
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
64
modules/ps_metrics/src/Environment/SegmentEnv.php
Normal file
64
modules/ps_metrics/src/Environment/SegmentEnv.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\Ps_metrics\Environment;
|
||||
|
||||
class SegmentEnv extends Env
|
||||
{
|
||||
/**
|
||||
* Firebase public api key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $segmentApiKey;
|
||||
|
||||
/**
|
||||
* SegmentEnv constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setSegmentApiKey($_ENV['SEGMENT_API_KEY']);
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for segmentApiKey
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSegmentApiKey()
|
||||
{
|
||||
return $this->segmentApiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for segmentApiKey
|
||||
*
|
||||
* @param string $apiKey
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setSegmentApiKey($apiKey)
|
||||
{
|
||||
$this->segmentApiKey = $apiKey;
|
||||
}
|
||||
}
|
||||
28
modules/ps_metrics/src/Environment/index.php
Normal file
28
modules/ps_metrics/src/Environment/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
|
||||
*/
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user