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(9mo ago)11589.0k↑42.3%6[5 issues](https://github.com/phpactor/class-to-file/issues)[2 PRs](https://github.com/phpactor/class-to-file/pulls)6MITPHPPHP ^8.1CI failing

Since Jan 21Pushed 9mo 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 3d 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

51

—

FairBetter than 95% of packages

Maintenance49

Moderate activity, may be stable

Popularity46

Moderate usage in the ecosystem

Community24

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

275d 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

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[civicrm/civicrm-core

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

751291.4k43](/packages/civicrm-civicrm-core)[phpro/soap-client

A general purpose SoapClient library

8896.1M54](/packages/phpro-soap-client)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M420](/packages/drupal-core-recommended)

PHPackages © 2026

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