Closed mbretter closed 8 years ago
Implement your own and override the Slim\Container
.
Please don't open multiple issues on the same topic.
copying all of the Slim\Container code just for adding some php doc, really?
If you need them yes.
@mbretter I started use league/container
as container. Using this service provider class. You can customize it what you need.
<?php namespace App\ServiceProviders;
use League\Container\ServiceProvider\AbstractServiceProvider;
use Slim\CallableResolver;
use Slim\Collection;
use Slim\Handlers\Error;
use Slim\Handlers\NotAllowed;
use Slim\Handlers\NotFound;
use Slim\Handlers\Strategies\RequestResponse;
use Slim\Http\Environment;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Router;
class SlimServiceProvider extends AbstractServiceProvider
{
/**
* @var array
*/
private $settings = [
'httpVersion' => '1.1',
'responseChunkSize' => 4096,
'outputBuffering' => 'append',
'determineRouteBeforeAppMiddleware' => false,
'displayErrorDetails' => false
];
/**
* @param array $settings
*/
public function __construct(array $settings = [])
{
$this->settings = array_merge($this->settings, $settings);
}
/**
* @var array
*/
protected $provides = [
'settings',
'environment',
'request',
'response',
'router',
'foundHandler',
'errorHandler',
'notFoundHandler',
'notAllowedHandler',
'callableResolver'
];
/**
* Use the register method to register items with the container via the
* protected $this->container property or the `getContainer` method
* from the ContainerAwareTrait.
*
* @return void
*/
public function register()
{
$this->container->share('settings', function() {
return new Collection($this->settings);
});
$this->container->share('environment', function() {
return new Environment($_SERVER);
});
$this->container->share('request', function() {
return Request::createFromEnvironment($this->container->get('environment'));
});
$this->container->share('response', function() {
$headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
$response = new Response(200, $headers);
return $response->withProtocolVersion($this->container->get('settings')['httpVersion']);
});
$this->container->share('router', function() {
return new Router();
});
$this->container->share('foundHandler', function() {
return new RequestResponse();
});
$this->container->share('errorHandler', function() {
return new Error($this->container->get('settings')['displayErrorDetails']);
});
$this->container->share('notFoundHandler', function() {
return new NotFound();
});
$this->container->share('notAllowedHandler', function() {
return new NotAllowed();
});
$this->container->share('callableResolver', function() {
return new CallableResolver($this->container);
});
}
}
thx, switching to a different container implementation looks like a good idea ...
It's related to https://github.com/slimphp/Slim/issues/1652
I would like to extend \Slim\Container just for putting my @property-read phpdoc, so that IDEs code completion works properly.
any ideas?