Skip to content

Commit

Permalink
PHP 8.1+ updates (#95)
Browse files Browse the repository at this point in the history
PHP 8.1+ updates
  • Loading branch information
dcarbone authored Apr 15, 2024
1 parent 50fce24 commit 2cb6b31
Show file tree
Hide file tree
Showing 159 changed files with 2,100 additions and 2,183 deletions.
26 changes: 26 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
assignees:
- 'dcarbone'
groups:
github-actions:
applies-to: version-updates
patterns:
- '*'

- package-ecosystem: 'composer'
directory: '/'
schedule:
interval: 'weekly'
assignees:
- 'dcarbone'

groups:
composer:
applies-to: version-updates
patterns:
- '*'
68 changes: 32 additions & 36 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:

pull_request:
branches:
- master
- main
paths:
- '.github/workflows/tests.yaml'
- '**.php'
Expand All @@ -31,75 +31,71 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ["7.4", "8.0", "8.1"]
fhir-version: ["DSTU1", "DSTU2", "STU3", "R4"]
php-version: [ '8.1', '8.2', '8.3' ]
fhir-version: ['DSTU1', 'DSTU2', 'STU3', 'R4']
include:
- php-version: "7.4"
phpunit-version: "9"
paratest-version: "6"
- php-version: "8.0"
phpunit-version: "9"
paratest-version: "6"
- php-version: "8.1"
phpunit-version: "9"
paratest-version: "6"
- php-version: '8.1'
phpunit-version: '10.5'
paratest-version: '7'
- php-version: '8.2'
phpunit-version: '11.1'
paratest-version: '7'
- php-version: '8.3'
phpunit-version: '11.1'
paratest-version: '7'
name: ${{ matrix.fhir-version }} - PHP ${{ matrix.php-version }} - PHPUnit ${{ matrix.phpunit-version }}
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@2.22.0
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: libxml simplexml json zip
# https://github.com/mheap/phpunit-github-actions-printer/blob/master/.github/workflows/ci.yml#L32

- name: Set PHPUnit Version
shell: pwsh
run: |
$content = Get-Content -Path 'composer.json' | ConvertFrom-Json
$content.{require-dev}.{phpunit/phpunit} = "^${{ matrix.phpunit-version }}"
$content | ConvertTo-Json | Set-Content -Path 'composer.json'
- uses: dcarbone/install-jq-action@v2
with:
force: true

- name: Set Paratest Version
shell: pwsh
- name: 'Set Composer Dep Versions'
run: |
$content = Get-Content -Path 'composer.json' | ConvertFrom-Json
$content.{require-dev}.{brianium/paratest} = "^${{ matrix.paratest-version }}"
$content | ConvertTo-Json | Set-Content -Path 'composer.json'
tmpf="$(mktemp)"
jq -rcM '."require-dev"."phpunit/phpunit" = "^${{ matrix.phpunit-version }}" | ."require-dev"."brianium/paratest" = "^${{ matrix.paratest-version }}"' composer.json > "${tmpf}"
mv "${tmpf}" composer.json
- name: Get Composer Cache Directory
- name: 'Get Composer Cache Directory'
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3.0.11
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.phpunit-version }}-${{ hashFiles('**/composer.lock') }}"

- name: Cache downloaded FHIR sources
uses: actions/cache@v2
- name: 'Cache downloaded FHIR sources'
uses: actions/cache@v4
with:
path: ./input
key: "fhir-${{ runner.os }}-${{ matrix.php-version }}-${{ matrix.phpunit-version }}-${{ hashFiles('**/composer.lock') }}"

- name: Install Composer deps
- name: 'Install Composer deps'
run: |
composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Generate code
- name: 'Generate code'
run: |
./bin/generate.sh --useExisting --versions '${{ matrix.fhir-version }}'
- uses: actions/setup-java@v3.6.0
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 18

- name: Install FHIR validator
- name: 'Install FHIR validator'
run: |
wget --quiet https://github.com/hapifhir/org.hl7.fhir.core/releases/download/5.6.75/validator_cli.jar -O ./bin/validator_cli.jar
wget --quiet https://github.com/hapifhir/org.hl7.fhir.core/releases/download/6.3.4/validator_cli.jar -O ./bin/validator_cli.jar
- name: Run tests
- name: 'Run tests'
run: |
./vendor/bin/paratest -c 'phpunit/${{ matrix.fhir-version }}.xml'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ configure and execute the generator.
| PHPFHIR Version | PHP Versions | FHIR Versions |
|-----------------|--------------|----------------------------------|
| v2 | 5.4-7.4 | DSTU1, DSTU2, STU3, R4 (<v4.3.0) |
| v3 | 7.4-8.1 | DSTU1, DSTU2, STU3, R4 |
| v3 | 8.1+ | DSTU1, DSTU2, STU3, R4 |

# Basic Usage

Expand Down Expand Up @@ -127,7 +127,7 @@ $definition = new \DCarbone\PHPFHIR\Definition($version_config);
$definition->buildDefinition();

