Completed
Push — master ( 28be9d...cc0dae )
by Raphael
02:46
created
src/Scaffolder/Compilers/AngularJs/ListChooseColumnsCompiler.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@
 block discarded – undo
10 10
 
11 11
 class ListChooseColumnsCompiler extends AbstractCompiler
12 12
 {
13
-	protected $cachePrefix 	= 'list_choose_column_';
14
-	protected $stubFilename = 'ChooseColumnsDialog.html' ;
15
-
16
-	public function __construct($scaffolderConfig, $modelData = null)
17
-	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
-		parent::__construct($scaffolderConfig, $modelData);
20
-	}
21
-
22
-	/**
23
-	 * Replace and store the Stub.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	public function replaceAndStore()
28
-	{
13
+    protected $cachePrefix 	= 'list_choose_column_';
14
+    protected $stubFilename = 'ChooseColumnsDialog.html' ;
15
+
16
+    public function __construct($scaffolderConfig, $modelData = null)
17
+    {
18
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
+        parent::__construct($scaffolderConfig, $modelData);
20
+    }
21
+
22
+    /**
23
+     * Replace and store the Stub.
24
+     *
25
+     * @return string
26
+     */
27
+    public function replaceAndStore()
28
+    {
29 29
 		
30
-		return $this->store(new FileToCompile(false, $this->modelData->modelHash));
30
+        return $this->store(new FileToCompile(false, $this->modelData->modelHash));
31 31
 		
32
-	}
32
+    }
33 33
 	
34
-	/**
35
-	 * Get output filename
36
-	 *
37
-	 *
38
-	 * @return $this
39
-	 */
40
-	protected function getOutputFilename()
41
-	{
42
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/list/' ;
43
-
44
-		Directory::createIfNotExists($folder, 0755, true);
45
-
46
-		return $folder .$this->modelData->tableName . '_columns.dialog.html';
47
-	}
34
+    /**
35
+     * Get output filename
36
+     *
37
+     *
38
+     * @return $this
39
+     */
40
+    protected function getOutputFilename()
41
+    {
42
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/list/' ;
43
+
44
+        Directory::createIfNotExists($folder, 0755, true);
45
+
46
+        return $folder .$this->modelData->tableName . '_columns.dialog.html';
47
+    }
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/RegisterTemplateCompiler.php 1 patch
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -13,204 +13,204 @@
 block discarded – undo
13 13
 
14 14
 class RegisterTemplateCompiler extends AbstractCompiler
15 15
 {
16
-	protected $cachePrefix 	= 'register_template_';
17
-	protected $stubFilename = 'RegisterTemplate.html' ;
18
-
19
-	public function __construct($scaffolderConfig, $modelData = null)
20
-	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
-		parent::__construct($scaffolderConfig, $modelData);
23
-	}
24
-
25
-	/**
26
-	 * Replace and store the Stub.
27
-	 *
28
-	 * @return string
29
-	 */
30
-	public function replaceAndStore()
31
-	{
16
+    protected $cachePrefix 	= 'register_template_';
17
+    protected $stubFilename = 'RegisterTemplate.html' ;
18
+
19
+    public function __construct($scaffolderConfig, $modelData = null)
20
+    {
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
+        parent::__construct($scaffolderConfig, $modelData);
23
+    }
24
+
25
+    /**
26
+     * Replace and store the Stub.
27
+     *
28
+     * @return string
29
+     */
30
+    public function replaceAndStore()
31
+    {
32 32
 		
33
-		return $this
34
-				->replaceInputFields()
35
-				->replaceBelongsToManyFields()
36
-				->store(new FileToCompile(false, $this->modelData->modelHash));
33
+        return $this
34
+                ->replaceInputFields()
35
+                ->replaceBelongsToManyFields()
36
+                ->store(new FileToCompile(false, $this->modelData->modelHash));
37 37
 		
38
-	}
38
+    }
39 39
 
40
-	/**
41
-	 * Replace input fields
42
-	 *
43
-	 * @return $this
44
-	 */
45
-	private function replaceInputFields(){
40
+    /**
41
+     * Replace input fields
42
+     *
43
+     * @return $this
44
+     */
45
+    private function replaceInputFields(){
46 46
 
47
-		$inputFields = $this->getInputFields();
47
+        $inputFields = $this->getInputFields();
48 48
 
49
-		$this->stub = str_replace('{{columns_inputs}}', $inputFields, $this->stub);
49
+        $this->stub = str_replace('{{columns_inputs}}', $inputFields, $this->stub);
50 50
 
51
-		return $this;
52
-	}
51
+        return $this;
52
+    }
53 53
 
54
-	/**
55
-	 * get search conditions
56
-	 *
57
-	 * @return $this
58
-	 */
59
-	public function getInputFields(){
54
+    /**
55
+     * get search conditions
56
+     *
57
+     * @return $this
58
+     */
59
+    public function getInputFields(){
60 60
 
61
-		$inputFields = $eagerFields = '';
61
+        $inputFields = $eagerFields = '';
62 62
 
63
-		foreach ($this->modelData->fields as $field)
64
-		{
65
-			$fieldStub = $this->getInputStubByField($field);
63
+        foreach ($this->modelData->fields as $field)
64
+        {
65
+            $fieldStub = $this->getInputStubByField($field);
66 66
 			
67
-			if($field->foreignKey){
67
+            if($field->foreignKey){
68 68
 				
69
-				$fieldStub 	= $this->replaceForeingStrings($field, $fieldStub) ;
70
-				$fieldStub = str_replace('{{foreign_model_name}}', strtolower(CamelCase::convertToCamelCase($field->foreignKey->table)), $fieldStub);
71
-			}
72
-
73
-			$inputFields .= $this->replaceFieldInput($field, $fieldStub) ;
74
-
75
-			// Check foreign key
76
-			if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
77
-			{
78
-				// search eager fields
79
-				$foreignModelData = $this->getModelData($field->foreignKey->table);
80
-				$foreignControllerCompiler = new RegisterTemplateCompiler($this->scaffolderConfig, $foreignModelData);
81
-				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
82
-				$eagerFields 	.= $foreignControllerCompiler->getInputFields();
83
-			}
84
-
85
-		}
86
-
87
-		// replace table name
88
-		$inputFields = str_replace('{{table_name}}', $this->modelData->tableName, $inputFields);
69
+                $fieldStub 	= $this->replaceForeingStrings($field, $fieldStub) ;
70
+                $fieldStub = str_replace('{{foreign_model_name}}', strtolower(CamelCase::convertToCamelCase($field->foreignKey->table)), $fieldStub);
71
+            }
72
+
73
+            $inputFields .= $this->replaceFieldInput($field, $fieldStub) ;
74
+
75
+            // Check foreign key
76
+            if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
77
+            {
78
+                // search eager fields
79
+                $foreignModelData = $this->getModelData($field->foreignKey->table);
80
+                $foreignControllerCompiler = new RegisterTemplateCompiler($this->scaffolderConfig, $foreignModelData);
81
+                $foreignControllerCompiler->setEagerTable($this->modelData->tableName);
82
+                $eagerFields 	.= $foreignControllerCompiler->getInputFields();
83
+            }
84
+
85
+        }
86
+
87
+        // replace table name
88
+        $inputFields = str_replace('{{table_name}}', $this->modelData->tableName, $inputFields);
89 89
 		
90
-		$this->stub = str_replace('{{eager_objects_inputs}}', $eagerFields, $this->stub); 
90
+        $this->stub = str_replace('{{eager_objects_inputs}}', $eagerFields, $this->stub); 
91 91
 
92
-		return $inputFields ;
92
+        return $inputFields ;
93 93
 
94
-	}
94
+    }
95 95
 
96
-	/**
97
-	 * Replace belongs to many fields
98
-	 *
99
-	 * @return $this
100
-	 */
101
-	protected function replaceBelongsToManyFields() {
96
+    /**
97
+     * Replace belongs to many fields
98
+     *
99
+     * @return $this
100
+     */
101
+    protected function replaceBelongsToManyFields() {
102 102
 		
103
-		$belongToManyFields = '';
103
+        $belongToManyFields = '';
104 104
 		
105
-		foreach ($this->modelData->reverseRelationships as $relationship)
106
-		{
107
-			if ($relationship->type == "belongsToMany") {
108
-				$fieldStub = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($relationship->ui). '.html');
109
-
110
-				$fieldStub = str_replace('{{related_table}}',CamelCase::convertToCamelCase($relationship->relatedTable), $fieldStub);
111
-				$fieldStub = str_replace('{{related_table_lw}}', strtolower(CamelCase::convertToCamelCase($relationship->relatedTable)), $fieldStub);
112
-				$fieldStub = str_replace('{{table_name}}', $this->modelData->tableName, $fieldStub);
113
-				$fieldStub = str_replace('{{related_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $fieldStub);
114
-				$fieldStub = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $fieldStub);
105
+        foreach ($this->modelData->reverseRelationships as $relationship)
106
+        {
107
+            if ($relationship->type == "belongsToMany") {
108
+                $fieldStub = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($relationship->ui). '.html');
109
+
110
+                $fieldStub = str_replace('{{related_table}}',CamelCase::convertToCamelCase($relationship->relatedTable), $fieldStub);
111
+                $fieldStub = str_replace('{{related_table_lw}}', strtolower(CamelCase::convertToCamelCase($relationship->relatedTable)), $fieldStub);
112
+                $fieldStub = str_replace('{{table_name}}', $this->modelData->tableName, $fieldStub);
113
+                $fieldStub = str_replace('{{related_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $fieldStub);
114
+                $fieldStub = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $fieldStub);
115 115
 				
116
-				$belongToManyFields .= $fieldStub;	
117
-			}
118
-		}
116
+                $belongToManyFields .= $fieldStub;	
117
+            }
118
+        }
119 119
 
120
-		$this->stub = str_replace('{{belongs_to_many_inputs}}', $belongToManyFields, $this->stub); 
120
+        $this->stub = str_replace('{{belongs_to_many_inputs}}', $belongToManyFields, $this->stub); 
121 121
 
122
-		return $this;
123
-	}
122
+        return $this;
123
+    }
124 124
 	
