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.

42 lines
930 B

3 years ago
  1. <?php
  2. /*
  3. Copyright (c) 2009 hamcrest.org
  4. */
  5. class GlobalFunctionFile extends FactoryFile
  6. {
  7. /**
  8. * @var string containing function definitions
  9. */
  10. private $functions;
  11. public function __construct($file)
  12. {
  13. parent::__construct($file, ' ');
  14. $this->functions = '';
  15. }
  16. public function addCall(FactoryCall $call)
  17. {
  18. $this->functions .= "\n" . $this->generateFactoryCall($call);
  19. }
  20. public function build()
  21. {
  22. $this->addFileHeader();
  23. $this->addPart('functions_imports');
  24. $this->addPart('functions_header');
  25. $this->addCode($this->functions);
  26. $this->addPart('functions_footer');
  27. }
  28. public function generateFactoryCall(FactoryCall $call)
  29. {
  30. $code = "if (!function_exists('{$call->getName()}')) {\n";
  31. $code.= parent::generateFactoryCall($call);
  32. $code.= "}\n";
  33. return $code;
  34. }
  35. }