Skip to content

Commit

Permalink
Merge pull request #341 from j0k3r/fix/2.x-update-deps
Browse files Browse the repository at this point in the history
[2.x] Update deps
  • Loading branch information
j0k3r authored Jan 4, 2024
2 parents a8524b4 + b1aff11 commit 3519a1e
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 94 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ name: "CS"
on:
pull_request:
branches:
- master
- "master"
- "2.x"
push:
branches:
- master
- "master"
- "2.x"

jobs:
coding-standards:
Expand All @@ -16,11 +18,11 @@ jobs:
strategy:
matrix:
php:
- "7.3"
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -33,7 +35,7 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Run PHP CS Fixer"
run: "php vendor/bin/php-cs-fixer fix --verbose --dry-run --format=checkstyle | cs2pr"
Expand Down
34 changes: 19 additions & 15 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
pull_request:
branches:
- "master"
- "2.x"
push:
branches:
- "master"
- "2.x"

env:
fail-fast: true
Expand All @@ -24,10 +26,13 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -43,7 +48,7 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Setup logs"
run: "mkdir -p build/logs"
Expand All @@ -62,7 +67,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -78,7 +83,7 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Setup logs"
run: "mkdir -p build/logs"
Expand Down Expand Up @@ -108,7 +113,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -124,7 +129,7 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "lowest"

Expand All @@ -145,7 +150,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -161,7 +166,7 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Setup adapter: Guzzle 5"
run: |
Expand All @@ -185,7 +190,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -201,7 +206,7 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Setup adapter: Guzzle 7"
run: |
Expand All @@ -225,7 +230,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -241,13 +246,12 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Setup adapter: cURL"
run: |
composer remove php-http/guzzle6-adapter --dev -n
composer require php-http/curl-client --dev -n
composer require zendframework/zend-diactoros --dev -n
- name: "Setup logs"
run: "mkdir -p build/logs"
Expand All @@ -266,7 +270,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -282,7 +286,7 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
uses: "ramsey/composer-install@v2"

- name: "Setup logs"
run: "mkdir -p build/logs"
Expand Down
28 changes: 16 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
"ext-curl": "*",
"ext-tidy": "*",
"fossar/htmlawed": "^1.2.7",
"http-interop/http-factory-guzzle": "^1.0",
"j0k3r/graby-site-config": "^1.0.110",
"http-interop/http-factory-guzzle": "^1.1",
"j0k3r/graby-site-config": "^1.0.181",
"j0k3r/httplug-ssrf-plugin": "^2.0",
"j0k3r/php-readability": "^1.2.3",
"j0k3r/php-readability": "^1.2.10",
"monolog/monolog": "^1.18.0|^2.0",
"php-http/client-common": "^2.3",
"php-http/discovery": "^1.12",
"php-http/httplug": "^2.2",
"php-http/message": "^1.9",
"simplepie/simplepie": "^1.5",
"smalot/pdfparser": "^1.0",
"symfony/options-resolver": "^3.4|^4.4|^5.3|^6.0",
"php-http/client-common": "^2.7",
"php-http/discovery": "^1.19",
"php-http/httplug": "^2.4",
"php-http/message": "^1.14",
"simplepie/simplepie": "^1.7",
"smalot/pdfparser": "^1.1",
"symfony/options-resolver": "^3.4|^4.4|^5.3|^6.0|^7.0",
"true/punycode": "^2.1",
"guzzlehttp/psr7": "^1.5.0|^2.0"
},
Expand All @@ -43,7 +43,7 @@
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"symfony/phpunit-bridge": "^5.3"
"symfony/phpunit-bridge": "^6.4.1"
},
"extra": {
"branch-alias": {
Expand All @@ -61,6 +61,10 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true,
"phpstan/extension-installer": true
}
}
}
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
</listener>
</listeners>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0" />
</php>

<!-- <logging>
<log type="coverage-html" target="build" lowUpperBound="35" highLowerBound="70"/>
</logging> -->
Expand Down
12 changes: 6 additions & 6 deletions src/Extractor/ContentExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class ContentExtractor
private $xpath;
private $html;
private $config;
private $siteConfig = null;
private $title = null;
private $language = null;
private $siteConfig;
private $title;
private $language;
private $authors = [];
private $body = null;
private $image = null;
private $body;
private $image;
private $nativeAd = false;
private $date = null;
private $date;
private $success = false;
private $nextPageUrl;
/** @var LoggerInterface */
Expand Down
12 changes: 4 additions & 8 deletions src/Extractor/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Http\Client\Common\Plugin\RedirectPlugin;
use Http\Client\Common\PluginClient;
use Http\Client\Exception\TransferException;
use Http\Client\HttpClient as Client;
use Http\Discovery\Psr17FactoryDiscovery;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand Down Expand Up @@ -42,11 +42,7 @@ class HttpClient
*/
private $responseHistory;

