wyrihaximus/list-classes-in-directory

Allows you to list full qualified class names in directories and files.

1.7.0 2024-07-16 12:35 UTC

README

Continuous Integration Latest Stable Version Total Downloads Code Coverage License

Install

To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^.

composer require wyrihaximus/list-classes-in-directory

Usage

get a list of classes from multiple directories.

use function WyriHaximus\Lister;

// $classes now contains a list of full qualified class names from 'src/' and 'tests/'
$classes = Lister::classesInDirectories(
    __DIR__ . '/src',
    __DIR__ . '/tests'
);


// use listInstantiatableClassesInDirectories() or listNonInstantiatableClassesInDirectories() to only consider classes that can actually be instantiated, or not.
$instantiatableClasses = Lister::instantiatableClassesInDirectory(
    __DIR__ . '/src',
    __DIR__ . '/tests'
);
$nonInstantiatableClasses = Lister::nonInstantiatableClassesInDirectory(
    __DIR__ . '/src',
    __DIR__ . '/tests'
);

get a list of classes from one directory.

use function WyriHaximus\Lister;

// $classes now contains a list of full qualified class names from __DIR__
$classes = Lister::classesInDirectory(__DIR__);

// use listInstantiatableClassesInDirectory() or listNonInstantiatableClassesInDirectory() to only consider classes that can actually be instantiated, or not.
$instantiatableClasses = Lister::instantiatableClassesInDirectory(__DIR__);
$nonInstantiatableClasses = Lister::nonInstantiatableClassesInDirectory(__DIR__);

get a list of classes from multiple files.

use function WyriHaximus\Lister;

// $classes now contains a list of full qualified class names from 'Bar.php' and 'Foo.php'
$classes = Lister::classesInFiles(
    __DIR__ . '/Bar.php',
    __DIR__ . '/Foo.php'
);

get a list of classes from one file.

use function WyriHaximus\Lister;

// $classes now contains a list of full qualified class names from 'Foo.php'
$classes = Lister::classesInFile(__DIR__.'/Foo.php');

Acknowledgement

This package is a shorthand function for using better reflection and is based on one of the examples.

License

The MIT License (MIT)

Copyright (c) 2024 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.