Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct(
*/
public function getCompiledPath($path)
{
return $this->cachePath.'/'.sha1('v2'.Str::after($path, $this->basePath)).'.'.$this->compiledExtension;
return $this->cachePath.'/'.hash('xxh128', 'v2'.Str::after($path, $this->basePath)).'.'.$this->compiledExtension;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function compileComponent($expression)
*/
public static function newComponentHash(string $component)
{
static::$componentHashStack[] = $hash = sha1($component);
static::$componentHashStack[] = $hash = hash('xxh128', $component);

return $hash;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function createBladeViewFromString($factory, $contents)
$directory = Container::getInstance()['config']->get('view.compiled')
);

if (! is_file($viewFile = $directory.'/'.sha1($contents).'.blade.php')) {
if (! is_file($viewFile = $directory.'/'.hash('xxh128', $contents).'.blade.php')) {
if (! is_dir($directory)) {
mkdir($directory, 0755, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/Concerns/ManagesLayouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static function parentPlaceholder($section = '')
if (! isset(static::$parentPlaceholder[$section])) {
$salt = static::parentPlaceholderSalt();

static::$parentPlaceholder[$section] = '##parent-placeholder-'.sha1($salt.$section).'##';
static::$parentPlaceholder[$section] = '##parent-placeholder-'.hash('xxh128', $salt.$section).'##';
}

return static::$parentPlaceholder[$section];
Expand Down
8 changes: 4 additions & 4 deletions tests/View/Blade/BladeComponentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testComponentsAreCompiled()

public function testClassComponentsAreCompiled()
{
$this->assertSame('<?php if (isset($component)) { $__componentOriginal32877a641c21ac6579f6376333c8770674a6058f = $component; } ?>
$this->assertSame('<?php if (isset($component)) { $__componentOriginal2dda3d2f2f9b76bd400bf03f0b84e87f = $component; } ?>
<?php $component = Illuminate\Tests\View\Blade\ComponentStub::class::resolve(["foo" => "bar"] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName(\'test\'); ?>
<?php if ($component->shouldRender()): ?>
Expand All @@ -36,9 +36,9 @@ public function testEndComponentClassesAreCompiled()

$this->assertSame('<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33)): ?>
<?php $component = $__componentOriginal0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33; ?>
<?php unset($__componentOriginal0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33); ?>
<?php if (isset($__componentOriginal79aef92e83454121ab6e5f64077e7d8a)): ?>
<?php $component = $__componentOriginal79aef92e83454121ab6e5f64077e7d8a; ?>
<?php unset($__componentOriginal79aef92e83454121ab6e5f64077e7d8a); ?>
<?php endif; ?>', $this->compiler->compileString('@endcomponentClass'));
}

Expand Down
8 changes: 4 additions & 4 deletions tests/View/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testInlineViewsGetCreated()
$this->viewFactory->shouldReceive('addNamespace')->once()->with('__components', '/tmp');

$component = new TestInlineViewComponent;
$this->assertSame('__components::c6327913fef3fca4518bcd7df1d0ff630758e241', $component->resolveView());
$this->assertSame('__components::57b7a54afa0eb51fd9b88eec031c9e9e', $component->resolveView());
}

public function testRegularViewsGetReturnedUsingViewHelper()
Expand Down Expand Up @@ -191,7 +191,7 @@ public function testBladeViewCacheWithInlineViewComponent()
->with('__components', '/tmp')
->twice();

$compiledViewName = '__components::c6327913fef3fca4518bcd7df1d0ff630758e241';
$compiledViewName = '__components::57b7a54afa0eb51fd9b88eec031c9e9e';
$contents = '::Hello {{ $title }}';
$cacheKey = $component::class.$contents;

Expand Down Expand Up @@ -227,8 +227,8 @@ public function testBladeViewCacheWithInlineViewComponentWhereRenderDependsOnPro
->with('__components', '/tmp')
->twice();

$compiledViewNameA = '__components::6dcd4ce23d88e2ee9568ba546c007c63d9131c1b';
$compiledViewNameB = '__components::ae4f281df5a5d0ff3cad6371f76d5c29b6d953ec';
$compiledViewNameA = '__components::9b0498cbe3839becd0d496e05c553485';
$compiledViewNameB = '__components::9d1b9bc4078a3e7274d3766ca02423f3';
$cacheAKey = $componentA::class.'::A';
$cacheBKey = $componentB::class.'::B';

Expand Down
26 changes: 13 additions & 13 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function tearDown(): void
public function testIsExpiredReturnsTrueIfCompiledFileDoesntExist()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('exists')->once()->with(__DIR__.'/'.sha1('v2foo').'.php')->andReturn(false);
$files->shouldReceive('exists')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php')->andReturn(false);
$this->assertTrue($compiler->isExpired('foo'));
}

Expand All @@ -33,18 +33,18 @@ public function testCannotConstructWithBadCachePath()
public function testIsExpiredReturnsTrueWhenModificationTimesWarrant()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('exists')->once()->with(__DIR__.'/'.sha1('v2foo').'.php')->andReturn(true);
$files->shouldReceive('exists')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php')->andReturn(true);
$files->shouldReceive('lastModified')->once()->with('foo')->andReturn(100);
$files->shouldReceive('lastModified')->once()->with(__DIR__.'/'.sha1('v2foo').'.php')->andReturn(0);
$files->shouldReceive('lastModified')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php')->andReturn(0);
$this->assertTrue($compiler->isExpired('foo'));
}

public function testIsExpiredReturnsFalseWhenUseCacheIsTrueAndNoFileModification()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('exists')->once()->with(__DIR__.'/'.sha1('v2foo').'.php')->andReturn(true);
$files->shouldReceive('exists')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php')->andReturn(true);
$files->shouldReceive('lastModified')->once()->with('foo')->andReturn(0);
$files->shouldReceive('lastModified')->once()->with(__DIR__.'/'.sha1('v2foo').'.php')->andReturn(100);
$files->shouldReceive('lastModified')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php')->andReturn(100);
$this->assertFalse($compiler->isExpired('foo'));
}

Expand All @@ -57,15 +57,15 @@ public function testIsExpiredReturnsTrueWhenUseCacheIsFalse()
public function testCompilePathIsProperlyCreated()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
$this->assertEquals(__DIR__.'/'.sha1('v2foo').'.php', $compiler->getCompiledPath('foo'));
$this->assertEquals(__DIR__.'/'.hash('xxh128', 'v2foo').'.php', $compiler->getCompiledPath('foo'));
}

public function testCompileCompilesFileAndReturnsContents()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('exists')->once()->with(__DIR__)->andReturn(true);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
$compiler->compile('foo');
}

Expand All @@ -75,7 +75,7 @@ public function testCompileCompilesFileAndReturnsContentsCreatingDirectory()
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('exists')->once()->with(__DIR__)->andReturn(false);
$files->shouldReceive('makeDirectory')->once()->with(__DIR__, 0777, true, true);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
$compiler->compile('foo');
}

Expand All @@ -84,7 +84,7 @@ public function testCompileCompilesAndGetThePath()
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('exists')->once()->with(__DIR__)->andReturn(true);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
$compiler->compile('foo');
$this->assertSame('foo', $compiler->getPath());
}
Expand All @@ -101,7 +101,7 @@ public function testCompileWithPathSetBefore()
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('exists')->once()->with(__DIR__)->andReturn(true);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php', 'Hello World<?php /**PATH foo ENDPATH**/ ?>');
// set path before compilation
$compiler->setPath('foo');
// trigger compilation with $path
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testIncludePathToTemplate($content, $compiled)
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn($content);
$files->shouldReceive('exists')->once()->with(__DIR__)->andReturn(true);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('v2foo').'.php', $compiled);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.hash('xxh128', 'v2foo').'.php', $compiled);

$compiler->compile('foo');
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public function testDontIncludeEmptyPath()
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('')->andReturn('Hello World');
$files->shouldReceive('exists')->once()->with(__DIR__)->andReturn(true);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('v2').'.php', 'Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.hash('xxh128', 'v2').'.php', 'Hello World');
$compiler->setPath('');
$compiler->compile();
}
Expand All @@ -197,7 +197,7 @@ public function testDontIncludeNullPath()
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with(null)->andReturn('Hello World');
$files->shouldReceive('exists')->once()->with(__DIR__)->andReturn(true);
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('v2').'.php', 'Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.hash('xxh128', 'v2').'.php', 'Hello World');
$compiler->setPath(null);
$compiler->compile();
}
Expand Down