/**
* @param Client $client Http client
* @param array $config
*/
public function __construct(Client $client, $config = [], LoggerInterface $logger = null)
public function __construct(ClientInterface $client, $config = [], LoggerInterface $logger = null)
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
Expand Down Expand Up @@ -254,7 +250,7 @@ public function fetch($url, $skipTypeVerification = false, $httpHeader = [])
// check for <meta name='fragment' content='!'/>
// for AJAX sites, e.g. Blogger with its dynamic views templates.
// Based on Google's spec: https://developers.google.com/webmasters/ajax-crawling/docs/specification
if (false === strpos($effectiveUrl, '_escaped_fragment_')) {
if (!str_contains($effectiveUrl, '_escaped_fragment_')) {
$redirectURL = $this->getMetaRefreshURL($effectiveUrl, $body) ?: $this->getUglyURL($effectiveUrl, $body);

if (false !== $redirectURL) {
Expand Down Expand Up @@ -296,7 +292,7 @@ private function cleanupUrl($url)
{
// rewrite part of urls to something more readable
foreach ($this->config['rewrite_url'] as $find => $action) {
if (false !== strpos($url, $find) && \is_array($action)) {
if (str_contains($url, $find) && \is_array($action)) {
$url = strtr($url, $action);
}
}
Expand Down
29 changes: 8 additions & 21 deletions src/Graby.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Psr7\UriResolver;
use Http\Client\Common\PluginClient;
use Http\Client\HttpClient as Client;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Http\Message\CookieJar;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Readability\Readability;
Expand All @@ -34,21 +34,17 @@ class Graby

private $config = [];

private $httpClient = null;
private $extractor = null;
private $httpClient;
private $extractor;

/** @var ConfigBuilder */
private $configBuilder;
private $punycode;

private $imgNoReferrer = false;
private $prefetchedContent = null;
private $prefetchedContent;

/**
* @param array $config
* @param Client|null $client Http client
*/
public function __construct($config = [], Client $client = null, ConfigBuilder $configBuilder = null)
public function __construct($config = [], ClientInterface $client = null, ConfigBuilder $configBuilder = null)
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
Expand Down Expand Up @@ -118,7 +114,7 @@ public function __construct($config = [], Client $client = null, ConfigBuilder $
);

$this->httpClient = new HttpClient(
$client ?: new PluginClient(HttpClientDiscovery::find(), [new CookiePlugin(new CookieJar())]),
$client ?: new PluginClient(Psr18ClientDiscovery::find(), [new CookiePlugin(new CookieJar())]),
$this->config['http_client'],
$this->logger
);
Expand Down Expand Up @@ -150,8 +146,6 @@ public function reloadConfigFiles()
* Return a config.
*
* @param string $key
*
* @return mixed
*/
public function getConfig($key)
{
Expand Down Expand Up @@ -226,7 +220,7 @@ public function cleanupHtml($contentBlock, $url)
}

// footnotes
if ('footnotes' === $this->config['content_links'] && false === strpos($url, 'wikipedia.org')) {
if ('footnotes' === $this->config['content_links'] && !str_contains($url, 'wikipedia.org')) {
$this->extractor->readability->addFootnotes($contentBlock);
}

Expand Down Expand Up @@ -343,13 +337,6 @@ private function doFetchContent($url)

$this->logger->debug('HTML after regex empty nodes stripping', ['html' => $html]);

// some non utf8 enconding might be breaking after converting to utf8
// when it happen the string (usually) starts with this character
// in that case, we'll take the default response instead of the utf8 forced one
if (0 === strpos(utf8_encode($response['body']), 'ÿþ')) {
$html = $response['body'];
}

// check site config for single page URL - fetch it if found
$isSinglePage = false;
if ($this->config['singlepage'] && null === $this->prefetchedContent && ($singlePageResponse = $this->getSinglePage($html, $effectiveUrl))) {
Expand Down
Loading

0 comments on commit 3519a1e

Please sign in to comment.