lumen-generators/src/Commands/BaseCommand.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2015-09-23 01:49:46 +01:00
<?php namespace Wn\Generators\Commands;
use Illuminate\Console\Command;
2015-09-23 02:39:13 +01:00
use Illuminate\Filesystem\Filesystem;
2015-09-23 01:49:46 +01:00
use Wn\Generators\Argument\ArgumentFormatLoader;
use Wn\Generators\Argument\ArgumentParser;
use Wn\Generators\Template\TemplateLoader;
class BaseCommand extends Command {
protected $fs;
protected $templates;
public function __construct(Filesystem $fs)
{
parent::__construct();
$this->fs = $fs;
$this->templates = new TemplateLoader($fs);
$this->argumentFormatLoader = new ArgumentFormatLoader($fs);
}
protected function getTemplate($name)
{
return $this->templates->load($name);
}
protected function getArgumentParser($name){
$format = $this->argumentFormatLoader->load($name);
return new ArgumentParser($format);
}
protected function save($content, $path)
{
$this->makeDirectory($path);
$this->fs->put($path, $content);
}
protected function makeDirectory($path)
{
if (!$this->fs->isDirectory(dirname($path))) {
$this->fs->makeDirectory(dirname($path), 0777, true, true);
}
}
}