Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ContainerLoggerTrait | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| initContainer | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\oatbox\log; |
| 23 | |
| 24 | use oat\oatbox\PimpleContainerTrait; |
| 25 | use Pimple\Container; |
| 26 | |
| 27 | trait ContainerLoggerTrait |
| 28 | { |
| 29 | // Adding container. |
| 30 | use PimpleContainerTrait; |
| 31 | |
| 32 | // Adding logger. |
| 33 | use LoggerAwareTrait; |
| 34 | |
| 35 | /** |
| 36 | * Initialize the container and the logger. |
| 37 | * |
| 38 | * @param Container $container The dependency container instance. |
| 39 | * @param string $key The returning dependency key. |
| 40 | * |
| 41 | * @return mixed |
| 42 | */ |
| 43 | public function initContainer($container, $key = '') |
| 44 | { |
| 45 | if ($container instanceof Container) { |
| 46 | $this->setContainer($container); |
| 47 | $this->setLogger( |
| 48 | $this->getContainer()->offsetGet(LoggerService::SERVICE_ID)->getLogger() |
| 49 | ); |
| 50 | |
| 51 | // @TODO: implemented because of the legacy, we will don't need it when we're using the container in every |
| 52 | // case. |
| 53 | if (!empty($key)) { |
| 54 | try { |
| 55 | return $this->getContainer()->offsetGet($key); |
| 56 | } catch (\InvalidArgumentException $e) { |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | return $container; |
| 64 | } |
| 65 | } |