PluginProbe
Code Snippets / 3.10.1
Code Snippets v3.10.1
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / Flat_Files / Handler_Registry.php

Handler_Registry.php in Code Snippets 3.10.1, at php/Flat_Files/Handler_Registry.php

55 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 Code_Snippets\Flat_Files;
4
5 use Code_Snippets\Flat_Files\Interfaces\Snippet_Type_Handler;
6
7 /**
8 * Class for storing registered handlers for converting the different snippet types into flat files.
9 *
10 * @package Code_Snippets
11 */
12 class Handler_Registry {
13
14 /**
15 * List of type handlers.
16 *
17 * @var Snippet_Type_Handler[]
18 */
19 private array $handlers = [];
20
21 /**
22 * Constructor.
23 *
24 * @param Snippet_Type_Handler[] $handlers Snippet type handlers to register.
25 */
26 public function __construct( array $handlers ) {
27 foreach ( $handlers as $type => $handler ) {
28 $this->register_handler( $type, $handler );
29 }
30 }
31
32 /**
33 * Registers a handler for a snippet type.
34 *
35 * @param string $type Handler key.
36 * @param Snippet_Type_Handler $handler Handler class.
37 *
38 * @return void
39 */
40 public function register_handler( string $type, Snippet_Type_Handler $handler ): void {
41 $this->handlers[ $type ] = $handler;
42 }
43
44 /**
45 * Gets the handler for a snippet type.
46 *
47 * @param string $type Handler key.
48 *
49 * @return Snippet_Type_Handler|null
50 */
51 public function get_handler( string $type ): ?Snippet_Type_Handler {
52 return $this->handlers[ $type ] ?? null;
53 }
54 }
55