Skip to content
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

Drop legacy support #29

Merged
merged 11 commits into from
Mar 18, 2024
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
54 changes: 0 additions & 54 deletions .github/workflows/run-tests-laravel-8-9.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: run-tests-laravel-7
name: "Run Tests - Current"

on: [push, pull_request]

Expand All @@ -9,33 +9,39 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0, 7.4, 7.2]
laravel: [7.*, 6.*, 5.8.*]
dependency-version: [prefer-stable]
php: [8.3, 8.2, 8.1, 8.0]
laravel: ["^11.0", "^10.0", "^9.0", "^8.12"]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*
- laravel: 5.8.*
testbench: 3.*
- laravel: ^11.0
testbench: 9.*
- laravel: ^10.0
testbench: 8.*
- laravel: ^9.0
testbench: 7.*
- laravel: ^8.12
testbench: ^6.23
exclude:
- laravel: 5.8.*
php: 8.0
- laravel: 5.8.*
php: 7.4
- laravel: ^10.0
php: 8.0
- laravel: ^8.12
php: 8.3
- laravel: ^11.0
php: 8.1
- laravel: ^11.0
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -48,5 +54,9 @@ jobs:
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" "mockery/mockery:^1.3.2" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Display PHP version
run: php -v | grep ^PHP | cut -d' ' -f2

- name: Execute tests
run: vendor/bin/phpunit --color=always tests
run: vendor/bin/phpunit
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Easily render meta tags within your Laravel application, using a fluent API
## Features

- Simple API
- Laravel `>=5.8 | 6.x | 7.x | 8.x | 9.x | 10.x` supported
- Render named, property, raw, Twitter card and OpenGraph type meta tags
- [Optionally, render default tags on every request](#default-tags)
- [Conditionally set tags](#conditionally-setting-tags)
Expand All @@ -23,7 +22,14 @@ Easily render meta tags within your Laravel application, using a fluent API

## Requirements

PHP >= 7.2, Laravel >= 5.8.
- PHP `^8.0`
- Laravel `^8.12`, `^9.0`, `^10.0` or `^11.0`

### Legacy Support / Upgrading

For PHP `<8.0` and Laravel `<8.12` / support, use package version [`^1.7.7`](https://github.com/f9webltd/laravel-meta/tree/1.7.7)

If upgrading from `^1.0`, see [UPGRADING](UPGRADING.md) for details.

## Installation

Expand Down Expand Up @@ -98,21 +104,11 @@ The `when()` is fluent and can be called multiple times:
```php
meta()
->set('title', 'the title')
-when(true, function ($meta) {
$meta->set('og:description', 'og description');
})
-when(false, function ($meta) {
$meta->set('referrer', 'no-referrer-when-downgrade');
})
-when(true, fn ($meta) => $meta->set('og:description', 'og description'))
-when(false, fn ($meta) => $meta->set('referrer', 'no-referrer-when-downgrade'))
->noIndex();
```

If using PHP >=7.4, [arrow functions](https://www.php.net/manual/en/functions.arrow.php) can be optionally used.

```php
meta()->when(true, fn($meta) => $meta->noIndex());
```

### Blade Directives

Blade directives are available, as an alternative to using PHP function within templates.
Expand Down
8 changes: 8 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Upgrading

## From 1.x to 2.x

- Run the following command to fetch the latets version of the package: `composer require f9webltd/laravel-meta:^2.0`
- The package now requires PHP `^8.0` and Laravel `^8.12` / `^9.0`, `^10.0` or `^11.0`
- The `meta()` helper function now **only** returns an instance of the `Meta` class, this is breaking change. Previously the helper acted as a short cut to fetch a specific tag. For example, `meta('title')` was previously the same as `meta()->get('title')`. This behaviour was removed for simplicity and to help with autocompletion. If using this function calls in the format `meta('title')` shoulod be adjusted to `meta()->get('title')`
- No further changes are required
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"role": "Developer"
}
],
"require": {
"php": "^7.2 | ^8.0",
"illuminate/config": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0"
},
"require-dev": {
"orchestra/testbench": ">=3.8",
"phpunit/phpunit": "^7.0|^8.0|^9.3"
},
"require": {
"php": "^8.0",
"illuminate/config": "^8.12|^9.0|^10.0|^11.0",
"illuminate/support": "^8.12|^9.0|^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^6.23|^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.4|^10.1"
},
"autoload": {
"psr-4": {
"F9Web\\Meta\\": "src"
Expand Down
2 changes: 2 additions & 0 deletions src/GuessesTitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace F9Web\Meta;

use function config;

use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Route;

use function optional;

trait GuessesTitles
Expand Down
2 changes: 2 additions & 0 deletions src/Tags/Canonical.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace F9Web\Meta\Tags;

use function config;

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\HtmlString;

use function sprintf;
use function str_replace;

Expand Down
2 changes: 2 additions & 0 deletions src/Tags/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace F9Web\Meta\Tags;

use function config;

use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;

use function sprintf;

class Description implements Tag
Expand Down
4 changes: 3 additions & 1 deletion src/Tags/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace F9Web\Meta\Tags;

use function config;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;

use function sprintf;

class Title implements Tag
Expand All @@ -20,7 +22,7 @@ public function render(string $key, $value = null, Collection $tags = null): Htm
{
$config = config('f9web-laravel-meta');

if (! ($title = Arr::get($tags ?? [], 'title'))) {
if (!($title = Arr::get($tags ?? [], 'title'))) {
return new HtmlString(
sprintf('<title>%s</title>', $config['fallback-meta-title'])
);
Expand Down
7 changes: 5 additions & 2 deletions src/TitleGuessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace F9Web\Meta;

use F9Web\Meta\Exceptions\GuessorException;

use function collect;
use function config;
use function explode;

use Illuminate\Support\Collection;

use function in_array;
use function parse_url;
use function str_replace;
Expand All @@ -30,13 +33,13 @@ public function render()
{
$config = config('f9web-laravel-meta.title-guessor');

if (! $config['enabled']) {
if (!$config['enabled']) {
return null;
}

$this->setMethod($config['method']);

if (! in_array($method = $this->getMethod(), ['route', 'uri'])) {
if (!in_array($method = $this->getMethod(), ['route', 'uri'])) {
throw new GuessorException();
}

Expand Down
16 changes: 3 additions & 13 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

use F9Web\Meta\Meta;

if (! function_exists('meta')) {
/**
* @param string|null $key
* @return array|\F9Web\Meta\Meta|string|null
*/
function meta(?string $key = null)
if (!function_exists('meta')) {
function meta(?string $key = null): Meta
{
$instance = resolve(Meta::class);

if ($key === null) {
return $instance;
}

return $instance->get($key);
return resolve(Meta::class);
}
}
3 changes: 1 addition & 2 deletions tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ function ($mock) {
->andReturnSelf();

$mock->shouldReceive('get')
->twice()
->once()
->with('title');
}
);

meta()->set('title', 'the meta title');
meta()->get('title');
meta('title');
}
}
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use F9Web\Meta\Meta;
use F9Web\Meta\MetaServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;

use function resolve;

abstract class TestCase extends OrchestraTestCase
Expand Down