Skip to content

Commit 0992083

Browse files
authored
Add support Laravel 10.x & remove unused package (#26)
* feat: support Laravel 10.x & remove unneccessary package * Update * Update * Update
1 parent a737879 commit 0992083

File tree

7 files changed

+44
-47
lines changed

7 files changed

+44
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
laravel: [8, 9]
14+
laravel: [8, 9, 10]
1515

1616
steps:
1717
- uses: actions/checkout@v2

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
},
2525
"require": {
2626
"php": "^8.0",
27-
"illuminate/support": "^8.24|^9.0",
28-
"imliam/laravel-blade-helper": "^1.4"
27+
"illuminate/support": "^8.24|^9.0|^10.0",
28+
"illuminate/view": "^8.24|^9.0|^10.0"
2929
},
3030
"require-dev": {
31-
"orchestra/testbench": "^6.23|^7.0",
32-
"nunomaduro/larastan": "^1.0",
33-
"pestphp/pest": "^1.2",
34-
"pestphp/pest-plugin-laravel": "^1.0",
31+
"orchestra/testbench": "^6.23|^7.0|^8.0",
32+
"nunomaduro/larastan": "^1.0|^2.4",
33+
"pestphp/pest": "^1.2|^2.0",
34+
"pestphp/pest-plugin-laravel": "^1.0|^2.0",
3535
"intervention/image": "^2.7"
3636
},
3737
"extra": {

phpstan.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ parameters:
1313
checkMissingIterableValueType: false
1414

1515
ignoreErrors:
16-
# Waiting for https://github.com/phpstan/phpstan/issues/5706
17-
- '#^Cannot call method (flipp|previewify|get|set)\(\) on ArchTech\\SEO\\SEOManager\|array\|string\|null\.$#'
1816
- '#^Method ArchTech\\SEO\\SEOManager::flipp\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
1917
- '#^Method ArchTech\\SEO\\SEOManager::previewify\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
18+
- '#^Method ArchTech\\SEO\\SEOManager::render\(\) has parameter \$args with no type specified\.$#'

src/SEOManager.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ArchTech\SEO;
66

77
use Closure;
8+
use Illuminate\Support\Arr;
89
use Illuminate\Support\Str;
910

1011
/**
@@ -323,6 +324,38 @@ public function __call(string $name, array $arguments): string|array|null|static
323324
return $this->get($key);
324325
}
325326

327+
/** Render blade directive. */
328+
public function render(...$args): array|string|null
329+
{
330+
// Flipp and Previewify support more arguments
331+
if (in_array($args[0], ['flipp', 'previewify'], true)) {
332+
$method = array_shift($args);
333+
334+
return $this->{$method}(...$args);
335+
}
336+
337+
// Two arguments indicate that we're setting a value, e.g. `@seo('title', 'foo')
338+
if (count($args) === 2) {
339+
return $this->set($args[0], $args[1]);
340+
}
341+
342+
// An array means we don't return anything, e.g. `@seo(['title' => 'foo'])
343+
if (is_array($args[0])) {
344+
foreach ($args[0] as $type => $value) {
345+
if (in_array($type, ['flipp', 'previewify'], true)) {
346+
$this->{$type}(...Arr::wrap($value));
347+
} else {
348+
$this->set($type, $value);
349+
}
350+
}
351+
352+
return null;
353+
}
354+
355+
// A single value means we fetch a value, e.g. `@seo('title')
356+
return $this->get($args[0]);
357+
}
358+
326359
/** Handle magic get. */
327360
public function __get(string $key): string|null
328361
{

src/SEOServiceProvider.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
namespace ArchTech\SEO;
66

77
use ArchTech\SEO\Commands\GenerateFaviconsCommand;
8-
use Illuminate\Support\Arr;
8+
use Illuminate\Support\Facades\Blade;
99
use Illuminate\Support\ServiceProvider;
10-
use ImLiam\BladeHelper\BladeHelperServiceProvider;
11-
use ImLiam\BladeHelper\Facades\BladeHelper;
1210

1311
class SEOServiceProvider extends ServiceProvider
1412
{
1513
public function register(): void
1614
{
1715
$this->app->singleton('seo', SEOManager::class);
18-
$this->app->register(BladeHelperServiceProvider::class);
1916
}
2017

2118
public function boot(): void
@@ -32,34 +29,8 @@ public function boot(): void
3229
__DIR__ . '/../assets/views' => resource_path('views/vendor/seo'),
3330
], 'seo-views');
3431

35-
BladeHelper::directive('seo', function (...$args) {
36-
// Flipp and Previewify support more arguments
37-
if (in_array($args[0], ['flipp', 'previewify'], true)) {
38-
$method = array_shift($args);
39-
40-
return seo()->{$method}(...$args);
41-
}
42-
43-
// Two arguments indicate that we're setting a value, e.g. `@seo('title', 'foo')
44-
if (count($args) === 2) {
45-
return seo()->set($args[0], $args[1]);
46-
}
47-
48-
// An array means we don't return anything, e.g. `@seo(['title' => 'foo'])
49-
if (is_array($args[0])) {
50-
foreach ($args[0] as $type => $value) {
51-
if (in_array($type, ['flipp', 'previewify'], true)) {
52-
seo()->{$type}(...Arr::wrap($value));
53-
} else {
54-
seo()->set($type, $value);
55-
}
56-
}
57-
58-
return null;
59-
}
60-
61-
// A single value means we fetch a value, e.g. `@seo('title')
62-
return seo()->get($args[0]);
32+
Blade::directive('seo', function ($expression) {
33+
return "<?php echo seo()->render($expression); ?>";
6334
});
6435
}
6536
}

tests/Pest/ExtensionTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
22

3-
use ArchTech\SEO\Tests\Etc\FacebookExtension;
4-
use Illuminate\Support\Facades\Blade;
5-
use Illuminate\View\Component;
6-
73
test('the twitter extension is disabled by default', function () {
84
expect(seo()->all())
95
->not()->toBeEmpty()

tests/TestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
use Orchestra\Testbench\TestCase as TestbenchTestCase;
66
use ArchTech\SEO\SEOServiceProvider;
7-
use ImLiam\BladeHelper\BladeHelperServiceProvider;
87

98
class TestCase extends TestbenchTestCase
109
{
1110
protected function getPackageProviders($app)
1211
{
1312
return [
1413
SEOServiceProvider::class,
15-
BladeHelperServiceProvider::class,
1614
];
1715
}
1816
}

0 commit comments

Comments
 (0)