Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 Copyright (c) 2009 hamcrest.org
5
 */
6
 
7
class FactoryClass
8
{
9
    /**
10
     * @var string
11
     */
12
    private $file;
13
 
14
    /**
15
     * @var ReflectionClass
16
     */
17
    private $reflector;
18
 
19
    /**
20
     * @var array
21
     */
22
    private $methods;
23
 
24
    public function __construct($file, ReflectionClass $class)
25
    {
26
        $this->file = $file;
27
        $this->reflector = $class;
28
        $this->extractFactoryMethods();
29
    }
30
 
31
    public function extractFactoryMethods()
32
    {
33
        $this->methods = array();
34
        foreach ($this->getPublicStaticMethods() as $method) {
35
            if ($method->isFactory()) {
36
                $this->methods[] = $method;
37
            }
38
        }
39
    }
40
 
41
    public function getPublicStaticMethods()
42
    {
43
        $methods = array();
44
        foreach ($this->reflector->getMethods(ReflectionMethod::IS_STATIC) as $method) {
45
            if ($method->isPublic() && $method->getDeclaringClass() == $this->reflector) {
46
                $methods[] = new FactoryMethod($this, $method);
47
            }
48
        }
49
        return $methods;
50
    }
51
 
52
    public function getFile()
53
    {
54
        return $this->file;
55
    }
56
 
57
    public function getName()
58
    {
59
        return $this->reflector->name;
60
    }
61
 
62
    public function isFactory()
63
    {
64
        return !empty($this->methods);
65
    }
66
 
67
    public function getMethods()
68
    {
69
        return $this->methods;
70
    }
71
}