Skip to content

Commit 4f56d47

Browse files
committed
laravel 8 while we're at it
1 parent 8eb97a7 commit 4f56d47

File tree

7 files changed

+2708
-325
lines changed

7 files changed

+2708
-325
lines changed

Assets/JsonManifest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ class JsonManifest implements ManifestInterface
1818
/**
1919
* JsonManifest constructor
2020
*
21-
* @param string $manifestPath Local filesystem path to JSON-encoded manifest
22-
* @param string $distUri Remote URI to assets root
21+
* @param string $manifestPath Local filesystem path to JSON-encoded manifest
22+
* @param string $distUri Remote URI to assets root
2323
*/
2424
public function __construct($manifestPath, $distUri)
2525
{
2626
$this->manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : [];
2727
$this->dist = $distUri;
2828
}
2929

30-
/** @inheritdoc */
31-
public function get($asset)
30+
public function get($asset): string
3231
{
3332
return isset($this->manifest[$asset]) ? $this->manifest[$asset] : $asset;
3433
}
3534

36-
/** @inheritdoc */
37-
public function getUri($asset)
35+
public function getUri($asset): string
3836
{
3937
return "{$this->dist}/{$this->get($asset)}";
4038
}

Assets/ManifestInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface ManifestInterface
1717
* @param string $asset The original name of the file before cache-busting
1818
* @return string
1919
*/
20-
public function get($asset);
20+
public function get($asset): string;
2121

2222
/**
2323
* Get the cache-busted URI
@@ -27,5 +27,5 @@ public function get($asset);
2727
* @param string $asset The original name of the file before cache-busting
2828
* @return string
2929
*/
30-
public function getUri($asset);
30+
public function getUri($asset): string;
3131
}

Template/Blade.php

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

33
namespace Roots\Sage\Template;
44

5-
use Illuminate\Contracts\Container\Container as ContainerContract;
65
use Illuminate\Contracts\View\Factory as FactoryContract;
76
use Illuminate\View\Engines\CompilerEngine;
8-
use Illuminate\View\Engines\EngineInterface;
97
use Illuminate\View\ViewFinderInterface;
108

