GithubHelp home page GithubHelp logo

gregoirehebert / composer-packages Goto Github PK

View Code? Open in Web Editor NEW

This project forked from drupol/composer-packages

0.0 3.0 0.0 94 KB

Composer Packages is a Composer plugin for getting information about installed packages in your project.

License: MIT License

PHP 70.84% HTML 29.16%

composer-packages's Introduction

Latest Stable Version GitHub stars Total Downloads Build Status Scrutinizer code quality Code Coverage Mutation testing badge License Say Thanks! Donate!

Composer Packages

Description

Composer Packages is a Composer plugin for getting information about installed packages in your project.

It could be very useful for anyone who wants to build a package discovery system, crawling the filesystem is then not needed.

Documentation

This package provides:

  • An easy way to get information about installed packages,
  • An easy way to retrieve packages that has a particular types,
  • An easy way to find the installation directory of a package.
  • An easy way to get any package version.
  • An easy way to get any package dependencies.

How does it work ?

When doing a composer update or composer install, the plugin will generate classes that are going to be automatically loaded by the Composer autoload system.

Those classes contains statical information about packages that are installed in your project. Among those static data, it also contains some useful methods. The number of methods in those classes can very depending on the number of packages that are in your project.

This package idea has been inspired by the package ocramius/package-versions from the amazing Marco Pivetta.

Requirements

  • PHP >= 7.1.3

Installation

composer require drupol/composer-packages --dev

Usage

To get packages of a particular type

<?php

declare(strict_types=1);

include './vendor/autoload.php';

use ComposerPackages\Types;

// Use your IDE auto completion to list all the available methods based on your installed packages.
$packages = Types::library();

foreach ($packages as $package) {
    $package->getName(); // $package is an instance of Composer\Package\PackageInterface
}

// You can also get an array
$packagesArray = iterator_to_array($packages);

To get a package

<?php

declare(strict_types=1);

include './vendor/autoload.php';

use ComposerPackages\Packages;
use Composer\Package\PackageInterface;

// Use your IDE auto completion to list all the available methods based on your installed packages.
$package = Packages::symfonyProcess();

// Package is an instance of Composer\Package\PackageInterface then:
$package->getName(); // To get the name.

// Find all the packages where the name starts with the letter "c".
$finder = static function (PackageInterface $package) : bool {
    return 'c' === str_split($package->getName())[0];
};

foreach (Packages::find($finder) as $package) {
    // Do something here.
}

To get an installation directory

<?php

declare(strict_types=1);

include './vendor/autoload.php';

use ComposerPackages\Directories;

// Use your IDE auto completion to list all the available methods based on your installed packages.
$directory = Directories::symfonyProcess();

To get a package version

<?php

declare(strict_types=1);

include './vendor/autoload.php';

use ComposerPackages\Versions;

// Use your IDE auto completion to list all the available methods based on your installed packages.
$version = Versions::symfonyProcess();

To get a package dependencies

<?php

declare(strict_types=1);

include './vendor/autoload.php';

use ComposerPackages\Dependencies;

// Use your IDE auto completion to list all the available methods based on your installed packages.
$dependencies = Dependencies::symfonyDependencyInjection();

foreach ($dependencies as $dependency) {
    echo $dependency; // $dependency is string, the package name.
}

// You can also get an array
$dependenciesArray = iterator_to_array($dependencies);

Note: If composer is not already installed, you might get an error like below when using this package:

In Types.php line […]:

  Attempted to load class "ArrayLoader" from namespace "Composer\Package\Loader".
  Did you forget a "use" statement for e.g. "…\ArrayLoader", "…\ArrayLoader" or "…\ArrayLoader"?

If you do, you can explicitly require composer in your project, to ensure it's available:

composer require composer/composer

To get a package version

<?php

declare(strict_types=1);

include './vendor/autoload.php';

use ComposerPackages\Versions;

// Use your IDE auto completion to list all the available methods based on your installed packages.
$version = Versions::symfonyProcess();

Code quality and tests

Every time changes are introduced into the library, Travis CI run the tests and the benchmarks.

The library has tests written with PHPUnit.

Before each commit some inspections are executed with GrumPHP, run ./vendor/bin/grumphp run to trigger them manually.

PHPInfection is used to ensure that your code is properly tested, run composer infection to test your code.

Contributing

Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)

composer-packages's People

Contributors

bobdenotter avatar carusogabriel avatar drupol avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.