1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Repository\CommitMessage; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class MergeTemplateFactory |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Merge templates. |
19
|
|
|
* |
20
|
|
|
* @var AbstractMergeTemplate[] |
21
|
|
|
*/ |
22
|
|
|
protected $mergeTemplates = array(); |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Adds merge template. |
26
|
|
|
* |
27
|
|
|
* @param AbstractMergeTemplate $merge_template Merge template. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
* @throws \LogicException When merge template is already added. |
31
|
|
|
*/ |
32
|
4 |
|
public function add(AbstractMergeTemplate $merge_template) |
33
|
|
|
{ |
34
|
4 |
|
$name = $merge_template->getName(); |
35
|
|
|
|
36
|
4 |
|
if ( array_key_exists($name, $this->mergeTemplates) ) { |
37
|
1 |
|
throw new \LogicException('The merge template with "' . $name . '" name is already added.'); |
38
|
|
|
} |
39
|
|
|
|
40
|
4 |
|
$this->mergeTemplates[$name] = $merge_template; |
41
|
4 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Gets merge template by name. |
45
|
|
|
* |
46
|
|
|
* @param string $name Merge template name. |
47
|
|
|
* |
48
|
|
|
* @return AbstractMergeTemplate |
49
|
|
|
* @throws \LogicException When merge template wasn't found. |
50
|
|
|
*/ |
51
|
2 |
|
public function get($name) |
52
|
|
|
{ |
53
|
2 |
|
if ( !array_key_exists($name, $this->mergeTemplates) ) { |
54
|
1 |
|
throw new \LogicException('The merge template with "' . $name . '" name is not found.'); |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
return $this->mergeTemplates[$name]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns merge template names. |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
1 |
|
public function getNames() |
66
|
|
|
{ |
67
|
1 |
|
return array_keys($this->mergeTemplates); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|