125
-	/**
126
-	 * replace field stub with fields and validations
127
-	 *
128
-	 * @param string $field
129
-	 * @param string $fieldStub
130
-	 *
131
-	 * @return $this
132
-	 */
133
-	protected function replaceFieldInput($field, $fieldStub){
134
-		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
135
-		$fieldStub = $this->replaceFieldValidations($field, $fieldStub) ;
136
-
137
-		return $fieldStub ;
138
-	}
139
-
140
-	/**
141
-	 * replace field stub with fields and validations
142
-	 *
143
-	 * @param string $field
144
-	 * @param string $fieldStub
145
-	 *
146
-	 * @return $this
147
-	 */
148
-	protected function replaceFieldValidations($field, $fieldStub){
149
-		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
125
+    /**
126
+     * replace field stub with fields and validations
127
+     *
128
+     * @param string $field
129
+     * @param string $fieldStub
130
+     *
131
+     * @return $this
132
+     */
133
+    protected function replaceFieldInput($field, $fieldStub){
134
+        $fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
135
+        $fieldStub = $this->replaceFieldValidations($field, $fieldStub) ;
136
+
137
+        return $fieldStub ;
138
+    }
139
+
140
+    /**
141
+     * replace field stub with fields and validations
142
+     *
143
+     * @param string $field
144
+     * @param string $fieldStub
145
+     *
146
+     * @return $this
147
+     */
148
+    protected function replaceFieldValidations($field, $fieldStub){
149
+        $fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
150 150
 		
151
-		$validationsConverted = Validator::convertValidations($field->validations);
151
+        $validationsConverted = Validator::convertValidations($field->validations);
152 152
 
153
-		$inputValidations = '' ; 
153
+        $inputValidations = '' ; 
154 154
 
155
-		foreach ($validationsConverted as $attribute => $value) {
156
-			if($value)
157
-				$inputValidations .=  ' '.$attribute.'="'. $value.'"' ;
158
-			else
159
-				$inputValidations .=  ' '.$attribute  ; 
160
-		}
155
+        foreach ($validationsConverted as $attribute => $value) {
156
+            if($value)
157
+                $inputValidations .=  ' '.$attribute.'="'. $value.'"' ;
158
+            else
159
+                $inputValidations .=  ' '.$attribute  ; 
160
+        }
161 161
 
162
-		$fieldStub = str_replace('{{field_validation}}', $inputValidations, $fieldStub);
162
+        $fieldStub = str_replace('{{field_validation}}', $inputValidations, $fieldStub);
163 163
 
164
-		return $fieldStub ;
165
-	}
164
+        return $fieldStub ;
165
+    }
166 166
 
167 167
 	
168
-	/**
169
-	 * get input field stub by ui type
170
-	 *
171
-	 * @param string $field
172
-	 *
173
-	 * @return $this
174
-	 */
175
-	private $inputStub = [];
176
-	private function getInputStubByField($field){
168
+    /**
169
+     * get input field stub by ui type
170
+     *
171
+     * @param string $field
172
+     *
173
+     * @return $this
174
+     */
175
+    private $inputStub = [];
176
+    private function getInputStubByField($field){
177 177
 		
178
-		if($field->index == 'primary'){
179
-			$uiType = 'primary' ;
180
-		}
181
-		elseif(isset($field->foreignKey) && $field->foreignKey){
182
-			if(isset($field->foreignKey->eager) && $field->foreignKey->eager)
183
-				$uiType = 'foreign_eager' ;
184
-			else 
185
-				$uiType = $field->type->ui ;
186
-		}
187
-		else {
188
-			$uiType = $field->type->ui ;
189
-		}
190
-
191
-		if(array_key_exists($uiType, $this->inputStub)){
192
-			return $this->inputStub[$uiType];
193
-		}
194
-		else {
195
-			$this->inputStub[$uiType] = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($uiType). '.html');
196
-
197
-			return $this->inputStub[$uiType];
198
-		}
199
-	}
200
-
201
-	/**
202
-	 * Get output filename
203
-	 *
204
-	 *
205
-	 * @return $this
206
-	 */
207
-	protected function getOutputFilename()
208
-	{
209
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
210
-
211
-		Directory::createIfNotExists($folder, 0755, true);
212
-
213
-		return $folder .$this->modelData->tableName . '_register.html';
214
-	}
178
+        if($field->index == 'primary'){
179
+            $uiType = 'primary' ;
180
+        }
181
+        elseif(isset($field->foreignKey) && $field->foreignKey){
182
+            if(isset($field->foreignKey->eager) && $field->foreignKey->eager)
183
+                $uiType = 'foreign_eager' ;
184
+            else 
185
+                $uiType = $field->type->ui ;
186
+        }
187
+        else {
188
+            $uiType = $field->type->ui ;
189
+        }
190
+
191
+        if(array_key_exists($uiType, $this->inputStub)){
192
+            return $this->inputStub[$uiType];
193
+        }
194
+        else {
195
+            $this->inputStub[$uiType] = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($uiType). '.html');
196
+
197
+            return $this->inputStub[$uiType];
198
+        }
199
+    }
200
+
201
+    /**
202
+     * Get output filename
203
+     *
204
+     *
205
+     * @return $this
206
+     */
207
+    protected function getOutputFilename()
208
+    {
209
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
210
+
211
+        Directory::createIfNotExists($folder, 0755, true);
212
+
213
+        return $folder .$this->modelData->tableName . '_register.html';
214
+    }
215 215
 
216 216
 }
217 217
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/ListModuleCompiler.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@
 block discarded – undo
10 10
 
11 11
 class ListModuleCompiler extends AbstractCompiler
12 12
 {
13
-	protected $cachePrefix 	= 'list_module_';
14
-	protected $stubFilename = 'ListModule.js' ;
15
-
16
-	public function __construct($scaffolderConfig, $modelData = null)
17
-	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
-		parent::__construct($scaffolderConfig, $modelData);
20
-	}
21
-
22
-	/**
23
-	 * Replace and store the Stub.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	public function replaceAndStore()
28
-	{
13
+    protected $cachePrefix 	= 'list_module_';
14
+    protected $stubFilename = 'ListModule.js' ;
15
+
16
+    public function __construct($scaffolderConfig, $modelData = null)
17
+    {
18
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
+        parent::__construct($scaffolderConfig, $modelData);
20
+    }
21
+
22
+    /**
23
+     * Replace and store the Stub.
24
+     *
25
+     * @return string
26
+     */
27
+    public function replaceAndStore()
28
+    {
29 29
 		
30
-		return $this->store(new FileToCompile(false, $this->modelData->modelHash));
30
+        return $this->store(new FileToCompile(false, $this->modelData->modelHash));
31 31
 		
32
-	}
32
+    }
33 33
 	
34
-	/**
35
-	 * Get output filename
36
-	 *
37
-	 *
38
-	 * @return $this
39
-	 */
40
-	protected function getOutputFilename()
41
-	{
42
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/list/' ;
43
-
44
-		Directory::createIfNotExists($folder, 0755, true);
45
-
46
-		return $folder .$this->modelData->tableName . '_list.module.js';
47
-	}
34
+    /**
35
+     * Get output filename
36
+     *
37
+     *
38
+     * @return $this
39
+     */
40
+    protected function getOutputFilename()
41
+    {
42
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/list/' ;
43
+
44
+        Directory::createIfNotExists($folder, 0755, true);
45
+
46
+        return $folder .$this->modelData->tableName . '_list.module.js';
47
+    }
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/IndexModuleCompiler.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -10,98 +10,98 @@
 block discarded – undo
10 10
 
11 11
 class IndexModuleCompiler extends AbstractCompiler
12 12
 {
13
-	protected $stubFilename = 'IndexModule.js' ;
13
+    protected $stubFilename = 'IndexModule.js' ;
14 14
 
15
-	protected $stubResourceFilename = 'IndexModuleModel.js' ;
16
-	protected $stubResource  ;
15
+    protected $stubResourceFilename = 'IndexModuleModel.js' ;
16
+    protected $stubResource  ;
17 17
 
18 18
 
19
-	public function __construct($scaffolderConfig, $modelData = null)
20
-	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
-		parent::__construct($scaffolderConfig, null);
19
+    public function __construct($scaffolderConfig, $modelData = null)
20
+    {
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
+        parent::__construct($scaffolderConfig, null);
23 23
 		
24
-		$this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename );
25
-	}
26
-
27
-	/**
28
-	 * Replace and store the Stub.
29
-	 *
30
-	 * @return string
31
-	 */
32
-	public function replaceAndStore(){}
33
-
34
-	/**
35
-	 * Compiles a resource.
36
-	 *
37
-	 * @param      $hash
38
-	 * @param null $extra
39
-	 *
40
-	 * @return string
41
-	 */
42
-	public function compile($extra = null) {}
43
-
44
-	/**
45
-	 * Compiles a group of routes.
46
-	 *
47
-	 * @param      $hash
48
-	 * @param null $extra
49
-	 *
50
-	 * @return mixed
51
-	 */
52
-	public function compileGroup($compiledIndexes)
53
-	{
54
-
55
-		$this->replaceIndexes($compiledIndexes)
56
-			->store(new FileToCompile(null, null));
57
-
58
-		return $this->stub;
59
-	}
60
-
61
-
62
-	/**
63
-	 * Get output filename
64
-	 *
65
-	 *
66
-	 * @return $this
67
-	 */
68
-	protected function getOutputFilename()
69
-	{
70
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->index);
71
-
72
-		return $folder  . 'index.module.js';
73
-	}
74
-
75
-
76
-	/**
77
-	 * Replace the resource.
78
-	 *
79
-	 * @param $this->modelName
80
-	 *
81
-	 * @return string routeStub
82
-	 */
83
-	public function replaceResource($modelData)
84
-	{
24
+        $this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename );
25
+    }
26
+
27
+    /**
28
+     * Replace and store the Stub.
29
+     *
30
+     * @return string
31
+     */
32
+    public function replaceAndStore(){}
33
+
34
+    /**
35
+     * Compiles a resource.
36
+     *
37
+     * @param      $hash
38
+     * @param null $extra
39
+     *
40
+     * @return string
41
+     */
42
+    public function compile($extra = null) {}
43
+
44
+    /**
45
+     * Compiles a group of routes.
46
+     *
47
+     * @param      $hash
48
+     * @param null $extra
49
+     *
50
+     * @return mixed
51
+     */
52
+    public function compileGroup($compiledIndexes)
53
+    {
54
+
55
+        $this->replaceIndexes($compiledIndexes)
56
+            ->store(new FileToCompile(null, null));
57
+
58
+        return $this->stub;
59
+    }
60
+
61
+
62
+    /**
63
+     * Get output filename
64
+     *
65
+     *
66
+     * @return $this
67
+     */
68
+    protected function getOutputFilename()
69
+    {
70
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->index);
71
+
72
+        return $folder  . 'index.module.js';
73
+    }
74
+
75
+
76
+    /**
77
+     * Replace the resource.
78
+     *
79
+     * @param $this->modelName
80
+     *
81
+     * @return string routeStub
82
+     */
83
+    public function replaceResource($modelData)
84
+    {
85 85
 		
86
-		$indexStub = str_replace('{{table_name_uc}}', $modelData->modelName, $this->stubResource);
87
-		$indexStub = str_replace('{{table_name}}', $modelData->tableName, $indexStub);
86
+        $indexStub = str_replace('{{table_name_uc}}', $modelData->modelName, $this->stubResource);
87
+        $indexStub = str_replace('{{table_name}}', $modelData->tableName, $indexStub);
88 88
 		
89
-		return $indexStub;
90
-	}
91
-
92
-	/**
93
-	 * Replace compiled routes.
94
-	 *
95
-	 * @param $compiledRoutes
96
-	 *
97
-	 * @return $this
98
-	 */
99
-	private function replaceIndexes($compiledIndexes)
100
-	{
101
-		$this->stub = str_replace('{{tables}}', $compiledIndexes, $this->stub);
102
-
103
-		return $this;
104
-	}
89
+        return $indexStub;
90
+    }
91
+
92
+    /**
93
+     * Replace compiled routes.
94
+     *
95
+     * @param $compiledRoutes
96
+     *
97
+     * @return $this
98
+     */
99
+    private function replaceIndexes($compiledIndexes)
100
+    {
101
+        $this->stub = str_replace('{{tables}}', $compiledIndexes, $this->stub);
102
+
103
+        return $this;
104
+    }
105 105
 
