aboutsummaryrefslogtreecommitdiff
path: root/lib/helpers.php
blob: d851d73b5bc5d8dde06cef32fe325835c46a976c (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
<?php

use Psr\Container\ContainerInterface;

/**
 * This function returns the Dependency Injection container used.
 *
 * ```
 * $container = app();
 * ```
 *
 * You may pass a class or interface name to resolve it from the container:
 *
 * ```
 * $logger = app(LoggerInterface::class);
 * ```
 *
 * @param string|null $entryId
 *
 * @return ContainerInterface|mixed either the DI container or the entry associated to the $entryId
 */
function app($entryId = null)
{
    $container = \Studip\DIContainer::getInstance();
    if (is_null($entryId)) {
        return $container;
    }

    return $container->get($entryId);
}