-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ListModifiedProperties() result will be sorted - fromArray() will only mark data keys as modified
- Loading branch information
1 parent
6ae9dd9
commit 368ac12
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Popo/Plugin/ClassPlugin/ModifiedToArrayClassPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Popo\Plugin\ClassPlugin; | ||
|
||
use Popo\Plugin\BuilderPluginInterface; | ||
use Popo\Plugin\ClassPluginInterface; | ||
|
||
class ModifiedToArrayClassPlugin implements ClassPluginInterface | ||
{ | ||
public function run(BuilderPluginInterface $builder): void | ||
{ | ||
$body = <<<EOF | ||
\$data = \$this->toArray(); | ||
\$modifiedProperties = \$this->listModifiedProperties(); | ||
return \array_filter(\$data, function (\$key) use (\$modifiedProperties) { | ||
return \in_array(\$key, \$modifiedProperties); | ||
}, \ARRAY_FILTER_USE_KEY); | ||
EOF; | ||
|
||
$builder->getClass() | ||
->addMethod('modifiedToArray') | ||
->setPublic() | ||
->setReturnType('array') | ||
->setBody($body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters