ock / adaptism
Library to map adapter classes.
dev-main
2024-12-08 17:52 UTC
Requires
- php: >=8.3
- ock/class-discovery: dev-main
- ock/dependency-injection: dev-main
- ock/egg: dev-main
- ock/helpers: dev-main
- psr/container: ^2.0
- symfony/dependency-injection: ^7.1.5
Requires (Dev)
- ock/testing: dev-main
- phpstan/phpstan: 2.0.x-dev
- phpunit/phpunit: ^10.5.38
- symfony/yaml: ^7.1.5
- dev-main
- dev-issue-39-controller_attributes-module
- dev-issue-39-prep
- dev-issue-110-module-snapshot-tests
- dev-issue-110-prep
- dev-issue-110-remove-old-tests
- dev-issue-110-revamp-exporter
- dev-issue-110-prep-1
- dev-issue-101-detect-recurring-objects
- dev-issue-101-drop-default-values
- dev-issue-101-increase-export-depth
- dev-issue-101-no-container-singleton-in-test
- dev-issue-110-prep-0
- dev-issue-111-NamespaceDirectory-tests
- dev-issue-113-definition-get-class-not-class-string
- dev-issue-103-dont-overwrite-service-definitions
- dev-issue-103-prep
- dev-issue-98-remove-symfony-config
- dev-issue-86-drupal-11-and-php-8-3
- dev-issue-99-phpstan-from-root
- dev-issue-86-phpunit-prep
- dev-issue-86-phpunit-recordings
- dev-issue-86-prep
- dev-issue-46-misc
- dev-issue-46-ock-preset-cleanup
- dev-issue-46-ock-preset-ui
- dev-issue-46-preset-formulas
- dev-issue-70-circular-dependencies-in-ParamToEgg_Chain
- dev-issue-75-no-replace-in-composer-json
- dev-issue-77-ock-form-element
- dev-issue-77-test-ock-report-demo-form
- dev-issue-81-element-types
- dev-issue-84-wait-for-ajax-on-drilldown-select
- dev-issue-86-DrupalTesting-package
- dev-issue-86-fix-tests
- dev-issue-86-phpunit-xml
- dev-issue-86-prep-composer-root-version
- dev-issue-86-rewrite-routing-test-base
- dev-issue-86-rewrite-services-test
- dev-issue-86-support-php-8-3
- dev-probe
- dev-issue-20-phpstan-github-action
- dev-issue-24-phpstan-in-helpers-package
- dev-issue-26-phpstan-class-discovery
- dev-issue-29-phpstan-dependency-injection
- dev-issue-30-ddev-here-command
- dev-issue-34-phpstan-testing-package
- dev-issue-38-different-phpstan-versions
- dev-issue-40-prep
- dev-issue-40-test-module-services
- dev-issue-41-test-routes
- dev-issue-42-drop-phpstan-2
- dev-issue-48-housekeeping
- dev-issue-52-phpstan-lv1-object-construction-kit
- dev-issue-52-phpstan-lv2-object-construction-kit
- dev-issue-52-phpstan-lv3-object-construction-kit
- dev-issue-52-phpstan-lv4-object-construction-kit
- dev-issue-52-phpstan-lv5-object-construction-kit
- dev-issue-52-phpstan-lv6-object-construction-kit
- dev-issue-52-phpstan-lv7-object-construction-kit
- dev-issue-52-phpstan-lv8-object-construction-kit
- dev-issue-52-phpstan-lv9-object-construction-kit
- dev-issue-52-phpstan-object-construction-kit
- dev-issue-52-phpstan-prep
- dev-issue-53-FormattableMarkup
- dev-issue-53-fixes
- dev-issue-53-prep
- dev-issue-53-replace-HtmlUtil-sanitize
- dev-issue-72-prep
- dev-issue-72-test-tagged-services
- dev-issue-11-github-actions-in-packages
- dev-issue-16-ci-per-module
- dev-issue-16-prep
- dev-issue-14-add-all-packages-to-split
This package is auto-updated.
Last update: 2024-12-08 19:05:20 UTC
README
Adaptism
Adaptism is a package that finds adapters for objects using a dispatch map.
Adapters can be annotated with attributes for discovery.
Convert objects
use Ock\Adaptism\Tests\Fixtures\Color\Hex\HexColorInterface; use Ock\Adaptism\Tests\Fixtures\Color\Rgb\RgbColor; use Ock\Adaptism\UniversalAdapter\UniversalAdapterInterface; function f(UniversalAdapterInterface $universalAdapter): void { $rgb = new RgbColor(255, 0, 0); $hex = $universalAdapter->adapt($rgb, HexColorInterface::class); assert($hex instanceof HexColorInterface); assert($hex->getHexCode() === 'ff0000'); }
Declare adapters
use Ock\Adaptism\Attribute\Adapter; use Ock\Adaptism\Attribute\Parameter\Adaptee; use Ock\Adaptism\Tests\Fixtures\Color\Hex\HexColorInterface; use Ock\Adaptism\Tests\Fixtures\Color\Rgb\RgbColor; use Ock\Adaptism\Tests\Fixtures\Color\Rgb\RgbColorInterface; class C { #[Adapter] public static function adapt( #[Adaptee] RgbColorInterface $rgb, ): HexColorInterface { return new RgbColor( sprintf( '%02x%02x%02x', $rgbColor->red(), $rgbColor->green(), $rgbColor->blue())); } }
More examples?
Study the tests!