PHPackages                             phpactor/class-to-file - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpactor/class-to-file

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpactor/class-to-file
======================

Library to covert class names to file paths and vice-versa

0.6.0(7mo ago)11527.7k↓40.4%6[2 PRs](https://github.com/phpactor/class-to-file/pulls)6MITPHPPHP ^8.1CI passing

Since Jan 21Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/phpactor/class-to-file)[ Packagist](https://packagist.org/packages/phpactor/class-to-file)[ RSS](/packages/phpactor-class-to-file/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (23)Used By (6)

Class To File Transformer
=========================

[](#class-to-file-transformer)

[![CI](https://github.com/phpactor/class-to-file/workflows/CI/badge.svg)](https://github.com/phpactor/class-to-file/workflows/CI/badge.svg)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9b7aee1efd403f6c3911cdaac06ffed74563a462e413cb1b21bfcdd97698bfca/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706163746f722f636c6173732d746f2d66696c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpactor/class-to-file/?branch=master)

This library provides facilities to guess/transform class names to files paths and vice-versa.

It uses the composer autoload to guess the best candidates using **PSR-0** and **PSR-4**.

Usage
-----

[](#usage)

```
// require the composer autoloader for the class you want to investigate
$autoloader = require(__DIR__ . '/vendor/autoload.php');

// for file candidates
$converter = ClassFileConverter::fromComposerAutoloader($autoloader);
$candidates = $classToFile->classToFileCandidates(ClassName::fromString('Foobar\\Barfoo\\MyClass'));

echo (string) $candidates->empty(); // return true if there are no candidates
echo (string) $candidates->best(); // path to the "best" candidate

// or for class candidates
$candidates = $classToFile->fileToClassCandidates(FilePath::fromString('lib/Foobar/BarFoo/MyClass.php'));
```

Doesn't composer provide file paths for classes?
------------------------------------------------

[](#doesnt-composer-provide-file-paths-for-classes)

Yes it does, but only if the class **exists**. One of the purposes of this class is to be able to determine a file path for a class which may not exist (for example to generate a class in a new file).

You may also want to do this and not pollute your autoloading environment (unfortunately this library currently [does pollute the autoloader](https://github.com/dantleech/class-to-file/issues/3), but it can be avoided in the future.

Why would you want to determine the class from a filename?
----------------------------------------------------------

[](#why-would-you-want-to-determine-the-class-from-a-filename)

Glad you asked! This is can be useful when you want to generate an empty class in an empty file.

When one autoloader isn't enough
--------------------------------

[](#when-one-autoloader-isnt-enough)

In some exceptional cases you may have a project which has more than one composer autoloader, this is supported through the `ChainFileToClass` and `ChainClassToFile` classes, or most simply through the *facade*:

```
$converter = ClassFileConverter::fromComposerAutoloaders([ $autoloader1, $autoloader2 ]);
```

Contributing
------------

[](#contributing)

This package is open source and welcomes contributions! Feel free to open a pull request on this repository.

Support
-------

[](#support)

- Create an issue on the main [Phpactor](https://github.com/phpactor/phpactor) repository.
- Join the `#phpactor` channel on the Slack [Symfony Devs](https://symfony.com/slack-invite) channel.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance63

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 92.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~200 days

Recently: every ~286 days

Total

15

Last Release

228d ago

Major Versions

0.5.2 → 81.x-dev2025-10-02

PHP version history (4 changes)0.3.4PHP ^7.2

0.4.0PHP ^7.3 || ^8.0

0.5PHP ^7.4 || ^8.0

81.x-devPHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/24ec7d5d6b7ea54007be5d7b4f43800381cc1e22929f7d2276fba30e497fdfa6?d=identicon)[dantleech](/maintainers/dantleech)

---

Top Contributors

[![dantleech](https://avatars.githubusercontent.com/u/530801?v=4)](https://github.com/dantleech "dantleech (89 commits)")[![przepompownia](https://avatars.githubusercontent.com/u/11404453?v=4)](https://github.com/przepompownia "przepompownia (2 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (2 commits)")[![greg0ire](https://avatars.githubusercontent.com/u/657779?v=4)](https://github.com/greg0ire "greg0ire (1 commits)")[![hutushen222](https://avatars.githubusercontent.com/u/352215?v=4)](https://github.com/hutushen222 "hutushen222 (1 commits)")[![mamazu](https://avatars.githubusercontent.com/u/14860264?v=4)](https://github.com/mamazu "mamazu (1 commits)")

---

Tags

composerphpactor

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpactor-class-to-file/health.svg)

```
[![Health](https://phpackages.com/badges/phpactor-class-to-file/health.svg)](https://phpackages.com/packages/phpactor-class-to-file)
```

###  Alternatives

[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

5694.9k1](/packages/sensiolabs-minify-bundle)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
