mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-12 09:54:03 +00:00
feat: support Laravel 10.x & remove unneccessary package
This commit is contained in:
parent
a737879baf
commit
2f9b36fa85
7 changed files with 40 additions and 43 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -11,7 +11,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
laravel: [8, 9]
|
laravel: [8, 9, 10]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.0",
|
"php": "^8.0",
|
||||||
"illuminate/support": "^8.24|^9.0",
|
"illuminate/support": "^8.24|^9.0|^10.0",
|
||||||
"imliam/laravel-blade-helper": "^1.4"
|
"illuminate/view": "^8.24|^9.0|^10.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"orchestra/testbench": "^6.23|^7.0",
|
"orchestra/testbench": "^6.23|^7.0",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ parameters:
|
||||||
checkMissingIterableValueType: false
|
checkMissingIterableValueType: false
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
# Waiting for https://github.com/phpstan/phpstan/issues/5706
|
|
||||||
- '#^Cannot call method (flipp|previewify|get|set)\(\) on ArchTech\\SEO\\SEOManager\|array\|string\|null\.$#'
|
|
||||||
- '#^Method ArchTech\\SEO\\SEOManager::flipp\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
|
- '#^Method ArchTech\\SEO\\SEOManager::flipp\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
|
||||||
- '#^Method ArchTech\\SEO\\SEOManager::previewify\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
|
- '#^Method ArchTech\\SEO\\SEOManager::previewify\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
|
||||||
|
- '#^Method ArchTech\\SEO\\SEOManager::render\(\) has parameter \$args with no type specified\.$#'
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace ArchTech\SEO;
|
namespace ArchTech\SEO;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -323,6 +324,38 @@ class SEOManager
|
||||||
return $this->get($key);
|
return $this->get($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Render blade directive. */
|
||||||
|
public function render(...$args): array|string|null
|
||||||
|
{
|
||||||
|
// Flipp and Previewify support more arguments
|
||||||
|
if (in_array($args[0], ['flipp', 'previewify'], true)) {
|
||||||
|
$method = array_shift($args);
|
||||||
|
|
||||||
|
return $this->{$method}(...$args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Two arguments indicate that we're setting a value, e.g. `@seo('title', 'foo')
|
||||||
|
if (count($args) === 2) {
|
||||||
|
return $this->set($args[0], $args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// An array means we don't return anything, e.g. `@seo(['title' => 'foo'])
|
||||||
|
if (is_array($args[0])) {
|
||||||
|
foreach ($args[0] as $type => $value) {
|
||||||
|
if (in_array($type, ['flipp', 'previewify'], true)) {
|
||||||
|
$this->{$type}(...Arr::wrap($value));
|
||||||
|
} else {
|
||||||
|
$this->set($type, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A single value means we fetch a value, e.g. `@seo('title')
|
||||||
|
return $this->get($args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
/** Handle magic get. */
|
/** Handle magic get. */
|
||||||
public function __get(string $key): string|null
|
public function __get(string $key): string|null
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,14 @@ declare(strict_types=1);
|
||||||
namespace ArchTech\SEO;
|
namespace ArchTech\SEO;
|
||||||
|
|
||||||
use ArchTech\SEO\Commands\GenerateFaviconsCommand;
|
use ArchTech\SEO\Commands\GenerateFaviconsCommand;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use ImLiam\BladeHelper\BladeHelperServiceProvider;
|
|
||||||
use ImLiam\BladeHelper\Facades\BladeHelper;
|
|
||||||
|
|
||||||
class SEOServiceProvider extends ServiceProvider
|
class SEOServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->app->singleton('seo', SEOManager::class);
|
$this->app->singleton('seo', SEOManager::class);
|
||||||
$this->app->register(BladeHelperServiceProvider::class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
|
|
@ -32,34 +29,8 @@ class SEOServiceProvider extends ServiceProvider
|
||||||
__DIR__ . '/../assets/views' => resource_path('views/vendor/seo'),
|
__DIR__ . '/../assets/views' => resource_path('views/vendor/seo'),
|
||||||
], 'seo-views');
|
], 'seo-views');
|
||||||
|
|
||||||
BladeHelper::directive('seo', function (...$args) {
|
Blade::directive('seo', function ($expression) {
|
||||||
// Flipp and Previewify support more arguments
|
return "<?php echo seo()->render($expression); ?>";
|
||||||
if (in_array($args[0], ['flipp', 'previewify'], true)) {
|
|
||||||
$method = array_shift($args);
|
|
||||||
|
|
||||||
return seo()->{$method}(...$args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Two arguments indicate that we're setting a value, e.g. `@seo('title', 'foo')
|
|
||||||
if (count($args) === 2) {
|
|
||||||
return seo()->set($args[0], $args[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// An array means we don't return anything, e.g. `@seo(['title' => 'foo'])
|
|
||||||
if (is_array($args[0])) {
|
|
||||||
foreach ($args[0] as $type => $value) {
|
|
||||||
if (in_array($type, ['flipp', 'previewify'], true)) {
|
|
||||||
seo()->{$type}(...Arr::wrap($value));
|
|
||||||
} else {
|
|
||||||
seo()->set($type, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A single value means we fetch a value, e.g. `@seo('title')
|
|
||||||
return seo()->get($args[0]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use ArchTech\SEO\Tests\Etc\FacebookExtension;
|
|
||||||
use Illuminate\Support\Facades\Blade;
|
|
||||||
use Illuminate\View\Component;
|
|
||||||
|
|
||||||
test('the twitter extension is disabled by default', function () {
|
test('the twitter extension is disabled by default', function () {
|
||||||
expect(seo()->all())
|
expect(seo()->all())
|
||||||
->not()->toBeEmpty()
|
->not()->toBeEmpty()
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ namespace ArchTech\SEO\Tests;
|
||||||
|
|
||||||
use Orchestra\Testbench\TestCase as TestbenchTestCase;
|
use Orchestra\Testbench\TestCase as TestbenchTestCase;
|
||||||
use ArchTech\SEO\SEOServiceProvider;
|
use ArchTech\SEO\SEOServiceProvider;
|
||||||
use ImLiam\BladeHelper\BladeHelperServiceProvider;
|
|
||||||
|
|
||||||
class TestCase extends TestbenchTestCase
|
class TestCase extends TestbenchTestCase
|
||||||
{
|
{
|
||||||
|
|
@ -12,7 +11,6 @@ class TestCase extends TestbenchTestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
SEOServiceProvider::class,
|
SEOServiceProvider::class,
|
||||||
BladeHelperServiceProvider::class,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue