FlashServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 1 1
A register() 0 17 3
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2017-2019 Atanas Angelov
6
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7
 * @link      https://wpemerge.com/
8
 */
9
10
namespace WPEmerge\Flash;
11
12
use WPEmerge\ServiceProviders\ServiceProviderInterface;
13
14
/**
15
 * Provide flash dependencies.
16
 *
17
 * @codeCoverageIgnore
18
 */
19
class FlashServiceProvider implements ServiceProviderInterface {
20
	/**
21
	 * {@inheritDoc}
22
	 */
23
	public function register( $container ) {
24
		$container[ WPEMERGE_FLASH_KEY ] = function ( $c ) {
25
			$session = null;
26
			if ( isset( $c[ WPEMERGE_SESSION_KEY ] ) ) {
27
				$session = &$c[ WPEMERGE_SESSION_KEY ];
28
			} else if ( isset( $_SESSION ) ) {
29
				$session = &$_SESSION;
30
			}
31
			return new Flash( $session );
32
		};
33
34
		$container[ FlashMiddleware::class ] = function ( $c ) {
35
			return new FlashMiddleware( $c[ WPEMERGE_FLASH_KEY ] );
36
		};
37
38
		$app = $container[ WPEMERGE_APPLICATION_KEY ];
39
		$app->alias( 'flash', WPEMERGE_FLASH_KEY );
40
	}
41
42
	/**
43
	 * {@inheritDoc}
44
	 */
45
	public function bootstrap( $container ) {
46
		// Nothing to bootstrap.
47
	}
48
}
49