119
/**
@@ -23,7 +21,6 @@
2321
*/
2422
class Blade
2523
{
26-
/** @var Factory */
2724
protected $env;
2825

2926
public function __construct(FactoryContract $env)
@@ -35,39 +32,41 @@ public function __construct(FactoryContract $env)
3532
* Get the compiler
3633
*
3734
* @return \Illuminate\View\Compilers\BladeCompiler
35+
* @throws \Illuminate\Contracts\Container\BindingResolutionException
3836
*/
39-
public function compiler()
37+
public function compiler(): \Illuminate\View\Compilers\BladeCompiler
4038
{
4139
static $engineResolver;
4240
if (!$engineResolver) {
4341
$engineResolver = $this->getContainer()->make('view.engine.resolver');
4442
}
43+
4544
return $engineResolver->resolve('blade')->getCompiler();
4645
}
4746

4847
/**
49-
* @param string $view
50-
* @param array $data
51-
* @param array $mergeData
48+
* @param string $view
49+
* @param array $data
50+
* @param array $mergeData
5251
* @return string
5352
*/
54-
public function render($view, $data = [], $mergeData = [])
53+
public function render($view, $data = [], $mergeData = []): string
5554
{
5655
/** @var \Illuminate\Contracts\Filesystem\Filesystem $filesystem */
5756
$filesystem = $this->getContainer()['files'];
57+
5858
return $this->{$filesystem->exists($view) ? 'file' : 'make'}($view, $data, $mergeData)->render();
5959
}
6060

6161
/**
62-
* @param string $file
63-
* @param array $data
64-
* @param array $mergeData
62+
* @param string $file
63+
* @param array $data
64+
* @param array $mergeData
6565
* @return string
6666
*/
6767
public function compiledPath($file, $data = [], $mergeData = [])
6868
{
6969
$rendered = $this->file($file, $data, $mergeData);
70-
/** @var EngineInterface $engine */
7170
$engine = $rendered->getEngine();
7271

7372
if (!($engine instanceof CompilerEngine)) {
@@ -80,14 +79,15 @@ public function compiledPath($file, $data = [], $mergeData = [])
8079
if ($compiler->isExpired($compiledPath)) {
8180
$compiler->compile($file);
8281
}
82+
8383
return $compiledPath;
8484
}
8585

8686
/**
87-
* @param string $file
87+
* @param string $file
8888
* @return string
8989
*/
90-
public function normalizeViewPath($file)
90+
public function normalizeViewPath($file): string
9191
{
9292
// Convert `\` to `/`
9393
$view = str_replace('\\', '/', $file);
@@ -108,10 +108,10 @@ public function normalizeViewPath($file)
108108
/**
109109
* Convert path to view namespace
110110
*
111-
* @param string $path
111+
* @param string $path
112112
* @return string
113113
*/
114-
public function applyNamespaceToPath($path)
114+
public function applyNamespaceToPath($path): string
115115
{
116116
/** @var ViewFinderInterface $finder */
117117
$finder = $this->getContainer()['view.finder'];
@@ -123,13 +123,14 @@ public function applyNamespaceToPath($path)
123123
$view = array_reduce(array_keys($hints), function ($view, $namespace) use ($delimiter, $hints) {
124124
return str_replace($hints[$namespace], $namespace.$delimiter, $view);
125125
}, $path);
126+
126127
return preg_replace("%{$delimiter}[\\/]*%", $delimiter, $view);
127128
}
128129

129130
/**
130131
* Pass any method to the view Factory instance.
131132
*
132-
* @param string $method
133+
* @param string $method
133134
* @param array $params
134135
* @return mixed
135136
*/

Template/BladeProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
class BladeProvider extends ViewServiceProvider
1515
{
1616
/**
17-
* @param ContainerContract $container
18-
* @param array $config
17+
* @param ContainerContract $container
18+
* @param array $config
1919
* @SuppressWarnings(PHPMD.StaticAccess)
2020
*/
2121
public function __construct(ContainerContract $container = null, $config = [])
@@ -65,6 +65,7 @@ public function registerViewFinder()
6565
$namespaces = $config['view.namespaces'];
6666
$finder = new FileViewFinder($app['files'], $paths);
6767
array_map([$finder, 'addNamespace'], array_keys($namespaces), $namespaces);
68+
6869
return $finder;
6970
}, true);
7071
}

Template/FileViewFinder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ class FileViewFinder extends \Illuminate\View\FileViewFinder
1212
* @param string $name
1313
* @return array
1414
*/
15-
public function getPossibleViewFiles($name)
15+
public function getPossibleViewFiles($name): array
1616
{
1717
$parts = explode(self::FALLBACK_PARTS_DELIMITER, $name);
1818
$templates[] = array_shift($parts);
1919
foreach ($parts as $i => $part) {
2020
$templates[] = $templates[$i].self::FALLBACK_PARTS_DELIMITER.$part;
2121
}
2222
rsort($templates);
23+
2324
return $this->getPossibleViewFilesFromTemplates($templates);
2425
}
2526

@@ -29,7 +30,7 @@ public function getPossibleViewFiles($name)
2930
* @param array $templates
3031
* @return array
3132
*/
32-
public function getPossibleViewFilesFromTemplates($templates)
33+
public function getPossibleViewFilesFromTemplates($templates): array
3334
{
3435
return call_user_func_array('array_merge', array_map(function ($template) {
3536
return array_map(function ($extension) use ($template) {

composer.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@
2828
}
2929
},
3030
"require": {
31-
"php": "^8.0",
32-
"composer/installers": "~1.0",
33-
"illuminate/view": "~7.0",
34-
"illuminate/config": "~7.0"
31+
"php": "^7.4",
32+
"composer/installers": "~2.0",
33+
"illuminate/view": "^8.0",
34+
"illuminate/config": "^8.0",
35+
"illuminate/support": "^8.0",
36+
"ext-json": "*"
3537
},
3638
"require-dev": {
37-
"squizlabs/php_codesniffer": "~3.5"
39+
"squizlabs/php_codesniffer": "~3.5",
40+
"friendsofphp/php-cs-fixer": "^3.8"
3841
},
3942
"scripts": {
40-
"test": [
41-
"phpcs --ignore=vendor --extensions=php --standard=PSR2 ."
43+
"cs-fix": [
44+
"php vendor/bin/php-cs-fixer fix --diff --config=.php_cs.dist.php -vvv"
4245
]
46+
},
47+
"config": {
48+
"allow-plugins": {
49+
"composer/installers": true
50+
}
4351
}
4452
}

0 commit comments

Comments
 (0)