akrabat / rka-slim-zfsm-container

Integration of Zend\ServiceManager into Slim 3
BSD 3-Clause "New" or "Revised" License
9 stars 3 forks source link

Can't set custom errorHandler #2

Closed garethellis36 closed 9 years ago

garethellis36 commented 9 years ago

Hello,

I'm completely new to using Zend Service Manager and implemented it in a new Slim app I am working on after reading this blog post about abstract factories by you.

After I had done this I then wanted to set-up a custom error handler to render a nice error page with Twig and I followed the instructions in this blog post, also by you.

When I try to define $container['errorHandler'], Zend\ServiceManager\Exception\InvalidServiceNameException is thrown with message A service by the name or alias "errorHandler" already exists and cannot be overridden, please use an alternate name.

Having looked at the source for your Container class, this appears to be hard-coded to use the built-in Slim error handler. Do I understand this correctly? If so, would you consider a PR for being able to pass in some alternatives for the hard-coded handlers?

garethellis36 commented 9 years ago

I just discovered ServiceManager::setAllowOverride() which simultaneously solved my problem and ruined my evening. Sorry to bother you!! :)

akrabat commented 9 years ago

I will be updating to match how it works with Slim\Container, so in future you can pass in overrides into the constructor.

e.g.

$containerSettings = [
    'invokeables' => [
        'errorHandler' => My\ErrorHandler::class,
    ],
    'settings' => [
         'setting1' => true,
    ],
];

This will be a BC break when it happens though, so look out for it!