-
Notifications
You must be signed in to change notification settings - Fork 19
Description
It is unclear how the FileInput driver is supposed to work when using the config file outside of a Laravel application. For example, building another composer package which has Archetype as a dependency.
When using Archetype this way, 'root' gets set to base_name(), which is returned as ".../vendor/orchestra/testbench-core/laravel/" in my package development environment.
There does not appear to be a way to set a custom config array without publishing the config file -- which I would rather not do within a package like this.
The other solution was to write my own custom FileInput driver which implements InputInterface. Using reflection it is trivial to find the filename of a given class, so I was going to use that and skip all of the root/absolutePath logic in the included FileInput driver.
class ArchetypeInputDriver implements InputInterface
{
public function load(string $className = null)
{
return (new PHPFileStorage())->get($this->getClassFilePath($className));
}
/**
* @throws \Exception
*/
protected function getClassFilePath($className)
{
try {
$reflection = new \ReflectionClass($className);
return $reflection->getFileName();
} catch (\ReflectionException $e) {
throw new \Exception("Archetype Input Driver: Class {$className} could not be found.");
}
}
}
This approach almost worked, except it appears the InputInterface is incomplete. It shows the interface only requiring a single method, however there are multiple other methods and properties used within the codebase. So when my implementation did not have them, there were many errors to fix.
Ex.
ErrorException {#3012
#message: "Undefined property: ArchetypeInputDriver::$filename"
#code: 0
#file: "./vendor/ajthinking/archetype/src/Drivers/FileOutput.php"
#line: 53
#severity: E_WARNING
trace: {
./vendor/ajthinking/archetype/src/Drivers/FileOutput.php:53 { …}