Ai
1 Star 0 Fork 0

sintall.com/laravel-source-generator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
GeneratorCommand.php 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
sintall.com 提交于 2017-12-07 10:38 +08:00 . dd
<?php
namespace Sinta\Generators\Laravel;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Sinta\Generators\FileGenerator;
abstract class GeneratorCommand extends Command
{
protected $type;
protected $stub_directory;
public function __construct()
{
parent::__construct();
$this->stub_directory = __DIR__.'/stubs';
}
public function getStubDirectory()
{
return $this->stub_directory;
}
public function setStubDirectory($path)
{
$this->stub_directory = $path;
}
public function handle()
{
$generator = FileGenerator::make($this->getRootDirectory(), $this->getStubDirectory());
if ($this->generate($generator) === false) {
return false;
}
$this->info($this->type.' created successfully.');
}
abstract protected function generate(FileGenerator $generator);
protected function convertToFullQualifyClassName($name)
{
if (Str::contains($name, '/')) {
$name = str_replace('/', '\\', $name);
}
if (Str::startsWith($name, '\\')) {
$name = substr($name, 1);
}
else {
$name = $this->getDefaultNamespace().'\\'.$name;
}
return $this->filterFullQualifyClassName($name, function ($part) {
return ucfirst($part);
});
}
protected function filterFullQualifyClassName($fqcn, callable $callback)
{
$parts = explode('\\', $fqcn);
foreach ($parts as &$part) {
$part = call_user_func($callback, $part);
}
return implode('\\', $parts);
}
protected function splitFullQualifyClassName($fqcn)
{
$parts = explode('\\', $fqcn);
$classname = array_pop($parts);
return [implode('\\', $parts), $classname];
}
protected function getRootNamespace()
{
return trim($this->laravel->getNamespace(), '\\');
}
protected function getDefaultNamespace()
{
return $this->getRootNamespace();
}
protected function getRootDirectory()
{
return $this->laravel['path'];
}
protected function getRelativePath($fqcn)
{
if (strpos($fqcn, $this->getRootNamespace().'\\') === 0) {
$relative = substr($fqcn, strlen($this->getRootNamespace()) + 1);
}
else {
$relative = $fqcn;
}
return str_replace('\\', '/', $relative);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/limary_admin/laravel-source-generator.git
git@gitee.com:limary_admin/laravel-source-generator.git
limary_admin
laravel-source-generator
laravel-source-generator
master

搜索帮助