Skip to content

Commit e0db989

Browse files
feature: Upgrade to PHP ^8.1, add support for Symfony ^7.1
For a full list of changes, see `CHANGELOG-3.x.md`.
1 parent 2a99717 commit e0db989

28 files changed

Lines changed: 854 additions & 617 deletions

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
test:
15+
name: Test with PHP ${{ matrix.php-versions }}
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php-versions: [8.1, 8.2, 8.3] # TODO - Add 8.4 once all tools/dependencies support it
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: ${{ matrix.php-versions }}
31+
32+
- name: Install dependencies
33+
uses: ramsey/composer-install@v3
34+
35+
- name: Run PHP-CS-Fixer
36+
run: composer phpcs:check
37+
38+
- name: Run PHPStan
39+
run: composer phpstan
40+
41+
- name: Run PHPUnit
42+
run: composer test

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
.idea/
22
composer.lock
33
vendor/
4+
5+
###> friendsofphp/php-cs-fixer ###
6+
/.php-cs-fixer.cache
7+
###< friendsofphp/php-cs-fixer ###
8+
9+
###> phpunit/phpunit ###
10+
/phpunit.xml
11+
/.phpunit.cache
12+
###< phpunit/phpunit ###

.php-cs-fixer.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Fusonic GmbH. All rights reserved.
5+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
11+
12+
$finder = (new PhpCsFixer\Finder())
13+
->in(__DIR__);
14+
15+
return (new PhpCsFixer\Config())
16+
->setParallelConfig(ParallelConfigFactory::detect())
17+
->setRules([
18+
'@PHP81Migration' => true,
19+
'@Symfony' => true,
20+
'@Symfony:risky' => true,
21+
'declare_strict_types' => true,
22+
'header_comment' => [
23+
'header' => 'Copyright (c) Fusonic GmbH. All rights reserved.'.\PHP_EOL.'Licensed under the MIT License. '.
24+
'See LICENSE file in the project root for license information.',
25+
'location' => 'after_open',
26+
],
27+
'no_useless_else' => true,
28+
'no_useless_return' => true,
29+
'php_unit_strict' => true,
30+
'single_line_throw' => false,
31+
'strict_comparison' => true,
32+
'strict_param' => true,
33+
])
34+
->setFinder($finder)
35+
->setRiskyAllowed(true);

.scrutinizer.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

CHANGELOG.md renamed to CHANGELOG-2.x.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG for 2.x
22

3+
## 2.3.0 (2023-12-05)
4+
5+
* Dropped dependency to deprecated `fusonic/linq` library
6+
37
## 2.2.0 (2022-01-20)
48

59
* Added compatibility with Symfony ^6.0

