-
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.
Merge pull request #7 from pixelfusion/feature/additional-enhancements
Feature/additional enhancements
- Loading branch information
Showing
22 changed files
with
266 additions
and
73 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
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
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
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,86 @@ | ||
<?php | ||
namespace Skeletor\Console; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class AddNewPackage extends SkeletorCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setName('package:add') | ||
->setDescription('Add new package') | ||
->addArgument('name', InputArgument::REQUIRED, 'Package name'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->setupCommand(); | ||
|
||
$package = $input->getArgument('name'); | ||
$this->cli->br()->yellow(sprintf('Skeletor - add new package, searching for %s', $package))->br(); | ||
|
||
$packageOptions = $this->packagistApi->searchPackage($package); | ||
if (empty($packageOptions)) { | ||
$this->cli->br()->red('package not found'); | ||
return; | ||
} | ||
|
||
$packageInfo['slug'] = $this->packageManager->specifyPackage($packageOptions); | ||
$packageInfo = $this->buildPackageInfo($packageInfo); | ||
if (in_array($packageInfo['name'], $this->packageManager->getAllPackageNames())) { | ||
$this->cli->br()->red('package already installed'); | ||
return; | ||
} | ||
|
||
$this->makePackageClass($packageInfo); | ||
$this->addPackageToConfig($packageInfo); | ||
} | ||
|
||
/** | ||
* @param array $packageInfo | ||
* @return array | ||
*/ | ||
protected function buildPackageInfo(array $packageInfo) | ||
{ | ||
$packageName = preg_replace('/\/|-/', ' ', $packageInfo['slug']); | ||
$packageName = ucwords($packageName); | ||
$packageInfo['name'] = $packageName; | ||
|
||
$packageName = preg_replace('/\s+/', '', $packageName); | ||
$packageInfo['class'] = $packageName.'Package'; | ||
|
||
return $packageInfo; | ||
} | ||
|
||
/** | ||
* @param array $packageInfo | ||
*/ | ||
protected function addPackageToConfig(array $packageInfo) | ||
{ | ||
$config = $this->configurator->getConfig(); | ||
$config['packages'][] = $packageInfo['class']; | ||
$this->configurator->storeConfig($config); | ||
} | ||
|
||
/** | ||
* @param array $packageInfo | ||
*/ | ||
protected function makePackageClass(array $packageInfo) | ||
{ | ||
//Read stub | ||
$stub = $this->skeletorFilesystem->read('Templates/stubs/package.stub'); | ||
|
||
//Replace stub dummy data | ||
foreach ($packageInfo as $key => $info) { | ||
$stub = str_replace($key.'Dummy', $info, $stub); | ||
} | ||
|
||
//Put final class in Skeletor | ||
$this->skeletorFilesystem->put( | ||
'Packages/'.$packageInfo['class'].'.php', | ||
$stub | ||
); | ||
} | ||
} |
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
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,31 @@ | ||
<?php | ||
namespace Skeletor\Console; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
|
||
abstract class SkeletorCommand extends Command | ||
{ | ||
protected $cli; | ||
protected $packagistApi; | ||
protected $configurator; | ||
protected $packageManager; | ||
protected $frameworkManager; | ||
protected $skeletorFilesystem; | ||
|
||
protected function setupCommand($dryRun = false) | ||
{ | ||
$this->getApplication()->registerServices($dryRun); | ||
|
||
$this->cli = $this->getApplication()->getCli(); | ||
$this->packagistApi = $this->getApplication()->getPackagistApi(); | ||
$this->configurator = $this->getApplication()->getConfigurator(); | ||
$this->skeletorFilesystem = $this->getApplication()->getSkeletorFilesystem(); | ||
|
||
$this->frameworkManager = $this->getApplication()->getFrameworkManager(); | ||
$this->packageManager = $this->getApplication()->getPackageManager(); | ||
|
||
$this->frameworkManager->setFrameworks($this->getApplication()->getFrameworks()); | ||
$this->packageManager->setPackages($this->getApplication()->getPackages()); | ||
$this->packageManager->setDefaultPackages($this->getApplication()->getDefaultPackages()); | ||
} | ||
} |
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
Oops, something went wrong.