Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileInput Driver Interface Is Unclear/Incomplete #86

Open
nickpoulos opened this issue Sep 24, 2024 · 0 comments
Open

FileInput Driver Interface Is Unclear/Incomplete #86

nickpoulos opened this issue Sep 24, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@nickpoulos
Copy link

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 { …}
@ajthinking ajthinking added the help wanted Extra attention is needed label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants