Passed
Push — master ( ca0a0b...aa0ed6 )
by Atanas
02:10
created

Extend::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 3
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Obsidian;
4
5
use Exception;
6
use Obsidian\Support\Arr;
7
use Obsidian\Routing\Conditions\ConditionInterface;
8
9
/**
10
 * Extend built-in functionality
11
 *
12
 * @codeCoverageIgnore
13
 */
14
class Extend {
15
	/**
16
	 * Dictionary of extensions
17
	 *
18
	 * @var array
19
	 */
20
	protected static $extensions = [];
21
22
	/**
23
	 * Get extensions for type
24
	 *
25
	 * @param  string $type
26
	 * @return array
27
	 */
28
	public static function get( $type ) {
29
		return Arr::get( static::$extensions, $type );
30
	}
31
32
	/**
33
	 * Set extension for type, with name and class name
34
	 *
35
	 * @throws Exception
36
	 * @param  string $type
37
	 * @param  string $name
38
	 * @param  string $class_name
39
	 * @return void
40
	 */
41
	public static function set( $type, $name, $class_name ) {
42
		if ( Framework::isBooted() ) {
43
			throw new Exception( 'Extensions must be registered before Obsidian is booted.' );
44
		}
45
		Arr::set( static::$extensions, $type . '.' . $name, $class_name );
46
	}
47
48
	/**
49
	 * Register a route condition
50
	 *
51
	 * @param  string $name
52
	 * @param  string $class_name
53
	 * @return void
54
	 */
55
	public static function routeCondition( $name, $class_name ) {
56
		static::set( ConditionInterface::class, $name, $class_name );
57
	}
58
}
59