Skip to content

Commit 1223682

Browse files
Merge pull request #2 from hexadog/develop
fix(trait): Performance issue when finding themes
2 parents 60bdd78 + e05bf63 commit 1223682

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

src/Providers/PackageServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public function register(): void
9999
$this->app->singleton('themes-manager', function () {
100100
return new ThemesManager(
101101
app(Factory::class),
102-
app(Filesystem::class),
103102
app(Translator::class)
104103
);
105104
});

src/Theme.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function setParent(Theme $theme)
169169

170170
/**
171171
* Get parent Theme
172-
*
172+
*
173173
* @return Theme|null
174174
*/
175175
public function getParent()
@@ -225,7 +225,7 @@ public function disabled(): bool
225225

226226
/**
227227
* Disable the current theme
228-
*
228+
*
229229
* @return Theme
230230
*/
231231
public function disable(bool $withEvent = true): Theme
@@ -248,7 +248,7 @@ public function disable(bool $withEvent = true): Theme
248248

249249
/**
250250
* Enable the current theme
251-
*
251+
*
252252
* @return Theme
253253
*/
254254
public function enable(bool $withEvent = true): Theme
@@ -275,7 +275,7 @@ public function enable(bool $withEvent = true): Theme
275275
*
276276
* @param string $url
277277
* @param boolean $absolutePath
278-
*
278+
*
279279
* @return string|null
280280
*/
281281
public function url($url, $absolutePath = false): ?string
@@ -345,7 +345,7 @@ public function listLayouts()
345345
* Clean Path by replacing all / by DIRECTORY_SEPARATOR
346346
*
347347
* @param string $path
348-
*
348+
*
349349
* @return string
350350
*/
351351
protected function cleanPath($path = '')

src/ThemesManager.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,21 @@ class ThemesManager
3939

4040
/**
4141
* View finder
42-
*
42+
*
4343
* @var \Illuminate\View\Factory
4444
*/
4545
private $view;
4646

47-
/**
48-
* File System
49-
*
50-
* @var \Illuminate\Contracts\Filesystem\Filesystem
51-
*/
52-
private $files;
53-
5447
/**
5548
* The constructor.
5649
*
5750
* @param Factory $view
5851
* @param Filesystem $files
5952
* @param Translator $lang
6053
*/
61-
public function __construct(Factory $view, Filesystem $files, Translator $lang)
54+
public function __construct(Factory $view, Translator $lang)
6255
{
6356
$this->view = $view;
64-
$this->files = $files;
6557
$this->lang = $lang;
6658
$this->basePath = Config::get('themes-manager.directory', 'themes');
6759

@@ -179,7 +171,7 @@ public function current(): ?Theme
179171

180172
/**
181173
* Enable a Theme from its name
182-
*
174+
*
183175
* @param string $name
184176
* @param bool $withEvent
185177
*
@@ -203,7 +195,7 @@ public function enable(string $name, bool $withEvent = true): ThemesManager
203195

204196
/**
205197
* Disable a Theme from its name
206-
*
198+
*
207199
* @param string $name
208200
* @param bool $withEvent
209201
*
@@ -240,7 +232,7 @@ public function asset(string $asset, $absolutePath = true): string
240232
*
241233
* @param string $asset
242234
* @param boolean $absolutePath
243-
*
235+
*
244236
* @return string
245237
*/
246238
public function style(string $asset, $absolutePath = true): string
@@ -259,7 +251,7 @@ public function style(string $asset, $absolutePath = true): string
259251
* @param boolean $absolutePath
260252
* @param string $type
261253
* @param string $level
262-
*
254+
*
263255
* @return string
264256
*/
265257
public function script(string $asset, string $mode = '', $absolutePath = true, string $type = 'text/javascript', string $level = 'functionality'): string
@@ -281,7 +273,7 @@ public function script(string $asset, string $mode = '', $absolutePath = true, s
281273
* @param string $class
282274
* @param array $attributes
283275
* @param boolean $absolutePath
284-
*
276+
*
285277
* @return string
286278
*/
287279
public function image(string $asset, string $alt = '', string $class = '', array $attributes = [], $absolutePath = true): string
@@ -313,7 +305,7 @@ public function mix($asset, $manifestDirectory = '')
313305
*
314306
* @param string $asset
315307
* @param boolean $absolutePath
316-
*
308+
*
317309
* @return string|null
318310
*/
319311
public function url(string $asset, $absolutePath = true): ?string
@@ -353,7 +345,7 @@ public function filterNonActive()
353345
* Return attributes in html format
354346
*
355347
* @param array $attributes
356-
*
348+
*
357349
* @return string
358350
*/
359351
private function htmlAttributes($attributes)

src/Traits/ComposerTrait.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Str;
77
use Hexadog\ThemesManager\Helpers\Json;
8+
use Symfony\Component\Finder\Finder;
89

910
trait ComposerTrait
1011
{
@@ -225,11 +226,12 @@ private function scan(string $path, string $class)
225226

226227
$path = base_path($path);
227228

228-
if ($this->files->exists($path)) {
229-
$foundComposers = array_filter($this->files->allFiles($path), function ($file) {
230-
return preg_match('/.*composer\.json$/U', $file->getFilename());
231-
});
229+
if (file_exists($path)) {
230+
$finder = new Finder();
231+
$foundComposers = $finder->files()->in($path)->exclude(['node_modules', 'vendor'])->name('composer.json');
232+
232233
foreach ($foundComposers as $foundComposer) {
234+
dump($foundComposer);
233235
$composerJson = new Json($foundComposer, app('files'));
234236

235237
if ($composerJson->get('type') === 'laravel-theme') {

0 commit comments

Comments
 (0)