GlobalFunctionFile.php 931 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 .= PHP_EOL . $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()}')) {";
  31. $code.= parent::generateFactoryCall($call);
  32. $code.= "}\n";
  33. return $code;
  34. }
  35. }