106 106
 	
107 107
 }
108 108
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/ModuleCompiler.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@
 block discarded – undo
10 10
 
11 11
 class ModuleCompiler extends AbstractCompiler
12 12
 {
13
-	protected $cachePrefix 	= 'module_';
14
-	protected $stubFilename = 'Module.js' ;
15
-
16
-	public function __construct($scaffolderConfig, $modelData = null)
17
-	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
-		parent::__construct($scaffolderConfig, $modelData);
20
-	}
21
-
22
-	/**
23
-	 * Replace and store the Stub.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	public function replaceAndStore()
28
-	{
13
+    protected $cachePrefix 	= 'module_';
14
+    protected $stubFilename = 'Module.js' ;
15
+
16
+    public function __construct($scaffolderConfig, $modelData = null)
17
+    {
18
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
+        parent::__construct($scaffolderConfig, $modelData);
20
+    }
21
+
22
+    /**
23
+     * Replace and store the Stub.
24
+     *
25
+     * @return string
26
+     */
27
+    public function replaceAndStore()
28
+    {
29 29
 		
30
-		return $this->store(new FileToCompile(false, $this->modelData->modelHash));
30
+        return $this->store(new FileToCompile(false, $this->modelData->modelHash));
31 31
 		
32
-	}
32
+    }
33 33
 	
34
-	/**
35
-	 * Get output filename
36
-	 *
37
-	 *
38
-	 * @return $this
39
-	 */
40
-	protected function getOutputFilename()
41
-	{
42
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/' ;
43
-
44
-		Directory::createIfNotExists($folder, 0755, true);
45
-
46
-		return $folder .  $this->modelData->tableName . '.module.js';
47
-	}
34
+    /**
35
+     * Get output filename
36
+     *
37
+     *
38
+     * @return $this
39
+     */
40
+    protected function getOutputFilename()
41
+    {
42
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/' ;
43
+
44
+        Directory::createIfNotExists($folder, 0755, true);
45
+
46
+        return $folder .  $this->modelData->tableName . '.module.js';
47
+    }
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/RegisterModuleCompiler.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@
 block discarded – undo
10 10
 
11 11
 class RegisterModuleCompiler extends AbstractCompiler
12 12
 {
13
-	protected $cachePrefix 	= 'register_module_';
14
-	protected $stubFilename = 'RegisterModule.js' ;
15
-
16
-	public function __construct($scaffolderConfig, $modelData = null)
17
-	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
-		parent::__construct($scaffolderConfig, $modelData);
20
-	}
21
-
22
-	/**
23
-	 * Replace and store the Stub.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	public function replaceAndStore()
28
-	{
13
+    protected $cachePrefix 	= 'register_module_';
14
+    protected $stubFilename = 'RegisterModule.js' ;
15
+
16
+    public function __construct($scaffolderConfig, $modelData = null)
17
+    {
18
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
+        parent::__construct($scaffolderConfig, $modelData);
20
+    }
21
+
22
+    /**
23
+     * Replace and store the Stub.
24
+     *
25
+     * @return string
26
+     */
27
+    public function replaceAndStore()
28
+    {
29 29
 		
30
-		return $this->store(new FileToCompile(false, $this->modelData->modelHash));
30
+        return $this->store(new FileToCompile(false, $this->modelData->modelHash));
31 31
 		
32
-	}
32
+    }
33 33
 	
34
-	/**
35
-	 * Get output filename
36
-	 *
37
-	 *
38
-	 * @return $this
39
-	 */
40
-	protected function getOutputFilename()
41
-	{
42
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
43
-
44
-		Directory::createIfNotExists($folder, 0755, true);
45
-
46
-		return $folder .$this->modelData->tableName . '_register.module.js';
47
-	}
34
+    /**
35
+     * Get output filename
36
+     *
37
+     *
38
+     * @return $this
39
+     */
40
+    protected function getOutputFilename()
41
+    {
42
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
43
+
44
+        Directory::createIfNotExists($folder, 0755, true);
45
+
46
+        return $folder .$this->modelData->tableName . '_register.module.js';
47
+    }
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AbstractCompiler.php 1 patch
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -9,266 +9,266 @@
 block discarded – undo
9 9
 
10 10
 abstract class AbstractCompiler
