PluginHandler.php in Database Sanitize 7
File
vendor/edisonlabs/merge-yaml/src/PluginHandler.php
View source
<?php
namespace EdisonLabs\MergeYaml;
use Composer\Composer;
use Composer\IO\IOInterface;
class PluginHandler {
protected $io;
public $outputDir;
public $fileNamePatterns;
public $sourcePaths = array();
public $isConfigured = false;
public function __construct(Composer $composer, IOInterface $io, array $configParameters = array()) {
$this->io = $io;
$config = $configParameters;
if (!$config) {
$extra = $composer
->getPackage()
->getExtra();
if (!isset($extra['merge-yaml'])) {
return;
}
$config = $extra['merge-yaml'];
}
if (empty($config['files'])) {
throw new \RuntimeException('Please configure merge-yaml files in your composer.json');
}
$this->fileNamePatterns = $config['files'];
if (empty($config['locations']) || !is_array($config['locations'])) {
throw new \RuntimeException('Please configure merge-yaml locations in your composer.json');
}
$this->sourcePaths = $config['locations'];
if (empty($config['output-dir'])) {
throw new \RuntimeException('Please configure merge-yaml output-dir in your composer.json');
}
$this->outputDir = $config['output-dir'];
$this->isConfigured = true;
}
public function createMergeFiles() {
if (!$this->isConfigured) {
$this->io
->write('> WARNING: merge-yaml is not configured', true);
return;
}
$mergeYaml = new MergeYaml($this->fileNamePatterns, $this->sourcePaths, $this->outputDir);
$processedFiles = $mergeYaml
->createMergeFiles();
if (empty($processedFiles)) {
$this->io
->write('> merge-yaml: No merge files have been created', true);
return;
}
foreach ($processedFiles as $fileName => $filePaths) {
foreach ($filePaths as $filePath) {
$this->io
->write("> merge-yaml: Merging {$filePath}", true);
}
$outputDir = $this->outputDir;
$this->io
->write("> merge-yaml: Merged in {$outputDir}/{$fileName}.merge.yml", true);
}
}
}