{"id":16760761,"url":"https://github.com/jerowork/file-class-reflector","last_synced_at":"2025-04-10T17:38:08.939Z","repository":{"id":46295031,"uuid":"400995026","full_name":"jerowork/file-class-reflector","owner":"jerowork","description":"Get fully-qualified class names based on directory and file paths.","archived":false,"fork":false,"pushed_at":"2023-06-19T12:59:09.000Z","size":104,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T09:41:26.638Z","etag":null,"topics":["class-name","fqcn","reflection"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jerowork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-29T08:56:11.000Z","updated_at":"2023-06-14T12:24:39.000Z","dependencies_parsed_at":"2025-02-17T17:46:17.795Z","dependency_job_id":null,"html_url":"https://github.com/jerowork/file-class-reflector","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jerowork%2Ffile-class-reflector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jerowork%2Ffile-class-reflector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jerowork%2Ffile-class-reflector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jerowork%2Ffile-class-reflector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jerowork","download_url":"https://codeload.github.com/jerowork/file-class-reflector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248262051,"owners_count":21074238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["class-name","fqcn","reflection"],"created_at":"2024-10-13T04:24:29.526Z","updated_at":"2025-04-10T17:38:08.924Z","avatar_url":"https://github.com/jerowork.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file-class-reflector\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fjerowork%2Ffile-class-reflector%2Fbadge%3Fref%3Dmain\u0026style=flat-square)](https://github.com/jerowork/file-class-reflector/actions)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/jerowork/file-class-reflector.svg?style=flat-square)](https://scrutinizer-ci.com/g/jerowork/file-class-reflector/code-structure)\n[![Quality Score](https://img.shields.io/scrutinizer/g/jerowork/file-class-reflector.svg?style=flat-square)](https://scrutinizer-ci.com/g/jerowork/file-class-reflector)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Packagist Version](https://img.shields.io/packagist/v/jerowork/file-class-reflector.svg?style=flat-square\u0026include_prereleases)](https://packagist.org/packages/jerowork/file-class-reflector)\n[![PHP Version](https://img.shields.io/badge/php-%5E8.1-8892BF.svg?style=flat-square)](http://www.php.net)\n\nGet fully-qualified classnames based on directory and file paths.\n\n## Installation\nInstall via [Composer](https://getcomposer.org):\n```bash\ncomposer require jerowork/file-class-reflector\n```\n\n## Usage\nThe `ClassReflector` makes use of the [nikic/php-parser](https://github.com/nikic/php-parser) \npackage to retrieve the fully-qualified class name from a file.\n\nBasic usage:\n\n```php\nuse Jerowork\\FileClassReflector\\NikicParser\\NikicParserClassReflectorFactory;\n\n// Create a new ClassReflector instance directly via a static factory method\n$reflector = NikicParserClassReflectorFactory::createInstance();\n\n// Add necessary directories and/or files and reflect\n$reflector\n    -\u003eaddDirectory(__DIR__ . '/some/directory')\n    -\u003ereflect();\n\n// Get all \\ReflectionClass found in files\n$classes = $reflector-\u003egetClasses();\n```\n\nThe `ClassReflectorFactory` can also be instantiated via the constructor.\nIn this way the factory can be added to a DI container. \n```php\nuse Jerowork\\FileClassReflector\\FileFinder\\RegexIterator\\RegexIteratorFileFinder;\nuse Jerowork\\FileClassReflector\\NikicParser\\NikicParserClassReflectorFactory;\nuse PhpParser\\NodeTraverser;\nuse PhpParser\\ParserFactory;\n\n// Create the factory\n$factory = new NikicParserClassReflectorFactory(\n    new RegexIteratorFileFinder(),\n    (new ParserFactory())-\u003ecreate(ParserFactory::PREFER_PHP7),\n    new NodeTraverser(),\n);\n\n// Create a new ClassReflector instance\n$reflector = $factory-\u003ecreate();\n\n// ...\n```\n\n### DI service definition\nAs a good practice we should always 'program to interfaces, not implementations', you should add this to your DI container.\n\nPSR-11 Container example:\n\n```php\nuse Jerowork\\FileClassReflector\\ClassReflectorFactory;\nuse Jerowork\\FileClassReflector\\FileFinder\\FileFinder;\nuse Jerowork\\FileClassReflector\\FileFinder\\RegexIterator\\RegexIteratorFileFinder;\nuse Jerowork\\FileClassReflector\\NikicParser\\NikicParserClassReflectorFactory;\nuse PhpParser\\NodeTraverser;\nuse PhpParser\\ParserFactory;\nuse Psr\\Container\\ContainerInterface;\n\nreturn [\n    ClassReflectorFactory::class =\u003e static function (ContainerInterface $container): ClassReflectorFactory {\n        return new NikicParserClassReflectorFactory(\n            new RegexIteratorFileFinder(),\n            (new ParserFactory())-\u003ecreate(ParserFactory::PREFER_PHP7),\n            new NodeTraverser(),\n        );\n    },\n    \n    FileFinder::class =\u003e static fn (): FileFinder =\u003e new RegexIteratorFileFinder(),\n];\n```\n\nSymfony YAML-file example:\n```yaml\nservices:\n  _defaults:\n    autowire: true\n    autoconfigure: true\n\n  Jerowork\\FileClassReflector\\ClassReflectorFactory:\n    class: Jerowork\\FileClassReflector\\NikicParser\\NikicParserClassReflectorFactory\n\n  Jerowork\\FileClassReflector\\FileFinder\\FileFinder:\n    class: Jerowork\\FileClassReflector\\FileFinder\\RegexIterator\\RegexIteratorFileFinder\n\n  PhpParser\\ParserFactory: ~\n\n  PhpParser\\Parser:\n    factory: ['@PhpParser\\ParserFactory', 'create']\n    arguments: [1] # 1 = ParserFactory::PREFER_PHP7\n\n  PhpParser\\NodeTraverser: ~\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjerowork%2Ffile-class-reflector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjerowork%2Ffile-class-reflector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjerowork%2Ffile-class-reflector/lists"}