| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Core; |
| 4 |
|
| 5 |
class AcymParameter |
| 6 |
{ |
| 7 |
private array $params = []; |
| 8 |
private object $paramObject; |
| 9 |
|
| 10 |
/** |
| 11 |
* @param null $params We expect a json encoded object, but it could directly be an object with protected data in Joomla 3 |
| 12 |
*/ |
| 13 |
public function __construct($params = null) |
| 14 |
{ |
| 15 |
if (is_string($params)) { |
| 16 |
$this->params = json_decode($params, true); |
| 17 |
} elseif (is_array($params)) { |
| 18 |
$this->params = $params; |
| 19 |
} elseif (is_object($params)) { |
| 20 |
$this->paramObject = $params; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* @param mixed $default |
| 26 |
* |
| 27 |
* @return mixed |
| 28 |
*/ |
| 29 |
public function get(string $path, $default = null) |
| 30 |
{ |
| 31 |
if (empty($this->paramObject)) { |
| 32 |
if (empty($this->params[$path]) && !(isset($this->params[$path]) && $this->params[$path] === '0')) { |
| 33 |
return $default; |
| 34 |
} |
| 35 |
|
| 36 |
return $this->params[$path]; |
| 37 |
} else { |
| 38 |
// Handle the object based parameters |
| 39 |
$value = $this->paramObject->get($path, 'noval'); |
| 40 |
if ($value === 'noval') { |
| 41 |
$value = $this->paramObject->get('data.'.$path, $default); |
| 42 |
} |
| 43 |
|
| 44 |
return $value; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|