PluginProbe
Hello Plus / 1.2.0
Hello Plus v1.2.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / forms / registrars / registrar.php

registrar.php in Hello Plus 1.2.0, at modules/forms/registrars/registrar.php

69 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 namespace HelloPlus\Modules\Forms\Registrars;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 /**
10 * Basic items registrar.
11 *
12 * TODO: Move to Core.
13 */
14 class Registrar {
15
16 /**
17 * @var array
18 */
19 private $items;
20
21 /**
22 * Registrar constructor.
23 *
24 * @return void
25 */
26 public function __construct() {
27 $this->items = [];
28 }
29
30 /**
31 * Register a new item.
32 *
33 * @param $instance - Item instance.
34 * @param string $id - Optional - For BC - Deprecated.
35 *
36 * @return boolean - Whether the item was registered.
37 */
38 public function register( $instance, $id = null ) {
39 // TODO: For BC. Remove in the future.
40 if ( ! $id ) {
41 // Get the ID or default to the class name.
42 $id = ( method_exists( $instance, 'get_id' ) ) ? $instance->get_id() : get_class( $instance );
43 }
44
45 if ( $this->get( $id ) ) {
46 return false;
47 }
48
49 $this->items[ $id ] = $instance;
50
51 return true;
52 }
53
54 /**
55 * Get an item by ID.
56 *
57 * @param string $id
58 *
59 * @return array|null
60 */
61 public function get( $id = null ) {
62 if ( ! $id ) {
63 return $this->items;
64 }
65
66 return isset( $this->items[ $id ] ) ? $this->items[ $id ] : null;
67 }
68 }
69