CHANGELOG-3.x.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# CHANGELOG for 3.x
2+
3+
## 3.0.0 (2024-01-13)
4+
5+
- Bumped the required PHP version from `^7.4 || ^8.0` to `^8.1`
6+
- Bumped the compatible Symfony version from `^3.0 || ^4.0 || ^5.0 || ^6.0` to `^5.4 || ^6.4 || ^7.1`
7+
- Upgraded PHPUnit from `^9.0` to `^10.5 || ^11.4` and updated tests accordingly
8+
- Added `composer test` script for running tests
9+
- Installed `friendsofphp/php-cs-fixer` and applied Fusonic's code style
10+
- Added `composer phpcs:check` script for validating code style
11+
- Added `composer phpcs:fix` script for fixing code style violations
12+
- Installed `phpstan/phpstan`, `phpstan/phpstan-deprecation-rules`, `phpstan/phpstan-phpunit` and
13+
`phpstan/phpstan-strict-rules` and fixed reported errors
14+
- Added `composer phpstan` script for validating code
15+
- Updated documentation
16+
- Switched to GitHub actions for automated testing

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014 Fusonic GmbH (http://www.fusonic.net)
1+
Copyright (c) 2014-2024 Fusonic GmbH (https://www.fusonic.net)
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,64 @@
11
# fusonic/opengraph
22

3-
[![Latest Stable Version](https://poser.pugx.org/fusonic/opengraph/v/stable)](https://packagist.org/packages/fusonic/opengraph)
4-
[![Total Downloads](https://poser.pugx.org/fusonic/opengraph/downloads)](https://packagist.org/packages/fusonic/opengraph)
5-
[![Build Status](https://api.travis-ci.org/fusonic/opengraph.svg)](https://travis-ci.org/fusonic/opengraph)
6-
[![License](https://poser.pugx.org/fusonic/opengraph/license)](https://packagist.org/packages/fusonic/opengraph)
3+
[![GitHub Release](https://img.shields.io/github/v/release/fusonic/opengraph)](https://github.com/fusonic/opengraph/releases/latest)
4+
[![Packagist Downloads](https://img.shields.io/packagist/dt/fusonic/opengraph?color=blue)](https://packagist.org/packages/fusonic/opengraph)
5+
[![Packagist License](https://img.shields.io/packagist/l/fusonic/opengraph)](https://github.com/fusonic/opengraph/blob/master/LICENSE)
6+
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/fusonic/opengraph/test)](https://github.com/fusonic/opengraph/actions/workflows/test.yml)
77

8-
A simple library to read Open Graph data from the web and generate HTML code to publish your own Open Graph objects. A fallback mode enables you to read data from websites that do not implement the Open Graph protocol.
8+
A simple library to read Open Graph data from the web and generate HTML code to publish your own Open Graph objects. A
9+
fallback mode enables you to read data from websites that do not implement the Open Graph protocol.
910

10-
Using this library you can easily retrieve stuff like meta data, video information from YouTube or Vimeo or image information from Flickr without using site-specific APIs since they all implement the Open Graph protocol.
11+
Using this library you can easily retrieve stuff like metadata, video information from YouTube or Vimeo or image
12+
information from Flickr without using site-specific APIs since they all implement the Open Graph protocol.
1113

12-
See [ogp.me](http://ogp.me) for information on the Open Graph protocol.
14+
See [ogp.me](https://ogp.me) for information on the Open Graph protocol.
1315

1416
## Requirements
1517

16-
* PHP 7.4+
17-
* [fusonic/linq](https://github.com/fusonic/linq)
18-
* [symfony/css-selector](https://github.com/symfony/CssSelector)
19-
* [symfony/dom-crawler](https://github.com/symfony/DomCrawler)
20-
* [psr/http-client](https://github.com/php-fig/http-client), [psr/http-factory](https://github.com/php-fig/http-factory) and compatible implementation such as [guzzle/guzzle](https://github.com/guzzle/guzzle)
18+
* PHP 8.1+
19+
* [symfony/css-selector](https://github.com/symfony/css-selector)
20+
* [symfony/dom-crawler](https://github.com/symfony/dom-crawler)
21+
* [psr/http-client](https://github.com/php-fig/http-client)
22+
* [psr/http-factory](https://github.com/php-fig/http-factory)
23+
* and compatible implementation such as [symfony/http-client](https://github.com/symfony/http-client)
2124

2225
## Installation
2326

2427
The most flexible installation method is using Composer:
2528

26-
``` bash
29+
```bash
2730
composer require fusonic/opengraph
2831
```
2932

30-
Install composer and run install command:
31-
``` bash
33+
Install Composer and run the `install` command:
34+
```bash
3235
curl -s http://getcomposer.org/installer | php
3336
php composer.phar install
3437
```
3538

36-
Once installed, include vendor/autoload.php in your script.
39+
Once installed, include `vendor/autoload.php` in your script.
3740

3841
``` php
39-
require "vendor/autoload.php";
42+
require 'vendor/autoload.php';
4043
```
4144

4245
## Usage
4346

4447
### Retrieve Open Graph data from a URL
4548

46-
``` php
49+
```php
50+
<?php
51+
4752
use Fusonic\OpenGraph\Consumer;
4853

4954
$consumer = new Consumer($httpClient, $httpRequestFactory);
50-
$object = $consumer->loadUrl("http://www.youtube.com/watch?v=P422jZg50X4");
55+
$object = $consumer->loadUrl('https://www.youtube.com/watch?v=P422jZg50X4');
5156

5257
// Basic information of the object
5358
echo "Title: " . $object->title; // Getting started with Facebook Open Graph
5459
echo "Site name: " . $object->siteName; // YouTube
5560
echo "Description: " . $object->description; // Originally recorded at the Facebook World ...
56-
echo "Canonical URL: " . $object->url; // http://www.youtube.com/watch?v=P422jZg50X4
61+
echo "Canonical URL: " . $object->url; // https://www.youtube.com/watch?v=P422jZg50X4
5762

5863
// Images
5964
$image = $object->images[0];
@@ -63,7 +68,7 @@ echo "Image[0] width: " . $image->width; // null (May return width in pi
6368

6469
// Videos
6570
$video = $object->videos[0];
66-
echo "Video URL: " . $video->url; // http://www.youtube.com/v/P422jZg50X4?version=3&autohide=1
71+
echo "Video URL: " . $video->url; // https://www.youtube.com/v/P422jZg50X4?version=3&autohide=1
6772
echo "Video height: " . $video->height; // 1080
6873
echo "Video width: " . $video->width; // 1920
6974
echo "Video type: " . $video->type; // application/x-shockwave-flash
@@ -73,7 +78,9 @@ _There are some more properties but these are the basic and most commonly used o
7378

7479
### Publish own Open Graph data
7580

76-
``` php
81+
```php
82+
<?php
83+
7784
use Fusonic\OpenGraph\Elements\Image;
7885
use Fusonic\OpenGraph\Elements\Video;
7986
use Fusonic\OpenGraph\Publisher;
@@ -86,14 +93,14 @@ $object = new Website();
8693
$object->title = "Getting started with Facebook Open Graph";
8794
$object->siteName = "YouTube";
8895
$object->description = "Originally recorded at the Facebook World ..."
89-
$object->url = "http://www.youtube.com/watch?v=P422jZg50X4";
96+
$object->url = "https://www.youtube.com/watch?v=P422jZg50X4";
9097

9198
// Images
9299
$image = new Image("https://i1.ytimg.com/vi/P422jZg50X4/maxresdefault.jpg");
93100
$object->images[] = $image;
94101

95102
// Videos
96-
$video = new Video("http://www.youtube.com/v/P422jZg50X4?version=3&autohide=1");
103+
$video = new Video("https://www.youtube.com/v/P422jZg50X4?version=3&autohide=1");
97104
$video->height = 1080;
98105
$video->width = 1920;
99106
$video->type = "application/x-shockwave-flash";
@@ -125,18 +132,20 @@ _HTML code is formatted just for displaying purposes. You may choose between HTM
125132

126133
## Running tests
127134

128-
You can run the test suite by running `phpunit` from the command line.
135+
You can run the test suite by running `composer test` from the command line.
129136

130137
## FAQ
131138

132139
**I don't get any information from a webpage, but Facebook shows information for the same URL. What do I do wrong?**
133140

134-
It seems that some pages (like Twitter) only publish OpenGraph information if Facebook's user agent string `facebookexternalhit/1.1` is used (see #28). So you should configure your PSR-18 client to use this user agent string:
141+
It seems that some pages (like Twitter/X) only publish Open Graph information if Facebook's user agent string
142+
`facebookexternalhit/1.1` is used (see [#28](https://github.com/fusonic/opengraph/issues/28)). So you should configure
143+
your PSR-18 client to use this user agent string:
135144

136145
```php
137-
$client = new Psr18Client(new NativeHttpClient([ "headers" => [ "User-Agent" => "facebookexternalhit/1.1" ] ]));
146+
$client = new Psr18Client(new NativeHttpClient(['headers' => ['User-Agent' => 'facebookexternalhit/1.1']]));
138147
```
139148

140149
## License
141150

142-
This library is licensed under the MIT license.
151+
fusonic/opengraph is licensed under the MIT license. See [LICENSE](LICENSE) for more information.

UPGRADE-3.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# UPGRADE FROM 2.2 TO 3.0
2+
3+
## Requirements
4+
- Bumped the required PHP version from `^7.4 || ^8.0` to `^8.1`
5+
- Bumped the compatible Symfony version from `^3.0 || ^4.0 || ^5.0 || ^6.0` to `^5.4 || ^6.4 || ^7.1`

0 commit comments

Comments
 (0)