Skip to content

Commit 5057284

Browse files
Merge pull request #10 from hexadog/develop
Develop
2 parents 09f3ab5 + 7b1e844 commit 5057284

File tree

8 files changed

+232
-63
lines changed

8 files changed

+232
-63
lines changed

config/config.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
| Symbolic path
1717
|--------------------------------------------------------------------------
1818
|
19-
| you can change the public themes path used for assets
19+
| you can change the public themes path used for assets.
2020
|
2121
*/
2222
'symlink_path' => 'themes',
@@ -31,4 +31,18 @@
3131
|
3232
*/
3333
'fallback_theme' => null,
34+
35+
/*
36+
|--------------------------------------------------------------------------
37+
| Caching
38+
|--------------------------------------------------------------------------
39+
|
40+
| Config for caching feature.
41+
|
42+
*/
43+
'cache' => [
44+
'enabled' => false,
45+
'key' => 'themes-manager',
46+
'lifetime' => 86400,
47+
],
3448
];

src/Console/Commands/Cache.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Hexadog\ThemesManager\Console\Commands;
4+
5+
use Hexadog\ThemesManager\Facades\ThemesManager;
6+
use Hexadog\ThemesManager\Console\Commands\AbstractCommand;
7+
8+
class Cache extends AbstractCommand
9+
{
10+
/**
11+
* The console command name.
12+
*
13+
* @var string
14+
*/
15+
protected $name = 'theme:cache';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Create themes cache';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Prompt for module's alias name
36+
*
37+
*/
38+
public function handle()
39+
{
40+
if (ThemesManager::buildCache()) {
41+
$this->sectionMessage('Themes Manager', 'Themes cache created succefully');
42+
} else {
43+
$this->error("An error occured while creating themes cache");
44+
}
45+
}
46+
}

src/Console/Commands/ClearCache.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Hexadog\ThemesManager\Console\Commands;
4+
5+
use Hexadog\ThemesManager\Facades\ThemesManager;
6+
use Hexadog\ThemesManager\Console\Commands\AbstractCommand;
7+
8+
class ClearCache extends AbstractCommand
9+
{
10+
/**
11+
* The console command name.
12+
*
13+
* @var string
14+
*/
15+
protected $name = 'theme:cache:clear';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Clear themes cache';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Prompt for module's alias name
36+
*
37+
*/
38+
public function handle()
39+
{
40+
if (ThemesManager::clearCache()) {
41+
$this->sectionMessage('Themes Manager', 'Themes cache cleared succefully');
42+
} else {
43+
$this->error("An error occured while clearing themes cache");
44+
}
45+
}
46+
}

src/Helpers/Json.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function getContents(): string
115115

116116
/**
117117
* Get file contents as array
118-
*
118+
*
119119
* @return array
120120
* @throws InvalidJsonException
121121
*/

src/Providers/PackageServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ReflectionClass;
77
use Illuminate\Support\Str;
88
use Illuminate\Routing\Router;
9+
use Illuminate\Cache\CacheManager;
910
use Illuminate\Filesystem\Filesystem;
1011
use Illuminate\Contracts\View\Factory;
1112
use Illuminate\Foundation\AliasLoader;
@@ -99,7 +100,8 @@ public function register(): void
99100
$this->app->singleton('themes-manager', function () {
100101
return new ThemesManager(
101102
app(Factory::class),
102-
app(Translator::class)
103+
app(Translator::class),
104+
app(CacheManager::class)
103105
);
104106
});
105107

@@ -127,6 +129,8 @@ protected function strapCommands()
127129
if ($this->app->runningInConsole() || config('app.env') == 'testing') {
128130
$this->commands([
129131
Commands\ActivateTheme::class,
132+
Commands\Cache::class,
133+
Commands\ClearCache::class,
130134
Commands\DeactivateTheme::class,
131135
Commands\ListThemes::class,
132136
Generators\MakeTheme::class,

src/Theme.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Hexadog\ThemesManager\Events\ThemeEnabling;
1414
use Hexadog\ThemesManager\Traits\ComposerTrait;
1515
use Hexadog\ThemesManager\Events\ThemeDisabling;
16+
use Illuminate\Support\Facades\Log;
1617

1718
class Theme
1819
{
@@ -25,13 +26,6 @@ class Theme
2526
*/
2627
protected $path;
2728

28-
/**
29-
* The theme assets path (within public storage).
30-
*
31-
* @var string
32-
*/
33-
protected $assetsPath;
34-
3529
/**
3630
* The Parent theme.
3731
*
@@ -112,9 +106,10 @@ public function getAssetsPath(string $path = null): string
112106
* Get theme views paths
113107
*
114108
* @param string $path
115-
* @return void
109+
*
110+
* @return array
116111
*/
117-
public function getViewPaths($path = '')
112+
public function getViewPaths($path = ''): array
118113
{
119114
// Build Paths array.
120115
// All paths are relative to Config::get('themes-manager.directory')
@@ -317,7 +312,7 @@ public function url($url, $absolutePath = false): ?string
317312
}
318313
}
319314

320-
\Log::warning("Asset [{$url}] not found for Theme [{$this->getName()}]");
315+
Log::warning("Asset [{$url}] not found for Theme [{$this->getName()}]");
321316

322317
return ltrim(str_replace('\\', '/', $url));
323318
}

0 commit comments

Comments
 (0)