|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SocialiteProviders\Generators\Compilers; |
|
4
|
|
|
|
|
5
|
|
|
use SocialiteProviders\Generators\Contexts\Stub; |
|
6
|
|
|
use Illuminate\Contracts\View\Factory as ViewFactory; |
|
7
|
|
|
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory; |
|
8
|
|
|
|
|
9
|
|
|
class Compiler |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The filesystem instance. |
|
13
|
|
|
* |
|
14
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $files; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Blade Engine. |
|
20
|
|
|
* |
|
21
|
|
|
* @var \Illuminate\View\Factory |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $view; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* View Context. |
|
27
|
|
|
* |
|
28
|
|
|
* @var \SocialiteProviders\Generators\Contexts\Stub |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $context; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Create a new compiler instance. |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $data |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(array $data) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->files = app('files'); |
|
40
|
|
|
$this->view = app(ViewFactory::class); |
|
41
|
|
|
$this->context = new Stub($data); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Generate the composer.json. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function composer() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->compile('composer', 'composer.json'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Generate the target file from a stub. |
|
54
|
|
|
* |
|
55
|
|
|
* @param $stub |
|
56
|
|
|
* @param $targetLocation |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function compile($stub, $targetLocation) |
|
59
|
|
|
{ |
|
60
|
|
|
$view = $this->view->make("generator.stubs::$stub", $this->context->toArray()); |
|
61
|
|
|
|
|
62
|
|
|
$contents = "<?php\r\n\r\n".$view->render(); |
|
63
|
|
|
|
|
64
|
|
|
$targetDir = base_path('/SocialiteProviders/'.$this->context->nameStudlyCase()); |
|
65
|
|
|
if (!$this->files->isDirectory($targetDir)) { |
|
66
|
|
|
$this->files->makeDirectory($targetDir, 0755, true, true); |
|
67
|
|
|
$this->files->makeDirectory($targetDir.'/src', 0755, true, true); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$this->files->put($targetDir.'/'.$targetLocation, $contents); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|