7 Service Provider Minimal Example
Vasily Komrakov edited this page 2017-01-13 16:18:02 +03:00

$container property name MUST be equals to the first word of class name in lower case: ExampleServiceProvider -> example.

namespace TorrentPier\ServiceProviders;

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use ExampleNamespace\Example;

/**
 * Class ExampleServiceProvider
 * @package TorrentPier\ServiceProviders
*/
class ExampleServiceProvider implements ServiceProviderInterface
{
    /**
     * @inheritdoc
     */
    public function register(Container $container)
    {
        $container['example'] = function (Container $container) {
            return new Example();
        };
    }
}