You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.4 KiB

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