Failed Conditions
Branch refactor/kernels (cc9370)
by Atanas
02:23
created

src/Flash/FlashServiceProvider.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2018 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\Facades\Application;
13
use WPEmerge\ServiceProviders\ServiceProviderInterface;
14
15
/**
16
 * Provide flash dependencies.
17
 *
18
 * @codeCoverageIgnore
19
 */
20
class FlashServiceProvider implements ServiceProviderInterface {
21
	/**
22
	 * {@inheritDoc}
23
	 */
24
	public function register( $container ) {
25
		$this->registerConfiguration( $container );
26
		$this->registerDependencies( $container );
27
		$this->registerFacades();
28
	}
29
30
	/**
31
	 * Register configuration options.
32
	 *
33
	 * @param  \Pimple\Container $container
34
	 * @return void
35
	 */
36
	protected function registerConfiguration( $container ) {
37
		$container[ WPEMERGE_ROUTING_GLOBAL_MIDDLEWARE_KEY ] = array_merge(
38
			$container[ WPEMERGE_ROUTING_GLOBAL_MIDDLEWARE_KEY ],
39
			[
40
				\WPEmerge\Flash\FlashMiddleware::class,
41
			]
42
		);
43
44
		$container[ WPEMERGE_ROUTING_MIDDLEWARE_PRIORITY_KEY ] = array_merge(
45
			$container[ WPEMERGE_ROUTING_MIDDLEWARE_PRIORITY_KEY ],
46
			[
47
				\WPEmerge\Flash\FlashMiddleware::class => 10,
48
			]
49
		);
50
	}
51
52
	/**
53
	 * Register dependencies.
54
	 *
55
	 * @param  \Pimple\Container $container
56
	 * @return void
57
	 */
58
	protected function registerDependencies( $container ) {
59
		$container[ WPEMERGE_FLASH_KEY ] = function ( $c ) {
60
			$session = null;
61
			if ( isset( $c[ WPEMERGE_SESSION_KEY ] ) ) {
62
				$session = &$c[ WPEMERGE_SESSION_KEY ];
63
			} else if ( isset( $_SESSION ) ) {
64
				$session = &$_SESSION;
65
			}
66
			return new \WPEmerge\Flash\Flash( $session );
67
		};
68
	}
69
70
	/**
71
	 * Register facades.
72
	 *
73
	 * @return void
74
	 */
75
	protected function registerFacades() {
76
		Application::facade( 'Flash', \WPEmerge\Facades\Flash::class );
0 ignored issues
show
The method facade() does not exist on WPEmerge\Facades\Application. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
		Application::/** @scrutinizer ignore-call */ 
77
               facade( 'Flash', \WPEmerge\Facades\Flash::class );
Loading history...
77
	}
78
79
	/**
80
	 * {@inheritDoc}
81
	 */
82
	public function bootstrap( $container ) {
83
		// Nothing to bootstrap.
84
	}
85
}
86