11 11
 {
12
-	protected $cachePrefix ;
13
-	protected $stubFilename;
14
-
15
-	protected $stub;
16
-	protected $scaffolderConfig ;
17
-	protected $modelName ;
18
-	protected $modelData ;
19
-	protected $stubsDirectory ;
20
-
21
-	protected $eagerTable ;
22
-
23
-	const CACHE_EXT = '.scf';
24
-
25
-	public function __construct($scaffolderConfig, $modelData = null)
26
-	{
27
-		$this->modelName = isset($modelData->modelName) ? $modelData->modelName : null  ;
28
-		$this->modelData = $modelData ;
29
-		$this->scaffolderConfig = $scaffolderConfig ;
30
-
31
-		$this->stub = File::get($this->stubsDirectory . $this->stubFilename );
32
-	}
33
-
34
-	/**
35
-	 * Compiles .
36
-	 *
37
-	 * @param null $extra
38
-	 *
39
-	 * @return string
40
-	 */
41
-	public function compile($extra = null)
42
-	{
43
-		if (File::exists(base_path('scaffolder-config/cache/' . $this->cachePrefix  . $this->modelData->modelHash . self::CACHE_EXT)))
44
-		{
45
-			return $this->store(new FileToCompile(true, $this->modelData->modelHash));
46
-		}
47
-		else
48
-		{
49
-
50
-			return $this->replacePrimaryKey()
51
-						->replaceClassName()
52
-						->replaceTableName()
53
-						->replaceRoutePrefix()
54
-						->replaceAndStore();
55
-		}
56
-	}
57
-
58
-	/**
59
-	 * Replace and store the Stub.
60
-	 *
61
-	 * @return string
62
-	 */
63
-	abstract protected function replaceAndStore();
64
-
65
-	/**
66
-	 * Store the compiled stub.
67
-	 *
68
-	 * @param string $eagerTable
69
-	 *
70
-	 * @return string
71
-	 */
72
-	protected function setEagerTable($eagerTable){
73
-		$this->eagerTable = $eagerTable.'.';
74
-	}
75
-
76
-	/**
77
-	 * Store the compiled stub.
78
-	 *
79
-	 * @param FileToCompile $fileToCompile
80
-	 *
81
-	 * @return string
82
-	 */
83
-	protected function store(FileToCompile $fileToCompile)
84
-	{
85
-		$path = $this->getOutputFilename();
86
-
87
-		// Store in cache
88
-		if ($fileToCompile->cached)
89
-		{
90
-			File::copy(base_path('scaffolder-config/cache/' . $this->cachePrefix . $fileToCompile->hash . self::CACHE_EXT), $path);
91
-		}
92
-		else
93
-		{
94
-			File::put(base_path('scaffolder-config/cache/' . $this->cachePrefix . $fileToCompile->hash . self::CACHE_EXT), $this->stub);
95
-			File::copy(base_path('scaffolder-config/cache/' . $this->cachePrefix . $fileToCompile->hash . self::CACHE_EXT), $path);
96
-		}
97
-
98
-		return $path;
99
-	}
100
-
101
-	/**
102
-	 * Get output filename
103
-	 *
104
-	 *
105
-	 * @return $this
106
-	 */
107
-	abstract protected function getOutputFilename();
108
-
109
-	/**
110
-	 * Replace the primary key.
111
-	 *
112
-	 * @param $this->modelData
113
-	 */
114
-	protected function replacePrimaryKey()
115
-	{
12
+    protected $cachePrefix ;
13
+    protected $stubFilename;
14
+
15
+    protected $stub;
16
+    protected $scaffolderConfig ;
17
+    protected $modelName ;
18
+    protected $modelData ;
19
+    protected $stubsDirectory ;
20
+
21
+    protected $eagerTable ;
22
+
23
+    const CACHE_EXT = '.scf';
24
+
25
+    public function __construct($scaffolderConfig, $modelData = null)
26
+    {
27
+        $this->modelName = isset($modelData->modelName) ? $modelData->modelName : null  ;
28
+        $this->modelData = $modelData ;
29
+        $this->scaffolderConfig = $scaffolderConfig ;
30
+
31
+        $this->stub = File::get($this->stubsDirectory . $this->stubFilename );
32
+    }
33
+
34
+    /**
35
+     * Compiles .
36
+     *
37
+     * @param null $extra
38
+     *
39
+     * @return string
40
+     */
41
+    public function compile($extra = null)
42
+    {
43
+        if (File::exists(base_path('scaffolder-config/cache/' . $this->cachePrefix  . $this->modelData->modelHash . self::CACHE_EXT)))
44
+        {
45
+            return $this->store(new FileToCompile(true, $this->modelData->modelHash));
46
+        }
47
+        else
48
+        {
49
+
50
+            return $this->replacePrimaryKey()
51
+                        ->replaceClassName()
52
+                        ->replaceTableName()
53
+                        ->replaceRoutePrefix()
54
+                        ->replaceAndStore();
55
+        }
56
+    }
57
+
58
+    /**
59
+     * Replace and store the Stub.
60
+     *
61
+     * @return string
62
+     */
63
+    abstract protected function replaceAndStore();
64
+
65
+    /**
66
+     * Store the compiled stub.
67
+     *
68
+     * @param string $eagerTable
69
+     *
70
+     * @return string
71
+     */
72
+    protected function setEagerTable($eagerTable){
73
+        $this->eagerTable = $eagerTable.'.';
74
+    }
75
+
76
+    /**
77
+     * Store the compiled stub.
78
+     *
79
+     * @param FileToCompile $fileToCompile
80
+     *
81
+     * @return string
82
+     */
83
+    protected function store(FileToCompile $fileToCompile)
84
+    {
85
+        $path = $this->getOutputFilename();
86
+
87
+        // Store in cache
88
+        if ($fileToCompile->cached)
89
+        {
90
+            File::copy(base_path('scaffolder-config/cache/' . $this->cachePrefix . $fileToCompile->hash . self::CACHE_EXT), $path);
91
+        }
92
+        else
93
+        {
94
+            File::put(base_path('scaffolder-config/cache/' . $this->cachePrefix . $fileToCompile->hash . self::CACHE_EXT), $this->stub);
95
+            File::copy(base_path('scaffolder-config/cache/' . $this->cachePrefix . $fileToCompile->hash . self::CACHE_EXT), $path);
96
+        }
97
+
98
+        return $path;
99
+    }
100
+
101
+    /**
102
+     * Get output filename
103
+     *
104
+     *
105
+     * @return $this
106
+     */
107
+    abstract protected function getOutputFilename();
108
+
109
+    /**
110
+     * Replace the primary key.
111
+     *
112
+     * @param $this->modelData
113
+     */
114
+    protected function replacePrimaryKey()
115
+    {
116 116
 		
117
-		$primaryKey = $this->getPrimaryKeyField()->name;
118
-
119
-		$this->stub = str_replace('{{primary_key}}', $primaryKey, $this->stub);
120
-
121
-		return $this;
122
-	}
123
-
124
-	protected function getPrimaryKeyField(){
125
-		$primaryKey = new stdClass;
126
-		$primaryKey->name = "id" ;
127
-		$primaryKey->index = "primary" ;
128
-		$primaryKey->declared =  false ;
129
-		$primaryKey->type = new stdClass ;
130
-		$primaryKey->type->ui = 'label' ;
131
-		$primaryKey->type->db = 'integer' ;
132
-		$primaryKey->foreignKey = [];
133
-		$primaryKey->validations = "required" ;
134
-
135
-		foreach ($this->modelData->fields as $field)
136
-		{
137
-			if ($field->index == 'primary')
138
-			{
139
-				$primaryKey = $field ;
140
-				break;
141
-			}
142
-		}
143
-
144
-		return $primaryKey ;
145
-	}
146
-
147
-	/**
148
-	 * Replace the class name.
149
-	 *
150
-	 *
151
-	 * @return $this
152
-	 */
153
-	protected function replaceClassName()
154
-	{
155
-		$this->stub = str_replace('{{class_name}}', $this->modelName, $this->stub);
156
-		$this->stub = str_replace('{{class_name_lw}}', strtolower($this->modelName), $this->stub);
157
-
158
-		return $this;
159
-	}
160
-
161
-	/**
162
-	 * Replace the table name.
163
-	 *
164
-	 * @return $this
165
-	 */
166
-	protected function replaceTableName()
167
-	{
168
-		$this->stub = str_replace('{{table_name}}', $this->modelData->tableName, $this->stub);
169
-
170
-		return $this;
171
-	}
172
-
173
-	/**
174
-	 * Replace the namespace.
175
-	 *
176
-	 * @return $this
177
-	 */
178
-	protected function replaceNamespace()
179
-	{
180
-		$this->stub = str_replace('{{namespace}}', $this->scaffolderConfig->generator->namespaces->models, $this->stub);
181
-
182
-		return $this;
183
-	}
184
-
185
-	/**
186
-	 * Replace the foreign strings by field.
187
-	 *
188
-	 * @param stdClass $field
189
-	 * @param string $originalStubPart
190
-	 *
191
-	 * @return $this
192
-	 */
193
-	protected function replaceForeingStrings($field,  $originalStubPart){
194
-		$replaceStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $originalStubPart);
195
-		$replaceStub = str_replace('{{table_name}}', $this->modelData->tableName, $replaceStub);
196
-		$replaceStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $replaceStub);
197
-		$replaceStub = str_replace('{{foreign_model}}', ucwords($field->foreignKey->table), $replaceStub);
198
-		$replaceStub = str_replace('{{field}}', $field->name, $replaceStub);
199
-
200
-		if(isset($this->scaffolderConfig->generator->namespaces))
201
-			$replaceStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $replaceStub);
202
-
203
-		return $replaceStub;
117
+        $primaryKey = $this->getPrimaryKeyField()->name;
118
+
119
+        $this->stub = str_replace('{{primary_key}}', $primaryKey, $this->stub);
120
+
121
+        return $this;
122
+    }
123
+
124
+    protected function getPrimaryKeyField(){
125
+        $primaryKey = new stdClass;
126
+        $primaryKey->name = "id" ;
127
+        $primaryKey->index = "primary" ;
128
+        $primaryKey->declared =  false ;
129
+        $primaryKey->type = new stdClass ;
130
+        $primaryKey->type->ui = 'label' ;
131
+        $primaryKey->type->db = 'integer' ;
132
+        $primaryKey->foreignKey = [];
133
+        $primaryKey->validations = "required" ;
134
+
135
+        foreach ($this->modelData->fields as $field)
136
+        {
137
+            if ($field->index == 'primary')
138
+            {
139
+                $primaryKey = $field ;
140
+                break;
141
+            }
142
+        }
143
+
144
+        return $primaryKey ;
145
+    }
146
+
147
+    /**
148
+     * Replace the class name.
149
+     *
150
+     *
151
+     * @return $this
152
+     */
153
+    protected function replaceClassName()
154
+    {
155
+        $this->stub = str_replace('{{class_name}}', $this->modelName, $this->stub);
156
+        $this->stub = str_replace('{{class_name_lw}}', strtolower($this->modelName), $this->stub);
157
+
158
+        return $this;
159
+    }
160
+
161
+    /**
162
+     * Replace the table name.
163
+     *
164
+     * @return $this
165
+     */
166
+    protected function replaceTableName()
167
+    {
168
+        $this->stub = str_replace('{{table_name}}', $this->modelData->tableName, $this->stub);
169
+
170
+        return $this;
171
+    }
172
+
173
+    /**
174
+     * Replace the namespace.
175
+     *
176
+     * @return $this
177
+     */
178
+    protected function replaceNamespace()
179
+    {
180
+        $this->stub = str_replace('{{namespace}}', $this->scaffolderConfig->generator->namespaces->models, $this->stub);
181
+
182
+        return $this;
183
+    }
184
+
185
+    /**
186
+     * Replace the foreign strings by field.
187
+     *
188
+     * @param stdClass $field
189
+     * @param string $originalStubPart
190
+     *
191
+     * @return $this
192
+     */
193
+    protected function replaceForeingStrings($field,  $originalStubPart){
194
+        $replaceStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $originalStubPart);
195
+        $replaceStub = str_replace('{{table_name}}', $this->modelData->tableName, $replaceStub);
196
+        $replaceStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $replaceStub);
197
+        $replaceStub = str_replace('{{foreign_model}}', ucwords($field->foreignKey->table), $replaceStub);
198
+        $replaceStub = str_replace('{{field}}', $field->name, $replaceStub);
199
+
200
+        if(isset($this->scaffolderConfig->generator->namespaces))
201
+            $replaceStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $replaceStub);
202
+
203
+        return $replaceStub;
204 204
 		
205
-	}
206
-
207
-	/**
208
-	 * Replace the fields strings by field.
209
-	 *
210
-	 * @param stdClass $field
211
-	 * @param string $originalStubPart
212
-	 *
213
-	 * @return $this
214
-	 */
215
-	protected function replaceFieldStrings($field,  $originalStubPart){
216
-		$replaceStub = str_replace('{{field}}', $field->name, $originalStubPart);
205
+    }
206
+
207
+    /**
208
+     * Replace the fields strings by field.
209
+     *
210
+     * @param stdClass $field
211
+     * @param string $originalStubPart
212
+     *
213
+     * @return $this
214
+     */
215
+    protected function replaceFieldStrings($field,  $originalStubPart){
216
+        $replaceStub = str_replace('{{field}}', $field->name, $originalStubPart);
217 217
 		
218
-		if($this->eagerTable) $this->eagerTable.'.' ;
218
+        if($this->eagerTable) $this->eagerTable.'.' ;
219 219
 
220
-		$replaceStub = str_replace('{{eager_table}}', $this->eagerTable, $replaceStub);
220
+        $replaceStub = str_replace('{{eager_table}}', $this->eagerTable, $replaceStub);
221 221
 
222
-		return $replaceStub;
222
+        return $replaceStub;
223 223
 		
224
-	}
225
-
226
-	/**
227
-	 * Replace the prefix.
228
-	 *
229
-	 * @return $this
230
-	 */
231
-	protected function replaceRoutePrefix()
232
-	{
233
-		$this->stub = str_replace('{{route_prefix}}', $this->scaffolderConfig->generator->routing->prefix, $this->stub);
234
-
235
-		return $this;
236
-	}
237
-
238
-	/**
239
-	 * get anoter model data
240
-	 *
241
-	 * @param string $tableName
242
-	 *
243
-	 * @return $this
244
-	 */
245
-	protected $modelDataArray = [];
246
-	protected function getModelData($tableName){
224
+    }
225
+
226
+    /**
227
+     * Replace the prefix.
228
+     *
229
+     * @return $this
230
+     */
231
+    protected function replaceRoutePrefix()
232
+    {
233
+        $this->stub = str_replace('{{route_prefix}}', $this->scaffolderConfig->generator->routing->prefix, $this->stub);
234
+
235
+        return $this;
236
+    }
237
+
238
+    /**
239
+     * get anoter model data
240
+     *
241
+     * @param string $tableName
242
+     *
243
+     * @return $this
244
+     */
245
+    protected $modelDataArray = [];
246
+    protected function getModelData($tableName){
247 247
 		
248
-		if(array_key_exists($tableName, $this->modelDataArray)){
249
-			return $this->modelDataArray[$tableName];
250
-		}
251
-		else {
248
+        if(array_key_exists($tableName, $this->modelDataArray)){
249
+            return $this->modelDataArray[$tableName];
250
+        }
251
+        else {
252 252
 
253
-			$modelFilename = base_path('scaffolder-config/models/') . $tableName . '.json' ;
253
+            $modelFilename = base_path('scaffolder-config/models/') . $tableName . '.json' ;
254 254
 
255
-			$modelData = Json::decodeFile($modelFilename);
255
+            $modelData = Json::decodeFile($modelFilename);
256 256
 
257
-			// Get model name
258
-			$modelName = ucwords($tableName);
257
+            // Get model name
258
+            $modelName = ucwords($tableName);
259 259
 
260
-			// Get model hash
261
-			$modelHash = md5_file($modelFilename);
260
+            // Get model hash
261
+            $modelHash = md5_file($modelFilename);
262 262
 
263
-			// Set model name
264
-			$modelData->modelName = $modelName ;
263
+            // Set model name
264
+            $modelData->modelName = $modelName ;
265 265
 
266
-			// Set model name
267
-			$modelData->modelHash = $modelHash ;
266
+            // Set model name
267
+            $modelData->modelHash = $modelHash ;
268 268
 
269
-			$this->modelDataArray[$tableName] = $modelData;
269
+            $this->modelDataArray[$tableName] = $modelData;
270 270
 
271
-			return $this->modelDataArray[$tableName];
272
-		}
273
-	}
271
+            return $this->modelDataArray[$tableName];
272
+        }
273
+    }
274 274
 }
