To implement checks for some magic _get()
functions, I'm trying to implement a "class reflection extension". The manual mentions how to write the extension files themselves, and to install them by adding a service
part to the neon file.
I've written an extension, and added it like so:
services:
-
class: TestClass
tags:
- phpstan.broker.methodsClassReflectionExtension
This results in the following error:
Service '0226': Class TestClass not found.
Things I've tried:
Several of these 'adding' tries actually warn if the file is not found: if, for instance, I make a deliberate typo in one of these, lets say the autoload one, it will warn me of a missing file. But only if I don't have the service
defined.
If I have the service defined and the deliberate typo in there, it returns above class-not-found (and not the typo), so I feel it's checking the extension before any of the parameters?
There seems to be a need for adding my file to a different autoloading mechanism. The question is, which and how?
I'm using
The extension class needs to be loaded in runtime. You can achieve that in two ways:
Make the class available for the Composer autoloader. It's usually sufficient to configure autoload-dev
section of your composer.json.
Create a file called something like phpstan-autoload.php
in which you require_once
the file with the extension class. And pass the path to the phpstan-autoload.php
file as --autoload-file|-a
option on the command line when running PHPStan.