Completed
Pull Request — master (#33)
by Martijn
02:35
created

TypeRegistry::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SwaggerGen;
4
5
/**
6
 * Registry of custom types.
7
 *
8
 * @package    SwaggerGen
9
 * @author     Martijn van der Lee <[email protected]>
10
 * @copyright  2014-2017 Martijn van der Lee
11
 * @license    https://opensource.org/licenses/MIT MIT
12
 */
13
class TypeRegistry
14
{
15
16
	/**
17
	 * Map of format-name => class-name
18
	 * 
19
	 * @var array
20
	 */
21
	private $formats = array();
22
23
	/**
24
	 * Add a type name from classname
25
	 * 
26
	 * @param type $classname
27
	 */
28
	public function add($classname)
29
	{
30
		if (is_subclass_of($classname, '\\SwaggerGen\\Swagger\\Type\\Custom\\ICustomType', true)) {
31
			foreach ($classname::getFormats() as $format) {
32
				$this->formats[$format] = $classname;
33
			}
34
		}
35
	}
36
37
	/**
38
	 * Remove type format by explicitely nulling it (disables it)
39
	 * 
40
	 * @param string $name
41
	 */
42
	public function remove($name)
43
	{
44
		$this->formats[$name] = null;
45
	}
46
47
	/**
48
	 * Is a type format known?
49
	 * 
50
	 * @return bool
51
	 */
52
	public function has($name)
53
	{
54
		return !empty($this->formats[$name]);
55
	}
56
57
	/**
58
	 * Get the format class name
59
	 * 
60
	 * @return null|string
61
	 */
62
	public function get($name)
63
	{
64
		return !empty($this->formats[$name]) ? $this->formats[$name] : null;
65
	}
66
67
}
68