2017 © Pedro Peláez
 

library class-to-file

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

image

phpactor/class-to-file

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

  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 3 Open issues
  • 2 Versions
  • 23 % Grown

The README.md

Class To File Transformer

CI Scrutinizer Code Quality, (*1)

This library provides facilities to guess/transform class names to files paths and vice-versa., (*2)

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

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?

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)., (*4)

You may also want to do this and not pollute your autoloading environment (unfortunately this library currently does pollute the autoloader, but it can be avoided in the future., (*5)

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., (*6)

When one autoloader isn't 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:, (*7)

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

Contributing

This package is open source and welcomes contributions! Feel free to open a pull request on this repository., (*8)

Support

  • Create an issue on the main Phpactor repository.
  • Join the #phpactor channel on the Slack Symfony Devs channel.

The Versions

28/01 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

The Development Requires

21/01 2018

dev-simple_improve

dev-simple_improve

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

  Sources   Download

MIT

The Requires

 

The Development Requires