lighth7015/runtime-class-info

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

1.3.2 2020-04-15 13:49 UTC

README

Build Status Latest Stable Version Total Downloads Code Coverage License PHP 7 ready

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\listClassesInDirectories;
use function WyriHaximus\listInstantiatableClassesInDirectories;
use function WyriHaximus\listNonInstantiatableClassesInDirectories;

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


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

get a list of classes from one directory.

use function WyriHaximus\listClassesInDirectory;
use function WyriHaximus\listInstantiatableClassesInDirectory;
use function WyriHaximus\listNonInstantiatableClassesInDirectory;

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

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

get a list of classes from multiple files.

use function WyriHaximus\listClassesInFiles;

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

get a list of classes from one file.

use function WyriHaximus\listClassesInFile;

// $classes now contains a list of full qualified class names from 'Foo.php'
$classes = listClassesInFile(__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) 2018 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.