ergebnis/classy

Provides a finder for classy constructs (classes, enums, interfaces, and traits).

1.5.0 2023-09-13 15:18 UTC

README

Integrate Merge Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

This package provides a finder for classy constructs (classes, enums, interfaces, and traits).

Installation

Run

composer require ergebnis/classy

Usage

Collect classy constructs from source code

Use Classy\Constructs::fromSource() to collect classy constructs in source code:

<?php

declare(strict_types=1);

use Ergebnis\Classy;

$source = <<<'PHP'
<?php

namespace Example;

class Foo {}

enum Bar {}

interface Baz {}

trait Qux {}
PHP;

$constructs = Classy\Constructs::fromSource($source);

$names = array_map(static function (Classy\Construct $construct): string {
    return $construct->name();
}, $constructs);

var_dump($names); // ['Example\Bar', 'Example\Baz', 'Example\Foo', 'Example\Qux']

Collect classy constructs from a directory

Use Classy\Constructs::fromDirectory() to collect classy constructs in a directory:

<?php

declare(strict_types=1);

use Ergebnis\Classy;

$constructs = Classy\Constructs::fromDirectory(__DIR__ . '/example');

$names = array_map(static function (Classy\Construct $construct): string {
    return $construct->name();
}, $constructs);

var_dump($names); // ['Example\Bar', 'Example\Bar\Baz', 'Example\Foo\Bar\Baz']

Changelog

The maintainers of this package record notable changes to this project in a changelog.

Contributing

The maintainers of this package suggest following the contribution guide.

Code of Conduct

The maintainers of this package ask contributors to follow the code of conduct.

General Support Policy

The maintainers of this package provide limited support.

You can support the maintenance of this package by sponsoring @localheinz or requesting an invoice for services related to this package.

PHP Version Support Policy

This package supports PHP versions with active support.

The maintainers of this package add support for a PHP version following its initial release and drop support for a PHP version when it has reached its end of active support.

Security Policy

This package has a security policy.

License

This package uses the MIT license.

Credits

The algorithm for finding classes in PHP files in Constructs has been adopted from Zend\File\ClassFileLocator (originally licensed under BSD-3-Clause).

Social

Follow @localheinz and @ergebnis on Twitter.