-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranslationTypeCollection.php
85 lines (71 loc) · 1.52 KB
/
TranslationTypeCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Bixie\Languagemanager\TranslationType;
class TranslationTypeCollection implements \IteratorAggregate, \Countable {
/**
* @var TranslationType[]
*/
protected $types;
/**
* Constructor.
* @param array $types
*/
public function __construct (array $types = []) {
foreach ($types as $name => $data) {
$this->add(new TranslationType($name, $data));
}
}
/**
* Gets pricefactor from collection.
* @param string $name
* @return TranslationType
*/
public function get ($name) {
return isset($this->types[$name]) ? $this->types[$name] : null;
}
/**
* Registers types to collection.
* @param array $types
*/
public function register ($types) {
foreach ((array) $types as $name => $data) {
$this->add(new TranslationType($name, $data));
}
}
/**
* Adds type to collection.
* @param TranslationType $type
*/
public function add (TranslationType $type) {
$this->types[$type->getName()] = $type;
}
/**
* @return TranslationType[]
*/
public function all () {
return $this->types;
}
/**
* Removes types from collection.
* @param string|array $name
*/
public function remove ($name) {
$names = (array)$name;
foreach ($names as $name) {
unset($this->types[$name]);
}
}
/**
* Countable interface implementation.
* @return int
*/
public function count () {
return count($this->types);
}
/**
* IteratorAggregate interface implementation.
* @return \ArrayIterator
*/
public function getIterator () {
return new \ArrayIterator($this->types);
}
}