aboutsummaryrefslogtreecommitdiff
path: root/lib/helpers.php
blob: 9bfedb1b17366628f397807beb6f14683a66e4bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

use Psr\Container\ContainerInterface;

/**
 * This function returns the Dependency Injection container used.
 *
 * ```
 * $container = app();
 * ```
 *
 * You may pass an entry name, a class or interface name to resolve it from the container:
 *
 * ```
 * $logger = app(LoggerInterface::class);
 * ```
 * @template T
 * @param T|class-string<T>|string|null $entryId    entry name or a class name
 * @param array       $parameters Optional parameters to use to build the entry.
 *                                Use this to force specific parameters to specific values.
 *                                Parameters not defined in this array will be resolved using the container.
 *
 * @return T|ContainerInterface|mixed either the DI container or the entry associated to the $entryId
 */
function app($entryId = null, $parameters = [])
{
    $container = \Studip\DIContainer::getInstance();
    if (is_null($entryId)) {
        return $container;
    }

    return $container->make($entryId, $parameters);
}

/**
 * @return \Studip\Session\Manager
 */
function sess() : Studip\Session\Manager
{
    return app()->get(Studip\Session\Manager::class);
}

/**
 * @return \Studip\Authentication\Manager
 */
function auth() : Studip\Authentication\Manager
{
    return app()->get(Studip\Authentication\Manager::class);
}