xylemical / class-mapper
Provides class mapping.
dev-master
2022-07-02 06:10 UTC
Requires
- php: >=8.0
Requires (Dev)
- xylemical/composer-dev-bundle: ^0.1.0
This package is auto-updated.
Last update: 2025-03-29 01:04:27 UTC
README
Provides framework for providing mapper of classes to names.
Install
The recommended way to install this library is through composer.
composer require xylemical/class-mapper
Usage
use Xylemical\ClassMapper\SingleClassMapper; use Xylemical\ClassMapper\MultipleClassMapper; use Xylemical\ClassMapper\ClassMapperManager; $manager = new ClassMapperManager(); $mapper = new SingleClassMapper('SingleInterface', [ Implementation::class => 'implementation', ]); $manager->addMapper($mapper); $name = $mapper->getName(Implementation::class); // $name == 'implementation' $class = $mapper->getClass('implementation'); // $class == Implementation::class $mapper = new MultipleClassMapper('MultipleInterface', [ Implementation1::class => 'implementation', Implementation2::class => 'implementation', ]) $manager->addMapper($mapper); $name = $mapper->getName(Implementation1::class); // $name == 'implementation' $class = $mapper->getClasses('implementation'); // $class == [Implementation1::class, Implementation2::class] $mapper = $manager->getMapper('SingleInterface'); // $mapper == SingleClassMapper $mapper = $manager->getMapper('MultipleInterface'); // $mapper == MultipleClassMapper.
License
MIT, see LICENSE.