PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.0
Defender Security – Malware Scanner, Login Security & Firewall v5.7.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / extra / plugins-cross-sell-page / core / class-container.php

class-container.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.0, at extra/plugins-cross-sell-page/core/class-container.php

64 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Container class used for DI.
4 *
5 * @link https://wpmudev.com/
6 * @since 1.0.0
7 *
8 * @author WPMUDEV (https://wpmudev.com)
9 * @package WPMUDEV/Plugin_Cross_Sell
10 *
11 * @copyright (c) 2025, Incsub (http://incsub.com)
12 */
13
14 namespace WPMUDEV\Modules\Plugin_Cross_Sell;
15
16 /**
17 * Dependency Injection Container class.
18 *
19 * @since 1.0.0
20 */
21 class Container {
22 /**
23 * Services list.
24 *
25 * @var array
26 */
27 private $services = array();
28
29 /**
30 * Pushes a service into the container.
31 *
32 * @param string $key Service key.
33 * @param mixed $value Service.
34 * @return void
35 */
36 public function set( string $key, $value ): void {
37 $this->services[ $key ] = $value;
38 }
39
40 /**
41 * Fetches a service from the container.
42 *
43 * @param string $key Service key.
44 * @throws \InvalidArgumentException If service not found.
45 */
46 public function get( string $key ) {
47 if ( ! isset( $this->services[ $key ] ) ) {
48 throw new \InvalidArgumentException( esc_html( "Service '{$key}' not found in container." ) );
49 }
50
51 return $this->services[ $key ];
52 }
53
54 /**
55 * Checks if a service is registered.
56 *
57 * @param string $key Service key.
58 * @return bool
59 */
60 public function has( string $key ): bool {
61 return isset( $this->services[ $key ] );
62 }
63 }
64