Generator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 112
rs 10
c 0
b 0
f 0
ccs 0
cts 71
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C create() 0 101 7
1
<?php
2
3
/**
4
 * Batch that generate files and folders
5
 *
6
 * @category  	src
7
 * @package   	src\Batch\Controller
8
 * @author    	Judicaël Paquet <[email protected]>
9
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
10
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
11
 * @version   	Release: 2.0.0
12
 * @filesource	https://github.com/las93/venus2
13
 * @link      	https://github.com/las93
14
 * @since     	2.0.0
15
 *
16
 * @tutorial    You could launch this Batch in /private/
17
 * 				php bin/console create_project -p [portal]
18
 * 				-p [portal] => it's the name where you want add your entities and models
19
 * 					by default, it's Batch
20
 */
21
namespace Venus\src\Batch\Controller;
22
23
use \Venus\src\Batch\common\Controller as Controller;
24
25
/**
26
 * Batch that generate files and folders
27
 *
28
 * @category  	src
29
 * @package   	src\Batch\Controller
30
 * @author    	Judicaël Paquet <[email protected]>
31
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
32
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
33
 * @version   	Release: 2.0.0
34
 * @filesource	https://github.com/las93/venus2
35
 * @link      	https://github.com/las93
36
 * @since     	2.0.0
37
 */
38
class Generator extends Controller
39
{
40
	/**
41
	 * run the batch to create a project in this framework
42
	 * @tutorial bin/console create_project
43
	 *
44
	 * @access public
45
	 * @param array $aOptions
46
	 * @throws \Exception
47
	 */
48
	public function create(array $aOptions = array())
49
	{
50
		/**
51
		 * option -p [portail]
52
		 */
53
		if (isset($aOptions['p'])) { $sPortal = $aOptions['p']; }
54
		else { $sPortal = 'Batch'; }
55
56
		if (!preg_match('/^[a-zA-Z0-9]+$/', $sPortal)) {
57
58
			echo 'You can`t create this portail :'.$sPortal.'! The name must containt just letters and numbers.';
59
			throw new \Exception('You can`t create this portail :'.$sPortal.'! The name must containt just letters and numbers.');
60
		}
61
62
		$sActualDirectory = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__);
63
		$sPrivatePath = str_replace('/Batch/app/Controller', DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app', $sActualDirectory).DIRECTORY_SEPARATOR;
64
        $sPublicPath = str_replace('/Batch/app/Controller', DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'public', $sActualDirectory).DIRECTORY_SEPARATOR;
65
66
        if (!is_writable($sActualDirectory.'/../../../')) {
67
68
            echo 'The batch can`t create public folders for '.$sPortal.'! Please check the rights.';
69
            throw new \Exception('The batch can`t create public folders for '.$sPortal.'! Please check the rights.');
70
        }
71
        else {
72
73
            if (!file_exists($sPrivatePath.'Controller')) {
74
75
                mkdir($sPublicPath . 'css', 0777, true);
76
                mkdir($sPublicPath . 'js', 0777, true);
77
                mkdir($sPublicPath . 'img', 0777, true);
78
            }
79
            else {
80
81
                echo 'The Project (public part) ' . $sPrivatePath . " exists\n";
82
            }
83
        }
84
85
		if (!is_writable($sActualDirectory.'/../../../')) {
86
87
			echo 'The batch can`t create private folders for '.$sPortal.'! Please check the rights.';
88
			throw new \Exception('The batch can`t create private folders for '.$sPortal.'! Please check the rights.');
89
		}
90
		else {
91
92
			if (!file_exists($sPrivatePath.'Controller')) {
93
94
				mkdir($sPrivatePath . 'Controller', 0777, true);
95
				mkdir($sPrivatePath . 'Entity', 0777, true);
96
				mkdir($sPrivatePath . 'Model', 0777, true);
97
				mkdir($sPrivatePath . 'View', 0777, true);
98
				mkdir($sPrivatePath . 'conf', 0777, true);
99
				mkdir($sPrivatePath . 'common', 0777, true);
100
101
                $sContent = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'common'.DIRECTORY_SEPARATOR.'Controller.php');
102
                $sContent = str_replace('Batch', $sPortal, $sContent);
103
                file_put_contents($sPrivatePath.'common'.DIRECTORY_SEPARATOR.'Controller.php', $sContent);
104
105
                $sContent = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'common'.DIRECTORY_SEPARATOR.'Model.php');
106
                $sContent = str_replace('Batch', $sPortal, $sContent);
107
                file_put_contents($sPrivatePath.'common'.DIRECTORY_SEPARATOR.'Model.php', $sContent);
108
109
                $sContent = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'common'.DIRECTORY_SEPARATOR.'Entity.php');
110
                $sContent = str_replace('Batch', $sPortal, $sContent);
111
                file_put_contents($sPrivatePath.'common'.DIRECTORY_SEPARATOR.'Entity.php', $sContent);
112
113
                $content = "<?php
114
115
namespace Venus\\src\\".$sPortal."\\Controller;
116
117
use \\Venus\\src\\".$sPortal."\\common\\Controller as Controller;
118
119
class ".$sPortal." extends Controller {
120
121
	public function __construct() {
122
123
		parent::__construct();
124
	}
125
126
	public function show() {
127
        ;
128
	}
129
}
130
";
131
132
                file_put_contents($sPrivatePath.'Controller'.DIRECTORY_SEPARATOR.$sPortal.'.php', $content);
133
			}
134
			else {
135
136
				echo 'The Project (private part) ' . $sPrivatePath . " exists\n";
137
			}
138
		}
139
140
		echo 'The project '.$sPortal.' is created!';
141
142
143
        echo "\n\n";
144
        echo Bash::setBackground("                                                                            ", 'green');
145
        echo Bash::setBackground("          [OK] The bundle is created                                        ", 'green');
146
        echo Bash::setBackground("                                                                            ", 'green');
147
        echo "\n\n";
148
	}
149
}
150