Skip to content

FileInput Driver Interface Is Unclear/Incomplete #86

Description

@nickpoulos

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 { …}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions