-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: vladitot | ||
* Date: 29.08.18 | ||
* Time: 12:00 | ||
*/ | ||
|
||
namespace ExtraPlugin; | ||
|
||
|
||
use Composer\Command\BaseCommand; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ExtraGetCommand extends BaseCommand | ||
{ | ||
/** | ||
* First-time set up | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setDescription('Can be used to to start scripts via tty'); | ||
$this->setName('runt'); | ||
$this->addArgument('param', InputArgument::REQUIRED, 'Name of script which need to run from "extra" block'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$commands = StaticHelper::getAllExtra('composer.json', 'extra-commands'); | ||
if (!isset($commands[$input->getArgument('param')])) { | ||
echo $input->getArgument('param').' - not found in extra -> extra-commands block'; | ||
exit(1); | ||
} | ||
$process = new \Symfony\Component\Process\Process($commands[$input->getArgument('param')]); | ||
$process->setTty(true); | ||
$process->run(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: vladitot | ||
* Date: 03.09.18 | ||
* Time: 16:28 | ||
*/ | ||
|
||
namespace ExtraPlugin; | ||
|
||
|
||
class StaticHelper | ||
{ | ||
/** | ||
* Getter params from extra | ||
* Say them, which key do you want to get. Another time you will able to export them, for example. | ||
* @param $file | ||
* @param $searchForString | ||
* @return array | ||
*/ | ||
public static function getAllExtra($file, $searchForString) { | ||
$searchFor = explode('-', $searchForString); | ||
$searchable = []; | ||
|
||
$content = json_decode(file_get_contents($file), true); | ||
if (isset($content['extra'])) { | ||
$currentEl = $content['extra']; | ||
|
||
foreach ($searchFor as $item) { | ||
if (isset($currentEl[$item])) { | ||
$currentEl = $currentEl[$item]; | ||
} else { | ||
break; | ||
} | ||
} | ||
if ($currentEl != $content['extra']) { | ||
$searchable = $currentEl; | ||
} | ||
} | ||
|
||
if (isset($content['extra']['merge-plugin']['include'])) { | ||
$extraIncludes = $content['extra']['merge-plugin']['include']; | ||
$includedFoundSearchables = []; | ||
foreach ($extraIncludes as $file) { | ||
$includedFoundSearchables = array_replace($includedFoundSearchables, self::getAllExtra($file, $searchForString)); | ||
} | ||
} else { | ||
$includedFoundSearchables = []; | ||
} | ||
return array_replace($searchable, $includedFoundSearchables); | ||
} | ||
} |