Given that each PHP file in our project contains a single class definition, how can I determine what class or classes are defined within the file?
I know I could jus
Or you could easily use AnnotationsParser from Nette\Reflection (installable using composer):
use Nette\Reflection\AnnotationsParser;
$classes = AnnotationsParser::parsePhp(file_get_contents($fileName));
var_dump($classes);
Output will be then something like this:
array(1) {
["Your\Class\Name"] =>
array(...) {
// property => comment
},
["Your\Class\Second"] =>
array(...) {
// property => comment
},
}
The parsePhp() method basically does something similar as examples in other answers, but you don't have to declare nor test the parsing yourselves.