Skip to content

Add support Laravel 10.x & remove unused package #26

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

Merged
merged 4 commits into from
Feb 15, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
laravel: [8, 9]
laravel: [8, 9, 10]

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
},
"require": {
"php": "^8.0",
"illuminate/support": "^8.24|^9.0",
"imliam/laravel-blade-helper": "^1.4"
"illuminate/support": "^8.24|^9.0|^10.0",
"illuminate/view": "^8.24|^9.0|^10.0"
},
"require-dev": {
"orchestra/testbench": "^6.23|^7.0",
"nunomaduro/larastan": "^1.0",
"pestphp/pest": "^1.2",
"pestphp/pest-plugin-laravel": "^1.0",
"orchestra/testbench": "^6.23|^7.0|^8.0",
"nunomaduro/larastan": "^1.0|^2.4",
"pestphp/pest": "^1.2|^2.0",
"pestphp/pest-plugin-laravel": "^1.0|^2.0",
"intervention/image": "^2.7"
},
"extra": {
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ parameters:
checkMissingIterableValueType: false

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::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\.$#'
33 changes: 33 additions & 0 deletions src/SEOManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace ArchTech\SEO;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -323,6 +324,38 @@ public function __call(string $name, array $arguments): string|array|null|static
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. */
public function __get(string $key): string|null
{
Expand Down
35 changes: 3 additions & 32 deletions src/SEOServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
namespace ArchTech\SEO;

use ArchTech\SEO\Commands\GenerateFaviconsCommand;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use ImLiam\BladeHelper\BladeHelperServiceProvider;
use ImLiam\BladeHelper\Facades\BladeHelper;

class SEOServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton('seo', SEOManager::class);
$this->app->register(BladeHelperServiceProvider::class);
}

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

BladeHelper::directive('seo', function (...$args) {
// Flipp and Previewify support more arguments
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]);
Blade::directive('seo', function ($expression) {
return "<?php echo seo()->render($expression); ?>";
});
}
}
4 changes: 0 additions & 4 deletions tests/Pest/ExtensionTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?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 () {
expect(seo()->all())
->not()->toBeEmpty()
Expand Down
2 changes: 0 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

use Orchestra\Testbench\TestCase as TestbenchTestCase;
use ArchTech\SEO\SEOServiceProvider;
use ImLiam\BladeHelper\BladeHelperServiceProvider;

class TestCase extends TestbenchTestCase
{
protected function getPackageProviders($app)
{
return [
SEOServiceProvider::class,
BladeHelperServiceProvider::class,
];
}
}