2017 © Pedro Peláez
 

library package-builder

Dependency Injection, Console and Kernel toolkit for Symplify packages.

image

symplify/package-builder

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  • PHP
  • 20 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 100 Versions
  • 39 % Grown

The README.md

Package Builder

Downloads total, (*1)

This tools helps you with Collectors in DependencyInjection, Console shortcuts, ParameterProvider as service and many more., (*2)

Install

composer require symplify/package-builder

Use

Get All Parameters via Service

  1. Register ParameterProvider service in your config:
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();

    $services->defaults()
        ->autowire()
        ->autoconfigure();

    $services->set(ParameterProvider::class)
        ->args([service('service_container')]);

    $parameter = $containerConfigurator->parameters();
    // will be used later
    $parameter->set('source', 'src');
};
  1. Require ParameterProvider in __construct() where needed:
namespace App\Configuration;

use Symplify\PackageBuilder\Parameter\ParameterProvider;

final class ProjectConfiguration
{
    /**
     * @var ParameterProvider
     */
    private $parameterProvider;

    public function __construct(ParameterProvider $parameterProvider)
    {
        $this->parameterProvider = $parameterProvider;
    }

    public function getSource(): string
    {
        // returns "src"
        return $this->parameterProvider->provideParameter('source');

        // use specific typed method to avoid `mixed`
        return $this->parameterProvider->provideStringParameter('source');
    }
}


, (*3)

Get Vendor Directory from Anywhere

use Symplify\PackageBuilder\Composer\VendorDirProvider;

$vendorDirProvider = new VendorDirProvider();
// returns path to vendor directory
$vendorDirProvider->provide();


, (*4)

Smart Compiler Passes for Lazy Programmers ↓

How to add compiler pass?, (*5)


, (*6)

Always Autowire this Type

Do you want to allow users to register services without worrying about autowiring? After all, they might forget it and that would break their code. Set types to always autowire:, (*7)

namespace App;

use PhpCsFixer\Fixer\FixerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass;

final class AppKernel extends Kernel
{
    protected function build(ContainerBuilder $containerBuilder): void
    {
        $containerBuilder->addCompilerPass(new AutowireInterfacesCompilerPass([FixerInterface::class]));
    }
}

This will make sure, that PhpCsFixer\Fixer\FixerInterface instances are always autowired., (*8)


, (*9)

That's all :), (*10)

Show Diff in Console Colors

use Symplify\PackageBuilder\Console\Output\ConsoleDiffer;

final class SomeCommand
{
    public function __construct(
        private ConsoleDiffer $consoleDiffer
    ) {
    }

    public function run(): void
    {
        // prints colored diff to the console output
        $this->consoleDiffer->diff('oldContent', 'newContent');
    }
}


, (*11)

Report Issues

In case you are experiencing a bug or want to request a new feature head over to the Symplify monorepo issue tracker, (*12)

Contribute

The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on symplify/symplify., (*13)

The Versions

07/05 2018
25/04 2018
24/04 2018
24/04 2018
07/04 2018
07/04 2018
07/04 2018
05/04 2018
02/04 2018
02/04 2018

v4.0.0beta1

4.0.0.0-beta1

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

01/04 2018

v4.0.0alpha6

4.0.0.0-alpha6

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/03 2018

v4.0.0alpha4

4.0.0.0-alpha4

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/03 2018

v4.0.0alpha5

4.0.0.0-alpha5

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

26/03 2018

dev-vendor-param-in-imports

dev-vendor-param-in-imports

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

26/03 2018

dev-throwable-renderer-tests

dev-throwable-renderer-tests

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2018

dev-ecs-tester

dev-ecs-tester

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2018

v4.0.0alpha3

4.0.0.0-alpha3

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/03 2018

dev-ecs-verbose-message

dev-ecs-verbose-message

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

15/03 2018

v4.0.0alpha2

4.0.0.0-alpha2

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/03 2018

v4.0.0alpha1

4.0.0.0-alpha1

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/12 2017
18/12 2017
18/12 2017
09/12 2017
09/12 2017
09/12 2017
08/12 2017
08/12 2017

v3.0.0-RC5

3.0.0.0-RC5

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

v3.0.0-RC1

3.0.0.0-RC1

Dependency Injection, Console and Kernel toolkit for Symplify packages.

  Sources   Download

MIT

The Requires

 

The Development Requires