Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* config.php
*/
return [
'dependencies' => [
'factories' => [
\Reliv\Server\Entity\Environment::class => \Reliv\Server\Factory\Environment::class
],
],
];
155 changes: 155 additions & 0 deletions src/Entity/Environment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php

namespace Reliv\Server\Entity;

/**
* Class Environment
*
* @author James Jervis <jjervis@relivinc.com>
* @copyright 2016 Reliv International
* @license License.txt
* @link https://github.com/reliv
*/
class Environment
{
/**
* @var string
*/
protected $configPath;

/**
* @var string
*/
protected $name;

/**
* @var array
*/
protected $options
= [
'isProduction' => true,
'initSet' => [
],
];

/**
* Environment constructor.
*
* @param string $envName
* @param array $options
* @param string $configPath
*/
public function __construct(
$envName,
array $options = [],
$configPath = null
) {
$this->setName($envName);
$this->setOptions($options);
$this->configPath = $configPath;
}

/**
* setOptions
*
* @param $options
*
* @return void
*/
protected function setOptions($options)
{
if (empty($options)) {
return;
}

array_merge(
$this->options,
$options
);
}

/**
* getOptions
*
* @return array
*/
public function getOptions()
{
return $this->options;
}

/**
* setName
*
* @param string $envName
*
* @return void
*/
protected function setName($envName)
{
$this->name = (string)$envName;
}

/**
* getName
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* getConfigPath
*
* @return string
*/
public function getConfigPath()
{
return $this->configPath;
}

/**
* get
*
* @param string $key
* @param null $default
*
* @return mixed|null
*/
public function get($key, $default = null)
{
if (array_key_exists($key, $this->options)) {
return $this->options[$key];
}

return $default;
}

/**
* isEnvironment
*
* @param $name
*
* @return bool
*/
public function isEnvironment($name)
{
$serverName = $this->getName();

return ($name === $serverName);
}

/**
* isProduction
*
* @return bool
*/
public function isProduction()
{
$isProduction = (bool)$this->get('isProduction', true);

return $isProduction;
}
}
Loading