Skip to content

Modules paths. #2

Description

@annavanbiemen

The Modules component should have some way to get paths to modules (preferably the path to the directory in which the src or classes directory of the package are contained).

    /**
     * Get module paths indexed by name
     *
     * When a file or directory is given, paths will be returned
     * to this specific file or directory within the modules, but
     * only for modules in which it actually exists.
     *
     * @param string $to File or directory
     * @return array
     */
    public function paths($to = null)
    {
        $paths = array_map(function (string $class) {
            return dirname(dirname((new ReflectionClass($class))->getFileName()));
        }, $this->classes);;

        if ($to) {
            $paths = array_filter(array_map(function (string $path) use ($to) {
                return $path . DIRECTORY_SEPARATOR . trim($to, DIRECTORY_SEPARATOR);
            }, $paths), 'file_exists');
        }

        return $paths;
    }

Metadata

Metadata

Assignees

No one assigned

    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