2017 © Pedro Peláez
 

library slim-symfony-container

Simple SlimPHP container integration with Symfony dependency injection container

image

jangolle/slim-symfony-container

Simple SlimPHP container integration with Symfony dependency injection container

  • Monday, February 12, 2018
  • by jangolle
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status codecov PHP from Packagist Packagist, (*1)

Slim with Symfony DI Container integration

Easily resolve Symfony ContainerBuilder and setup in it all default Slim Application dependencies if necessary. Loader resolve symfony configuration params and setup slim default settings with params to symfony ParameterBag., (*2)

Installation

Library is available on Packagist., (*3)

Installation via composer is the recommended way to install it., (*4)

Just add this line to required section of your composer.json file:, (*5)

"jangolle/slim-symfony-container": "~1.0"

or just run in console, (*6)

cd /path/to/your/project
composer require jangolle/slim-symfony-container

Default usage

You can directly create ContainerBuilder and use it from scratch to setup with SlimDefaultServicesInjection like this:, (*7)

<?php
declare(strict_types=1);

use JanGolle\SlimSymfonyContainer\ContainerManager;
use JanGolle\SlimSymfonyContainer\Loader\SlimDefaultServicesInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;

$containerManager = new ContainerManager();
$container = new ContainerBuilder();

$container = $containerManager->resolveContainer($container, new SlimDefaultServicesInjection());

$app = new \Slim\App($container);

//setup routes or something

$app->run();

Use with Symfony configs

If you want your symfony configuration files in your project you can actually do something like:, (*8)

<?php
declare(strict_types=1);

use JanGolle\SlimSymfonyContainer\ContainerManager;
use JanGolle\SlimSymfonyContainer\Loader\SlimDefaultServicesInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

$containerManager = new ContainerManager();
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/path/to/config'));
$loader->load('services.yaml');

$container = $containerManager->resolveContainer($container, new SlimDefaultServicesInjection());

$app = new \Slim\App($container);

//setup routes or something

$app->run();

Your services.yaml parameters block might look like this:, (*9)

parameters:
  slim.settings.httpVersion: '1.1'
  slim.settings.responseChunkSize: 4096
  slim.settings.displayErrorDetails: !php/const DEBUG

NOTE: You can override default SLIM settings in your config file with your custom values.. or not, it's up to you :) All SLIM necessary settings will be applied to container injection with your params or not., (*10)

Custom wrapper class

If you have your own container that is instance of Symfony\Component\DependencyInjection\ContainerBuilder and you want to setup it with Slim dependencies you can do like this:, (*11)

$container = new YourCustomContainer($fullOfParams);//instance of Symfony\Component\DependencyInjection\ContainerBuilder
$container = $containerManager->resolveContainer($container, new SlimDefaultServicesInjection());

or you can just instantiate it with default constructor via ::class as first arg of resolveContainer:, (*12)

$container = $containerManager->resolveContainer(YourCustomContainer::class, new SlimDefaultServicesInjection());

Container access inside app

Inside your routes scope $this will return our container which is actually instance of Symfony\Component\DependencyInjection\ContainerBuilder, (*13)

//...
$app->get(
    '/your/route',
    function (Request $request, Response $response, array $args) {
        $this->get('someService')->doSomeStuff();

        return $response;
    }
);

PhpStorm Symfony Plugin support

If you are using PhpStorm IDE you can install in it Symfony plugin and get access to typehinting and IDE autocomplite for services., (*14)

Thanks for your attention!, (*15)

The Versions

12/02 2018

dev-master

9999999-dev https://github.com/JanGolle/slim-symfony-container

Simple SlimPHP container integration with Symfony dependency injection container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Elijah Zakirov

container symfony slim di container

12/02 2018

v1.0.1

1.0.1.0 https://github.com/JanGolle/slim-symfony-container

Simple SlimPHP container integration with Symfony dependency injection container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Elijah Zakirov

container symfony slim di container

11/02 2018

v1.0.0

1.0.0.0 https://github.com/JanGolle/slim-symfony-container

Simple SlimPHP container integration with Symfony dependency injection container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Elijah Zakirov

container symfony slim di container