Skip to content

Commit 09f3ab5

Browse files
Merge pull request #9 from hexadog/develop
Develop
2 parents daa479e + d2e6dd1 commit 09f3ab5

File tree

8 files changed

+86
-95
lines changed

8 files changed

+86
-95
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p align="center"><img src="https://i.ibb.co/RbnsDrr/logo.png"></p>
1+
<p align="center"><img src="https://i.ibb.co/pKJgXY5/laravel-modules-manager.png" height="192"></p>
22

33
<p align="center">
44
<a href="https://packagist.org/packages/hexadog/laravel-themes-manager">

src/Console/Commands/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class AbstractCommand extends Command
1212
SectionMessage;
1313

1414
/**
15-
* @var \Hexadog\ThemesManager\Theme|mixed
15+
* @var mixed
1616
*/
1717
protected $theme;
1818

src/Console/Commands/ActivateTheme.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
namespace Hexadog\ThemesManager\Console\Commands;
44

5-
use Hexadog\ThemesManager\Console\Commands\Traits\BlockMessage;
6-
use Hexadog\ThemesManager\Console\Commands\Traits\SectionMessage;
7-
use Hexadog\ThemesManager\Facades\ThemesManager;
8-
use Illuminate\Console\Command;
5+
use Hexadog\ThemesManager\Console\Commands\AbstractCommand;
96

