Container-Interop wrapper for Pimple 3.0

While the Pimple developers are waiting for the PSR it does not mean you have too.

  • container-interop
Published
Updated

PHP middleware is growing fast these days. One of the nicest features is that you can mix and match different packages from different frameworks or even use standalone packages.

For dependency containers this is now really easy if they implement the ContainerInterface. For Pimple 1.x the is the pimle-interop wrapper. For Pimple 3.x there isn’t one yet and the developpers have decided to wait unit container-interop is accepted as a PSR. But this doesn’t mean you have to wait…

Use this code as a wrapper and you are done.

<?php

namespace Pimple;

use Pimple\Container as Pimple;
use Interop\Container\ContainerInterface;

/**
 * ContainerInterface wrapper for Pimple 3.0
 */
class PimpleContainer extends Pimple implements ContainerInterface
{
    public function get($id)
    {
        return $this->offsetGet($id);
    }
    public function has($id)
    {
        return $this->offsetExists($id);
    }
}