Skip to content

Commit

Permalink
feature #165 V2: Rewrite with PHP 8.1 enums (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

V2: Rewrite with PHP 8.1 enums

WIP POC to observe what could be relevant to keep from this lib and its integrations while moving to PHP 8.1 native enums…

Relates to #124

---

#### random thoughts

- [x] [WeakMap/SplObjStorage](https://wiki.php.net/rfc/enumerations#splobjectstorage_and_weakmaps) for readables?
- [x] For now, no requirements for a FlaggedEnumInterface, no specific methods. But it requires an int backed enum. Drop the interface and replace by backed type reflection checks?

#### notes

- Enum may not include __toString (from PHP)
- Cannot implement FlaggedEnum as before, since we can only define cases for each bit, but cannot hold a $value and have a FlaggedEnum instance with multiple bits. Instead, we might need a FlagBag. Will impact forms, dbal types, js generation, …
- readables for Flagged enum combination might be difficult to write using the same interfaces. Dedicated system for a FlagBag?
- FlagBag controller arg resolver?

Commits
-------

e21a5bf Update CI branches
8019e3d Update cs-fixer
5135227 Remove FlagEnumInterface & add docs
2d1c212 Complete README.md
7e1d3e4 Add Symfony Bundle & configuration for generating BDAL types
e4905fb Basic doctrine dbal types dumper
2117f82 Basic Doctrine types
7db6f59 Clean the deps & CI
69f3a71 Add Symfony Form type with readable enums supports
ae2bcc6 Use enum cases as keys in readables
b7fa48b Base readable implem uses annotations
1633fae V2: Rewrite with PHP 8.1 enums
  • Loading branch information
ogizanagi committed Dec 14, 2021
2 parents b0bab15 + e21a5bf commit e841eb6
Show file tree
Hide file tree
Showing 171 changed files with 1,601 additions and 10,518 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ indent_size = 2

[*.md]
trim_trailing_whitespace = false
max_line_length = 120
62 changes: 12 additions & 50 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch: ~
push:
branches:
- 1.x
- 2.x
pull_request: ~

jobs:
Expand Down Expand Up @@ -39,48 +39,30 @@ jobs:
fail-fast: false
matrix:
include:
# Previous Symfony versions & lowest deps
- name: 'Test lowest deps [Linux, PHP 7.3]'
# Lowest deps
- name: 'Test lowest deps [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '7.3'
php: '8.1'
composer-flags: '--prefer-lowest'
mongodb: true
allow-unstable: true

# Previous Symfony versions
- name: 'Test Symfony 5.3 [Linux, PHP 8.0]'
os: 'ubuntu-latest'
php: '8.0'
symfony: '5.3.*'
#

# Previous PHP versions
- name: 'Test Symfony 5.4 [Linux, PHP 7.3]'
os: 'ubuntu-latest'
php: '7.3'
symfony: '5.4.*@dev'
allow-unstable: true

- name: 'Test Symfony 5.4 [Linux, PHP 7.4] (with code coverage)'
os: 'ubuntu-latest'
php: '7.4'
mongodb: true
symfony: '5.4.*@dev'
allow-unstable: true
code-coverage: true
#

# Most recent versions
- name: 'Test Symfony 5.4 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '5.4.*@dev'
# For now: Could not install mongodb on PHP 8.1.0-dev
#mongodb: true
allow-unstable: true

- name: 'Test Symfony 5.4 [Windows, PHP 8.0]'
- name: 'Test Symfony 5.4 [Windows, PHP 8.1]'
os: 'windows-latest'
php: '8.0'
php: '8.1'
symfony: '5.4.*@dev'
mongodb: true
allow-unstable: true

- name: 'Test Symfony 6.0 [Linux, PHP 8.1]'
Expand All @@ -90,13 +72,11 @@ jobs:
allow-unstable: true

# Bleeding edge (unreleased dev versions where failures are allowed)
- name: 'Test next Symfony [Linux, PHP 8.2] (allowed failure)'
- name: 'Test next Symfony [Linux, PHP 8.1] (allowed failure)'
os: 'ubuntu-latest'
php: '8.2'
php: '8.1'
symfony: '6.1.*@dev'
composer-flags: '--ignore-platform-req php'
# For now: Could not install mongodb on PHP 8.1.0-dev
#mongodb: true
allow-unstable: true
allow-failure: true

Expand All @@ -113,20 +93,10 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo_sqlite
coverage: pcov
extensions: pdo_sqlite ${{ matrix.mongodb && ', mongodb' }}
tools: 'composer:v2,flex'

- name: 'Start MongoDB (Linux)'
uses: supercharge/[email protected]
if: ${{ matrix.mongodb && matrix.os == 'ubuntu-latest' }}

- name: 'Start MongoDB (Windows)'
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install mongodb
if: ${{ matrix.mongodb && matrix.os == 'windows-latest' }}

- name: 'Get composer cache directory'
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand All @@ -142,14 +112,6 @@ jobs:
run: composer config minimum-stability dev
if: ${{ matrix.allow-unstable }}

- name: 'Remove packages not allowing Symfony 6 yet'
run: composer remove --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "nelmio/alice" "api-platform/core"
if: ${{ matrix.symfony == '6.0.*@dev' }}

- name: 'Require Doctrine MongoDB dependencies'
run: composer require --no-update ${{ matrix.composer-flags }} --dev --no-interaction --ansi "doctrine/mongodb-odm:^2.2" "doctrine/mongodb-odm-bundle:^4.3"
if: ${{ matrix.mongodb }}

- name: 'Install dependencies'
run: composer update --prefer-dist ${{ matrix.composer-flags }} --ansi
env:
Expand Down
7 changes: 2 additions & 5 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('tests/Fixtures/Integration/Symfony/var')
->exclude('tests/Fixtures/Bridge/Doctrine/DBAL/Types/TypesDumperTest')
->exclude('tests/Fixtures/Bridge/Doctrine/ODM/Types/TypesDumperTest')
// Excluded until php-cs-fixer supports PHP 8 attributes:
->notPath('src/Bridge/Symfony/Validator/Constraint/Enum.php')
->notPath('tests/Fixtures/Bridge/Symfony/Validator/Constraint/ObjectWithEnumChoiceAsPhpAttribute.php')
->exclude('tests/Unit/Bridge/Doctrine/DBAL/Types/TypesDumperTest')
;

return (new PhpCsFixer\Config())
Expand All @@ -26,6 +22,7 @@
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'header_comment' => ['header' => $header],
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'no_unneeded_final_method' => false, // final private __construct is a valid use-case
Expand Down
20 changes: 3 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PHP_CS_FIXER_VERSION=v3.3.2
PHP_CS_FIXER_VERSION=v3.4.0

###########
# Install #
Expand All @@ -14,7 +14,7 @@ install:
composer update --prefer-dist

install-lowest: setup
install-lowest: export SYMFONY_REQUIRE = 4.4.*
install-lowest: export SYMFONY_REQUIRE = 5.4.*@dev
install-lowest:
composer config minimum-stability --unset
composer update --prefer-lowest
Expand All @@ -27,30 +27,16 @@ install-54:

install-60: setup
install-60: export SYMFONY_REQUIRE = 6.0.*@dev
install-60: remove-60unready-deps
install-60:
composer config minimum-stability dev
composer update

install-61: setup
install-61: export SYMFONY_REQUIRE = 6.1.*@dev
install-61: remove-60unready-deps
install-61:
composer config minimum-stability dev
composer update

remove-60unready-deps:
# Tmp remove packages not allowing Symfony 6 yet
composer remove --no-update --no-interaction --dev "nelmio/alice" "api-platform/core"

add-odm:
composer require --no-update --no-interaction --dev "doctrine/mongodb-odm:^2.2" "doctrine/mongodb-odm-bundle:^4.3"
@echo "Run again appropriate install target to update dependencies"

remove-odm:
composer remove --no-update --no-interaction --dev "doctrine/mongodb-odm" "doctrine/mongodb-odm-bundle"
@echo "Run again appropriate install target to update dependencies"

########
# Test #
########
Expand Down Expand Up @@ -81,4 +67,4 @@ fix-php-cs-fixer:

lint-php-cs-fixer: php-cs-fixer.phar
lint-php-cs-fixer:
./php-cs-fixer.phar fix --no-interaction --dry-run --diff
./php-cs-fixer.phar fix --no-interaction --dry-run --diff -vvv
Loading

0 comments on commit e841eb6

Please sign in to comment.