Skip to content

Commit

Permalink
Merge pull request #45 from samsonasik/pimple-support
Browse files Browse the repository at this point in the history
Add Pimple support
  • Loading branch information
samsonasik authored May 29, 2018
2 parents bfe8085 + 1ab89f1 commit 2039ddb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "samsonasik/error-hero-module",
"type": "library",
"description": "A Hero for your Zend Framework application to trap php errors & exceptions",
"keywords": ["zf2", "zf3", "error", "expressive", "hero", "log", "logger", "logging", "mail", "db", "doctrine", "handler", "psr3", "psr7", "psr11", "psr15", "zend-view", "twig", "plates", "symfony", "aura", "auryn"],
"keywords": ["zf2", "zf3", "error", "expressive", "hero", "log", "logger", "logging", "mail", "db", "doctrine", "handler", "psr3", "psr7", "psr11", "psr15", "zend-view", "twig", "plates", "symfony", "aura", "auryn", "pimple"],
"homepage": "https://github.com/samsonasik/ErrorHeroModule",
"license": "MIT",
"authors": [
Expand Down Expand Up @@ -33,6 +33,7 @@
"php-coveralls/php-coveralls": "^2.0",
"phpstan/phpstan": "0.10.xdev",
"phpstan/phpstan-beberlei-assert": "0.10.xdev",
"pimple/pimple": "^3.2",
"symfony/dependency-injection": "^4.0",
"zendframework/zend-expressive": "^3.0",
"zendframework/zend-expressive-zendviewrenderer": "^2.0",
Expand Down
3 changes: 3 additions & 0 deletions spec/Middleware/ExpressiveFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use ErrorHeroModule\Spec\Fixture\NotSupportedContainer;
use Kahlan\Plugin\Double;
use Northwoods\Container\InjectorContainer as AurynInjectorContainer;
use Pimple\Container as PimpleContainer;
use Pimple\Psr11\Container as Psr11PimpleContainer;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
use Zend\Db\Adapter\Adapter;
Expand All @@ -31,6 +33,7 @@
AuraContainer::class => (new AuraContainerBuilder())->newInstance(),
SymfonyContainerBuilder::class => new SymfonyContainerBuilder(),
AurynInjectorContainer::class => new AurynInjectorContainer(new AurynInjector()),
Psr11PimpleContainer::class => new Psr11PimpleContainer(new PimpleContainer()),
];
});

Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/ExpressiveFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use ErrorHeroModule\Transformer\AuraService;
use ErrorHeroModule\Transformer\AurynService;
use ErrorHeroModule\Transformer\Doctrine;
use ErrorHeroModule\Transformer\PimpleService;
use ErrorHeroModule\Transformer\SymfonyService;
use Northwoods\Container\InjectorContainer as AurynInjectorContainer;
use Pimple\Psr11\Container as Psr11PimpleContainer;
use Psr\Container\ContainerInterface;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
Expand All @@ -24,6 +26,7 @@ class ExpressiveFactory
SymfonyContainerBuilder::class => SymfonyService::class,
AuraContainer::class => AuraService::class,
AurynInjectorContainer::class => AurynService::class,
Psr11PimpleContainer::class => PimpleService::class,
];

private function createMiddlewareInstance(ContainerInterface $container, array $configuration) : Expressive
Expand Down
28 changes: 28 additions & 0 deletions src/Transformer/PimpleService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace ErrorHeroModule\Transformer;

use Assert\Assertion;
use Closure;
use Pimple\Psr11\Container as Psr11PimpleContainer;
use Psr\Container\ContainerInterface;

class PimpleService extends TransformerAbstract implements TransformerInterface
{
public static function transform(ContainerInterface $container, array $configuration) : ContainerInterface
{
Assertion::isInstanceOf($container, Psr11PimpleContainer::class);

$dbAdapterConfig = parent::getDbAdapterConfig($configuration);
$logger = parent::getLoggerInstance($configuration, $dbAdapterConfig);

$pimple = & Closure::bind(function & ($container) {
return $container->pimple;
}, null, $container)($container);
$pimple['ErrorHeroModuleLogger'] = $logger;

return $container;
}
}

0 comments on commit 2039ddb

Please sign in to comment.