https://github.com/psychob/reflection-file
PHP Abstraction for reflection file
https://github.com/psychob/reflection-file
Last synced: 6 months ago
JSON representation
PHP Abstraction for reflection file
- Host: GitHub
- URL: https://github.com/psychob/reflection-file
- Owner: psychob
- Created: 2019-06-19T12:42:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-01-26T03:29:29.000Z (over 1 year ago)
- Last Synced: 2025-09-07T09:42:24.700Z (11 months ago)
- Language: PHP
- Size: 67.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ReflectionFile
[](https://packagist.org/packages/psychob/reflection-file)
[](LICENSE)
[](https://php.net/)
A powerful PHP library for analyzing PHP files through reflection. This library extends PHP's native reflection capabilities by allowing you to examine PHP files without loading them into memory, providing information about classes, interfaces, traits, and other declarations.
## Features
- Analyze PHP files without executing them
- Extract information about:
- Namespaces
- Classes (including abstract classes)
- Interfaces
- Traits
- Functions
- Objects
- Enums
- Lazy loading support for better performance
- Safe file parsing
## Requirements
- PHP 8.3 or higher
- Composer
## Installation
Install via Composer:
```bash
composer require psychob/reflection-file
```
## Usage
### Basic Usage
```php
getNamesOfClasses();
// Get all interfaces
$interfaces = $reflection->getNamesOfInterfaces();
// Get all traits
$traits = $reflection->getNamesOfTraits();
// Get namespace information
$namespace = $reflection->getFirstNameOfNamespace();
```
### Performance Optimization
The library supports deferred parsing and loading for better performance:
```php
getNamesOfClasses(); // Triggers parsing
// Manual control over loading
$reflection->load(); // Explicitly load the file
```
## Advanced Features
### Namespace Analysis
```php
$namespaces = $reflection->getNamesOfNamespaces();
$firstNamespace = $reflection->getFirstNameOfNamespace();
```
### Class Analysis
```php
$classes = $reflection->getNamesOfClasses();
$abstractClasses = $reflection->getNamesOfAbstractClasses();
```
### Other Declarations
```php
$interfaces = $reflection->getNamesOfInterfaces();
$traits = $reflection->getNamesOfTraits();
$functions = $reflection->getNamesOfFunctions();
$enums = $reflection->getNamesOfEnums();
```
## Security Considerations
This library parses PHP files. Always ensure you're analyzing trusted files, as parsing untrusted PHP files could potentially expose your application to security risks.
## License
This project is licensed under the Mozilla Public License Version 2.0 - see the [LICENSE](https://www.mozilla.org/en-US/MPL/2.0/) file for details.
## Author
- Andrzej Budzanowski