Skip to content

Commit

Permalink
+ own Application, Request
Browse files Browse the repository at this point in the history
+ alises
  • Loading branch information
hiqsol committed May 7, 2015
1 parent a1d4db1 commit d5968d9
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 48 deletions.
10 changes: 9 additions & 1 deletion .hidev/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@
}
}
},
"deps": "all",
"all": {
"deps": "LICENSE, composer, .gitignore, README.md, CHANGELOG.md"
"deps": "git, composer, LICENSE, README.md, CHANGELOG.md"
},
"aliases": {
"h": "grep",
"g": "default/grep"
},
"test": {
"deps": "LICENSE"
},
"composer": {
"self-update": true
Expand Down
55 changes: 55 additions & 0 deletions components/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace hiqdev\hidev\components;

use Yii;
use hiqdev\hidev\controllers\DefaultController;

/**
* The Request.
* Redefined for aliases.
*/
class Request extends \yii\console\Request
{
/**
* @var name of script called, like $0 in sh/perl
*/
protected $_self;

protected $_args;

/**
* Returns the command line arguments.
* @return array the command line arguments. It does not include the entry script name.
*/
public function getParams()
{
if (!isset($this->_args)) {
if (isset($_SERVER['argv'])) {
$args = $_SERVER['argv'];
$this->_self = array_shift($args);
$command = $args[0];
$alias = Yii::$app->config->aliases->get($command);
if ($alias) {
array_shift($args);
$args = array_merge($alias, $args);
}
$action = $args[0];
if (Yii::$app->config->hasItem($action)) {
array_shift($args);
array_unshift($args, 'default/run', $action);
} elseif (DefaultController::hasAction($action)) {
array_shift($args);
array_unshift($args, "default/$action");
}
$this->_args = $args;
} else {
$this->_args = [];
}
$this->setParams($this->_args);
}

return $this->_args;
}

}
35 changes: 33 additions & 2 deletions controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,56 @@
* @link https://hiqdev.com/hidev
* @package hidev
* @license BSD 3-clause
* @copyright Copyright (c) 2015 HiQDev
* @copyright Copyright (c) 2015 HiQDev
*/

namespace hiqdev\hidev\controllers;

use Yii;
use yii\helpers\Inflector;

/**
* Generate class API documentation.
*/
class DefaultController extends \yii\console\Controller
{

/**
* Check has action.
*/
public static function hasAction($id)
{
return method_exists(get_called_class(), 'action'.Inflector::id2camel($id));
}

/**
* The main command: do the magic!
*/
public function actionIndex()
{
Yii::$app->config->all->run();
Yii::$app->config->run();
return 0;
}

/**
* Run the goal.
*/
public function actionRun($goal)
{
if (!Yii::$app->config->hasItem($goal)) {
d("Can't run goal '$goal'");
}
Yii::$app->config->getItem($goal)->run();
return 0;
}

/**
* The grep command.
*/
public function actionGrep()
{
d('HERE AT grep');
return 0;
}

}
26 changes: 26 additions & 0 deletions goals/Aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* Highy Integrated Development.
*
* @link https://hiqdev.com/hidev
* @package hidev
* @license BSD 3-clause
* @copyright Copyright (c) 2015 HiQDev
*/

namespace hiqdev\hidev\goals;

use Yii;
use hiqdev\hidev\helpers\Helper;

class Aliases extends \hiqdev\collection\Object
{
public $name;

public function getItem($name)
{
return Helper::csplit(parent::getItem($name),' ');
}

}
21 changes: 9 additions & 12 deletions goals/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,26 @@ class Base extends \hiqdev\collection\Manager

public $done = false;

public function setName($name)
{
$this->setItem('name', (string)$name);
}

public function getName()
{
return $this->getRaw('name');
return (string)$this->getRaw('name');
}

protected $_deps;

public function setDeps($deps)
{
$this->_deps = $deps;
$res = $this->getDeps();
foreach (Helper::ksplit($deps) as $d => $e) {
$res[$d] = $e;
}
$this->setItem('deps', $res);
}

public function getDeps()
{
return Helper::ksplit($this->_deps);
return Helper::ksplit($this->getRaw('deps'));
}

public function deps()
public function runDeps()
{
foreach ($this->getDeps() as $name => $enabled) {
if (!$enabled) {
Expand All @@ -69,7 +66,7 @@ public function run()
return;
}
Yii::trace("Started: $this->name");
$this->deps();
$this->runDeps();
$this->make();
$this->done = true;
}
Expand Down
5 changes: 4 additions & 1 deletion goals/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
*/
class Composer extends Base
{
protected $_deps = 'composer.json';
public function init()
{
$this->setDeps('composer.json');
}
}
34 changes: 3 additions & 31 deletions goals/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,11 @@ public function getItemConfig($name = null, array $config = [])
], $config);
}

/**
* Creates goal if not exists else updates.
* This makes goals unique by name.
*
* @param string $name item name.
* @param array $config item instance configuration.
*
* @return item instance.
*/
/* XXX looks like it is not needed anymore
protected function createItem($name, $config = [])

public function make()
{
$item = $this->getRaw($name);
if (is_object($item)) {
$item->mset($config);
} else {
$item = parent::createItem($name, array_merge((array)$item, (array)$config));
$this->set($name,$item);
}
return $item;
Base::make();
}
*/

/**
* Bootstraps config. Reads or creates if doesn't exist
Expand All @@ -130,16 +113,5 @@ public function bootstrap($app)
$this->mset($this->file->load());
}

/*
public function setPackage($value)
{
return $this->setItem('package', $value);
}
public function setVendor($value)
{
return $this->setItem('vendor', $value);
}
*/

}
25 changes: 25 additions & 0 deletions goals/Git.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* Highy Integrated Development.
*
* @link https://hiqdev.com/hidev
* @package hidev
* @license BSD 3-clause
* @copyright Copyright (c) 2015 HiQDev
*/

namespace hiqdev\hidev\goals;

use Yii;

/**
* Goal for Git
*/
class Git extends Base
{
public function init()
{
$this->setDeps('.gitignore');
}
}
5 changes: 4 additions & 1 deletion hidev
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');

Yii::setLogger(Yii::createObject('hiqdev\hidev\components\Logger'));

$application = new yii\console\Application([
$application = new hiqdev\hidev\components\Application([
'id' => 'hidev',
'name' => 'HiDev - integrate your development',
'basePath' => __DIR__,
Expand All @@ -47,6 +47,9 @@ $application = new yii\console\Application([
'config' => [
'class' => 'hiqdev\hidev\goals\Config',
],
'request' => [
'class' => 'hiqdev\hidev\components\Request',
],
'view' => [
'class' => 'hiqdev\hidev\components\View',
'theme' => [
Expand Down

0 comments on commit d5968d9

Please sign in to comment.