Skip to content

Commit

Permalink
redoing goals to controllers BROKEN init & dump look working
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jan 12, 2016
1 parent b4a6ad3 commit 0ff3351
Show file tree
Hide file tree
Showing 30 changed files with 530 additions and 473 deletions.
3 changes: 2 additions & 1 deletion bin/hidev
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));

require_once(__DIR__ . '/../_bootstrap.php');

exit(hidev\base\Application::main());
exit(hidev\base\Application::main(require __DIR__ . '/../src/base/config.php'));

80 changes: 66 additions & 14 deletions src/base/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,27 @@ class Application extends \yii\console\Application implements ViewContextInterfa

protected $_viewPath;

public static function main()
protected $_config;

public function __construct($config = [])
{
$this->_config = $config;
parent::__construct($config);
}

/**
* Creates application with given config and runs it.
* @param array $config
* @return int exit code
*/
public static function main(array $config)
{
try {
Yii::setLogger(Yii::createObject('hidev\base\Logger'));
$config = ArrayHelper::merge(
require dirname(dirname(__DIR__)) . '/.hidev/vendor/yiisoft/yii2-extraconfig.php',
require dirname(dirname(__DIR__)) . '/vendor/yiisoft/yii2-extraconfig.php',
require __DIR__ . '/config.php'
static::readExtraVendor($config['vendorPath']),
$config
);
# var_dump($config); die();
foreach ($config['aliases'] as $name => $alias) {
Yii::setAlias($name, $alias);
}
$exitCode = (new static($config))->run();
} catch (Exception $e) {
if ($e instanceof InvalidParamException || $e instanceof ConsoleException) {
Expand All @@ -55,6 +63,50 @@ public static function main()
return $exitCode;
}

public static function readExtraVendor($dir)
{
return require $dir . '/yiisoft/yii2-extraconfig.php';
}

/**
* Load extra config files.
* @param array $config
* @return void
*/
public function loadExtraVendor($dir)
{
$this->setExtraConfig(static::readExtraVendor($dir));
}

/**
* Implements extra configuration.
* @param array $config
* @return void
*/
public function setExtraConfig($config)
{
$this->_config = $config = ArrayHelper::merge($config, $this->_config);

if (!empty($config['aliases'])) {
$this->setAliases($config['aliases']);
}
if (!empty($config['modules'])) {
$this->setModules($config['modules']);
/*$this->setModules(ArrayHelper::merge(
$config['modules'],
ArrayHelper::getItems($this->modules, array_keys($config['modules']))
));*/
}
if (!empty($config['components'])) {
foreach ($config['components'] as $id => $component) {
if ($this->has($id, true)) {
unset($config['components'][$id]);
}
}
$this->setComponents($config['components']);
}
}

/*public function getViewPath()
{
if ($this->_viewPath === null) {
Expand All @@ -66,14 +118,14 @@ public static function main()

public function createControllerByID($id)
{
if (!$this->get('config')->hasGoal($id)) {
var_dump("CANT RUN GOAL: $id");
#var_dump(ArrayHelper::toArray($this->get('config')));
throw new InvalidConfigException("can't run goal '$id'");
if ($this->get('config')->hasGoal($id)) {
return $this->get('config')->get($id);
}

#var_dump( $this->get('config')->get($id) );
return $this->get('config')->get($id);
$controller = parent::createControllerByID($id);
$this->get('config')->set($id, $controller);

return $controller;
}

public function runRequest($string)
Expand Down
10 changes: 6 additions & 4 deletions src/goals/SvnignoreGoal.php → src/base/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
*/

namespace hidev\goals;
namespace hidev\base;

use Yii;

/**
* Goal for svn:ignore.
* Basic controller.
*/
class SvnignoreGoal extends VcsignoreGoal
class Controller extends \yii\console\Controller
{
protected $_fileType = 'svnignore';
public $defaultAction = 'perform';
}
22 changes: 5 additions & 17 deletions src/base/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
return [
'id' => 'hidev',
'name' => 'HiDev',
'basePath' => '@hidev',
'vendorPath' => '@vendor',
'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'runtimePath' => dirname(substr(__DIR__, 0, 7) === 'phar://' ? $_SERVER['SCRIPT_NAME'] : dirname(__DIR__)) . '/runtime',
'enableCoreCommands' => false,
'controllerNamespace' => 'hidev\\controllers',
Expand All @@ -22,26 +22,14 @@
'cache' => [
'class' => 'yii\caching\FileCache',
],
'request' => [
/*'request' => [
'class' => 'hidev\base\Request',
],
],*/
'binaries' => [
'class' => 'hidev\components\Binaries',
],
'config' => [
'class' => 'hidev\components\Config',
'git' => 'hidev\goals\GitGoal',
'init' => 'hidev\goals\InitGoal',
'start' => 'hidev\goals\StartGoal',
'github' => 'hidev\goals\GitHubGoal',
'update' => 'hidev\goals\UpdateGoal',
'vendor' => 'hidev\goals\VendorGoal',
'commits' => 'hidev\goals\CommitsGoal',
'install' => 'hidev\goals\InstallGoal',
'package' => 'hidev\goals\PackageGoal',
'.gitignore' => 'hidev\goals\GitignoreGoal',
'vcsignore' => 'hidev\goals\VcsignoreGoal',
'CHANGELOG.md' => 'hidev\goals\ChangelogGoal',
'class' => 'hidev\components\Config',
],
'view' => [
'class' => 'hidev\base\View',
Expand Down
67 changes: 27 additions & 40 deletions src/components/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace hidev\components;

use hidev\base\File;
use hidev\helpers\Helper;
use Yii;
use yii\base\BootstrapInterface;
Expand All @@ -24,73 +25,59 @@ class Config extends \hiqdev\yii2\collection\Object
{
public $file = '.hidev/config.yml';

public function hasGoal($name)
protected $_included = [];

public function hasGoal($id)
{
return $this->hasItem($name);
return $this->hasItem($id);
}

/*public function findGoal($name)
/*public function findGoal($id)
{
$config = $this->getGoals()->get($name);
$config = $this->getGoals()->get($id);
return is_scalar($config) ? ['class' => $config] : (array) $config;
}*/

public function getItemConfig($name = null, array $config = [])
public function getItemConfig($id = null, array $config = [])
{
var_dump($config); die('getItemConfig');
return ArrayHelper::merge([
'goalName' => $name,
'class' => 'hidev\goals\DefaultGoal',
'class' => 'hidev\controllers\CommonController',
], $config);
}

protected function createItem($name, $config = [])
protected function createItem($id, $config = [])
{
$config = is_scalar($config) ? ['class' => $config] : (array) $config;
return Yii::createObject($this->getItemConfig($name, $config), [$name, Yii::$app]);
return Yii::createObject($this->getItemConfig($id, $config), [$id, $this->module]);
}

public function getItem($name)
public function getItem($id)
{
if ($name === 'default') {
return $this;
}
$item = &$this->_items[$name];
$item = &$this->_items[$id];
#var_dump($item);
#if (is_array($item) || is_null($item)) {
if (!is_object($item)) {
$item = $this->createItem($name, $item ?: []);
if (is_array($item)) {
$item = $this->createItem($id, $item);
}

return $item;
}

/**
* Loads all the configs. Reads or creates if doesn't exist.
* @void
* Include config file, unique only.
* @param string|array $path
* @return bool true if the path was unique and loaded
*/
public function loadAllConfigs()
public function includeConfig($path)
{
if (!file_exists($this->file)) {
throw new InvalidParamException('No config found. Use hidev init vendor/package');
}
if (Yii::$app->get('configs')) {
foreach (Yii::$app->get as $path) {
$this->includeConfig($path);
}
$file = File::create($path);
$path = $file->getPath();
if (!isset($this->_included[$path])) {
$this->_included[$path] = $path;
$this->setItems($file->load());
return true;
}
$this->includeConfig($this->file);
if ($this->has('include')) {
foreach (Helper::csplit($this->rawItem('include')) as $path) {
$this->includeConfig($path);
}
}
}

public function includeConfig($path)
{
$file = Yii::createObject(array_merge([
'class' => 'hidev\base\File',
], is_array($path) ? $path : compact('path')));
$this->setItems($file->load());
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
*/

namespace hidev\goals;
namespace hidev\controllers;

use hidev\helpers\Helper;

class AliasesGoal extends DefaultGoal
class AliasesController extends CommonController
{
public function getItem($name)
{
Expand Down
22 changes: 22 additions & 0 deletions src/controllers/ChangelogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* Task runner, code generator and build tool for easier continuos integration
*
* @link https://github.com/hiqdev/hidev
* @package hidev
* @license BSD-3-Clause
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
*/

namespace hidev\controllers;

/**
* Controller for CHANGELOG.md file.
*/
class ChangelogController extends FileController
{
protected $_before = ['commits'];

public $fileType = 'changelog';
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
*/

namespace hidev\goals;
namespace hidev\controllers;

/**
* Goal for reading and writing commits history to build CHANGELOG.md.
* Controller for reading and writing commits history to build CHANGELOG.md.
*/
class CommitsGoal extends FileGoal
class CommitsController extends FileController
{
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
$this->setDeps($this->getVcs()->goalName);
}

protected $_file = '.hidev/commits.md';

protected $_fileType = 'commits';
public $fileType = 'commits';

public function getHistory()
{
Expand Down
Loading

0 comments on commit 0ff3351

Please sign in to comment.