We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||||||
2 | |||||||
3 | namespace Backpack\CRUD\app\Console\Commands\Themes; |
||||||
4 | |||||||
5 | trait InstallsTheme |
||||||
6 | { |
||||||
7 | use \Backpack\CRUD\app\Console\Commands\Traits\PrettyCommandOutput; |
||||||
8 | use \Backpack\CRUD\app\Console\Commands\Traits\AddonsHelper; |
||||||
9 | |||||||
10 | /** |
||||||
11 | * The name and signature of the console command. |
||||||
12 | * |
||||||
13 | * @var string |
||||||
14 | */ |
||||||
15 | // protected $signature = 'backpack:require:theme-name {--debug} : Show process output or not. Useful for debugging.'; |
||||||
16 | |||||||
17 | /** |
||||||
18 | * The console command description. |
||||||
19 | * |
||||||
20 | * @var string |
||||||
21 | */ |
||||||
22 | // protected $description = 'Install Backpack\'s XXX Theme'; |
||||||
23 | |||||||
24 | /** |
||||||
25 | * Backpack addons install attribute. |
||||||
26 | * |
||||||
27 | * @var array |
||||||
28 | */ |
||||||
29 | // public static $addon = [ |
||||||
30 | // 'name' => 'CoreUIv2', |
||||||
31 | // 'description' => [ |
||||||
32 | // 'UI provided by CoreUIv2, a Boostrap 4 template.', |
||||||
33 | // '<fg=blue>https://github.com/laravel-backpack/theme-coreuiv2/</>', |
||||||
34 | // ], |
||||||
35 | // 'repo' => 'backpack/theme-coreuiv2', |
||||||
36 | // 'path' => 'vendor/backpack/theme-coreuiv2', |
||||||
37 | // 'command' => 'backpack:require:theme-coreuiv2', |
||||||
38 | // 'view_namespace' => 'backpack.theme-coreuiv2::', |
||||||
39 | // 'publish_tag' => 'theme-coreuiv2-config', |
||||||
40 | // ]; |
||||||
41 | |||||||
42 | /** |
||||||
43 | * Run the theme installation process. |
||||||
44 | * |
||||||
45 | * @return void |
||||||
46 | */ |
||||||
47 | public function installTheme() |
||||||
48 | { |
||||||
49 | // Check if it is installed |
||||||
50 | if ($this->isInstalled()) { |
||||||
51 | $this->newLine(); |
||||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
52 | $this->line(sprintf(' %s was already installed', self::$addon['name']), 'fg=red'); |
||||||
0 ignored issues
–
show
It seems like
line() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
53 | $this->newLine(); |
||||||
54 | |||||||
55 | return; |
||||||
56 | } |
||||||
57 | |||||||
58 | $this->newLine(); |
||||||
59 | $this->progressBlock($this->description); |
||||||
60 | |||||||
61 | // Require package |
||||||
62 | try { |
||||||
63 | $this->composerRequire(self::$addon['repo']); |
||||||
64 | $this->closeProgressBlock(); |
||||||
65 | } catch (\Throwable $e) { |
||||||
66 | $this->errorProgressBlock(); |
||||||
67 | $this->line(' '.$e->getMessage(), 'fg=red'); |
||||||
68 | $this->newLine(); |
||||||
69 | |||||||
70 | return; |
||||||
71 | } |
||||||
72 | |||||||
73 | // Display general error in case it failed |
||||||
74 | if (! $this->isInstalled()) { |
||||||
75 | $this->errorProgressBlock(); |
||||||
76 | $this->note('For further information please check the log file.'); |
||||||
77 | $this->note('You can also follow the manual installation process documented on Github.'); |
||||||
78 | $this->newLine(); |
||||||
79 | |||||||
80 | return; |
||||||
81 | } |
||||||
82 | |||||||
83 | // Publish the theme config file |
||||||
84 | $this->progressBlock('Publish theme config file'); |
||||||
85 | |||||||
86 | // manually include the provider in the run-time |
||||||
87 | if (! class_exists(self::$addon['provider'])) { |
||||||
88 | include self::$addon['provider_path'] ?? self::$addon['path'].'/src/AddonServiceProvider.php'; |
||||||
89 | app()->register(self::$addon['provider']); |
||||||
0 ignored issues
–
show
The method
register() does not exist on Illuminate\Container\Container . Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
90 | } |
||||||
91 | |||||||
92 | $this->executeArtisanProcess('vendor:publish', [ |
||||||
93 | '--tag' => self::$addon['publish_tag'], |
||||||
94 | ]); |
||||||
95 | $this->closeProgressBlock(); |
||||||
96 | |||||||
97 | // add this theme's view namespace to the ui config file |
||||||
98 | $this->progressBlock('Use theme as view namespace in <fg=blue>config/backpack/ui.php</>'); |
||||||
99 | $this->useViewNamespaceInConfigFile(); |
||||||
100 | $this->closeProgressBlock(); |
||||||
101 | $this->newLine(); |
||||||
102 | } |
||||||
103 | |||||||
104 | public function isInstalled() |
||||||
105 | { |
||||||
106 | return file_exists(self::$addon['path'].'/composer.json'); |
||||||
107 | } |
||||||
108 | |||||||
109 | public function useViewNamespaceInConfigFile() |
||||||
110 | { |
||||||
111 | $config_file = config_path('backpack/ui.php'); |
||||||
112 | $config_contents = file_get_contents($config_file); |
||||||
113 | $config_contents = preg_replace("/'view_namespace' => '.*'/", "'view_namespace' => '".self::$addon['view_namespace']."'", $config_contents); |
||||||
114 | $config_contents = preg_replace("/'view_namespace_fallback' => '.*'/", "'view_namespace_fallback' => '".self::$addon['view_namespace']."'", $config_contents); |
||||||
115 | |||||||
116 | file_put_contents($config_file, $config_contents); |
||||||
117 | } |
||||||
118 | } |
||||||
119 |