stagem/class-finder

Extremely simple and fast Class Finder

Installs: 8 706

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 4

Forks: 0

Open Issues: 0

Type:project

1.0 2019-06-15 10:15 UTC

This package is auto-updated.

Last update: 2024-04-29 04:13:28 UTC


README

Extremely simple and fast Class Finder.

The package allows you to get Fully Qualified Class Name (FQCN) from file or directory path. There are no dependencies on the Composer Autoloader, Reflection, RegEx, or get_declared_classes().

Many similar packages already implement this functionality but all of them suffer from overengineering or performance issues. When your project becomes big and it has tens of thousands of classes with the huge numbers of config you need a simple and fast solution to operate all of it.

Installation

Use Composer to install this library in your projects:

$ composer require stagem/class-finder

Usage

Find in file path

<?php

use Stagem\ClassFinder\ClassFinder;

$class = (new ClassFinder())->getClassFromFile('/path/to/App/ClassName.php');

var_dump($class);
// App\ClassName

Find in directory path

<?php 

use Stagem\ClassFinder\ClassFinder;

$classes = (new ClassFinder())->getClassesInDir('/path/to/App/Model');

var_dump($classes);
/**
 *  array (
 *    0 => '\\App\\Model\\Product',
 *    1 => '\\App\\Model\\Cart',
 *    2 => '\\App\\Model\\Order',
 *    3 => '\\App\\Model\\Shipment',
 *  )
 */