jmf / class-list
Retrieves the list of all the classes (actual and parent classes) of a given class or object.
1.0.0
2024-08-15 16:38 UTC
Requires
- php: >=8.3
- webmozart/assert: ^1.11
Requires (Dev)
- phing/phing: ^2.17
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.1
- rector/rector: ^1.0
- squizlabs/php_codesniffer: ^3.8
README
Retrieves the list of all the classes (actual and parent classes) of a given class or object.
Installation & Requirements
Install with Composer:
composer require jmf/class-list
Usage
With objects
<?php use Jmf\ClassList\ClassesResolver; $resolver = new ClassesResolver(); class Foo {} class Bar extends Foo {} class Baz extends Bar {} $foo = new Foo(); $bar = new Bar(); $baz = new Baz(); print_r($resolver->resolve($foo)); print_r($resolver->resolve($bar)); print_r($resolver->resolve($baz));
Will output:
Array
(
[0] => Foo
)
Array
(
[0] => Bar
[1] => Foo
)
Array
(
[0] => Baz
[1] => Bar
[2] => Foo
)
With classes
<?php use Jmf\ClassList\ClassesResolver; $resolver = new ClassesResolver(); class Foo {} class Bar extends Foo {} class Baz extends Bar {} print_r($resolver->resolve(Foo::class)); print_r($resolver->resolve(Bar::class)); print_r($resolver->resolve(Baz::class));
Will output:
Array
(
[0] => Foo
)
Array
(
[0] => Bar
[1] => Foo
)
Array
(
[0] => Baz
[1] => Bar
[2] => Foo
)