275 275
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/Core/ModelCompiler.php 1 patch
Indentation   +569 added lines, -569 removed lines patch added patch discarded remove patch
@@ -11,692 +11,692 @@
 block discarded – undo
11 11
 
12 12
 class ModelCompiler extends AbstractCompiler
13 13
 {
14
-	protected $cachePrefix 	= 'model_';
15
-	protected $stubFilename = 'Model/Model.php' ;
16
-
17
-	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
18
-	{
19
-		if ($stubName)
20
-			$this->stubFilename = $stubName;
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
-		parent::__construct($scaffolderConfig, $modelData);
23
-	}
24
-
25
-	/**
26
-	 * Replace and store the Stub.
27
-	 *
28
-	 * @return string
29
-	 */
30
-	public function replaceAndStore()
31
-	{
14
+    protected $cachePrefix 	= 'model_';
15
+    protected $stubFilename = 'Model/Model.php' ;
16
+
17
+    public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
18
+    {
19
+        if ($stubName)
20
+            $this->stubFilename = $stubName;
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
+        parent::__construct($scaffolderConfig, $modelData);
23
+    }
24
+
25
+    /**
26
+     * Replace and store the Stub.
27
+     *
28
+     * @return string
29
+     */
30
+    public function replaceAndStore()
31
+    {
32 32
 		
33
-		return $this->replaceNamespace()
34
-				->replaceNamespaceModelExtend()
35
-				->setPrimaryKey()
36
-				->setTimeStamps()
37
-				->addFillable()
38
-				->addEnumFields()
39
-				->addRules()
40
-				->addBelongsTo()
41
-				->addReverseRelationship()
42
-				->replaceEagerCode()
43
-				->replaceRelationshipTables()
44
-				->replaceSearchConditions()
45
-				->replaceSimpleFilter()
46
-				->replaceSortConditions()
47
-				->replaceReverseRelationshipsFunctions()
48
-				->replaceCheckbox()
49
-				->store(new FileToCompile(false, $this->modelData->modelHash));
33
+        return $this->replaceNamespace()
34
+                ->replaceNamespaceModelExtend()
35
+                ->setPrimaryKey()
36
+                ->setTimeStamps()
37
+                ->addFillable()
38
+                ->addEnumFields()
39
+                ->addRules()
40
+                ->addBelongsTo()
41
+                ->addReverseRelationship()
42
+                ->replaceEagerCode()
43
+                ->replaceRelationshipTables()
44
+                ->replaceSearchConditions()
45
+                ->replaceSimpleFilter()
46
+                ->replaceSortConditions()
47
+                ->replaceReverseRelationshipsFunctions()
48
+                ->replaceCheckbox()
49
+                ->store(new FileToCompile(false, $this->modelData->modelHash));
50 50
 		
51
-	}
51
+    }
52 52
 	
53
-	/**
54
-	 * Get output filename
55
-	 *
56
-	 *
57
-	 * @return $this
58
-	 */
59
-	protected function getOutputFilename()
60
-	{
61
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ;
62
-
63
-		return $folder .  $this->modelName . '.php';
64
-	}
53
+    /**
54
+     * Get output filename
55
+     *
56
+     *
57
+     * @return $this
58
+     */
59
+    protected function getOutputFilename()
60
+    {
61
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ;
62
+
63
+        return $folder .  $this->modelName . '.php';
64
+    }
65 65
 
66 66
 	
67 67
 
68
-	/**
69
-	 * Replace the namespace which the model extends
70
-	 *
71
-	 * @param $this->scaffolderConfig
72
-	 *
73
-	 * @return $this
74
-	 */
75
-	private function replaceNamespaceModelExtend()
76
-	{
77
-		$this->stub = str_replace('{{namespace_model_extend}}', $this->scaffolderConfig->generator->inheritance->model, $this->stub);
78
-
79
-		return $this;
80
-	}
81
-
82
-	/**
83
-	 * Add fillable.
84
-	 *
85
-	 * @return $this
86
-	 */
87
-	private function addFillable()
88
-	{
89
-		$fields = '';
90
-		$firstIteration = true;
91
-
92
-		foreach ($this->modelData->fields as $field)
93
-		{
94
-			if($field->index == "primary")
95
-				continue ;
96
-			if($this->modelData->timeStamps && $field->name == "created_at")
97
-				continue ;
98
-			if($this->modelData->timeStamps && $field->name == "updated_at")
99
-				continue ;
100
-
101
-			if ($firstIteration)
102
-			{
103
-				$fields .= sprintf("'%s'," . PHP_EOL, $field->name);
104
-				$firstIteration = false;
105
-			}
106
-			else
107
-			{
108
-				$fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name);
109
-			}
110
-		}
111
-
112
-		$this->stub = str_replace('{{fillable}}', $fields, $this->stub);
113
-
114
-		return $this;
115
-	}
116
-
117
-	private function addEnumFields() {
118
-
119
-		$items = '';
120
-		$arrays = '';
68
+    /**
69
+     * Replace the namespace which the model extends
70
+     *
71
+     * @param $this->scaffolderConfig
72
+     *
73
+     * @return $this
74
+     */
75
+    private function replaceNamespaceModelExtend()
76
+    {
77
+        $this->stub = str_replace('{{namespace_model_extend}}', $this->scaffolderConfig->generator->inheritance->model, $this->stub);
78
+
79
+        return $this;
80
+    }
81
+
82
+    /**
83
+     * Add fillable.
84
+     *
85
+     * @return $this
86
+     */
87
+    private function addFillable()
88
+    {
89
+        $fields = '';
90
+        $firstIteration = true;
91
+
92
+        foreach ($this->modelData->fields as $field)
93
+        {
94
+            if($field->index == "primary")
95
+                continue ;
96
+            if($this->modelData->timeStamps && $field->name == "created_at")
97
+                continue ;
98
+            if($this->modelData->timeStamps && $field->name == "updated_at")
99
+                continue ;
100
+
101
+            if ($firstIteration)
102
+            {
103
+                $fields .= sprintf("'%s'," . PHP_EOL, $field->name);
104
+                $firstIteration = false;
105
+            }
106
+            else
107
+            {
108
+                $fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name);
109
+            }
110
+        }
111
+
112
+        $this->stub = str_replace('{{fillable}}', $fields, $this->stub);
113
+
114
+        return $this;
115
+    }
116
+
117
+    private function addEnumFields() {
118
+
119
+        $items = '';
120
+        $arrays = '';
121 121
 		
122
-		foreach ($this->modelData->fields as $field) {
123
-			$enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php');
122
+        foreach ($this->modelData->fields as $field) {
123
+            $enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php');
124 124
 
125
-			if ($field->type->db == "enum") {
126
-				$items = '';
125
+            if ($field->type->db == "enum") {
126
+                $items = '';
127 127
 				
128
-				foreach ($field->options as $key => $option) {
129
-					$items .= "'" . $option . "'";
130
-					if ($key < (count($field->options) - 1))
131
-						$items .= ", ";
128
+                foreach ($field->options as $key => $option) {
129
+                    $items .= "'" . $option . "'";
130
+                    if ($key < (count($field->options) - 1))
131
+                        $items .= ", ";
132 132
 
133
-				}
133
+                }
134 134
 
135 135
 
136
-				$enumStub = str_replace('{{field_options}}', $items, $enumStub);
137
-				$enumStub = str_replace('{{field_name}}', $field->name, $enumStub);	
136
+                $enumStub = str_replace('{{field_options}}', $items, $enumStub);
137
+                $enumStub = str_replace('{{field_name}}', $field->name, $enumStub);	
138 138
 					
139
-				$arrays .= $enumStub;
139
+                $arrays .= $enumStub;
140 140
 
141 141
 				
142
-			}
143
-		}
144
-
145
-		$this->stub = str_replace('{{enum}}', $arrays, $this->stub);
146
-
147
-		return $this;
148
-	}
149
-
150
-	/**
151
-	 * Set validations.
152
-	 *
153
-	 *
154
-	 * @return $this
155
-	 */
156
-	private function addRules()
157
-	{
158
-		$fields = '';
159
-		$firstIteration = true;
160
-
161
-		foreach ($this->modelData->fields as $field)
162
-		{
163
-			if($field->index == "primary")
164
-				continue ;
165
-			if($this->modelData->timeStamps && $field->name == "created_at")
166
-				continue ;
167
-			if($this->modelData->timeStamps && $field->name == "updated_at")
168
-				continue ;
169
-
170
-			if ($firstIteration)
171
-			{
172
-				$fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
173
-				$firstIteration = false;
174
-			}
175
-			else
176
-			{
177
-				$fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
178
-			}
179
-		}
180
-
181
-		$fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields);
182
-		//var_dump($fields);
183
-
184
-		$this->stub = str_replace('{{validations}}', $fields, $this->stub);
185
-
186
-		return $this;
187
-	}
188
-
189
-	/**
190
-	 * Set the timestamps value.
191
-	 *
192
-	 */
193
-	private function setTimeStamps()
194
-	{
195
-		if($this->modelData->timeStamps)
196
-		{
197
-			$this->stub = str_replace('{{timestamps}}', ' ', $this->stub);
198
-		} else {
199
-			$this->stub = str_replace('{{timestamps}}', 'public $timestamps = false;', $this->stub);
200
-		}
201
-
202
-		return $this;
203
-	}
204
-
205
-	/**
206
-	 *  Set the primary key.
207
-	 *
208
-	 */
209
-	private function setPrimaryKey()
210
-	{
211
-		$primaryKey = '// Using default primary key' . PHP_EOL;
212
-
213
-		$field = $this->getPrimaryKeyField() ;
214
-
215
-		$primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL;
216
-
217
-		$this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub);
218
-
219
-		return $this;
220
-	}
221
-
222
-	/**
223
-	 * Add belongsTo Relationships.
224
-	 *
225
-	 *
226
-	 * @return $this
227
-	 */
228
-	private function addBelongsTo()
229
-	{
230
-		$functions = '';
231
-
232
-		$eagerArray = [];
142
+            }
143
+        }
144
+
145
+        $this->stub = str_replace('{{enum}}', $arrays, $this->stub);
146
+
147
+        return $this;
148
+    }
149
+
150
+    /**
151
+     * Set validations.
152
+     *
153
+     *
154
+     * @return $this
155
+     */
156
+    private function addRules()
157
+    {
158
+        $fields = '';
159
+        $firstIteration = true;
160
+
161
+        foreach ($this->modelData->fields as $field)
162
+        {
163
+            if($field->index == "primary")
164
+                continue ;
165
+            if($this->modelData->timeStamps && $field->name == "created_at")
166
+                continue ;
167
+            if($this->modelData->timeStamps && $field->name == "updated_at")
168
+                continue ;
169
+
170
+            if ($firstIteration)
171
+            {
172
+                $fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
173
+                $firstIteration = false;
174
+            }
175
+            else
176
+            {
177
+                $fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
178
+            }
179
+        }
180
+
181
+        $fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields);
182
+        //var_dump($fields);
183
+
184
+        $this->stub = str_replace('{{validations}}', $fields, $this->stub);
185
+
186
+        return $this;
187
+    }
188
+
189
+    /**
190
+     * Set the timestamps value.
191
+     *
192
+     */
193
+    private function setTimeStamps()
194
+    {
195
+        if($this->modelData->timeStamps)
196
+        {
197
+            $this->stub = str_replace('{{timestamps}}', ' ', $this->stub);
198
+        } else {
199
+            $this->stub = str_replace('{{timestamps}}', 'public $timestamps = false;', $this->stub);
200
+        }
201
+
202
+        return $this;
203
+    }
204
+
205
+    /**
206
+     *  Set the primary key.
207
+     *
208
+     */
209
+    private function setPrimaryKey()
210
+    {
211
+        $primaryKey = '// Using default primary key' . PHP_EOL;
212
+
213
+        $field = $this->getPrimaryKeyField() ;
214
+
215
+        $primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL;
216
+
217
+        $this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub);
218
+
219
+        return $this;
220
+    }
221
+
222
+    /**
223
+     * Add belongsTo Relationships.
224
+     *
225
+     *
226
+     * @return $this
227
+     */
228
+    private function addBelongsTo()
229
+    {
230
+        $functions = '';
231
+
232
+        $eagerArray = [];
233 233
 		
234
-		foreach ($this->modelData->fields as $field)
235
-		{
234
+        foreach ($this->modelData->fields as $field)
235
+        {
236 236
 			
237
-			// Check foreign key
238
-			if (isset($field->foreignKey->relationship))
239
-			{
240
-				$belongsToStub = "";
241
-				$functionName = $field->foreignKey->table;
242
-
243
-				if ($field->foreignKey->relationship == "belongsTo") {
244
-					$belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php');
245
-					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
246
-					$belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub);
247
-					$belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub);
248
-				}
249
-				elseif ($field->foreignKey->relationship == "belongsToMany") {
250
-					$belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
251
-					$functionName = CamelCase::pluralize($field->foreignKey->table);
252
-					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
253
-					$belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub);
254
-					$belongsToStub = str_replace('{{related_field}}', $field->foreignKey->field, $belongsToStub);
255
-					$belongsToStub = str_replace('{{table_name}}', $field->foreignKey->table, $belongsToStub);
256
-				}
237
+            // Check foreign key
238
+            if (isset($field->foreignKey->relationship))
239
+            {
240
+                $belongsToStub = "";
241
+                $functionName = $field->foreignKey->table;
242
+
243
+                if ($field->foreignKey->relationship == "belongsTo") {
244
+                    $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php');
245
+                    $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
246
+                    $belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub);
247
+                    $belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub);
248
+                }
249
+                elseif ($field->foreignKey->relationship == "belongsToMany") {
250
+                    $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
251
+                    $functionName = CamelCase::pluralize($field->foreignKey->table);
252
+                    $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
253
+                    $belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub);
254
+                    $belongsToStub = str_replace('{{related_field}}', $field->foreignKey->field, $belongsToStub);
255
+                    $belongsToStub = str_replace('{{table_name}}', $field->foreignKey->table, $belongsToStub);
256
+                }
257 257
 				
