FactoryClass.php
1.4 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
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
<?php
/*
Copyright (c) 2009 hamcrest.org
*/
class FactoryClass
{
/**
* @var string
*/
private $file;
/**
* @var ReflectionClass
*/
private $reflector;
/**
* @var array
*/
private $methods;
public function __construct($file, ReflectionClass $class)
{
$this->file = $file;
$this->reflector = $class;
$this->extractFactoryMethods();
}
public function extractFactoryMethods()
{
$this->methods = array();
foreach ($this->getPublicStaticMethods() as $method) {
if ($method->isFactory()) {
$this->methods[] = $method;
}
}
}
public function getPublicStaticMethods()
{
$methods = array();
foreach ($this->reflector->getMethods(ReflectionMethod::IS_STATIC) as $method) {
if ($method->isPublic() && $method->getDeclaringClass() == $this->reflector) {
$methods[] = new FactoryMethod($this, $method);
}
}
return $methods;
}
public function getFile()
{
return $this->file;
}
public function getName()
{
return $this->reflector->name;
}
public function isFactory()
{
return !empty($this->methods);
}
public function getMethods()
{
return $this->methods;
}
}