Skip to content

Commit

Permalink
Merge pull request #60 from CakeDC/feature/59
Browse files Browse the repository at this point in the history
Feature/59
  • Loading branch information
arusinowski authored Apr 26, 2024
2 parents 84e3ca9 + 5b30845 commit 7e8ac1a
Show file tree
Hide file tree
Showing 29 changed files with 123 additions and 89 deletions.
39 changes: 35 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
/composer.lock
/plugins
/composer.phar
/phpunit.xml
/.phpunit.result.cache
/phpunit.phar
/config/Migrations/schema-dump-default.lock
/vendor/
/.idea/
*.diff
*.err
*.log
*.orig
*.rej
*.swo
*.swp
*.vi
*~
/.ddev/
.idea/*
nbproject/*
.vscode
.DS_Store
.cache
.project
.settings
.svn
errors.err
tags
node_modules
package-lock.json
/nbproject/
/vendor
/webroot/css/style.css.map
/webroot/mix.js.map
/webroot/mix-manifest.json
/tools/
/.phpunit.cache/
/auth.json
/.ddev
/.idea
/.phpunit.result.cache
4 changes: 2 additions & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.32" installed="1.10.32" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.15.0" installed="5.15.0" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.23.1" installed="5.23.1" location="./tools/psalm" copy="false"/>
</phive>
6 changes: 0 additions & 6 deletions .semver

This file was deleted.

10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Changelog
=========

* 3.0.0-dev CakePHP 5.x support
* 3.1.0
* fixed issue with $constant beeing of type /Cake/ORM/Entity
* fixed issue with missing support for non hydrated results in src/Model/Behavior/Strategy/ConstStrategy.php

* 2.0.0 CakePHP 4.x support
* 3.0.0
* CakePHP 5.x support

* 2.0.0
* CakePHP 4.x support

* 1.2.0
* Documentation improved
Expand Down
2 changes: 1 addition & 1 deletion Docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Home
Requirements
------------

* CakePHP 5.0+
* CakePHP 5.0.6+
* PHP 8.1+

Documentation
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ Enumeration list for [CakePHP 5](http://cakephp.org).
Versions and branches
---------------------

| CakePHP | CakeDC Enum Plugin | Tag | Notes |
|:----------|:-------------------------------------------------------|:------|:---------|
| ^5.0.0 | [3.next](https://github.com/cakedc/enum/tree/3next) | 3.0.0 | unstable |
| ^4.0 | [2.next](https://github.com/cakedc/enum/tree/2.next) | 2.0.4 | stable |
| ^3.7 | [master](https://github.com/cakedc/enum/tree/master) | 1.5.0 | stable |
| ^3.7 | [develop](https://github.com/cakedc/enum/tree/develop) | - | unstable |
| ^3.6 | [master](https://github.com/cakedc/enum/tree/1.4.0) | 1.4.0 | stable |
| 3.1 - 3.5 | | 1.3.0 | stable |

| CakePHP | CakeDC Enum Plugin | Tag | Notes |
|:--------|:-----------------------------------------------------------|:------|:-------|
| ^5.0.6 | [3.next](https://github.com/cakedc/enum/tree/3.next-cake5) | 3.1.0 | stable |
| ^4.0 | [2.next](https://github.com/cakedc/enum/tree/2.next) | 2.0.4 | stable |

Install
-------
Expand All @@ -45,7 +40,7 @@ $this->addPlugin('CakeDC/Enum');
Requirements
------------

* CakePHP 5.0+
* CakePHP 5.0.6+
* PHP 8.1+

Documentation
Expand All @@ -68,6 +63,6 @@ This repository follows the [CakeDC Plugin Standard](http://cakedc.com/plugin-st
License
-------

Copyright 2015 - 2023 Cake Development Corporation (CakeDC). All rights reserved.
Copyright 2015 - 2024 Cake Development Corporation (CakeDC). All rights reserved.

Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

31 changes: 14 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,23 @@
}
},
"scripts": {
"analyse": [
"@stan",
"@psalm"
],
"check": [
"@cs-check",
"@test",
"@analyse"
"@test"
],
"cs-check": "phpcs --colors --parallel=16 -p src/ tests/",
"cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/",
"phpstan": "tools/phpstan analyse",
"psalm": "tools/psalm --show-info=false",
"stan": [
"@phpstan",
"@psalm"
],
"cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"test": "phpunit --stderr",
"stan": "phpstan analyse src/",
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.2 && mv composer.backup composer.json",
"stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon",
"psalm-rebuild-baseline": "php vendor/psalm/phar/psalm.phar --show-info=false --set-baseline=psalm-baseline.xml src/",
"rector": "rector process",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.11.2 && mv composer.backup composer.json",
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml"
"stan-tests": "phpstan.phar analyze -c tests/phpstan.neon",
"stan-baseline": "phpstan.phar --generate-baseline",
"stan-setup": "phive install",
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover=clover.xml"
},
"config": {
"allow-plugins": {
Expand Down
4 changes: 2 additions & 2 deletions config/Migrations/001_create_enum_lookups.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<ruleset name="Throttle">
<ruleset name="cakedc/enum">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />
Expand Down
4 changes: 2 additions & 2 deletions src/EnumPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/EnumBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/Exception/InvalidAliasListException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/Exception/MissingEnumStrategyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/Strategy/AbstractStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/Strategy/ConfigStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
24 changes: 18 additions & 6 deletions src/Model/Behavior/Strategy/ConstStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down Expand Up @@ -124,10 +124,14 @@ public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObjec
$query->clearContain()->contain($contain);

$query->formatResults(fn (CollectionInterface $results) => $results
->map(function (EntityInterface $row): EntityInterface {
->map(function (mixed $row): mixed {
if (is_string($row) || !$row) {
return $row;
}

$constant = Hash::get($row, $this->getConfig('field'));

if ($constant instanceof Entity) {
if ($constant instanceof EntityInterface) {
return $row;
}

Expand All @@ -138,8 +142,16 @@ public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObjec
'value' => $constant,
], ['markClean' => true, 'markNew' => false]);

$row->set($field, $value);
$row->setDirty($field, false);
if (is_array($row)) {
$row[$field] = $value->toArray();

return $row;
}

if ($row instanceof EntityInterface) {
$row->set($field, $value);
$row->setDirty($field, false);
}

return $row;
}));
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/Strategy/LookupStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/Strategy/StrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
declare(strict_types=1);

/**
* Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2015 - 2023, Cake Development Corporation (http://cakedc.com)
* @copyright Copyright 2015 - 2024, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

Expand Down
Loading

0 comments on commit 7e8ac1a

Please sign in to comment.