10-
class ActivateTheme extends Command
7+
class ActivateTheme extends AbstractCommand
118
{
12-
use BlockMessage;
13-
use SectionMessage;
14-
159
/**
1610
* The console command signature.
1711
*
@@ -42,26 +36,19 @@ public function __construct()
4236
*/
4337
public function handle()
4438
{
45-
if (!ThemesManager::has($this->argument('name'))) {
46-
$this->error("Theme with name {$this->argument('name')} does not exists!");
47-
48-
return false;
49-
}
50-
51-
$theme = ThemesManager::get($this->argument('name'));
39+
$this->validateName();
5240

53-
if ($theme->isActive()) {
41+
if ($this->theme->isActive()) {
5442
$this->error("Theme with name {$this->argument('name')} is already active!");
5543

5644
return false;
5745
}
5846

5947
$this->sectionMessage('Themes Manager', 'Activating theme...');
60-
if ($theme->activate()) {
61-
$this->sectionMessage('Themes Manager', 'Theme deactivated succefully');
48+
if ($this->theme->activate()) {
49+
$this->sectionMessage('Themes Manager', 'Theme activated succefully');
6250
} else {
6351
$this->error("Error while activating Theme with name {$this->argument('name')}!");
6452
}
65-
$this->sectionMessage('Themes Manager', 'Theme activated succefully');
6653
}
6754
}

src/Console/Commands/DeactivateTheme.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
namespace Hexadog\ThemesManager\Console\Commands;
44

5-
use Hexadog\ThemesManager\Console\Commands\Traits\BlockMessage;
6-
use Hexadog\ThemesManager\Console\Commands\Traits\SectionMessage;
7-
use Hexadog\ThemesManager\Facades\ThemesManager;
8-
use Illuminate\Console\Command;
5+
use Hexadog\ThemesManager\Console\Commands\AbstractCommand;
96

10-
class DeactivateTheme extends Command
7+
class DeactivateTheme extends AbstractCommand
118
{
12-
use BlockMessage;
13-
use SectionMessage;
14-
159
/**
1610
* The console command signature.
1711
*
@@ -42,23 +36,17 @@ public function __construct()
4236
*/
4337
public function handle()
4438
{
45-
if (!ThemesManager::has($this->argument('name'))) {
46-
$this->error("Theme with name {$this->argument('name')} does not exists!");
47-
48-
return false;
49-
}
50-
51-
$theme = ThemesManager::get($this->argument('name'));
39+
$this->validateName();
5240

53-
if (!$theme->isActive()) {
41+
if (!$this->theme->isActive()) {
5442
$this->error("Theme with name {$this->argument('name')} is already deactivated!");
5543

5644
return false;
5745
}
5846

5947
$this->sectionMessage('Themes Manager', 'Deactivating theme...');
6048

61-
if ($theme->deactivate()) {
49+
if ($this->theme->deactivate()) {
6250
$this->sectionMessage('Themes Manager', 'Theme deactivated succefully');
6351
} else {
6452
$this->error("Error while deactivating Theme with name {$this->argument('name')}!");

src/Helpers/Json.php

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,35 @@
99
class Json
1010
{
1111
/**
12-
* The file path.
12+
* The file path
1313
*
1414
* @var string
1515
*/
1616
protected $path;
1717

1818
/**
19-
* The laravel filesystem instance.
19+
* The laravel filesystem instance
2020
*
2121
* @var \Illuminate\Filesystem\Filesystem
2222
*/
2323
protected $filesystem;
2424

2525
/**
26-
* The attributes collection.
26+
* The attributes collection
2727
*
2828
* @var \Illuminate\Support\Collection
2929
*/
3030
protected $attributes;
3131

3232
/**
33-
* The constructor.
33+
* The constructor
3434
*
35-
* @param mixed $path
35+
* @param string $path
3636
* @param \Illuminate\Filesystem\Filesystem $filesystem
3737
*/
38-
public function __construct($path, Filesystem $filesystem = null)
38+
public function __construct(string $path, Filesystem $filesystem = null)
3939
{
40-
$this->path = (string) $path;
40+
$this->path = $path;
4141
$this->filesystem = $filesystem ?: new Filesystem();
4242
$this->attributes = collect($this->getAttributes());
4343
}
@@ -47,78 +47,79 @@ public function __construct($path, Filesystem $filesystem = null)
4747
*
4848
* @return Filesystem
4949
*/
50-
public function getFilesystem()
50+
public function getFilesystem(): Filesystem
5151
{
5252
return $this->filesystem;
5353
}
5454

5555
/**
56-
* Set filesystem.
56+
* Set filesystem
5757
*
5858
* @param Filesystem $filesystem
5959
*
60-
* @return $this
60+
* @return Json
6161
*/
62-
public function setFilesystem(Filesystem $filesystem)
62+
public function setFilesystem(Filesystem $filesystem): Json
6363
{
6464
$this->filesystem = $filesystem;
6565

6666
return $this;
6767
}
6868

6969
/**
70-
* Get path.
70+
* Get path
7171
*
7272
* @return string
7373
*/
74-
public function getPath()
74+
public function getPath(): string
7575
{
7676
return $this->path;
7777
}
7878

7979
/**
80-
* Set path.
80+
* Set path
8181
*
82-
* @param mixed $path
82+
* @param string $path
8383
*
84-
* @return $this
84+
* @return Json
8585
*/
86-
public function setPath($path)
86+
public function setPath(string $path): Json
8787
{
88-
$this->path = (string) $path;
88+
$this->path = $path;
8989

9090
return $this;
9191
}
9292

9393
/**
94-
* Make new instance.
94+
* Make new instance
9595
*
96-
* @param string $path
96+
* @param string $path
9797
* @param \Illuminate\Filesystem\Filesystem $filesystem
9898
*
99-
* @return static
99+
* @return Json
100100
*/
101-
public static function make($path, Filesystem $filesystem = null)
101+
public static function make(string $path, Filesystem $filesystem = null): Json
102102
{
103103
return new static($path, $filesystem);
104104
}
105105

106106
/**
107-
* Get file content.
107+
* Get file content
108108
*
109109
* @return string
110110
*/
111-
public function getContents()
111+
public function getContents(): string
112112
{
113113
return $this->filesystem->get($this->getPath());
114114
}
115115

116116
/**
117-
* Get file contents as array.
117+
* Get file contents as array
118+
*
118119
* @return array
119-
* @throws \Exception
120+
* @throws InvalidJsonException
120121
*/
121-
public function getAttributes()
122+
public function getAttributes(): array
122123
{
123124
$attributes = json_decode($this->getContents(), 1);
124125

@@ -131,40 +132,40 @@ public function getAttributes()
131132
}
132133

133134
/**
134-
* Convert the given array data to pretty json.
135+
* Convert the given array data to pretty json
135136
*
136137
* @param array $data
137138
*
138-
* @return string
139+
* @return string|false
139140
*/
140141
public function toJsonPretty(array $data = null)
141142
{
142143
return json_encode($data ?: $this->attributes, JSON_PRETTY_PRINT);
143144
}
144145

145146
/**
146-
* Update json contents from array data.
147+
* Update json contents from array data
147148
*
148149
* @param array $data
149150
*
150151
* @return bool
151152
*/
152-
public function update(array $data)
153+
public function update(array $data): bool
153154
{
154155
$this->attributes = collect(array_merge($this->attributes->toArray(), $data));
155156

156157
return $this->save();
157158
}
158159

159160
/**
160-
* Set a specific key & value.
161+
* Set a specific key & value
161162
*
162163
* @param string $key
163164
* @param mixed $value
164165
*
165-
* @return $this
166+
* @return Json
166167
*/
167-
public function set($key, $value)
168+
public function set($key, $value): Json
168169
{
169170
$attributes = $this->attributes->toArray();
170171

@@ -176,17 +177,17 @@ public function set($key, $value)
176177
}
177178

178179
/**
179-
* Save the current attributes array to the file storage.
180+
* Save the current attributes array to the file storage
180181
*
181182
* @return bool
182183
*/
183-
public function save()
184+
public function save(): bool
184185
{
185-
return $this->filesystem->put($this->getPath(), $this->toJsonPretty());
186+
return (bool) $this->filesystem->put($this->getPath(), $this->toJsonPretty());
186187
}
187188

188189
/**
189-
* Handle magic method __get.
190+
* Handle magic method __get
190191
*
191192
* @param string $key
192193
*
@@ -198,7 +199,7 @@ public function __get($key)
198199
}
199200

200201
/**
201-
* Get the specified attribute from json file.
202+
* Get the specified attribute from json file
202203
*
203204
* @param $key
204205
* @param null $default
@@ -211,7 +212,7 @@ public function get($key, $default = null)
211212
}
212213

213214
/**
214-
* Handle call to __call method.
215+
* Handle call to __call method
215216
*
216217
* @param string $method
217218
* @param array $arguments
@@ -228,7 +229,7 @@ public function __call($method, $arguments = [])
228229
}
229230

230231
/**
231-
* Handle call to __toString method.
232+
* Handle call to __toString method
232233
*
233234
* @return string
234235
*/

src/Theme.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function deactivate()
9595
*/
9696
public function getPath(string $path = null): string
9797
{
98-
return $this->path . $this->cleanPath($path);
98+
return $this->cleanPath(Str::finish($this->path, DIRECTORY_SEPARATOR) . $path);
9999
}
100100

101101
/**
@@ -352,8 +352,8 @@ protected function cleanPath($path = '')
352352
{
353353
$path = str_replace('/', DIRECTORY_SEPARATOR, $path);
354354

355-
if ($path && !is_file($path) && !Str::endsWith($path, DIRECTORY_SEPARATOR)) {
356-
$path = $path . DIRECTORY_SEPARATOR;
355+
if ($path && !is_file($path)) {
356+
Str::finish($path, DIRECTORY_SEPARATOR);
357357
}
358358

359359
return $path;

0 commit comments

Comments
 (0)