alex-oleshkevich/classnames

A missing class name extractor from PHP files.

1.2 2019-11-05 09:16 UTC

This package is auto-updated.

Last update: 2024-10-24 17:40:33 UTC


README

This library extracts entity names from php files.
Supports plain classes, multiple entity per file, classes within curly namespaces, etc.

Build Status Latest Stable Version Monthly Downloads Total Downloads Latest Unstable Version Deps. Status

Installation

composer install alex-oleshkevich/classnames

Example

$extractor = new \ClassNames\ClassNames;
$classes = $extractor->getClassNames('/path/to/file.php');
// or 
$interfaces = $extractor->getInterfaceNames('/path/to/file.php');
// or 
$traits = $extractor->getTraitNames('/path/to/file.php');

All functions listed above return a plain array of found entities.

// file "/path/to/file.php"
namespace TestAsset {
    class Asset {}
    class Asset2 {}
}

$extractor = new \ClassNames\ClassNames;
$classes = $extractor->getClassNames('/path/to/file.php');
print_r($classes);
/**
* Array
* (
*     [0] => TestAsset\Asset
*     [1] => TestAsset\Asset2
* )
*/