Skip to content

Commit

Permalink
Merge pull request #1385 from NatLibFi/php81-support
Browse files Browse the repository at this point in the history
Add support for PHP 8.1
  • Loading branch information
osma authored Feb 9, 2023
2 parents b13b2c4 + 417ae45 commit 6c48032
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ["7.3", "7.4", "8.0"]
php_version: ["7.3", "7.4", "8.0", "8.1"]
experimental: [false]
include:
- php_version: "8.1"
- php_version: "8.2"
experimental: true

steps:
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
"components/jquery": "3.6.*",
"components/handlebars.js": "v4.7.7",
"davidstutz/bootstrap-multiselect": "v1.1.1",
"easyrdf/easyrdf": "1.1.*",
"sweetrdf/easyrdf": "1.7.*",
"etdsolutions/waypoints": "4.0.0",
"symfony/polyfill-php80": "1.*",
"symfony/polyfill-php81": "1.*",
"twig/twig": "^2.15.3",
"twig/extensions": "1.5.*",
"twbs/bootstrap": "5.1.*",
Expand All @@ -49,15 +50,15 @@
"ext-intl": "*",
"ext-mbstring": "*",
"ext-xsl": "*",
"monolog/monolog": "1.23.*",
"monolog/monolog": "1.27.*",
"newerton/jquery-mousewheel": "dev-master",
"pamelafox/lscache": "1.0.5"
},
"require-dev": {
"phpunit/phpunit": "9.5.*",
"umpirsky/twig-gettext-extractor": "1.3.*",
"symfony/dom-crawler": "5.4.*",
"mockery/mockery": "1.3.5"
"mockery/mockery": "1.5.1"
},
"autoload": {
"classmap": ["controller/", "model/", "model/sparql/"]
Expand Down
14 changes: 7 additions & 7 deletions controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ protected function negotiateFormat($choices, $accept, $format)

private function isSecure()
{
if ($protocol = filter_input(INPUT_SERVER, 'HTTP_X_FORWARDED_PROTO', FILTER_SANITIZE_STRING)) {
if ($protocol = filter_input(INPUT_SERVER, 'HTTP_X_FORWARDED_PROTO', FILTER_SANITIZE_FULL_SPECIAL_CHARS)) {
return \in_array(strtolower($protocol), ['https', 'on', 'ssl', '1'], true);
}

return filter_input(INPUT_SERVER, 'HTTPS', FILTER_SANITIZE_STRING) !== null;
return filter_input(INPUT_SERVER, 'HTTPS', FILTER_SANITIZE_FULL_SPECIAL_CHARS) !== null;
}

private function guessBaseHref()
{
$script_name = filter_input(INPUT_SERVER, 'SCRIPT_NAME', FILTER_SANITIZE_STRING);
$script_filename = filter_input(INPUT_SERVER, 'SCRIPT_FILENAME', FILTER_SANITIZE_STRING);
$script_name = filter_input(INPUT_SERVER, 'SCRIPT_NAME', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$script_filename = filter_input(INPUT_SERVER, 'SCRIPT_FILENAME', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$script_filename = realpath($script_filename); // resolve any symlinks (see #274)
$script_filename = str_replace("\\", "/", $script_filename); // fixing windows paths with \ (see #309)
$base_dir = __DIR__; // Absolute path to your installation, ex: /var/www/mywebsite
Expand All @@ -109,9 +109,9 @@ private function guessBaseHref()
$base_url = preg_replace("!^{$doc_root}!", '', $base_dir);
$base_url = str_replace('/controller', '/', $base_url);
$protocol = $this->isSecure() ? 'https' : 'http';
$port = filter_input(INPUT_SERVER, 'SERVER_PORT', FILTER_SANITIZE_STRING);
$port = filter_input(INPUT_SERVER, 'SERVER_PORT', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$disp_port = ($port == 80 || $port == 443) ? '' : ":$port";
$domain = filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_STRING);
$domain = filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
return "$protocol://{$domain}{$disp_port}{$base_url}";
}

Expand Down Expand Up @@ -308,7 +308,7 @@ protected function sendNotModifiedHeader($modifiedDate): bool
protected function getIfModifiedSince()
{
$ifModifiedSince = null;
$ifModSinceHeader = filter_input(INPUT_SERVER, 'HTTP_IF_MODIFIED_SINCE', FILTER_SANITIZE_STRING);
$ifModSinceHeader = filter_input(INPUT_SERVER, 'HTTP_IF_MODIFIED_SINCE', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if ($ifModSinceHeader) {
// example value set by a browser: "Mon, 11 May 2020 10:46:57 GMT"
$ifModifiedSince = new DateTime($ifModSinceHeader);
Expand Down
4 changes: 2 additions & 2 deletions controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RestController extends Controller
private function returnJson($data)
{
// wrap with JSONP callback if requested
if (filter_input(INPUT_GET, 'callback', FILTER_SANITIZE_STRING)) {
if (filter_input(INPUT_GET, 'callback', FILTER_SANITIZE_FULL_SPECIAL_CHARS)) {
header("Content-type: application/javascript; charset=utf-8");
echo filter_input(INPUT_GET, 'callback', FILTER_UNSAFE_RAW) . "(" . json_encode($data) . ");";
return;
Expand All @@ -32,7 +32,7 @@ private function returnJson($data)
// otherwise negotiate suitable format for the response and return that
$negotiator = new \Negotiation\Negotiator();
$priorities = array('application/json', 'application/ld+json');
$best = filter_input(INPUT_SERVER, 'HTTP_ACCEPT', FILTER_SANITIZE_STRING) ? $negotiator->getBest(filter_input(INPUT_SERVER, 'HTTP_ACCEPT', FILTER_SANITIZE_STRING), $priorities) : null;
$best = filter_input(INPUT_SERVER, 'HTTP_ACCEPT', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ? $negotiator->getBest(filter_input(INPUT_SERVER, 'HTTP_ACCEPT', FILTER_SANITIZE_FULL_SPECIAL_CHARS), $priorities) : null;
$format = ($best !== null) ? $best->getValue() : $priorities[0];
header("Content-type: $format; charset=utf-8");
header("Vary: Accept"); // inform caches that we made a choice based on Accept header
Expand Down
8 changes: 4 additions & 4 deletions controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public function __construct($model)
public function guessLanguage($vocid = null)
{
// 1. select language based on SKOSMOS_LANGUAGE cookie
if (filter_input(INPUT_COOKIE, 'SKOSMOS_LANGUAGE', FILTER_SANITIZE_STRING)) {
return filter_input(INPUT_COOKIE, 'SKOSMOS_LANGUAGE', FILTER_SANITIZE_STRING);
if (filter_input(INPUT_COOKIE, 'SKOSMOS_LANGUAGE', FILTER_SANITIZE_FULL_SPECIAL_CHARS)) {
return filter_input(INPUT_COOKIE, 'SKOSMOS_LANGUAGE', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}

// 2. if vocabulary given, select based on the default language of the vocabulary
Expand All @@ -101,7 +101,7 @@ public function guessLanguage($vocid = null)
$this->negotiator = new \Negotiation\LanguageNegotiator();
$langcodes = array_keys($this->languages);
// using a random language from the configured UI languages when there is no accept language header set
$acceptLanguage = filter_input(INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE', FILTER_SANITIZE_STRING) ? filter_input(INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE', FILTER_SANITIZE_STRING) : $langcodes[0];
$acceptLanguage = filter_input(INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ? filter_input(INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE', FILTER_SANITIZE_FULL_SPECIAL_CHARS) : $langcodes[0];
$bestLang = $this->negotiator->getBest($acceptLanguage, $langcodes);
if (isset($bestLang) && in_array($bestLang, $langcodes)) {
return $bestLang->getValue();
Expand Down Expand Up @@ -566,7 +566,7 @@ public function invokeGenericErrorPage($request, $message = null)
'request' => $request,
'vocab' => $request->getVocab(),
'message' => $message,
'requested_page' => filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING),
'requested_page' => filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
));
}

Expand Down
4 changes: 2 additions & 2 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ private function getForeignLabelList($prop, $key) {

foreach ($labels as $lit) {
// filtering away subsets of the current language eg. en vs en-GB
if ($lit->getLang() != $this->clang && strpos($lit->getLang(), $this->getEnvLang() . '-') !== 0) {
$langCode = $lit->getLang() ? $lit->getLang() : '';
$langCode = strval($lit->getLang());
if ($langCode != $this->clang && strpos($langCode, $this->getEnvLang() . '-') !== 0) {
$ret[$langCode][$key][] = new ConceptPropertyValueLiteral($this->model, $this->vocab, $this->resource, $lit, $prop);
}
}
Expand Down
6 changes: 3 additions & 3 deletions model/ConceptSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getSearchTerm() : string
$term = $this->request->getQueryParamRaw('q') !== null ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query');
if ((!isset($term) || strlen(trim($term)) === 0) && $this->rest)
$term = $this->request->getQueryParamRaw('label');
$term = trim($term); // surrounding whitespace is not considered significant
$term = trim(strval($term)); // surrounding whitespace is not considered significant
$term = Normalizer::normalize( $term, Normalizer::FORM_C ); //Normalize decomposed unicode characters #1184
if ($this->rest) {
return $term;
Expand All @@ -96,8 +96,8 @@ private function getDefaultTypeLimit()
$type = array('skos:Concept');
if ($this->request->getVocab()) {
$conf = $this->request->getVocab()->getConfig();
$type[] = $conf->getArrayClassURI();
$type[] = $conf->getGroupClassURI();
$type[] = strval($conf->getArrayClassURI());
$type[] = strval($conf->getGroupClassURI());
}
return array_filter($type, 'strlen');
}
Expand Down
6 changes: 3 additions & 3 deletions model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function searchConceptsAndInfo($params)
$params->setUnique(true);
$allhits = $this->searchConcepts($params);
$count = sizeof($allhits);
$hits = array_slice($allhits, $params->getOffset(), $params->getSearchLimit());
$hits = array_slice($allhits, intval($params->getOffset()), $params->getSearchLimit());

$ret = array();
$uris = array();
Expand Down Expand Up @@ -521,8 +521,8 @@ public function guessVocabularyFromURI($uri, $preferredVocabId = null)

// try to guess the URI space and look it up in the cache
$res = new EasyRdf\Resource($uri);
$namespace = substr($uri, 0, -strlen($res->localName()));
if (array_key_exists($namespace, $this->vocabsByUriSpace)) {
$namespace = substr(strval($uri), 0, -strlen(strval($res->localName())));
if ($namespace && array_key_exists($namespace, $this->vocabsByUriSpace)) {
$vocabs = $this->vocabsByUriSpace[$namespace];
return $this->disambiguateVocabulary($vocabs, $uri, $preferredVocabId);
}
Expand Down
10 changes: 5 additions & 5 deletions model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function setServerConstant($paramName, $value)
public function getQueryParam($paramName)
{
if (!isset($this->queryParams[$paramName])) return null;
$val = filter_var($this->queryParams[$paramName], FILTER_SANITIZE_STRING);
$val = filter_var($this->queryParams[$paramName], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
return ($val !== null ? str_replace('\\', '', $val) : null);
}

Expand All @@ -92,7 +92,7 @@ public function getQueryParamRaw($paramName)
public function getQueryParamPOST($paramName)
{
if (!isset($this->queryParamsPOST[$paramName])) return null;
return filter_var($this->queryParamsPOST[$paramName], FILTER_SANITIZE_STRING);
return filter_var($this->queryParamsPOST[$paramName], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}

public function getQueryParamBoolean($paramName, $default)
Expand All @@ -107,7 +107,7 @@ public function getQueryParamBoolean($paramName, $default)
public function getServerConstant($paramName)
{
if (!isset($this->serverConstants[$paramName])) return null;
return filter_var($this->serverConstants[$paramName], FILTER_SANITIZE_STRING);
return filter_var($this->serverConstants[$paramName], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}

public function getLang()
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getRequestUri()
public function getLangUrl($newlang=null)
{
$script_name = str_replace('/index.php', '', $this->getServerConstant('SCRIPT_NAME'));
$langurl = substr(str_replace($script_name, '', $this->getServerConstant('REQUEST_URI')), 1);
$langurl = substr(str_replace($script_name, '', strval($this->getServerConstant('REQUEST_URI'))), 1);
if ($newlang !== null) {
$langurl = preg_replace("#^(.*/)?{$this->lang}/#", "$1{$newlang}/", $langurl);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public function getURI()
public function setURI($uri)
{
if ($uri !== '') {
$this->uri = rtrim($uri);
$this->uri = rtrim(strval($uri));
}

}
Expand Down
4 changes: 2 additions & 2 deletions model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ protected function initializeHttpClient() {
// client, set the same type of cache control headers also in subsequent
// in the SPARQL requests (this is useful for performance testing)
// @codeCoverageIgnoreStart
$cacheControl = filter_input(INPUT_SERVER, 'HTTP_CACHE_CONTROL', FILTER_SANITIZE_STRING);
$pragma = filter_input(INPUT_SERVER, 'HTTP_PRAGMA', FILTER_SANITIZE_STRING);
$cacheControl = filter_input(INPUT_SERVER, 'HTTP_CACHE_CONTROL', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$pragma = filter_input(INPUT_SERVER, 'HTTP_PRAGMA', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if ($cacheControl !== null || $pragma !== null) {
$val = $pragma !== null ? $pragma : $cacheControl;
$httpclient->setHeaders('Cache-Control', $val);
Expand Down
2 changes: 1 addition & 1 deletion tests/PluginRegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function setUp() : void
'global-plugin-charlie',
'test-plugin3'
)))
->setMethods(['getPlugins'])
->onlyMethods(['getPlugins'])
->getMock();
$this->stubplugs = array ('imaginary-plugin' => array ( 'js' => array ( 0 => 'imaginaryPlugin.js', ),
'css' => array ( 0 => 'stylesheet.css', ),
Expand Down
4 changes: 2 additions & 2 deletions tests/VocabularyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function testSearchConceptsAlphabeticalEverything() {
public function testGetBreadCrumbs() {
$model = new Model(new GlobalConfig('/../tests/testconfig.ttl'));
$resource = $this->getMockBuilder('EasyRdf\Resource')->disableOriginalConstructor()->getMock();
$vocabstub = $this->getMockBuilder('Vocabulary')->setMethods(array('getConceptTransitiveBroaders'))->setConstructorArgs(array($model, $resource))->getMock();
$vocabstub = $this->getMockBuilder('Vocabulary')->onlyMethods(array('getConceptTransitiveBroaders'))->setConstructorArgs(array($model, $resource))->getMock();
$vocabstub->method('getConceptTransitiveBroaders')->willReturn(array ( 'http://www.yso.fi/onto/yso/p4762' => array ( 'label' => 'objects', ), 'http://www.yso.fi/onto/yso/p1674' => array ( 'label' => 'physical whole', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p4762', ), ), 'http://www.yso.fi/onto/yso/p14606' => array ( 'label' => 'layers', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p1674', ), ), ));
$result = $vocabstub->getBreadCrumbs('en', 'http://www.yso.fi/onto/yso/p14606');
foreach($result['breadcrumbs'][0] as $crumb)
Expand All @@ -404,7 +404,7 @@ public function testGetBreadCrumbs() {
public function testGetBreadCrumbsShortening() {
$model = new Model(new GlobalConfig('/../tests/testconfig.ttl'));
$resource = $this->getMockBuilder('EasyRdf\Resource')->disableOriginalConstructor()->getMock();
$vocabstub = $this->getMockBuilder('Vocabulary')->setMethods(array('getConceptTransitiveBroaders'))->setConstructorArgs(array($model, $resource))->getMock();
$vocabstub = $this->getMockBuilder('Vocabulary')->onlyMethods(array('getConceptTransitiveBroaders'))->setConstructorArgs(array($model, $resource))->getMock();
$vocabstub->method('getConceptTransitiveBroaders')->willReturn(array ( 'http://www.yso.fi/onto/yso/p4762' => array ( 'label' => 'objects', ), 'http://www.yso.fi/onto/yso/p13871' => array ( 'label' => 'thai language', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p10834', ), ), 'http://www.yso.fi/onto/yso/p556' => array ( 'label' => 'languages', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p2881', ), ), 'http://www.yso.fi/onto/yso/p8965' => array ( 'label' => 'Sino-Tibetan languages', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p556', ), ), 'http://www.yso.fi/onto/yso/p3358' => array ( 'label' => 'systems', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p4762', ), ), 'http://www.yso.fi/onto/yso/p10834' => array ( 'label' => 'Tai languages', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p8965', ), ), 'http://www.yso.fi/onto/yso/p2881' => array ( 'label' => 'cultural systems', 'direct' => array ( 0 => 'http://www.yso.fi/onto/yso/p3358', ), ), ) );
$result = $vocabstub->getBreadCrumbs('en', 'http://www.yso.fi/onto/yso/p13871');
$this->assertEquals(6, sizeof($result['breadcrumbs'][0]));
Expand Down

0 comments on commit 6c48032

Please sign in to comment.