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

This package is auto-updated.

Last update: 2024-10-15 16:57:23 UTC


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
)