-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generation.php
52 lines (46 loc) · 1.66 KB
/
Generation.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
50
51
52
<?php
require("Twig.php");
class Generation
{
private $className;
private $properties = array();
private $stopScript = false;
private $twig;
public function __construct()
{
$twig = new Twig('templates');
$this->twig = $twig->getTwig();
echo "Name of the class : \n";
$handle = fopen("php://stdin", "r");
$classNameTemp = fgets($handle);
$this->className = trim($classNameTemp);
fclose($handle);
while (!$this->stopScript) {
echo "Name of attr (:q to quit) : \n";
$attr = fopen("php://stdin", "r");
$content = fgets($attr);
if (trim($content) == ":q") {
$this->stopScript = true;
} else {
$this->properties[] = trim($content);
}
fclose($attr);
}
$this->createServiceClass();
$this->createRepositoryClass();
}
private function createServiceClass()
{
$name = trim($this->className . "Service.php");
$name = $name = preg_replace("/[\n\r]/", "", $name);
$template = $this->twig->render('serviceClass.twig', array("class" => $this->className, "properties" => $this->properties));
file_put_contents($name, $template);
}
private function createRepositoryClass()
{
$name = trim($this->className . "Repository.php");
$name = preg_replace("/[\n\r]/", "", $name);
$template = $this->twig->render('repositoryClass.twig', array("class" => $this->className, "properties" => $this->properties));
file_put_contents($name, $template);
}
}