$builder = new \DCarbone\PHPFHIR\Builder($config, $definition);
$builder->build();
$builder->render();
```

Using the above code will generate class files under the included [output](./output) directory, under the namespace
Expand Down
2 changes: 1 addition & 1 deletion bin/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Generator default configuration file
*
* Copyright 2017 Pim Koeman ([email protected])
* Copyright 2017-2022 Daniel Carbone ([email protected])
* Copyright 2017-2024 Daniel Carbone ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
35 changes: 23 additions & 12 deletions bin/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Download and generation script for all major FHIR versions
*
* Copyright 2017 Pim Koeman ([email protected])
* Copyright 2017-2022 Daniel Carbone ([email protected])
* Copyright 2017-2024 Daniel Carbone ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,16 +21,26 @@

namespace PHPFHIRCLI;

date_default_timezone_set('UTC');

// --- autoload setup
const AUTOLOAD_CLASS_FILEPATH = __DIR__ . '/../vendor/autoload.php';

date_default_timezone_set('UTC');
require __DIR__ . '/../vendor/autoload.php';
// ensure composer autoload class exists.
if (!file_exists(AUTOLOAD_CLASS_FILEPATH)) {
echo sprintf("Unable to locate composer autoload file expected at path: %s\n\n", AUTOLOAD_CLASS_FILEPATH);
echo "Please run \"composer install\" from the root of the project directory\n\n";
exit(1);
}

require AUTOLOAD_CLASS_FILEPATH;

// --- use statements

use DCarbone\PHPFHIR\Builder;
use DCarbone\PHPFHIR\Config;
use DCarbone\PHPFHIR\Definition;
use JetBrains\PhpStorm\NoReturn;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
Expand Down Expand Up @@ -114,15 +124,15 @@ function missing_config_text(bool $return): string
/**
* @param bool $err
*/
function exit_with_help(bool $err = false): void
#[NoReturn] function exit_with_help(bool $err = false): void
{
global $config_location_def;
$env_var = ENV_GENERATE_CONFIG_FILE;
$out = <<<STRING
PHP-FHIR: Tools for creating PHP classes from the HL7 FHIR Specification
Copyright 2016-2022 Daniel Carbone ([email protected])
Copyright 2016-2024 Daniel Carbone ([email protected])
- Links:
Source: https://github.com/dcarbone/php-fhir
Expand Down Expand Up @@ -178,7 +188,7 @@ function ask(string $q): bool
foreach ($ins as $in) {
$resp = stream_get_line($in, 25, "\n");
if (is_string($resp)) {
return substr(strtolower($resp), 0, 1) === 'y';
return str_starts_with(strtolower($resp), 'y');
}
return false;
}
Expand Down Expand Up @@ -210,7 +220,7 @@ function is_dir_empty(string $dir): bool
{
$res = glob($dir, GLOB_NOSORT);
foreach ($res as $r) {
if (0 === strpos($r, '.')) {
if (str_starts_with($r, '.')) {
continue;
}
return false;
Expand All @@ -230,7 +240,7 @@ function is_dir_empty(string $dir): bool
} else {
$next = trim($argv[$i + 1]);
}
if (false !== strpos($arg, '=')) {
if (str_contains($arg, '=')) {
list($arg, $next) = explode('=', $arg, 2);
$found_equal = true;
}
Expand Down Expand Up @@ -326,6 +336,7 @@ function is_dir_empty(string $dir): bool
exit(1);
}

// determine if monolog is present, otherwise use null logger
if (class_exists('\\Monolog\\Logger')) {
$formatter = new LineFormatter(LineFormatter::SIMPLE_FORMAT);
$handler = new StreamHandler('php://stdout', $log_level);
Expand Down Expand Up @@ -436,7 +447,7 @@ function is_dir_empty(string $dir): bool
}

if ($unzip) {
if (class_exists('\\ZipArchive', true)) {
if (class_exists('\\ZipArchive')) {
echo "ext-zip found\n";

$zip = new \ZipArchive();
Expand Down Expand Up @@ -480,11 +491,11 @@ function is_dir_empty(string $dir): bool

$builder = new Builder($build_config, $definition);
if ($only_library) {
$builder->buildFHIRClasses();
$builder->renderFHIRClasses();
} elseif ($only_tests) {
$builder->buildTestClasses();
$builder->renderTestClasses();
} else {
$builder->build();
$builder->render();
}
}

Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"homepage": "https://github.com/dcarbone/php-fhir",
"authors": [
{
"name": "Daniel Paul Carbone",
"email": "[email protected]"
"name": "Daniel Carbone",
"email": "[email protected]",
"homepage": "https://github.com/dcarbone"
}
],
"keywords": [
Expand All @@ -18,19 +19,18 @@
"php-fhir"
],
"require": {
"php": "7.4.* || 8.*",
"php": "^8.1",
"ext-simplexml": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-dom": "*",
"myclabs/php-enum": "^1.8",
"psr/log": "^1.1 || ^3.0"
"psr/log": "^3.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^9.5",
"brianium/paratest": "^v6.4",
"monolog/monolog": "^2.8.0 || ^3.2.0"
"phpunit/phpunit": "^11.0",
"brianium/paratest": "^v7.4",
"monolog/monolog": "^3.2.0"
},
"replace": {
"php-fhir/parser": "*",
Expand Down
Loading

0 comments on commit 2cb6b31

Please sign in to comment.