2017 © Pedro Peláez
 

composer-plugin composer-locator

Locates Composer package root folders by package name

image

mindplay/composer-locator

Locates Composer package root folders by package name

  • Monday, May 8, 2017
  • by mindplay.dk
  • Repository
  • 2 Watchers
  • 52 Stars
  • 10,575 Installations
  • PHP
  • 9 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 10 Versions
  • 16 % Grown

The README.md

mindplay/composer-locator

⚠️ DEPRECATED: use Composer Runtime Utilities

This Composer plugin provides a means of locating the installation path for a given Composer package name., (*1)

PHP Version CI, (*2)

Use this to locate vendor package roots, e.g. when working with template files or other assets in a package, locating and discovering plugins, and so on., (*3)

It works regardless of installers affecting the individual package installation paths, and also works whether the package in question is currently the root package/project or a dependency., (*4)

Usage

Add to your composer.json file:, (*5)

{
    "require": {
        "mindplay/composer-locator": "^2"
    },
    "config": {
        "allow-plugins": {
            "mindplay/composer-locator": true
        }
    }
}

Running composer install or composer update will bootstrap your project with a generated class containing a registry of Composer package installation paths., (*6)

To obtain the installation path for given package:, (*7)

$path = ComposerLocator::getPath("vendor/package"); // => "/path/to/vendor/package" 

If the specified package name is not found, the function throws a RuntimeException., (*8)

To check whether a given package is installed:, (*9)

$is_installed = ComposerLocator::isInstalled("vendor/package"); // => (bool) true|false 

The root Composer project package doesn't necessarily have a package name - to get the root path of the root Composer project, without specifying the package name:, (*10)

$path = ComposerLocator::getRootPath(); // => "/path/to/project/root" 

You can also get a list of all installed packages via ComposerLocator::getPackages(), or obtain a full key/value map of package-names to absolute root paths via ComposerLocator::getPaths()., (*11)

Why?

Needing to know the root path of a package installation folder is quite a common requirement, such as when you need to specify paths to template files or other assets., (*12)

The problem is that Composer itself offers no simple and reliable way to do that., (*13)

You can use reflection to get the path to a known class or interface from the package, and then dirname() up from your src folder to the package installation root, but that approach isn't very robust, since the location of a class file may change from one version to another., (*14)

Even if you know the path of the vendor root folder, and the {vendor}/{package} folder name convention, there is no guarantee that's always where packages are installed - something like composer-installers could affect the installation paths., (*15)

Also, when developing a library, during testing and development, the package will be installed as the root/project package, but this path will be different when it's installed as a dependency in another project., (*16)

The Versions

08/05 2017

dev-master

9999999-dev

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1
  • php >= 5.4

 

The Development Requires

08/05 2017

2.1.3

2.1.3.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • php >= 5.4
  • composer-plugin-api ^1

 

The Development Requires

09/04 2017

dev-test-suite

dev-test-suite

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • php >= 5.4
  • composer-plugin-api ^1

 

The Development Requires

09/04 2017

2.1.2

2.1.2.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • php >= 5.4
  • composer-plugin-api ^1

 

The Development Requires

07/06 2016

2.1.1

2.1.1.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • php >= 5.4
  • composer-plugin-api ^1

 

The Development Requires

06/06 2016

2.1.0

2.1.0.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • php >= 5.4
  • composer-plugin-api ^1

 

The Development Requires

04/05 2016

2.0.1

2.0.1.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • php >= 5.4
  • composer-plugin-api ^1

 

The Development Requires

29/04 2016

2.0.0

2.0.0.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1

 

The Development Requires

19/04 2016

1.0.1

1.0.1.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1

 

The Development Requires

19/04 2016

1.0.0

1.0.0.0

Locates Composer package root folders by package name

  Sources   Download

MIT

The Requires

  • composer-plugin-api ^1

 

The Development Requires