[core] Backported str_starts_with, str_ends_with and str_contains from php 8 (#2318)

This commit is contained in:
Eugene Molotov 2021-10-30 01:06:04 +05:00 committed by GitHub
parent 9254d14f50
commit b86ed70376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 10 deletions

View File

@ -47,15 +47,6 @@ class NordbayernBridge extends BridgeAbstract {
) )
)); ));
private function startsWith($string, $startString) {
$len = strlen($startString);
return (substr($string, 0, $len) === $startString);
}
private function contains($haystack, $needle) {
return (strpos($haystack, $needle) !== false);
}
private function getUseFullContent($rawContent) { private function getUseFullContent($rawContent) {
$content = ''; $content = '';
foreach($rawContent->children as $element) { foreach($rawContent->children as $element) {
@ -109,7 +100,7 @@ class NordbayernBridge extends BridgeAbstract {
// exclude police reports if descired // exclude police reports if descired
if($this->getInput('policeReports') || if($this->getInput('policeReports') ||
!self::contains($item['content'], 'Hier geht es zu allen aktuellen Polizeimeldungen.')) { !str_contains($item['content'], 'Hier geht es zu allen aktuellen Polizeimeldungen.')) {
$this->items[] = $item; $this->items[] = $item;
} }

32
lib/php8backports.php Normal file
View File

@ -0,0 +1,32 @@
<?php
/**
* This file is part of RSS-Bridge, a PHP project capable of generating RSS and
* Atom feeds for websites that don't have one.
*
* For the full license information, please view the UNLICENSE file distributed
* with this source code.
*
* @package Core
* @license http://unlicense.org/ UNLICENSE
* @link https://github.com/rss-bridge/rss-bridge
*/
// based on https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Str.php
if (!function_exists('str_starts_with')) {
function str_starts_with($haystack, $needle) {
return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0;
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with($haystack, $needle) {
return $needle !== '' && substr($haystack, -strlen($needle)) === (string)$needle;
}
}
if (!function_exists('str_contains')) {
function str_contains($haystack, $needle) {
return $needle !== '' && mb_strpos($haystack, $needle) !== false;
}
}

View File

@ -80,6 +80,7 @@ require_once PATH_LIB . 'XPathAbstract.php';
require_once PATH_LIB . 'html.php'; require_once PATH_LIB . 'html.php';
require_once PATH_LIB . 'error.php'; require_once PATH_LIB . 'error.php';
require_once PATH_LIB . 'contents.php'; require_once PATH_LIB . 'contents.php';
require_once PATH_LIB . 'php8backports.php';
// Vendor // Vendor
define('MAX_FILE_SIZE', 10000000); /* Allow larger files for simple_html_dom */ define('MAX_FILE_SIZE', 10000000); /* Allow larger files for simple_html_dom */