Skip to content

Commit

Permalink
Feature/php8 (#9)
Browse files Browse the repository at this point in the history
* Add 8.1 to composer & php workflow

* Add branch to php workflow

* Test PHP8.1 updates

* Remove 7.4 support from test

* Remove old checkout action

* Fix PHP8.1 issues

* Add 8.2, 8.3

* Code quality fixes

* PHPStan fixes

* Use native union types

* Docs reorganisation

* Move phplint to GitHub action

* Make data providers public static

* PHPStan 4 fixes

* feat!: Require Symfony 6 / PHP 8.1

* Test in Symfony 6 & 7

* Fix to php -v

* Testing lock GitHub action to Symfony 6/7

* Exclude PHP 8.1 & Symfony 7

* test
  • Loading branch information
simonrjones authored Jun 24, 2024
1 parent f9d9680 commit 7a57343
Show file tree
Hide file tree
Showing 91 changed files with 696 additions and 1,290 deletions.
29 changes: 22 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@ jobs:

strategy:
matrix:
php-versions: ['7.4']
php: ['8.1', '8.2', '8.3']
symfony: ['6.4', '7.1']
exclude:
- php: '8.1'
symfony: '7.1'

runs-on: ubuntu-latest

name: On PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}

steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

# https://github.com/marketplace/actions/setup-php-action
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180

- uses: actions/checkout@v2

- name: Check PHP version
run: php -v

Expand All @@ -41,8 +46,18 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Code lint PHP files
run: ./vendor/bin/phplint
- name: Install Symfony ${{ matrix.symfony }} packages
run: |
composer update symfony/http-client:${{ matrix.symfony }}
composer update symfony/cache:${{ matrix.symfony }}
composer update symfony/stopwatch:${{ matrix.symfony }}
composer update symfony/property-access:${{ matrix.symfony }}
- name: Lint PHP files
run: |
curl -Ls https://github.com/overtrue/phplint/releases/latest/download/phplint.phar -o /usr/local/bin/phplint
chmod +x /usr/local/bin/phplint
/usr/local/bin/phplint --no-cache --no-progress -v
- name: Coding standards
run: ./vendor/bin/phpcs
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: release-please

on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
# Uses https://github.com/marketplace/actions/release-please-action
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
release-type: php
package-name: strata/data
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.0] - 2021-TBC
## [0.9.0] - TBC

### Changed
- Minimum requirements PHP 8.1

## [0.8.0] - 2023-02-10

