Skip to content

Commit b37735f

Browse files
committed
fix error is make helper command and add make provider command
1 parent f7fc1ba commit b37735f

File tree

8 files changed

+425
-195
lines changed

8 files changed

+425
-195
lines changed

src/Command.php

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
3+
namespace Guysolamour\Command\Console\Commands;
4+
5+
use Illuminate\Support\Str;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Container\Container;
8+
use Illuminate\Filesystem\Filesystem;
9+
10+
11+
abstract class BaseCommand extends Command
12+
{
13+
14+
/**
15+
* @var string
16+
*/
17+
protected $template_path = '';
18+
19+
20+
protected $filesystem;
21+
22+
23+
public function __construct()
24+
{
25+
parent::__construct();
26+
27+
$this->template_path = (dirname(dirname(__DIR__))) . "/templates";
28+
$this->filesystem = new Filesystem;
29+
}
30+
31+
32+
/**
33+
* Parse guard name
34+
* Get the guard name in different cases
35+
* @param string $name
36+
* @return array
37+
*/
38+
protected function parseName($name = null) :array
39+
{
40+
return [
41+
'{{namespace}}' => $this->getNamespace(),
42+
// '{{pluralCamel}}' => Str::plural(Str::camel($name)),
43+
// '{{pluralSlug}}' => Str::plural(Str::slug($name)),
44+
// '{{pluralSnake}}' => Str::plural(Str::snake($name)),
45+
// '{{pluralClass}}' => Str::plural(Str::studly($name)),
46+
// '{{singularCamel}}' => Str::singular(Str::camel($name)),
47+
// '{{singularSlug}}' => Str::singular(Str::slug($name)),
48+
// '{{singularSnake}}' => Str::singular(Str::snake($name)),
49+
// '{{singularClass}}' => Str::singular(Str::studly($name)),
50+
];
51+
}
52+
53+
/**
54+
* Get project namespace
55+
* Default: App
56+
* @return string
57+
*/
58+
protected function getNamespace()
59+
{
60+
$namespace = Container::getInstance()->getNamespace();
61+
return rtrim($namespace, '\\');
62+
}
63+
64+
65+
/**
66+
* @param string|array $files
67+
* @param string $path
68+
* @return void
69+
*/
70+
protected function compliedAndWriteFile($files, string $path): void
71+
{
72+
73+
if (is_array($files)) {
74+
foreach ($files as $file) {
75+
$this->compliedAndWriteFile($file, $path);
76+
}
77+
return;
78+
}
79+
80+
$data_map = $this->parseName();
81+
82+
$stub = $this->isSingleFile($files) ? $files : $this->filesystem->get($files->getRealPath());
83+
84+
$this->createDirectoryIfNotExists(
85+
$path,
86+
!$this->isSingleFile($files)
87+
);
88+
$complied = strtr($stub, $data_map);
89+
90+
$this->writeFile(
91+
$complied,
92+
$this->isSingleFile($files) ? $path : $path . '/' . $files->getFilenameWithoutExtension() . '.php'
93+
);
94+
}
95+
96+
97+
protected function compliedAndWriteFileRecursively($files, string $path)
98+
{
99+
if (is_array($files)) {
100+
foreach ($files as $file) {
101+
$this->compliedAndWriteFileRecursively($file, $path);
102+
}
103+
return;
104+
}
105+
106+
$this->compliedAndWriteFile(
107+
$this->filesystem->get($files),
108+
$path . '/' . $files->getRelativePath() . '/' . $files->getFilenameWithoutExtension() . '.php'
109+
);
110+
}
111+
112+
/**
113+
* @param string|array $files
114+
* @param string $search
115+
* @param string $path
116+
* @return void
117+
*/
118+
protected function replaceAndWriteFile($files, string $search, $replace, string $path)
119+
{
120+
if (is_array($files)) {
121+
foreach ($files as $file) {
122+
$this->replaceAndWriteFile($file, $search, $replace, $path);
123+
}
124+
return;
125+
}
126+
127+
$stub = $this->isSingleFile($files) ? $files : $this->filesystem->get($files->getRealPath());
128+
// $stub = $this->filesystem->get($files->getRealPath());
129+
$this->createDirectoryIfNotExists(
130+
$path,
131+
!$this->isSingleFile($files)
132+
);
133+
$complied = str_replace($search, $replace, $stub);
134+
135+
$this->writeFile(
136+
$complied,
137+
$this->isSingleFile($files) ? $path : $path . '/' . $files->getFilenameWithoutExtension() . '.php'
138+
);
139+
}
140+
141+
142+
/**
143+
* Permet de créer un dossier
144+
* @param string $path
145+
* @param boolean $folder Permet de savoir si le chemin passé est un dossier ou fichier
146+
* @return void
147+
*/
148+
protected function createDirectoryIfNotExists(string $path, bool $folder = true): void
149+
{
150+
151+
$dir = $folder ? $path : $this->filesystem->dirname($path);
152+
153+
if (!$this->filesystem->exists($dir)) {
154+
$this->filesystem->makeDirectory($dir, 0755, true);
155+
}
156+
}
157+
158+
/**
159+
* @param mixte $compiled
160+
* @param string $path
161+
* @return void
162+
*/
163+
protected function writeFile($compiled, string $path): void
164+
{
165+
// dd($path, $compiled);
166+
$this->filesystem->put(
167+
$path,
168+
$compiled
169+
);
170+
}
171+
172+
173+
protected function isSingleFile($file): bool
174+
{
175+
return is_string($file);
176+
}
177+
178+
}

src/Console/Commands/Helper/CreateHelper.php

Lines changed: 0 additions & 177 deletions
This file was deleted.

0 commit comments

Comments
 (0)