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