Issues (16)

config/container.php (1 issue)

1
<?php
2
3
use App\Storage\Pdo;
4
use Awurth\SlimValidation\Validator;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Validator. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use Cartalyst\Sentinel\Native\Facades\Sentinel;
6
use Cartalyst\Sentinel\Native\SentinelBootstrapper;
7
use Illuminate\Database\Capsule\Manager;
8
use Monolog\Handler\StreamHandler;
9
use Monolog\Logger;
10
use Monolog\Processor\UidProcessor;
11
use OAuth2\Server;
12
use OAuth2\GrantType\RefreshToken;
13
use OAuth2\GrantType\UserCredentials;
14
15
$capsule = new Manager();
16
$capsule->addConnection($container['settings']['eloquent']);
17
$capsule->setAsGlobal();
18
$capsule->bootEloquent();
19
20
$container['sentinel'] = function ($container) {
21
    $sentinel = new Sentinel(new SentinelBootstrapper($container['settings']['sentinel']));
22
    return $sentinel->getSentinel();
23
};
24
25
$container['oauth'] = function ($container) use ($capsule) {
26
    $storage = new Pdo($capsule->getConnection()->getPdo(), $container['settings']['oauth']['pdo']);
27
28
    $server = new Server($storage);
29
    $server->addGrantType(new UserCredentials($storage));
30
    $server->addGrantType(new RefreshToken($storage));
31
32
    return $server;
33
};
34
35
$container['validator'] = function () {
36
    return new Validator(false);
37
};
38
39
$container['monolog'] = function ($container) {
40
    $config = $container['settings']['monolog'];
41
42
    $logger = new Logger($config['name']);
43
    $logger->pushProcessor(new UidProcessor());
44
    $logger->pushHandler(new StreamHandler($config['path'], $config['level']));
45
46
    return $logger;
47
};
48