258
-				$belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub);
259
-				$belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub);
258
+                $belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub);
259
+                $belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub);
260 260
 				
261
-				$functions .= $belongsToStub ;
261
+                $functions .= $belongsToStub ;
262 262
 
263
-				if(isset($field->foreignKey->eager) && $field->foreignKey->eager){
264
-					array_push($eagerArray, "'".$field->foreignKey->table."'");
265
-				}
266
-			}
263
+                if(isset($field->foreignKey->eager) && $field->foreignKey->eager){
264
+                    array_push($eagerArray, "'".$field->foreignKey->table."'");
265
+                }
266
+            }
267 267
 
268 268
 			
269
-		}
269
+        }
270 270
 
271
-		$this->stub = str_replace('{{belongsTo}}', $functions, $this->stub);
271
+        $this->stub = str_replace('{{belongsTo}}', $functions, $this->stub);
272 272
 
273
-		$this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub);
273
+        $this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub);
274 274
 
275
-		return $this;
276
-	}
275
+        return $this;
276
+    }
277 277
 
278
-	private function addReverseRelationship()
279
-	{
280
-		$functions = '';
278
+    private function addReverseRelationship()
279
+    {
280
+        $functions = '';
281 281
 
282
-		$eagerArray = [];
282
+        $eagerArray = [];
283 283
 
284
-		foreach ($this->modelData->reverseRelationships as $relationship)
285
-		{
284
+        foreach ($this->modelData->reverseRelationships as $relationship)
285
+        {
286 286
 			
287
-			// Check foreign key
288
-			if ($relationship->foreignKey)
289
-			{
290
-				$reverseRelationshipStub = "";
291
-				$functionName = '';
292
-				if ($relationship->type == "hasOne")
293
-					$functionName = strtolower($relationship->modelName);
294
-				else 
295
-					$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
287
+            // Check foreign key
288
+            if ($relationship->foreignKey)
289
+            {
290
+                $reverseRelationshipStub = "";
291
+                $functionName = '';
292
+                if ($relationship->type == "hasOne")
293
+                    $functionName = strtolower($relationship->modelName);
294
+                else 
295
+                    $functionName = CamelCase::pluralize(strtolower($relationship->modelName));
296 296
 				
297
-				if ($relationship->type == "belongsToMany") {
298
-					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
299
-					$reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub);
300
-					$reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub);
301
-					$reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub);
302
-					$reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub);
303
-					$reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub);
304
-				}
305
-				else {
306
-					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php');
307
-					$reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub);
308
-					$reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub);
309
-					$reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub);
310
-					$reverseRelationshipStub = str_replace('{{type}}', $relationship->type, $reverseRelationshipStub);
311
-					$reverseRelationshipStub = str_replace('{{foreign_table}}', $functionName, $reverseRelationshipStub);
312
-				}
297
+                if ($relationship->type == "belongsToMany") {
298
+                    $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
299
+                    $reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub);
300
+                    $reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub);
301
+                    $reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub);
302
+                    $reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub);
303
+                    $reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub);
304
+                }
305
+                else {
306
+                    $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php');
307
+                    $reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub);
308
+                    $reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub);
309
+                    $reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub);
310
+                    $reverseRelationshipStub = str_replace('{{type}}', $relationship->type, $reverseRelationshipStub);
311
+                    $reverseRelationshipStub = str_replace('{{foreign_table}}', $functionName, $reverseRelationshipStub);
312
+                }
313 313
 					
314
-				$reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub);
314
+                $reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub);
315 315
 				
316
-				$functions .= $reverseRelationshipStub ;
316
+                $functions .= $reverseRelationshipStub ;
317 317
 
318
-				if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){
319
-					array_push($eagerArray, "'".$relationship->foreignKey->table."'");
320
-				}
321
-			}
318
+                if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){
319
+                    array_push($eagerArray, "'".$relationship->foreignKey->table."'");
320
+                }
321
+            }
322 322
 
323 323
 			
324
-		}
324
+        }
325 325
 
326
-		$this->stub = str_replace('{{reverseRelationship}}', $functions, $this->stub);
326
+        $this->stub = str_replace('{{reverseRelationship}}', $functions, $this->stub);
327 327
 
328 328
 
329
-		return $this;
330
-	}
329
+        return $this;
330
+    }
331 331
 
332 332
 
333
-	/**
334
-	 * Replace eager code for each foreing key with eager = true 
335
-	 *
336
-	 * @return $this
337
-	 */
338
-	private function replaceEagerCode()
339
-	{
340
-		$storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
341
-		$eagerConditions = $eagerJoins = '';
333
+    /**
334
+     * Replace eager code for each foreing key with eager = true 
335
+     *
336
+     * @return $this
337
+     */
338
+    private function replaceEagerCode()
339
+    {
340
+        $storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
341
+        $eagerConditions = $eagerJoins = '';
342 342
 
343
-		$storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
344
-		$updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
345
-		$rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
346
-		$useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
347
-		$joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
343
+        $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
344
+        $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
345
+        $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
346
+        $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
347
+        $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
348 348
 
349
-		foreach ($this->modelData->fields as $field)
350
-		{
349
+        foreach ($this->modelData->fields as $field)
350
+        {
351 351
 			
352
-			// Check foreign key
353
-			if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
354
-			{
355
-
356
-				$storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
357
-				$updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
358
-				$ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
359
-				$useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
360
-				$eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
361
-
362
-				// search eager fields
363
-				$foreignModelData = $this->getModelData($field->foreignKey->table);
364
-				$foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
365
-				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
366
-				$eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
367
-				$eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
368
-				$eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
369
-				$eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
370
-				$ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
371
-			}
372
-
373
-		}
374
-
375
-		$this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub);
376
-		$this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub);
377
-		$this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub);
378
-		$this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub);
379
-		$this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub);
380
-		$this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub);
381
-		$this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub);
352
+            // Check foreign key
353
+            if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
354
+            {
355
+
356
+                $storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
357
+                $updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
358
+                $ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
359
+                $useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
360
+                $eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
361
+
362
+                // search eager fields
363
+                $foreignModelData = $this->getModelData($field->foreignKey->table);
364
+                $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
365
+                $foreignControllerCompiler->setEagerTable($this->modelData->tableName);
366
+                $eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
367
+                $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
368
+                $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
369
+                $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
370
+                $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
371
+            }
372
+
373
+        }
374
+
375
+        $this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub);
376
+        $this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub);
377
+        $this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub);
378
+        $this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub);
379
+        $this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub);
380
+        $this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub);
381
+        $this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub);
382 382
 		
383 383
 
384 384
 
385
-		return $this;
386
-	}
385
+        return $this;
386
+    }
387 387
 