### Added
- Refactored [Frontend](https://github.com/strata/frontend) data layer into its own repo
- Flexible data access layer for accessing data, transforming, and mapping from HTTP APIs
- Added support for GraphQL, Rest and HTTP data providers
- Added query manager and query objects to help sending data requests and structure returned data
-
35 changes: 15 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
# Data

The purpose of this package is to help read data from APIs and other external sources.
A simple way to manage data retrieval from APIs and other sources. This package is built using Symfony components and can
be used with any PHP application, Symfony, Laravel or plain PHP.

Features:
You can:

* Download data via HTTP APIs
* Throw exceptions on failed requests
* Supports REST and GraphQL
* Decode data from a variety of formats (e.g. JSON, Markdown)
* Automated debug information (logging and time profiling)
* Read data from REST and GraphQL APIs
* Authenticate with APIs
* Handle errors consistently
* Cache requests to increase performance
* Tools to help detect whether data has changed since last request
* Transform data (e.g. convert source category to match local category name)
* Decode data from a variety of formats (e.g. JSON, Markdown)
* Transform data (e.g. map a category name)
* Work out if data has changed since the last request

Planned for the future:
See the [documentation](docs/README.md) for more.

* Validate data items to see whether they contain required data properties
* Efficient bulk API queries via concurrent requests
* Download data via local, FTP, S3 filesystem (via Flysystem)
You can use this with the [frontend](https://github.com/strata/frontend) package to help you build a frontend website.

## Status
Please note this software is in development, usage may change before the 1.0 release.

## Requirements

* PHP 7.4+
* PHP 8.1+
* [Composer](https://getcomposer.org/)

## Installation

Install via Composer:

```
composer require strata/data:^0.8
composer require strata/data:^0.9
```

## Documentation

See [docs](docs/README.md) - these are currently being cleaned up and we plan to publish better docs for v0.10.

## Thanks to

https://developer.happyr.com/http-client-and-caching
* [Symfony](https://symfony.com/)
* https://developer.happyr.com/http-client-and-caching
61 changes: 28 additions & 33 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
"authors": [
{
"name": "Simon Jones",
"email": "[email protected]",
"homepage": "https://studio24.net/",
"role": "Developer"
"email": "[email protected]"
}
],
"require": {
"php": "^7.4|^8.0",
"ext-json": "*",
"symfony/http-client": "^5.4|^6.0",
"php": "^8.1",
"erusev/parsedown-extra": "^0.8",
"laminas/laminas-feed": "^2.22",
"league/commonmark": "^2.4",
"spatie/yaml-front-matter": "^2.0",
"erusev/parsedown-extra": "^0.8.1",
"symfony/cache": "^5.4|^6.0",
"symfony/stopwatch": "^5.4|^6.0",
"symfony/monolog-bundle": "^3.7",
"symfony/property-access": "^5.4|^6.0",
"laminas/laminas-feed": "^2.16",
"league/commonmark": "^2.2"
"symfony/http-client": "^6.4|^7.1",
"symfony/cache": "^6.4|^7.1",
"symfony/stopwatch": "^6.4|^7.1",
"symfony/property-access": "^6.4|^7.1",
"symfony/monolog-bundle": "^3.7"
},
"autoload": {
"psr-4": {
Expand All @@ -31,39 +28,37 @@
"exclude-from-classmap": ["/tests/"]
},
"require-dev": {
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.0",
"overtrue/phplint": "^3.0",
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.10",
"phpstan/phpstan": "^1.11",
"roave/security-advisories": "dev-latest"
},
"scripts": {
"lint": [
"./vendor/bin/phplint"
],
"cs": [
"phpcs": [
"./vendor/bin/phpcs"
],
"fix": [
"phpcbf": [
"./vendor/bin/phpcbf"
],
"unit": [
"phpunit": [
"./vendor/bin/phpunit"
],
"phpstan": [
"./vendor/bin/phpstan analyse --memory-limit 512M"
],
"test": [
"composer lint",
"composer cs",
"composer unit"
"composer phpcs",
"composer phpunit"
]
},
"scripts-descriptions": {
"lint": "Lint PHP files",
"cs": "Test coding standards are met in PHP code",
"fix": "Fix PHP code so it meets coding standards",
"unit": "Run PHPUnit tests",
"test": "Run all tests (phplint, phpcs, phpunit)"
},
"config": {
"allow-plugins": false
},

"extra": {
"symfony": {
"allow-contrib": false,
"require": "7.2.*"
}
}
}
46 changes: 44 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
# Introduction

_Please note: documentation is in progress._
A simple way to manage data retrieval from APIs and other sources. This package is built using Symfony components and can
be used with any PHP application, Symfony, Laravel or plain PHP.

You can use this with the [frontend](https://github.com/strata/frontend) package to help you build a frontend website.

You can:

* Read data from REST and GraphQL APIs
* Authenticate with APIs
* Handle errors consistently
* Cache requests to increase performance
* Decode data from a variety of formats (e.g. JSON, Markdown)
* Transform data (e.g. map a category name)
* Work out if data has changed since the last request

## Changelog

All notable changes to strata/data are documented on [GitHub](https://github.com/strata/data/blob/main/CHANGELOG.md).

## Retrieving data

Strata Data has a lightweight architecture.

Data is retrieved via a **[Data provider](retrieving-data/data-providers.md)** . This could be a REST API, GraphQL API, or other source.
Data providers wrap up data reading functionality along with support for **[caching](advanced-usage/caching.md)**, decoding raw data, error handling and helpers to make development easier.

You use **[queries](retrieving-data/query.md)** to make running a data request easier.
A **[query manager](retrieving-data/query-manager.md)** can be used to manage multiple queries.

Single data is returned as either an object or array.

A collection of data is returned as a collection object, containing either objects or arrays.

## Changing data

Returned data can be modified via **[transformers](changing-data/transformers.md)** or **[mappers](changing-data/mapping.md)**. Transformers change data, while mappers map data to an object or array.

**[Pagination](changing-data/mapping#setting-pagination)** can be automated when you return a collection of results.

## Advanced usage

You can [validate data](advanced-usage/validating.md) to check it is valid. This is useful if you need to check data before you use it (e.g. a data import).

[Data history](data-history.md) can be used to help determine if retrieved data has changed since last access.

Read and write data from external data providers in a standardised format.
18 changes: 9 additions & 9 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# Table of contents

* [Introduction](README.md)
* [Principles](principles.md)

## Usage

* [Installation](usage/installation.md)
* [Making a request](usage/making-requests.md)
* [Caching](usage/caching.md)
* [Validation](usage/validating.md)
* [Getting started](getting-started.md)
* [About](about.md)

## Retrieving data

* [Intro](retrieving-data/README.md)
* [Introduction](retrieving-data/README.md)
* [Making a request](retrieving-data/making-requests.md)
* [Property paths](retrieving-data/property-paths.md)
* [Data providers](retrieving-data/data-providers.md)
* [HTTP data provider](retrieving-data/http.md)
* [GraphQL data provider](retrieving-data/graphql.md)
* [Queries](retrieving-data/query.md)
* [GraphQL queries](retrieving-data/graphql.md)
* [Query Manager](retrieving-data/query-manager.md)
* [Custom query classes](retrieving-data/custom-query-classes.md)
* [Bulk queries](retrieving-data/bulk-queries.md)

## Changing data

* [Introduction](changing-data/README.md)
* [Transforming and mapping data](changing-data/changing-data.md)
* [Accessing properties](changing-data/property-paths.md)
* [Transforming data](changing-data/transformers.md)
Expand All @@ -31,6 +29,8 @@

## Advanced usage

* [Validation](advanced-usage/validating.md)
* [Caching](advanced-usage/caching.md)
* [Data History](advanced-usage/data-history.md)
* [Events](advanced-usage/events.md)
* [Testing API requests](advanced-usage/testing-api-requests.md)
Expand Down
6 changes: 6 additions & 0 deletions docs/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# About

Strata is developed by [Studio 24](https://www.studio24.net/), a digital design and development agency
based in Cambridge, UK, focussed on building accessible, sustainable websites and web apps that work for everyone.

You can [get in touch](https://www.studio24.net/contact/) about how we can help on your PHP web application project.
2 changes: 1 addition & 1 deletion docs/caching.md → docs/advanced-usage/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ On data providers:

### Query Manager caching

The [query manager](retrieving-data/query-manager.md) uses similar techniques to control caching:
The [query manager](../retrieving-data/query-manager.md) uses similar techniques to control caching:

On the query manager:

Expand Down
6 changes: 3 additions & 3 deletions docs/advanced-usage/testing-api-requests.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Testing API requests

When testing HTTP requests you need to create mock responses based on what would actually be returned from a real HTTP request. Symfony's HTTPClient has support for [testing HTTP requests](https://symfony.com/doc/current/components/http_client.html#testing-http-clients-and-responses).
When testing HTTP requests you need to create mock responses based on what would actually be returned from a real HTTP request. Symfony's HTTPClient has support for [testing HTTP requests](https://symfony.com/doc/current/http_client.html#http-client-and-responses).

You can also use `MockResponseFromFile` to generate a mock response easily from a file.
You can also use the`MockResponseFromFile` class to generate a mock response easily from a file.

## MockResponseFromFile

Expand All @@ -16,7 +16,7 @@ Allows you to load a mock request from file.

Body file is loaded from `{$filename}`

The optional info file is loaded from `{$filename}.info.php` and must contain the `$info` variable \(array\). By default mock responses return a 200 status code which you can change by setting the `$info` array.
The optional info file is loaded from `{$filename}.info.php` and must contain the `$info` variable (array). By default mock responses return a 200 status code which you can change by setting the `$info` array.

### Usage

Expand Down
2 changes: 1 addition & 1 deletion docs/validating.md → docs/advanced-usage/validating.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A simple validation rules system exists, inspired by [Laravel's Validation](http

Simply create a new instance of `Strata\Data\Validate\ValidationRules` and pass in the validation requirements in the
constructor. This is an array made up of the property path to the field you want to validate and the validation rule.
See [how to write property paths](property-paths.md).
See [how to write property paths](../retrieving-data/property-paths.md).

The rules format is:

Expand Down
2 changes: 1 addition & 1 deletion docs/changing-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Example use cases are:
* Map a single item to an object (and optionally type set item fields, e.g. to an DateTime object)
* Map a collection of items to a set of objects

We use Symfony's PropertyAccess component to help read and write data. See [how to write property paths](../property-paths.md)
We use Symfony's PropertyAccess component to help read and write data. See [how to write property paths](../retrieving-data/property-paths.md)
for more details.
Loading

0 comments on commit 7a57343

Please sign in to comment.