RoboFile.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. require __DIR__.'/vendor/autoload.php';
  3. /**
  4. * This is project's console commands configuration for Robo task runner.
  5. *
  6. * @see http://robo.li/
  7. */
  8. class RoboFile extends \Robo\Tasks
  9. {
  10. /**
  11. * Generates fault exception classes
  12. */
  13. public function faults()
  14. {
  15. $faultReflection = new \ReflectionClass('Supervisor\Exception\Fault');
  16. $faults = array_flip($faultReflection->getConstants());
  17. $this->taskCleanDir([__DIR__.'/src/Exception/Fault'])->run();
  18. foreach ($faults as $code => $name) {
  19. $exName = $this->createExceptionName($name);
  20. $file = sprintf(__DIR__.'/src/Exception/Fault/%s.php', $exName);
  21. $this->taskWriteToFile($file)
  22. ->textFromFile(__DIR__.'/resources/FaultTemplate.php')
  23. ->place('FAULT_NAME', $name)
  24. ->place('FaultName', $exName)
  25. ->run();
  26. }
  27. }
  28. /**
  29. * Returns a CamelCased exception name from UNDER_SCORED fault string
  30. *
  31. * @param string $faultString
  32. *
  33. * @return string
  34. */
  35. protected function createExceptionName($faultString)
  36. {
  37. $parts = explode('_', $faultString);
  38. $parts = array_map(function($el) { return ucfirst(strtolower($el)); }, $parts);
  39. return implode('', $parts);
  40. }
  41. }