<?php 
namespace Yjtec\Consul\Commands;
use Illuminate\Support\Str;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
class TplCommand extends GeneratorCommand{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'consul:tpl ';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'make the consul env.tpl';

    /**
     * set stub
     * @return [type] [description]
     */
    protected function getStub(){
        return __DIR__.'/../../stubs/env.stub';
    }
    /**
     * set path
     * @param  string $name
     * @return string
     */
    protected function getPath($name){
        return base_path('.env.tpl');
    }
    /**
     * set input name
     * @return string
     */
    protected function getNameInput(){
        return 'env.tpl';
    }

    protected function buildClass($name){
        // 获取模版文件内容
        $stub = $this->files->get($this->getStub());
        return $this->replaceContent($stub);
    }

    protected function replaceContent($stub){
        return str_replace(
            ['{RootPath}', '{AppName}', '{GlobalName}'],
            [config('consul.root_path'), config('app.name'), config('consul.global')],
            $stub
        );
    }

}