forked from ScrumBoard-it/ScrumBoard-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryInterface.php
More file actions
45 lines (37 loc) · 1.06 KB
/
FactoryInterface.php
File metadata and controls
45 lines (37 loc) · 1.06 KB
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
<?php
namespace CanalTP\ScrumBoardItBundle;
use CanalTP\ScrumBoardItBundle\Exception\ClassNotFoundException;
/**
* @author Johan Rouve <johan.rouve@gmail.com>
*/
abstract class FactoryInterface {
protected $suffix;
public function __construct($suffix = null) {
if (!is_null($suffix)) {
$this->setSuffix($suffix);
}
}
public function getSuffix() {
return $this->suffix;
}
public function setSuffix($suffix) {
$this->suffix = $suffix;
return $this;
}
public function get($name) {
$className = $name.$this->getSuffix();
$class = $this->getNamespace().'\\'.$className;
if (class_exists($class)) {
$instance = new $class();
return $instance;
} else {
throw new ClassNotFoundException($class);
}
}
public function getNamespace(){
$factoryClass = get_class($this);
$folder = explode('\\', $factoryClass);
array_pop($folder);
return implode('\\', $folder);
}
}