Skip to content

Commit

Permalink
added ConfigPlugin helper
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Apr 19, 2017
1 parent 770069b commit 1626fc1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
29 changes: 14 additions & 15 deletions src/base/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace hidev\base;

use Exception;
use hidev\helpers\ConfigPlugin;
use Yii;
use yii\base\InvalidParamException;
use yii\base\ViewContextInterface;
Expand Down Expand Up @@ -59,32 +60,25 @@ public static function main(array $config)

public static function create(array $config)
{
Yii::setLogger(Yii::createObject('hidev\base\Logger'));
$config = ArrayHelper::merge(
Yii::setLogger(Yii::createObject(\hidev\base\Logger::class));
/*$config = ArrayHelper::merge(
static::readVendorConfig($config['vendorPath'], 'hidev'),
$config
);
);*/

return new static($config);
}

public static function readVendorConfig($vendor, $name)
public function loadExtraConfig($path)
{
$path = Yii::getAlias(static::buildConfigPath($vendor, $name));

return file_exists($path) ? require $path : [];
$this->setExtraConfig(static::readConfig($path));
}

public static function buildConfigPath($vendor, $name)
public static function readConfig($path)
{
/// doesn't work when dependencies are not installed
/// return \hiqdev\composer\config\Builder::path($name, $vendor);
return "$vendor/hiqdev/composer-config-plugin-output/$name.php";
}
$path = Yii::getAlias($path);

public function loadExtraConfig($path)
{
$this->setExtraConfig(static::readExtraConfig($path));
return file_exists($path) ? require $path : [];
}

/**
Expand All @@ -97,6 +91,11 @@ public function loadExtraVendor($vendor)
$this->setExtraConfig(static::readVendorConfig($vendor, 'hidev'));
}

public function readVendorConfig($vendor, $name)
{
return static::readConfig(ConfigPlugin::path($vendor, $name));
}

/**
* Sets extra environment variables.
* @param array $config
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/StartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace hidev\controllers;

use hidev\base\File;
use hidev\helpers\ConfigPlugin;
use Yii;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;
Expand Down Expand Up @@ -126,7 +127,7 @@ protected function requireAll()
throw new InvalidParamException('Failed initialize project with composer install');
}
}
if (file_exists('vendor/hiqdev/composer-config-plugin-output/hidev.php')) {
if (file_exists(ConfigPlugin::path('vendor', 'hidev'))) {
$vendors[] = 'vendor';
}
if (!empty($vendors)) {
Expand Down
24 changes: 24 additions & 0 deletions src/helpers/ConfigPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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\helpers;

/**
* Composer config plugin helper.
*/
class ConfigPlugin
{
public static function path($vendor, $name)
{
/// doesn't work when dependencies are not installed
/// return \hiqdev\composer\config\Builder::path($name, $vendor);
return "$vendor/hiqdev/composer-config-plugin-output/$name.php";
}
}

0 comments on commit 1626fc1

Please sign in to comment.