Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Handle custom extensions when caching views #48524

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Illuminate/Foundation/Console/ViewCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ protected function compileViews(Collection $views)
*/
protected function bladeFilesIn(array $paths)
{
$extensions = collect($this->laravel['view']->getExtensions())
->filter(fn ($value) => $value === 'blade')
->keys()
->map(fn ($extension) => "*.{$extension}")
->all();

return collect(
Finder::create()
->in($paths)
->exclude('vendor')
->name('*.blade.php')
->name($extensions)
->files()
);
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/View/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Illuminate\Tests\Integration\View;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
use Illuminate\View\Component;
use Orchestra\Testbench\TestCase;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

class BladeTest extends TestCase
{
Expand Down Expand Up @@ -166,6 +169,21 @@ public function test_bound_name_attribute_can_be_used_if_using_short_slot_names_
</div>', trim($content));
}

public function testViewCacheCommandHandlesConfiguredBladeExtensions()
{
$this->artisan('view:clear');

View::addExtension('sh', 'blade');
$this->artisan('view:cache');

$compiledFiles = Finder::create()->in(Config::get('view.compiled'))->files();
$found = collect($compiledFiles)
->contains(fn (SplFileInfo $file) => str_contains($file->getContents(), 'echo "<?php echo e($scriptMessage); ?>" > output.log'));
$this->assertTrue($found);

$this->artisan('view:clear');
}

protected function getEnvironmentSetUp($app)
{
$app['config']->set('view.paths', [__DIR__.'/templates']);
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/View/templates/different-extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "{{ $scriptMessage }}" > output.log