388
-	/**
389
-	 * replace relationship tables
390
-	 *
391
-	 * @return $this
392
-	 */
393
-	public function replaceRelationshipTables() {
388
+    /**
389
+     * replace relationship tables
390
+     *
391
+     * @return $this
392
+     */
393
+    public function replaceRelationshipTables() {
394 394
 
395
-		$functions = "";
396
-		$functionsCall = "";
397
-		$removeAll = "";
398
-		$removeAllCall = "";
399
-		$includes = "";
400
-		$joins = "";
401
-		$joinSorts = "";
395
+        $functions = "";
396
+        $functionsCall = "";
397
+        $removeAll = "";
398
+        $removeAllCall = "";
399
+        $includes = "";
400
+        $joins = "";
401
+        $joinSorts = "";
402 402
 
403
-		$method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php');
403
+        $method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php');
404 404
 
405
-		foreach ($this->modelData->reverseRelationships as $relationship) {
405
+        foreach ($this->modelData->reverseRelationships as $relationship) {
406 406
 
407
-			if ($relationship->type == "belongsToMany") {
408
-				$relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable);
409
-				$relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable));
407
+            if ($relationship->type == "belongsToMany") {
408
+                $relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable);
409
+                $relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable));
410 410
 
411
-				$replacedMethod = '';
412
-				$replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method);
413
-				$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
414
-				$replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod);
415
-				$replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod);
416
-				$replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod);
417
-				$replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod);
418
-				$replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod);
411
+                $replacedMethod = '';
412
+                $replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method);
413
+                $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
414
+                $replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod);
415
+                $replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod);
416
+                $replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod);
417
+                $replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod);
418
+                $replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod);
419 419
 
420
-				$functions .= $replacedMethod;
420
+                $functions .= $replacedMethod;
421 421
 
422
-				$methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))';
423
-				$methodCall .= "\n\t\t\t";
424
-				$methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});';
425
-				$methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall);
426
-				$methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
427
-				$methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
422
+                $methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))';
423
+                $methodCall .= "\n\t\t\t";
424
+                $methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});';
425
+                $methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall);
426
+                $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
427
+                $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
428 428
 
429
-				$functionsCall .= $methodCall . "\n\t\t";
429
+                $functionsCall .= $methodCall . "\n\t\t";
430 430
 				
431
-				$removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
432
-				$removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
433
-				$removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
434
-				$removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
435
-				$removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod);
431
+                $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
432
+                $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
433
+                $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
434
+                $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
435
+                $removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod);
436 436
 				
437
-				$removeAll .= $removeAllMethod;
437
+                $removeAll .= $removeAllMethod;
438 438
 
439
-				$removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);';
440
-				$removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
441
-				$removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
439
+                $removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);';
440
+                $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
441
+                $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
442 442
 				
443
-				$removeAllCall .= $removeAllCallMethod . "\n\t\t";
443
+                $removeAllCall .= $removeAllCallMethod . "\n\t\t";
444 444
 
445
-				$joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
446
-				$joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
447
-				$joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
448
-				$joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
449
-				$joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub);
450
-				$joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
451
-				$joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
445
+                $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
446
+                $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
447
+                $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
448
+                $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
449
+                $joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub);
450
+                $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
451
+                $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
452 452
 
453
-				$joins .= $joinRelationshipTableStub . "\n";
453
+                $joins .= $joinRelationshipTableStub . "\n";
454 454
 
455
-				$use = 'use App\Models\{{foreign_table}};';
456
-				$use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
455
+                $use = 'use App\Models\{{foreign_table}};';
456
+                $use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
457 457
 
458
-				$includes .= $use . "\n";
459
-			}
460
-		}
458
+                $includes .= $use . "\n";
459
+            }
460
+        }
461 461
 
462
-		$this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub);
462
+        $this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub);
463 463
 
464
-		$this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub);
464
+        $this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub);
465 465
 
466
-		$this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub);
466
+        $this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub);
467 467
 
468
-		$this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub);
468
+        $this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub);
469 469
 
470
-		$this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub);
470
+        $this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub);
471 471
 
472
-		$this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub);
472
+        $this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub);
473 473
 
474 474
 		
475 475
 		
476
-		return $this;
476
+        return $this;
477 477
 
478
-	}
478
+    }
479 479
 
480 480
 
481
-	/**
482
-	 * Replace search conditions
483
-	 *
484
-	 * @return $this
485
-	 */
486
-	private function replaceSearchConditions(){
481
+    /**
482
+     * Replace search conditions
483
+     *
484
+     * @return $this
485
+     */
486
+    private function replaceSearchConditions(){
487 487
 
488
-		$searchConditions = $this->getSearchConditions();
488
+        $searchConditions = $this->getSearchConditions();
489 489
 
490
-		$this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub);
490
+        $this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub);
491 491
 
492
-		return $this;
493
-	}
492
+        return $this;
493
+    }
494 494
 
495
-	/**
496
-	 * get search conditions
497
-	 *
498
-	 * @return $this
499
-	 */
500
-	public function getSearchConditions(){
495
+    /**
496
+     * get search conditions
497
+     *
498
+     * @return $this
499
+     */
500
+    public function getSearchConditions(){
501 501
 
502
-		$fieldConditions = '';
502
+        $fieldConditions = '';
503 503
 
504
-		$searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
504
+        $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
505 505
 
506
-		foreach ($this->modelData->fields as $field)
507
-		{
506
+        foreach ($this->modelData->fields as $field)
507
+        {
508 508
 
509
-			$fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
509
+            $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
510 510
 
511
-		}
511
+        }
512 512
 
513
-		// replace all field conditions
514
-		$searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions);
513
+        // replace all field conditions
514
+        $searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions);
515 515
 
516
-		// replace table name
517
-		$searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
516
+        // replace table name
517
+        $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
518 518
 
519
-		return $searchConditions ;
519
+        return $searchConditions ;
520 520
 
521
-	}
521
+    }
522 522
 
523
-	/**
524
-	 * get search conditions stub by db type
525
-	 *
526
-	 * @param string $field
527
-	 *
528
-	 * @return $this
529
-	 */
530
-	private $conditionsStub = [];
531
-	private function getConditionStubByField($field){
523
+    /**
524
+     * get search conditions stub by db type
525
+     *
526
+     * @param string $field
527
+     *
528
+     * @return $this
529
+     */
530
+    private $conditionsStub = [];
531
+    private function getConditionStubByField($field){
532 532
 		
533
-		if($field->index == 'primary'){
534
-			$dbType = 'primary' ;
535
-		}
536
-		elseif($field->foreignKey){
537
-			$dbType = 'primary' ;
538
-		}
539
-		elseif($field->type->db == 'enum'){
540
-			$dbType = 'primary' ;
541
-		}
542
-		elseif($field->type->db == 'boolean'){
543
-			$dbType = 'primary' ;
544
-		}
545
-		elseif($field->type->db == 'text'){
546
-			$dbType = 'string' ;
547
-		}
548
-		else {
549
-			$dbType = $field->type->db ;
550
-		}
551
-
552
-		if(array_key_exists($dbType, $this->conditionsStub)){
553
-			return $this->conditionsStub[$dbType];
554
-		}
555
-		else {
556
-			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
557
-
558
-			return $this->conditionsStub[$dbType];
559
-		}
560
-	}
561
-
562
-	public function replaceSortConditions()	{
563
-		$joinSorts = '';
564
-
565
-		foreach ($this->modelData->fields as $field) {
566
-			if($field->foreignKey){
567
-				$joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
568
-				$joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
569
-				$joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
570
-				$joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
571
-				$joinSorts .= $joinSortStub;
572
-
573
-			}
533
+        if($field->index == 'primary'){
534
+            $dbType = 'primary' ;
535
+        }
536
+        elseif($field->foreignKey){
537
+            $dbType = 'primary' ;
538
+        }
539
+        elseif($field->type->db == 'enum'){
540
+            $dbType = 'primary' ;
541
+        }
542
+        elseif($field->type->db == 'boolean'){
543
+            $dbType = 'primary' ;
544
+        }
545
+        elseif($field->type->db == 'text'){
546
+            $dbType = 'string' ;
547
+        }
548
+        else {
549
+            $dbType = $field->type->db ;
550
+        }
551
+
552
+        if(array_key_exists($dbType, $this->conditionsStub)){
553
+            return $this->conditionsStub[$dbType];
554
+        }
555
+        else {
556
+            $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
557
+
558
+            return $this->conditionsStub[$dbType];
559
+        }
560
+    }
561
+
562
+    public function replaceSortConditions()	{
563
+        $joinSorts = '';
564
+
565
+        foreach ($this->modelData->fields as $field) {
566
+            if($field->foreignKey){
567
+                $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
568
+                $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
569
+                $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
570
+                $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
571
+                $joinSorts .= $joinSortStub;
572
+
573
+            }
574 574
 			
575 575
 	
576 576
 			
577
-		}
577
+        }
578 578
 		
579 579
 
580
-		$this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub);
580
+        $this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub);
581 581
 
582
-		return $this;
583
-	}
582
+        return $this;
583
+    }
584 584
 
585 585
 
586 586
 
587
-	/**
588
-	 * replace reverse relationships
589
-	 *
590
-	 * @return $this
591
-	 */
592
-	public function replaceReverseRelationshipsFunctions(){
587
+    /**
588
+     * replace reverse relationships
589
+     *
590
+     * @return $this
591
+     */
592
+    public function replaceReverseRelationshipsFunctions(){
593 593
 
594
-		$functions = '';
594
+        $functions = '';
595 595
 
596
-		$method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php');
596
+        $method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php');
597 597
 
598
-		foreach ($this->modelData->reverseRelationships as $relationship)
599
-		{
600
-			$functionName = '';
601
-			if ($relationship->type == "hasOne")
602
-				$functionName = strtolower($relationship->modelName);
603
-			elseif ($relationship->type == "belongsToMany") 
604
-				$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
605
-			else 
606
-				$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
598
+        foreach ($this->modelData->reverseRelationships as $relationship)
599
+        {
600
+            $functionName = '';
601
+            if ($relationship->type == "hasOne")
602
+                $functionName = strtolower($relationship->modelName);
603
+            elseif ($relationship->type == "belongsToMany") 
604
+                $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
605
+            else 
606
+                $functionName = CamelCase::pluralize(strtolower($relationship->modelName));
607 607
 
608
-			$replacedMethod = '';
609
-			$replacedMethod = str_replace('{{function_name}}', $functionName, $method);
610
-			$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
611
-			$replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod);
608
+            $replacedMethod = '';
609
+            $replacedMethod = str_replace('{{function_name}}', $functionName, $method);
610
+            $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
611
+            $replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod);
612 612
 
613
-			$functions .= $replacedMethod;
614
-		}
613
+            $functions .= $replacedMethod;
614
+        }
615 615
 
616
-		$this->stub = str_replace('{{reverseRelationshipFunctions}}', $functions, $this->stub);
616
+        $this->stub = str_replace('{{reverseRelationshipFunctions}}', $functions, $this->stub);
617 617
 
618
-		return $this;
618
+        return $this;
619 619
 
620
-	}
620
+    }
621 621
 
