This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AbstractBaseContainer.php
87 lines (77 loc) · 2.5 KB
/
AbstractBaseContainer.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Dhii\Di;
use Dhii\Data\Container\NormalizeContainerCapableTrait;
use Dhii\Util\Normalization\NormalizeArrayCapableTrait;
use Dhii\Util\Normalization\NormalizeStringCapableTrait;
use Psr\Container\ContainerExceptionInterface;
use Dhii\Util\String\StringableInterface as Stringable;
use Exception as RootException;
use Psr\Container\ContainerInterface as BaseContainerInterface;
use Dhii\Data\Container\AbstractBaseContainer as BaseAbstractBaseContainer;
/**
* Common functionality for regular DI containers.
*
* @since [*next-version*]
*/
abstract class AbstractBaseContainer extends BaseAbstractBaseContainer
{
/* Data object methods.
*
* @since [*next-version*]
*/
use DataObjectTrait;
/* Ability to normalize into an array.
*
* @since [*next-version*]
*/
use NormalizeArrayCapableTrait;
/* Ability to normalize into a container.
*
* @since [*next-version*]
*/
use NormalizeContainerCapableTrait;
/* Ability to normalize into a string.
*
* @since [*next-version*]
*/
use NormalizeStringCapableTrait;
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
public function get($key)
{
return $this->_getService($key);
}
/**
* Throws a container exception.
*
* @param string|Stringable|null $message The exception message, if any.
* @param int|string|Stringable|null $code The numeric exception code, if any.
* @param RootException|null $previous The inner exception, if any.
* @param BaseContainerInterface|null $container The associated container, if any. Pass `true` to use available container.
*
* @throws ContainerExceptionInterface
*/
protected function _throwContainerException($message = null, $code = null, $previous = null, $container = null)
{
$container = $container === true
? $this
: $container;
throw $this->_createContainerException($message, $code, $previous, $container);
}
/**
* Retrieves a service by key.
*
* @since [*next-version*]
*
* @param string|int|float|bool|Stringable $key The key, for which to get the service.
*
* @throw NotFoundExceptionInterface If no service or definition found for key.
* @throw ContainerExceptionInterface If service or service definition could not be retrieved.
*
* @return mixed The corresponding service.
*/
abstract protected function _getService($key);
}