for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Automation tool mixed with code generator for easier continuous development
*
* @link https://github.com/hiqdev/hidev
* @package hidev
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
*/
namespace hidev\base;
use Yii;
use yii\helpers\ArrayHelper;
class Interpolator
{
public $data;
public function interpolate(&$data)
$this->data = &$data;
$this->do($data);
}
private function do(&$data)
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.
if (is_array($data)) {
foreach ($data as &$item) {
$this->do($item);
} elseif (is_string($data)) {
$data
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
class A { var $property; }
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.
$data = preg_replace_callback('/\\$(\\w+)\\[\'(.+?)\'\\]/', function ($matches) {
return $this->get($matches[1], $matches[2]);
}, $data);
public function get($scope, $name)
if ($scope === 'params') {
return $this->data['params'][$name];
} elseif ($scope === '_ENV') {
return $_ENV[$name];
} else {
return "\$${scope}['$name']";
public function getConfig($name)
list($goal, $subname) = explode('.', $name, 2);
return ArrayHelper::getValue(Yii::$app->get('config')->getGoal($goal), $subname);