This library can be used, among other things, to retrieve the classes, interfaces, traits, enums, functions and constants declared in a file

Overview

marijnvanwezel/reflection-file

Library that allows reflection of files.

This library can be used, among other things, to retrieve the classes, interfaces, traits, enums, functions and constants declared in a file.

This package uses static analysis instead of dynamic analysis for reflection, and therefore has fewer false-positives to alternatives like get_declared_classes() and works without including the reflected files in your project.

It has full support for namespaces (braced and unbraced) and works with files that have multiple namespaces.

This package requires PHP 8.1 or higher.

Installation

You can add this library as a dependency to your project using Composer:

composer require marijnvanwezel/reflection-file

Usage

To reflect a file, you can create a new ReflectionFile:

use ReflectionFile\ReflectionFile;

$reflectionFile = new ReflectionFile('/path/to/file');

Getting the filename

To get the filename of a file, use getFileName:

$fileName = $reflectionFile->getFileName();

Getting the pathname

To get the pathname of a file, use getPathName:

$pathName = $reflectionFile->getPathName();

Getting the source

To get the source of a file, use getSource:

$source = $reflectionFile->getSource();

Getting the declared classes

To get a file's declared classes, use getClasses or getClassNames:

/** @var ReflectionClass[] $classes */
$classes = $reflectionFile->getClasses();

/** @var string[] $classes */
$classes = $reflectionFile->getClassNames();

Getting the declared traits

To get a file's declared traits, use getTraits or getTraitNames:

/** @var ReflectionClass[] $traits */
$traits = $reflectionFile->getTraits();

/** @var string[] $traits */
$traits = $reflectionFile->getTraitNames();

Getting the declared interfaces

To get a file's declared interfaces, use getInterfaces or getInterfaceNames:

/** @var ReflectionClass[] $interfaces */
$interfaces = $reflectionFile->getInterfaces();

/** @var string[] $interfaces */
$interfaces = $reflectionFile->getInterfaceNames();

Getting the declared enums

To get a file's declared enums, use getEnums or getEnumNames:

/** @var ReflectionEnum[] $enums */
$enums = $reflectionFile->getEnums();

/** @var string[] $enums */
$enums = $reflectionFile->getEnumNames();

Getting the declared functions

To get a file's declared functions, use getFunctions or getFunctionNames:

/** @var ReflectionFunction[] $functions */
$functions = $reflectionFile->getFunctions();

/** @var string[] $functions */
$functions = $reflectionFile->getFunctionNames();

Getting the declared constants

To get a file's declared constants, use getConstantNames:

/** @var string[] $constants */
$constants = $reflectionFile->getConstantNames();
You might also like...
World Currency list in PHP constants and in array (Currency::USD)
World Currency list in PHP constants and in array (Currency::USD)

World Currency list in PHP constants and in array (Currency::USD) If you need to work with currencies in the code and describe each time "USD", "EUR"

YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic.

YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic. It is built based on the combination of ideas from the Yii framework and Laravel framework (yl).

📦 "PHP type names" contains the list of constants for the available PHP data types.

PHP type names PHP type names 📄 Description Simple library containing the list of constants for the available PHP data types. Use those constant type

Track any ip address with IP-Tracer. IP-Tracer is developed for Linux and Termux. you can retrieve any ip address information using IP-Tracer.
Track any ip address with IP-Tracer. IP-Tracer is developed for Linux and Termux. you can retrieve any ip address information using IP-Tracer.

IP-Tracer is used to track an ip address. IP-Tracer is developed for Termux and Linux based systems. you can easily retrieve ip address information using IP-Tracer. IP-Tracer use ip-api to track ip address.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

Support for PHP 8.1 enums in Doctrine.

Doctrine Native Enums This library provides first-class support to PHP Enums, introduced in PHP 8.1, within your Doctrine entities. Installation compo

Helpers for making PHP enums more lovable.

Enums A collection of enum helpers for PHP. InvokableCases Names Values Options From Metadata You can read more about the idea on Twitter. I originall

A collection of standards as PHP Enums: ISO3166, ISO4217, ISO639...
A collection of standards as PHP Enums: ISO3166, ISO4217, ISO639...

Standards A collection of standards as PHP Enums Setup Make sure you are running PHP 8.1 or higher to use this package To start right away, run the fo

Collection of useful PHP functions, mini-classes, and snippets for every day.

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

Owner
Marijn van Wezel
Marijn van Wezel
A PHP library that can be used manually as well as a CLI script that you can just run on your file

Run phpcs on files and only report new warnings/errors compared to the previous version. This is both a PHP library that can be used manually as well

Payton Swick 20 Aug 4, 2022
Here is the top 100 PHP functions: it is the list of the most often used PHP native functions

Here is the top 100 PHP functions: it is the list of the most often used PHP native functions. If you are a PHP developer, you must know the Top 100 PHP Functions deeply.

Max Base 16 Dec 11, 2022
A PHP library for all things Minecraft: Java Edition

Phpcraft A PHP library for all things Minecraft: Java Edition. This project has been abandoned! The limited subset of 1.8.x - 1.15.x that has been imp

null 16 Nov 29, 2022
Traits used primarily in the v6 package but also available as a helper package for applications

Phalcon Traits This package contains traits with methods that are used for Phalcon v6 onward. It can also be useful to others that want short snippets

The Phalcon PHP Framework 5 Oct 7, 2022
The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

QOSSMIC GmbH 389 Nov 24, 2022
PHPStan extension for sealed classes and interfaces.

Sealed classes with PHPStan This extension adds support for sealed classes and interfaces to PHPStan. Installation To use this extension, require it v

Jiří Pudil 14 Nov 28, 2022
bin/magento command to display configured preferences for classes or interfaces

bin/magento command to display configured preferences for classes or interfaces A bin/magento command that will show you the configured preferences fo

David Manners 14 Jul 18, 2022
Um repositório com classes, interfaces para padronizar os projetos de PHP da empresa

php-utils PHP Utilities for Laravel/Lumen Installation cd /path/to/your/project composer require logcomex/php-utils Utilities Packages Contracts Excep

LogComex 1 Oct 10, 2022
This is a plugin for pocketmine-mp, when locking a player's items helps players not to lose items or throw things around causing server lag.

[] LockedItem| v1.0.0 Player's item lock Features Player's item lock Players aren't afraid of losing items For Devolopers You can access to LockedItem

JeroGamingYT 3 Jan 4, 2022
A PocketMine-MP plugin that lets you teleport among offline players

OfflinePlayerTP A PocketMine-MP plugin that lets you teleport among offline players. Commands Command Description /otp <player> Teleport to (offline)

Muqsit Rayyan 8 Sep 23, 2022