Skip to content

[Feature Request]: Find Composer's /vendor/ path #46

@szepeviktor

Description

@szepeviktor

Is your feature request related to a problem?

AssetPathResolver may improve with this method.

use Composer\Autoload\ClassLoader;
use ReflectionClass;

    /**
     * @throws \RuntimeException
     */
    public static function getVendorPath(): string
    {
        $reflector = new ReflectionClass(ClassLoader::class);
        $classLoaderPath = $reflector->getFileName();
        if ($classLoaderPath === false) {
            throw new \RuntimeException('Unable to find Composer ClassLoader file.');
        }

        $vendorPath = dirname($classLoaderPath, 2);
        if (!is_dir($vendorPath)) {
            throw new \RuntimeException('Unable to detect vendor path.');
        }

        return $vendorPath;
    }

Describe the desired solution

Use the above method.

Describe the alternatives that you have considered

https://github.com/szepeviktor/package-path/blob/master/src/PackagePath.php#L38

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions