-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
5d302a6
commit 711e078
Showing
6 changed files
with
192 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
use LaravelHelper\Commands\SetupIDE; | ||
use Symfony\Component\Console\Application; | ||
|
||
$app = new Application('Laravel Helper', '0.1'); | ||
|
||
$app->add(new SetupIDE()); | ||
|
||
$app->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,33 @@ | ||
<?php | ||
|
||
namespace LaravelHelper\Commands; | ||
|
||
use LaravelHelper\Processes\BaseProcess; | ||
|
||
class InstallLaravelIDEHelper extends BaseProcess | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $command = ['composer', 'require', '--dev', 'barryvdh/laravel-ide-helper']; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $timeOut = 3600; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $reason = 'maybe network, maybe time is too short'; | ||
|
||
/** | ||
* @return void | ||
* | ||
* @throws ProcessFailed | ||
*/ | ||
public function run() | ||
{ | ||
parent::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,30 @@ | ||
<?php | ||
|
||
namespace LaravelHelper\Commands; | ||
|
||
use LaravelHelper\Processes\LaravelRoot; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class SetupIDE extends Command | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('setupIDE')->setDescription('Setup everything for IDE'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
(new LaravelRoot())->run(); | ||
(new InstallLaravelIDEHelper())->run(); | ||
$output->writeln('done!'); | ||
return 0; | ||
} | ||
} | ||
// $io = new SymfonyStyle($input, $output); | ||
// $io->section('Starting to add helper files'); | ||
// $io->progressStart(2); | ||
// $io->progressAdvance(); | ||
// $io->progressFinish(); |
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,18 @@ | ||
<?php | ||
|
||
namespace LaravelHelper\Exceptions; | ||
|
||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
use Symfony\Component\Process\Process; | ||
|
||
class ProcessFailed extends ProcessFailedException | ||
{ | ||
public function __construct(Process $process, string $reason = 'not sure') | ||
{ | ||
parent::__construct($process); | ||
$this->message .= sprintf( | ||
"\n\nThe reason why it failed:\n================\n%s", | ||
$reason | ||
); | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
namespace LaravelHelper\Processes; | ||
|
||
use Exception; | ||
use LaravelHelper\Exceptions\ProcessFailed; | ||
use Symfony\Component\Process\Process; | ||
|
||
class BaseProcess | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $command = []; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $timeOut = 60; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $reason = 'not sure why'; | ||
|
||
/** | ||
* @return void | ||
* | ||
* @throws ProcessFailed|Exception | ||
*/ | ||
protected function run() | ||
{ | ||
$this->validateCommand(); | ||
|
||
$process = $this->runProcess(); | ||
|
||
if ($this->processFailed($process)) | ||
throw new Exception($this->reason, 1); | ||
} | ||
|
||
private function processFailed(Process $process): bool | ||
{ | ||
return !$process->isSuccessful(); | ||
} | ||
|
||
private function runProcess(): Process | ||
{ | ||
$process = new Process($this->command); | ||
|
||
$process->setTimeout($this->timeOut)->run($this->printOutput()); | ||
|
||
return $process; | ||
} | ||
|
||
private function printOutput(): callable | ||
{ | ||
return function ($type, $buffer) { | ||
echo $buffer; | ||
}; | ||
} | ||
|
||
/** | ||
* @throws Exception|void | ||
*/ | ||
private function validateCommand() | ||
{ | ||
if (empty($this->command)) | ||
throw new Exception('You need to pass some command', 1); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace LaravelHelper\Processes; | ||
|
||
use LaravelHelper\Exceptions\ProcessFailed; | ||
|
||
class LaravelRoot extends BaseProcess | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $command = ['php', 'artisan']; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $reason = 'It is not the root of Laravel'; | ||
|
||
/** | ||
* @return void | ||
* | ||
* @throws ProcessFailed | ||
*/ | ||
public function run() | ||
{ | ||
parent::run(); | ||
} | ||
} |