PluginProbe
Code Snippets / 3.8.1
Code Snippets v3.8.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 / registry.php

registry.php in Code Snippets 3.8.1, at php/flat-files/registry.php

48 lines 997 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets;
4
5 class Snippet_Handler_Registry {
6 /**
7 * @var Snippet_Type_Handler_Interface[]
8 */
9 private array $handlers = [];
10
11 /**
12 * Constructor
13 *
14 * @param Snippet_Type_Handler_Interface[] $handlers
15 */
16 public function __construct( array $handlers ) {
17 foreach ( $handlers as $type => $handler ) {
18 $this->register_handler( $type, $handler );
19 }
20 }
21
22 /**
23 * Registers a handler for a snippet type.
24 *
25 * @param string $type
26 * @param Snippet_Type_Handler_Interface $handler
27 * @return void
28 */
29 public function register_handler( string $type, Snippet_Type_Handler_Interface $handler ): void {
30 $this->handlers[ $type ] = $handler;
31 }
32
33 /**
34 * Gets the handler for a snippet type.
35 *
36 * @param string $type
37 *
38 * @return Snippet_Type_Handler_Interface|null
39 */
40 public function get_handler( string $type ): ?Snippet_Type_Handler_Interface {
41 if ( ! isset( $this->handlers[ $type ] ) ) {
42 return null;
43 }
44
45 return $this->handlers[ $type ];
46 }
47 }
48