622 622
 
623
-	/**
624
-	 * replace checkbox fields
625
-	 *
626
-	 * @return $this
627
-	 */
628
-	public function replaceCheckbox(){
623
+    /**
624
+     * replace checkbox fields
625
+     *
626
+     * @return $this
627
+     */
628
+    public function replaceCheckbox(){
629 629
 
630
-		$method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php');
631
-		$key = false;
630
+        $method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php');
631
+        $key = false;
632 632
 
633
-		$method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
634
-		$method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method);
635
-		$method = str_replace('{{model_name}}', $this->modelData->modelName, $method);
636
-		$this->stub = str_replace('{{checkbox}}', $method, $this->stub);
633
+        $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
634
+        $method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method);
635
+        $method = str_replace('{{model_name}}', $this->modelData->modelName, $method);
636
+        $this->stub = str_replace('{{checkbox}}', $method, $this->stub);
637 637
 
638
-		return $this;
638
+        return $this;
639 639
 
640
-	}
640
+    }
641 641
 
642 642
 
643
-	/**
644
-	 * Replace simple filter
645
-	 *
646
-	 * @return $this
647
-	 */
648
-	private function replaceSimpleFilter(){
649
-		$i = 0;
643
+    /**
644
+     * Replace simple filter
645
+     *
646
+     * @return $this
647
+     */
648
+    private function replaceSimpleFilter(){
649
+        $i = 0;
650 650
 
651
-		$stubSimpleFilter = '';
651
+        $stubSimpleFilter = '';
652 652
 
653
-		foreach ($this->modelData->fields as $field)
654
-		{
655
-			//var_dump($field->name);
653
+        foreach ($this->modelData->fields as $field)
654
+        {
655
+            //var_dump($field->name);
656 656
 			
657
-			if($field->index == 'primary'){
658
-				$dbType = 'primaryKey' ;
659
-			}
660
-			elseif($field->foreignKey){
661
-				$dbType = 'primary' ;
662
-			}
663
-			elseif($field->type->db == 'enum'){
664
-				$dbType = 'primary' ;
665
-			}
666
-			elseif($field->type->db == 'boolean'){
667
-				$dbType = 'primary' ;
668
-			}
669
-			elseif($field->type->db == 'text'){
670
-				$dbType = 'string' ;
671
-			}
672
-			else {
673
-				$dbType = $field->type->db ;
674
-			}
657
+            if($field->index == 'primary'){
658
+                $dbType = 'primaryKey' ;
659
+            }
660
+            elseif($field->foreignKey){
661
+                $dbType = 'primary' ;
662
+            }
663
+            elseif($field->type->db == 'enum'){
664
+                $dbType = 'primary' ;
665
+            }
666
+            elseif($field->type->db == 'boolean'){
667
+                $dbType = 'primary' ;
668
+            }
669
+            elseif($field->type->db == 'text'){
670
+                $dbType = 'string' ;
671
+            }
672
+            else {
673
+                $dbType = $field->type->db ;
674
+            }
675 675
 			
676
-			if($dbType == 'primaryKey')
677
-			{
678
-				$stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
679
-			}
680
-
681
-			if($dbType == 'primary')
682
-			{
683
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
684
-			}
685
-
686
-			if($dbType == 'string')
687
-			{
688
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
689
-			}
690
-
691
-			if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
692
-			{
693
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
694
-			}
695
-
696
-		}
697
-		$stubSimpleFilter .= ';';
698
-		$this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub);
699
-
700
-		return $this;
701
-	}
676
+            if($dbType == 'primaryKey')
677
+            {
678
+                $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
679
+            }
680
+
681
+            if($dbType == 'primary')
682
+            {
683
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
684
+            }
685
+
686
+            if($dbType == 'string')
687
+            {
688
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
689
+            }
690
+
691
+            if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
692
+            {
693
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
694
+            }
695
+
696
+        }
697
+        $stubSimpleFilter .= ';';
698
+        $this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub);
699
+
700
+        return $this;
701
+    }
702 702
 }
703 703
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/Core/MigrationCompiler.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -10,130 +10,130 @@
 block discarded – undo
10 10
 
11 11
 class MigrationCompiler extends AbstractCompiler
12 12
 {
13
-	private $date;
13
+    private $date;
14 14
 
15
-	protected $cachePrefix 	= 'migration_';
16
-	protected $stubFilename = 'Migration.php' ;
15
+    protected $cachePrefix 	= 'migration_';
16
+    protected $stubFilename = 'Migration.php' ;
17 17
 
18
-	public function __construct($scaffolderConfig, $modelData = null)
19
-	{
20
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
18
+    public function __construct($scaffolderConfig, $modelData = null)
19
+    {
20
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
21 21
 
22
-		parent::__construct($scaffolderConfig, $modelData);
22
+        parent::__construct($scaffolderConfig, $modelData);
23 23
 
24
-		$this->date = Carbon::now();
25
-	}
24
+        $this->date = Carbon::now();
25
+    }
26 26
 
27
-	/**
28
-	 * Replace and store the Stub.
29
-	 *
30
-	 * @return string
31
-	 */
32
-	public function replaceAndStore()
33
-	{
27
+    /**
28
+     * Replace and store the Stub.
29
+     *
30
+     * @return string
31
+     */
32
+    public function replaceAndStore()
33
+    {
34 34
 		
35
-		return $this->addFields()
36
-					->store(new FileToCompile(false, $this->modelData->modelHash));
35
+        return $this->addFields()
36
+                    ->store(new FileToCompile(false, $this->modelData->modelHash));
37 37
 		
38
-	}
39
-
40
-	/**
41
-	 * Get output filename
42
-	 *
43
-	 *
44
-	 * @return $this
45
-	 */
46
-	protected function getOutputFilename()
47
-	{
48
-
49
-		return  PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php';
50
-	}
51
-
52
-	/**
53
-	 * Add fields.
54
-	 *
55
-	 * @param $modelData
56
-	 *
57
-	 * @return $this
58
-	 */
59
-	private function addFields()
60
-	{
61
-		// Default primary key
62
-		$fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL;
63
-
64
-		// Check primary key
65
-		# TODO FIX, primary
38
+    }
39
+
40
+    /**
41
+     * Get output filename
42
+     *
43
+     *
44
+     * @return $this
45
+     */
46
+    protected function getOutputFilename()
47
+    {
48
+
49
+        return  PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php';
50
+    }
51
+
52
+    /**
53
+     * Add fields.
54
+     *
55
+     * @param $modelData
56
+     *
57
+     * @return $this
58
+     */
59
+    private function addFields()
60
+    {
61
+        // Default primary key
62
+        $fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL;
63
+
64
+        // Check primary key
65
+        # TODO FIX, primary
66 66
 		
67
-		foreach ($this->modelData->fields as $field)
68
-		{
69
-			$parsedModifiers = '';
70
-
71
-			if($field->index == "primary")
72
-				continue ;
73
-			if($this->modelData->timeStamps && $field->name == "created_at")
74
-				continue ;
75
-			if($this->modelData->timeStamps && $field->name == "updated_at")
76
-				continue ;
77
-
78
-			// Check modifiers
79
-			if (!empty($field->modifiers))
80
-			{
81
-				$modifiersArray = explode(':', $field->modifiers);
82
-
83
-				foreach ($modifiersArray as $modifier)
84
-				{
85
-					$modifierAndValue = explode(',', $modifier);
86
-
87
-					if (count($modifierAndValue) == 2)
88
-					{
89
-						$parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')';
90
-					}
91
-					else
92
-					{
93
-						$parsedModifiers .= '->' . $modifierAndValue[0] . '()';
94
-					}
95
-				}
96
-			}
97
-
98
-			// Check foreign key for unsigned modifier
99
-			if ($field->foreignKey)
100
-			{
101
-				$parsedModifiers .= '->unsigned()';
102
-			}
103
-
104
-			// Check indexes
105
-			if ($field->index != 'none')
106
-			{
107
-				$fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index);
108
-			}
109
-			else
110
-			{
111
-				if ($field->type->db == "enum") {
112
-					$items = '';
113
-					foreach ($field->options as $key => $option) {
114
-						$items .= "'" . $option . "'";
115
-						if ($key < (count($field->options) - 1))
116
-							$items .= ", ";
117
-					}
118
-
119
-					$fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items);
120
-				}
121
-				else
122
-					$fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
123
-			}
124
-
125
-			// Check foreign key
126
-			if ($field->foreignKey)
127
-			{
128
-				$fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table);
129
-			}
130
-		}
131
-
132
-		if($this->modelData->timeStamps)
133
-			$fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL;
134
-
135
-		$this->stub = str_replace('{{fields}}', $fields, $this->stub);
136
-
137
-		return $this;
138
-	}
67
+        foreach ($this->modelData->fields as $field)
68
+        {
69
+            $parsedModifiers = '';
70
+
71
+            if($field->index == "primary")
72
+                continue ;
73
+            if($this->modelData->timeStamps && $field->name == "created_at")
74
+                continue ;
75
+            if($this->modelData->timeStamps && $field->name == "updated_at")
76
+                continue ;
77
+
78
+            // Check modifiers
79
+            if (!empty($field->modifiers))
80
+            {
81
+                $modifiersArray = explode(':', $field->modifiers);
82
+
83
+                foreach ($modifiersArray as $modifier)
84
+                {
85
+                    $modifierAndValue = explode(',', $modifier);
86
+
87
+                    if (count($modifierAndValue) == 2)
88
+                    {
89
+                        $parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')';
90
+                    }
91
+                    else
92
+                    {
93
+                        $parsedModifiers .= '->' . $modifierAndValue[0] . '()';
94
+                    }
95
+                }
96
+            }
97
+
98
+            // Check foreign key for unsigned modifier
99
+            if ($field->foreignKey)
100
+            {
101
+                $parsedModifiers .= '->unsigned()';
102
+            }
103
+
104
+            // Check indexes
105
+            if ($field->index != 'none')
106
+            {
107
+                $fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index);
108
+            }
109
+            else
110
+            {
111
+                if ($field->type->db == "enum") {
112
+                    $items = '';
113
+                    foreach ($field->options as $key => $option) {
114
+                        $items .= "'" . $option . "'";
115
+                        if ($key < (count($field->options) - 1))
116
+                            $items .= ", ";
117
+                    }
118
+
119
+                    $fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items);
120
+                }
121
+                else
122
+                    $fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
123
+            }
124
+
125
+            // Check foreign key
126
+            if ($field->foreignKey)
127
+            {
128
+                $fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table);
129
+            }
130
+        }
131
+
132
+        if($this->modelData->timeStamps)
133
+            $fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL;
134
+
135
+        $this->stub = str_replace('{{fields}}', $fields, $this->stub);
136
+
137
+        return $this;
138
+    }
139 139
 }
140 140
\ No newline at end of file
Please login to merge, or discard this patch.