@@ -4,6 +4,9 @@ |
||
4 | 4 | |
5 | 5 | class Arrays |
6 | 6 | { |
7 | + /** |
|
8 | + * @param integer $targetIndex |
|
9 | + */ |
|
7 | 10 | public static function moveElement($array, $toMove, $targetIndex) { |
8 | 11 | if (count($array) == 1) |
9 | 12 | return $array; |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | class Arrays |
6 | 6 | { |
7 | - public static function moveElement($array, $toMove, $targetIndex) { |
|
8 | - if (count($array) == 1) |
|
9 | - return $array; |
|
10 | - if (is_int($toMove)) { |
|
11 | - $tmp = array_splice($array, $toMove, 1); |
|
12 | - array_splice($array, $targetIndex, 0, $tmp); |
|
13 | - $output = $array; |
|
14 | - } |
|
15 | - elseif (is_string($toMove)) { |
|
16 | - $indexToMove = array_search($toMove, array_keys($array)); |
|
17 | - $itemToMove = $array[$toMove]; |
|
18 | - array_splice($array, $indexToMove, 1); |
|
19 | - $i = 0; |
|
20 | - $output = Array(); |
|
21 | - foreach($array as $key => $item) { |
|
22 | - if ($i == $targetIndex) { |
|
23 | - $output[$toMove] = $itemToMove; |
|
24 | - } |
|
25 | - $output[$key] = $item; |
|
26 | - $i++; |
|
27 | - } |
|
28 | - } |
|
29 | - return $output; |
|
30 | - } |
|
7 | + public static function moveElement($array, $toMove, $targetIndex) { |
|
8 | + if (count($array) == 1) |
|
9 | + return $array; |
|
10 | + if (is_int($toMove)) { |
|
11 | + $tmp = array_splice($array, $toMove, 1); |
|
12 | + array_splice($array, $targetIndex, 0, $tmp); |
|
13 | + $output = $array; |
|
14 | + } |
|
15 | + elseif (is_string($toMove)) { |
|
16 | + $indexToMove = array_search($toMove, array_keys($array)); |
|
17 | + $itemToMove = $array[$toMove]; |
|
18 | + array_splice($array, $indexToMove, 1); |
|
19 | + $i = 0; |
|
20 | + $output = Array(); |
|
21 | + foreach($array as $key => $item) { |
|
22 | + if ($i == $targetIndex) { |
|
23 | + $output[$toMove] = $itemToMove; |
|
24 | + } |
|
25 | + $output[$key] = $item; |
|
26 | + $i++; |
|
27 | + } |
|
28 | + } |
|
29 | + return $output; |
|
30 | + } |
|
31 | 31 | } |
32 | 32 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | array_splice($array, $indexToMove, 1); |
19 | 19 | $i = 0; |
20 | 20 | $output = Array(); |
21 | - foreach($array as $key => $item) { |
|
21 | + foreach ($array as $key => $item) { |
|
22 | 22 | if ($i == $targetIndex) { |
23 | 23 | $output[$toMove] = $itemToMove; |
24 | 24 | } |
@@ -5,14 +5,14 @@ |
||
5 | 5 | class Arrays |
6 | 6 | { |
7 | 7 | public static function moveElement($array, $toMove, $targetIndex) { |
8 | - if (count($array) == 1) |
|
9 | - return $array; |
|
8 | + if (count($array) == 1) { |
|
9 | + return $array; |
|
10 | + } |
|
10 | 11 | if (is_int($toMove)) { |
11 | 12 | $tmp = array_splice($array, $toMove, 1); |
12 | 13 | array_splice($array, $targetIndex, 0, $tmp); |
13 | 14 | $output = $array; |
14 | - } |
|
15 | - elseif (is_string($toMove)) { |
|
15 | + } elseif (is_string($toMove)) { |
|
16 | 16 | $indexToMove = array_search($toMove, array_keys($array)); |
17 | 17 | $itemToMove = $array[$toMove]; |
18 | 18 | array_splice($array, $indexToMove, 1); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param string $rule |
36 | 36 | * @param string $parameter |
37 | - * @return array |
|
37 | + * @return string |
|
38 | 38 | */ |
39 | 39 | public static function parseParameters($rule, $parameter) |
40 | 40 | { |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * Explode the rules into an array of rules. |
50 | 50 | * |
51 | - * @param string $rules |
|
51 | + * @param string $rule |
|
52 | 52 | * @return array |
53 | 53 | */ |
54 | 54 | public static function explodeRule($rule) |
@@ -2,9 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace Scaffolder\Support; |
4 | 4 | |
5 | -use Illuminate\Support\Arr; |
|
6 | -use Illuminate\Support\Str; |
|
7 | - |
|
8 | 5 | class Validator |
9 | 6 | { |
10 | 7 | /** |
@@ -7,104 +7,104 @@ |
||
7 | 7 | |
8 | 8 | class Validator |
9 | 9 | { |
10 | - /** |
|
11 | - * Parse a string based rule. |
|
12 | - * |
|
13 | - * @param string $rules |
|
14 | - * @return array |
|
15 | - */ |
|
16 | - public static function parseStringRule($rules) |
|
17 | - { |
|
18 | - $parameters = []; |
|
19 | - |
|
20 | - // The format for specifying validation rules and parameters follows an |
|
21 | - // easy {rule}:{parameters} formatting convention. For instance the |
|
22 | - // rule "Max:3" states that the value may only be three letters. |
|
23 | - if (strpos($rules, ':') !== false) { |
|
24 | - list($rules, $parameter) = explode(':', $rules, 2); |
|
25 | - |
|
26 | - $parameters = self::parseParameters($rules, $parameter); |
|
27 | - } |
|
28 | - |
|
29 | - return [(trim($rules)), $parameters]; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Parse a parameter list. |
|
34 | - * |
|
35 | - * @param string $rule |
|
36 | - * @param string $parameter |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public static function parseParameters($rule, $parameter) |
|
40 | - { |
|
41 | - if (strtolower($rule) == 'regex') { |
|
42 | - return [$parameter]; |
|
43 | - } |
|
44 | - |
|
45 | - return str_getcsv($parameter); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Explode the rules into an array of rules. |
|
50 | - * |
|
51 | - * @param string $rules |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public static function explodeRule($rule) |
|
55 | - { |
|
56 | - return explode('|', $rule); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Convert laravel validations to theme validation angular js. |
|
61 | - * |
|
62 | - * @param string $validations |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public static function convertValidations($validations, $blnSearch = false){ |
|
66 | - $validationsConverted = []; |
|
67 | - foreach (self::explodeRule($validations) as $validation) { |
|
68 | - $validation = self::parseStringRule($validation); |
|
69 | - |
|
70 | - if(isset($validation[0])){ |
|
71 | - |
|
72 | - $rule = $validation[0]; |
|
73 | - $values = $validation[1]; |
|
74 | - |
|
75 | - switch ($rule) { |
|
76 | - case 'required': |
|
77 | - if($blnSearch) { |
|
78 | - $attribute = null ; |
|
79 | - $attributeValue = null ; |
|
80 | - } |
|
81 | - else { |
|
82 | - $attribute = "required" ; |
|
83 | - $attributeValue = null ; |
|
84 | - } |
|
10 | + /** |
|
11 | + * Parse a string based rule. |
|
12 | + * |
|
13 | + * @param string $rules |
|
14 | + * @return array |
|
15 | + */ |
|
16 | + public static function parseStringRule($rules) |
|
17 | + { |
|
18 | + $parameters = []; |
|
19 | + |
|
20 | + // The format for specifying validation rules and parameters follows an |
|
21 | + // easy {rule}:{parameters} formatting convention. For instance the |
|
22 | + // rule "Max:3" states that the value may only be three letters. |
|
23 | + if (strpos($rules, ':') !== false) { |
|
24 | + list($rules, $parameter) = explode(':', $rules, 2); |
|
25 | + |
|
26 | + $parameters = self::parseParameters($rules, $parameter); |
|
27 | + } |
|
28 | + |
|
29 | + return [(trim($rules)), $parameters]; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Parse a parameter list. |
|
34 | + * |
|
35 | + * @param string $rule |
|
36 | + * @param string $parameter |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public static function parseParameters($rule, $parameter) |
|
40 | + { |
|
41 | + if (strtolower($rule) == 'regex') { |
|
42 | + return [$parameter]; |
|
43 | + } |
|
44 | + |
|
45 | + return str_getcsv($parameter); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Explode the rules into an array of rules. |
|
50 | + * |
|
51 | + * @param string $rules |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public static function explodeRule($rule) |
|
55 | + { |
|
56 | + return explode('|', $rule); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Convert laravel validations to theme validation angular js. |
|
61 | + * |
|
62 | + * @param string $validations |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public static function convertValidations($validations, $blnSearch = false){ |
|
66 | + $validationsConverted = []; |
|
67 | + foreach (self::explodeRule($validations) as $validation) { |
|
68 | + $validation = self::parseStringRule($validation); |
|
69 | + |
|
70 | + if(isset($validation[0])){ |
|
71 | + |
|
72 | + $rule = $validation[0]; |
|
73 | + $values = $validation[1]; |
|
74 | + |
|
75 | + switch ($rule) { |
|
76 | + case 'required': |
|
77 | + if($blnSearch) { |
|
78 | + $attribute = null ; |
|
79 | + $attributeValue = null ; |
|
80 | + } |
|
81 | + else { |
|
82 | + $attribute = "required" ; |
|
83 | + $attributeValue = null ; |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'max': |
|
89 | - case 'min': |
|
90 | - $attribute = $rule.'length' ; |
|
91 | - $attributeValue = $values[0] ; |
|
92 | - break; |
|
88 | + case 'max': |
|
89 | + case 'min': |
|
90 | + $attribute = $rule.'length' ; |
|
91 | + $attributeValue = $values[0] ; |
|
92 | + break; |
|
93 | 93 | |
94 | - default: |
|
95 | - $attribute = null ; |
|
96 | - $attributeValue = null ; |
|
97 | - break; |
|
98 | - } |
|
94 | + default: |
|
95 | + $attribute = null ; |
|
96 | + $attributeValue = null ; |
|
97 | + break; |
|
98 | + } |
|
99 | 99 | |
100 | - if($attribute) |
|
101 | - $validationsConverted[$attribute] = $attributeValue ; |
|
100 | + if($attribute) |
|
101 | + $validationsConverted[$attribute] = $attributeValue ; |
|
102 | 102 | |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | - return $validationsConverted ; |
|
108 | - } |
|
107 | + return $validationsConverted ; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
111 | 111 | \ No newline at end of file |
@@ -62,49 +62,49 @@ |
||
62 | 62 | * @param string $validations |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public static function convertValidations($validations, $blnSearch = false){ |
|
65 | + public static function convertValidations($validations, $blnSearch = false) { |
|
66 | 66 | $validationsConverted = []; |
67 | 67 | foreach (self::explodeRule($validations) as $validation) { |
68 | 68 | $validation = self::parseStringRule($validation); |
69 | 69 | |
70 | - if(isset($validation[0])){ |
|
70 | + if (isset($validation[0])) { |
|
71 | 71 | |
72 | 72 | $rule = $validation[0]; |
73 | 73 | $values = $validation[1]; |
74 | 74 | |
75 | 75 | switch ($rule) { |
76 | 76 | case 'required': |
77 | - if($blnSearch) { |
|
78 | - $attribute = null ; |
|
79 | - $attributeValue = null ; |
|
77 | + if ($blnSearch) { |
|
78 | + $attribute = null; |
|
79 | + $attributeValue = null; |
|
80 | 80 | } |
81 | 81 | else { |
82 | - $attribute = "required" ; |
|
83 | - $attributeValue = null ; |
|
82 | + $attribute = "required"; |
|
83 | + $attributeValue = null; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | break; |
87 | 87 | |
88 | 88 | case 'max': |
89 | 89 | case 'min': |
90 | - $attribute = $rule.'length' ; |
|
91 | - $attributeValue = $values[0] ; |
|
90 | + $attribute = $rule.'length'; |
|
91 | + $attributeValue = $values[0]; |
|
92 | 92 | break; |
93 | 93 | |
94 | 94 | default: |
95 | - $attribute = null ; |
|
96 | - $attributeValue = null ; |
|
95 | + $attribute = null; |
|
96 | + $attributeValue = null; |
|
97 | 97 | break; |
98 | 98 | } |
99 | 99 | |
100 | - if($attribute) |
|
101 | - $validationsConverted[$attribute] = $attributeValue ; |
|
100 | + if ($attribute) |
|
101 | + $validationsConverted[$attribute] = $attributeValue; |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | 105 | } |
106 | 106 | |
107 | - return $validationsConverted ; |
|
107 | + return $validationsConverted; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
111 | 111 | \ No newline at end of file |
@@ -77,8 +77,7 @@ discard block |
||
77 | 77 | if($blnSearch) { |
78 | 78 | $attribute = null ; |
79 | 79 | $attributeValue = null ; |
80 | - } |
|
81 | - else { |
|
80 | + } else { |
|
82 | 81 | $attribute = "required" ; |
83 | 82 | $attributeValue = null ; |
84 | 83 | } |
@@ -97,8 +96,9 @@ discard block |
||
97 | 96 | break; |
98 | 97 | } |
99 | 98 | |
100 | - if($attribute) |
|
101 | - $validationsConverted[$attribute] = $attributeValue ; |
|
99 | + if($attribute) { |
|
100 | + $validationsConverted[$attribute] = $attributeValue ; |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
104 | 104 |
@@ -6,13 +6,13 @@ |
||
6 | 6 | |
7 | 7 | class Directory |
8 | 8 | { |
9 | - public static function createIfNotExists($path, $mode = 0755, $recursive = false, $force = false) |
|
10 | - { |
|
11 | - if (!File::isDirectory($path)) |
|
12 | - { |
|
13 | - File::makeDirectory($path, $mode, $recursive , $force ); |
|
14 | - } |
|
15 | - } |
|
9 | + public static function createIfNotExists($path, $mode = 0755, $recursive = false, $force = false) |
|
10 | + { |
|
11 | + if (!File::isDirectory($path)) |
|
12 | + { |
|
13 | + File::makeDirectory($path, $mode, $recursive , $force ); |
|
14 | + } |
|
15 | + } |
|
16 | 16 | |
17 | 17 | |
18 | 18 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | { |
11 | 11 | if (!File::isDirectory($path)) |
12 | 12 | { |
13 | - File::makeDirectory($path, $mode, $recursive , $force ); |
|
13 | + File::makeDirectory($path, $mode, $recursive, $force); |
|
14 | 14 | } |
15 | 15 | } |
16 | 16 |
@@ -4,70 +4,70 @@ |
||
4 | 4 | |
5 | 5 | class CamelCase |
6 | 6 | { |
7 | - /** |
|
8 | - * Given an underscore_separated_string, this will convert the string |
|
9 | - * to CamelCaseNotation. Note that this will ignore any casing in the |
|
10 | - * underscore separated string. |
|
11 | - * |
|
12 | - * @param string $strString |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - public static function convertToCamelCase($strString) { |
|
16 | - return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($strString)))); |
|
17 | - } |
|
7 | + /** |
|
8 | + * Given an underscore_separated_string, this will convert the string |
|
9 | + * to CamelCaseNotation. Note that this will ignore any casing in the |
|
10 | + * underscore separated string. |
|
11 | + * |
|
12 | + * @param string $strString |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + public static function convertToCamelCase($strString) { |
|
16 | + return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($strString)))); |
|
17 | + } |
|
18 | 18 | |
19 | - public static function underscoreFromCamelCase($strName) { |
|
20 | - if (strlen($strName) == 0) return ''; |
|
19 | + public static function underscoreFromCamelCase($strName) { |
|
20 | + if (strlen($strName) == 0) return ''; |
|
21 | 21 | |
22 | - $strToReturn = self::FirstCharacter($strName); |
|
22 | + $strToReturn = self::FirstCharacter($strName); |
|
23 | 23 | |
24 | - for ($intIndex = 1; $intIndex < strlen($strName); $intIndex++) { |
|
25 | - $strChar = substr($strName, $intIndex, 1); |
|
26 | - if (strtoupper($strChar) == $strChar) |
|
27 | - $strToReturn .= '_' . $strChar; |
|
28 | - else |
|
29 | - $strToReturn .= $strChar; |
|
30 | - } |
|
24 | + for ($intIndex = 1; $intIndex < strlen($strName); $intIndex++) { |
|
25 | + $strChar = substr($strName, $intIndex, 1); |
|
26 | + if (strtoupper($strChar) == $strChar) |
|
27 | + $strToReturn .= '_' . $strChar; |
|
28 | + else |
|
29 | + $strToReturn .= $strChar; |
|
30 | + } |
|
31 | 31 | |
32 | - return strtolower($strToReturn); |
|
33 | - } |
|
32 | + return strtolower($strToReturn); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Returns the first character of a given string, or null if the given |
|
37 | - * string is null. |
|
38 | - * @param string $strString |
|
39 | - * @return string the first character, or null |
|
40 | - */ |
|
41 | - public final static function firstCharacter($strString) { |
|
42 | - if (strlen($strString) > 0) |
|
43 | - return substr($strString, 0 , 1); |
|
44 | - else |
|
45 | - return null; |
|
46 | - } |
|
35 | + /** |
|
36 | + * Returns the first character of a given string, or null if the given |
|
37 | + * string is null. |
|
38 | + * @param string $strString |
|
39 | + * @return string the first character, or null |
|
40 | + */ |
|
41 | + public final static function firstCharacter($strString) { |
|
42 | + if (strlen($strString) > 0) |
|
43 | + return substr($strString, 0 , 1); |
|
44 | + else |
|
45 | + return null; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - public static function pluralize($strName) { |
|
50 | - // Special Rules go Here |
|
51 | - switch (true) { |
|
52 | - case (strtolower($strName) == 'play'): |
|
53 | - return $strName . 's'; |
|
54 | - } |
|
49 | + public static function pluralize($strName) { |
|
50 | + // Special Rules go Here |
|
51 | + switch (true) { |
|
52 | + case (strtolower($strName) == 'play'): |
|
53 | + return $strName . 's'; |
|
54 | + } |
|
55 | 55 | |
56 | - $intLength = strlen($strName); |
|
57 | - if (substr($strName, $intLength - 1) == "y") |
|
58 | - return substr($strName, 0, $intLength - 1) . "ies"; |
|
59 | - if (substr($strName, $intLength - 1) == "s") |
|
60 | - return $strName . "es"; |
|
61 | - if (substr($strName, $intLength - 1) == "x") |
|
62 | - return $strName . "es"; |
|
63 | - if (substr($strName, $intLength - 1) == "z") |
|
64 | - return $strName . "zes"; |
|
65 | - if (substr($strName, $intLength - 2) == "sh") |
|
66 | - return $strName . "es"; |
|
67 | - if (substr($strName, $intLength - 2) == "ch") |
|
68 | - return $strName . "es"; |
|
56 | + $intLength = strlen($strName); |
|
57 | + if (substr($strName, $intLength - 1) == "y") |
|
58 | + return substr($strName, 0, $intLength - 1) . "ies"; |
|
59 | + if (substr($strName, $intLength - 1) == "s") |
|
60 | + return $strName . "es"; |
|
61 | + if (substr($strName, $intLength - 1) == "x") |
|
62 | + return $strName . "es"; |
|
63 | + if (substr($strName, $intLength - 1) == "z") |
|
64 | + return $strName . "zes"; |
|
65 | + if (substr($strName, $intLength - 2) == "sh") |
|
66 | + return $strName . "es"; |
|
67 | + if (substr($strName, $intLength - 2) == "ch") |
|
68 | + return $strName . "es"; |
|
69 | 69 | |
70 | - return $strName . "s"; |
|
71 | - } |
|
70 | + return $strName . "s"; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | } |
74 | 74 | \ No newline at end of file |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | for ($intIndex = 1; $intIndex < strlen($strName); $intIndex++) { |
25 | 25 | $strChar = substr($strName, $intIndex, 1); |
26 | 26 | if (strtoupper($strChar) == $strChar) |
27 | - $strToReturn .= '_' . $strChar; |
|
27 | + $strToReturn .= '_'.$strChar; |
|
28 | 28 | else |
29 | 29 | $strToReturn .= $strChar; |
30 | 30 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public final static function firstCharacter($strString) { |
42 | 42 | if (strlen($strString) > 0) |
43 | - return substr($strString, 0 , 1); |
|
43 | + return substr($strString, 0, 1); |
|
44 | 44 | else |
45 | 45 | return null; |
46 | 46 | } |
@@ -50,24 +50,24 @@ discard block |
||
50 | 50 | // Special Rules go Here |
51 | 51 | switch (true) { |
52 | 52 | case (strtolower($strName) == 'play'): |
53 | - return $strName . 's'; |
|
53 | + return $strName.'s'; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | $intLength = strlen($strName); |
57 | 57 | if (substr($strName, $intLength - 1) == "y") |
58 | - return substr($strName, 0, $intLength - 1) . "ies"; |
|
58 | + return substr($strName, 0, $intLength - 1)."ies"; |
|
59 | 59 | if (substr($strName, $intLength - 1) == "s") |
60 | - return $strName . "es"; |
|
60 | + return $strName."es"; |
|
61 | 61 | if (substr($strName, $intLength - 1) == "x") |
62 | - return $strName . "es"; |
|
62 | + return $strName."es"; |
|
63 | 63 | if (substr($strName, $intLength - 1) == "z") |
64 | - return $strName . "zes"; |
|
64 | + return $strName."zes"; |
|
65 | 65 | if (substr($strName, $intLength - 2) == "sh") |
66 | - return $strName . "es"; |
|
66 | + return $strName."es"; |
|
67 | 67 | if (substr($strName, $intLength - 2) == "ch") |
68 | - return $strName . "es"; |
|
68 | + return $strName."es"; |
|
69 | 69 | |
70 | - return $strName . "s"; |
|
70 | + return $strName."s"; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | } |
74 | 74 | \ No newline at end of file |
@@ -17,16 +17,19 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public static function underscoreFromCamelCase($strName) { |
20 | - if (strlen($strName) == 0) return ''; |
|
20 | + if (strlen($strName) == 0) { |
|
21 | + return ''; |
|
22 | + } |
|
21 | 23 | |
22 | 24 | $strToReturn = self::FirstCharacter($strName); |
23 | 25 | |
24 | 26 | for ($intIndex = 1; $intIndex < strlen($strName); $intIndex++) { |
25 | 27 | $strChar = substr($strName, $intIndex, 1); |
26 | - if (strtoupper($strChar) == $strChar) |
|
27 | - $strToReturn .= '_' . $strChar; |
|
28 | - else |
|
29 | - $strToReturn .= $strChar; |
|
28 | + if (strtoupper($strChar) == $strChar) { |
|
29 | + $strToReturn .= '_' . $strChar; |
|
30 | + } else { |
|
31 | + $strToReturn .= $strChar; |
|
32 | + } |
|
30 | 33 | } |
31 | 34 | |
32 | 35 | return strtolower($strToReturn); |
@@ -39,10 +42,11 @@ discard block |
||
39 | 42 | * @return string the first character, or null |
40 | 43 | */ |
41 | 44 | public final static function firstCharacter($strString) { |
42 | - if (strlen($strString) > 0) |
|
43 | - return substr($strString, 0 , 1); |
|
44 | - else |
|
45 | - return null; |
|
45 | + if (strlen($strString) > 0) { |
|
46 | + return substr($strString, 0 , 1); |
|
47 | + } else { |
|
48 | + return null; |
|
49 | + } |
|
46 | 50 | } |
47 | 51 | |
48 | 52 | |
@@ -54,18 +58,24 @@ discard block |
||
54 | 58 | } |
55 | 59 | |
56 | 60 | $intLength = strlen($strName); |
57 | - if (substr($strName, $intLength - 1) == "y") |
|
58 | - return substr($strName, 0, $intLength - 1) . "ies"; |
|
59 | - if (substr($strName, $intLength - 1) == "s") |
|
60 | - return $strName . "es"; |
|
61 | - if (substr($strName, $intLength - 1) == "x") |
|
62 | - return $strName . "es"; |
|
63 | - if (substr($strName, $intLength - 1) == "z") |
|
64 | - return $strName . "zes"; |
|
65 | - if (substr($strName, $intLength - 2) == "sh") |
|
66 | - return $strName . "es"; |
|
67 | - if (substr($strName, $intLength - 2) == "ch") |
|
68 | - return $strName . "es"; |
|
61 | + if (substr($strName, $intLength - 1) == "y") { |
|
62 | + return substr($strName, 0, $intLength - 1) . "ies"; |
|
63 | + } |
|
64 | + if (substr($strName, $intLength - 1) == "s") { |
|
65 | + return $strName . "es"; |
|
66 | + } |
|
67 | + if (substr($strName, $intLength - 1) == "x") { |
|
68 | + return $strName . "es"; |
|
69 | + } |
|
70 | + if (substr($strName, $intLength - 1) == "z") { |
|
71 | + return $strName . "zes"; |
|
72 | + } |
|
73 | + if (substr($strName, $intLength - 2) == "sh") { |
|
74 | + return $strName . "es"; |
|
75 | + } |
|
76 | + if (substr($strName, $intLength - 2) == "ch") { |
|
77 | + return $strName . "es"; |
|
78 | + } |
|
69 | 79 | |
70 | 80 | return $strName . "s"; |
71 | 81 | } |
@@ -13,60 +13,60 @@ |
||
13 | 13 | |
14 | 14 | class BuildCommand extends Command |
15 | 15 | { |
16 | - protected $signature = 'scaffolder:build {app=webapp}'; |
|
16 | + protected $signature = 'scaffolder:build {app=webapp}'; |
|
17 | 17 | |
18 | - protected $description = 'Build the generated code to public folder'; |
|
18 | + protected $description = 'Build the generated code to public folder'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Execute the Command. |
|
22 | - */ |
|
23 | - public function handle() |
|
24 | - { |
|
20 | + /** |
|
21 | + * Execute the Command. |
|
22 | + */ |
|
23 | + public function handle() |
|
24 | + { |
|
25 | 25 | |
26 | 26 | |
27 | - switch ($this->argument('app')) { |
|
28 | - case 'webapp': |
|
27 | + switch ($this->argument('app')) { |
|
28 | + case 'webapp': |
|
29 | 29 | |
30 | - $this->cleanPublicFolder(); |
|
30 | + $this->cleanPublicFolder(); |
|
31 | 31 | |
32 | - $gulpCommand = sprintf('gulp build --cwd "%s/codificar/scaffolder-theme-material/"', base_path('vendor')); |
|
32 | + $gulpCommand = sprintf('gulp build --cwd "%s/codificar/scaffolder-theme-material/"', base_path('vendor')); |
|
33 | 33 | |
34 | - //$this->info('- gulpCommand: '. $gulpCommand); |
|
34 | + //$this->info('- gulpCommand: '. $gulpCommand); |
|
35 | 35 | |
36 | - $handle = popen($gulpCommand, 'r'); |
|
36 | + $handle = popen($gulpCommand, 'r'); |
|
37 | 37 | |
38 | - while(!feof($handle)) |
|
39 | - { |
|
40 | - // send the current file part to the browser |
|
41 | - $this->info(fread($handle, 1024)); |
|
42 | - } |
|
38 | + while(!feof($handle)) |
|
39 | + { |
|
40 | + // send the current file part to the browser |
|
41 | + $this->info(fread($handle, 1024)); |
|
42 | + } |
|
43 | 43 | |
44 | - fclose($handle); |
|
44 | + fclose($handle); |
|
45 | 45 | |
46 | - // php artisan serve |
|
47 | - $this->call('serve'); |
|
46 | + // php artisan serve |
|
47 | + $this->call('serve'); |
|
48 | 48 | |
49 | - break; |
|
49 | + break; |
|
50 | 50 | |
51 | - default: |
|
52 | - $this->info('Invalid arguments'); |
|
53 | - break; |
|
54 | - } |
|
51 | + default: |
|
52 | + $this->info('Invalid arguments'); |
|
53 | + break; |
|
54 | + } |
|
55 | 55 | |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - private function cleanPublicFolder(){ |
|
59 | - $this->info('Cleaning public directory'); |
|
58 | + private function cleanPublicFolder(){ |
|
59 | + $this->info('Cleaning public directory'); |
|
60 | 60 | |
61 | - File::deleteDirectory(sprintf("%s/app", base_path('public'))); |
|
62 | - File::deleteDirectory(sprintf("%s/assets", base_path('public'))); |
|
63 | - File::deleteDirectory(sprintf("%s/fonts", base_path('public'))); |
|
64 | - File::deleteDirectory(sprintf("%s/maps", base_path('public'))); |
|
65 | - File::deleteDirectory(sprintf("%s/scripts", base_path('public'))); |
|
66 | - File::deleteDirectory(sprintf("%s/styles", base_path('public'))); |
|
61 | + File::deleteDirectory(sprintf("%s/app", base_path('public'))); |
|
62 | + File::deleteDirectory(sprintf("%s/assets", base_path('public'))); |
|
63 | + File::deleteDirectory(sprintf("%s/fonts", base_path('public'))); |
|
64 | + File::deleteDirectory(sprintf("%s/maps", base_path('public'))); |
|
65 | + File::deleteDirectory(sprintf("%s/scripts", base_path('public'))); |
|
66 | + File::deleteDirectory(sprintf("%s/styles", base_path('public'))); |
|
67 | 67 | |
68 | - File::delete(sprintf("%s/index.html", base_path('public'))); |
|
69 | - } |
|
68 | + File::delete(sprintf("%s/index.html", base_path('public'))); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | 72 | } |
73 | 73 | \ No newline at end of file |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use Illuminate\Console\Command; |
6 | 6 | use Illuminate\Support\Facades\File; |
7 | 7 | |
8 | -use stdClass ; |
|
8 | +use stdClass; |
|
9 | 9 | |
10 | 10 | // Support classes |
11 | 11 | use Scaffolder\Support\Directory; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | $handle = popen($gulpCommand, 'r'); |
37 | 37 | |
38 | - while(!feof($handle)) |
|
38 | + while (!feof($handle)) |
|
39 | 39 | { |
40 | 40 | // send the current file part to the browser |
41 | 41 | $this->info(fread($handle, 1024)); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | } |
57 | 57 | |
58 | - private function cleanPublicFolder(){ |
|
58 | + private function cleanPublicFolder() { |
|
59 | 59 | $this->info('Cleaning public directory'); |
60 | 60 | |
61 | 61 | File::deleteDirectory(sprintf("%s/app", base_path('public'))); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
46 | 46 | { |
47 | - $path = PathParser::parse($scaffolderConfig->generator->paths->views) . 'layouts/page.blade.php'; |
|
47 | + $path = PathParser::parse($scaffolderConfig->generator->paths->views).'layouts/page.blade.php'; |
|
48 | 48 | |
49 | 49 | File::put($path, $compiled); |
50 | 50 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | <a href='/%s' class='waves-effect'> |
99 | 99 | %ss |
100 | 100 | </a> |
101 | - </li>", $scaffolderConfig->generator->routing->prefix . '/' . strtolower($link), $link); |
|
101 | + </li>", $scaffolderConfig->generator->routing->prefix.'/'.strtolower($link), $link); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $this->stub = str_replace('{{links}}', $navLinks, $this->stub); |
@@ -11,112 +11,112 @@ |
||
11 | 11 | |
12 | 12 | class CreateViewCompiler extends AbstractViewCompiler |
13 | 13 | { |
14 | - use InputTypeResolverTrait; |
|
14 | + use InputTypeResolverTrait; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Compiles the create view. |
|
18 | - * |
|
19 | - * @param $stub |
|
20 | - * @param $modelName |
|
21 | - * @param $modelData |
|
22 | - * @param $scaffolderConfig |
|
23 | - * @param $hash |
|
24 | - * @param null $extra |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
|
29 | - { |
|
30 | - if (File::exists(base_path('scaffolder-config/cache/view_create_' . $hash . self::CACHE_EXT))) |
|
31 | - { |
|
32 | - return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
|
33 | - } |
|
34 | - else |
|
35 | - { |
|
36 | - $this->stub = $stub; |
|
16 | + /** |
|
17 | + * Compiles the create view. |
|
18 | + * |
|
19 | + * @param $stub |
|
20 | + * @param $modelName |
|
21 | + * @param $modelData |
|
22 | + * @param $scaffolderConfig |
|
23 | + * @param $hash |
|
24 | + * @param null $extra |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
|
29 | + { |
|
30 | + if (File::exists(base_path('scaffolder-config/cache/view_create_' . $hash . self::CACHE_EXT))) |
|
31 | + { |
|
32 | + return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
|
33 | + } |
|
34 | + else |
|
35 | + { |
|
36 | + $this->stub = $stub; |
|
37 | 37 | |
38 | - return $this->replaceClassName($modelName) |
|
39 | - ->replaceBreadcrumb($modelName) |
|
40 | - ->addFields($modelData) |
|
41 | - ->replaceRoutePrefix($scaffolderConfig->generator->routing->prefix) |
|
42 | - ->store($modelName, $scaffolderConfig, $this->stub, new FileToCompile(false, $hash)); |
|
43 | - } |
|
44 | - } |
|
38 | + return $this->replaceClassName($modelName) |
|
39 | + ->replaceBreadcrumb($modelName) |
|
40 | + ->addFields($modelData) |
|
41 | + ->replaceRoutePrefix($scaffolderConfig->generator->routing->prefix) |
|
42 | + ->store($modelName, $scaffolderConfig, $this->stub, new FileToCompile(false, $hash)); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Store the compiled stub. |
|
48 | - * |
|
49 | - * @param $modelName |
|
50 | - * @param $scaffolderConfig |
|
51 | - * @param $compiled |
|
52 | - * @param FileToCompile $fileToCompile |
|
53 | - * |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
|
57 | - { |
|
58 | - $folder = PathParser::parse($scaffolderConfig->generator->paths->views) . strtolower($modelName) ; |
|
46 | + /** |
|
47 | + * Store the compiled stub. |
|
48 | + * |
|
49 | + * @param $modelName |
|
50 | + * @param $scaffolderConfig |
|
51 | + * @param $compiled |
|
52 | + * @param FileToCompile $fileToCompile |
|
53 | + * |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
|
57 | + { |
|
58 | + $folder = PathParser::parse($scaffolderConfig->generator->paths->views) . strtolower($modelName) ; |
|
59 | 59 | |
60 | - // create folder directory |
|
61 | - Directory::createIfNotExists($folder, 0755, true); |
|
60 | + // create folder directory |
|
61 | + Directory::createIfNotExists($folder, 0755, true); |
|
62 | 62 | |
63 | - $path = $folder . '/create.blade.php'; |
|
63 | + $path = $folder . '/create.blade.php'; |
|
64 | 64 | |
65 | - // Store in cache |
|
66 | - if ($fileToCompile->cached) |
|
67 | - { |
|
68 | - File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
69 | - } |
|
70 | - else |
|
71 | - { |
|
72 | - File::put(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
|
73 | - File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
74 | - } |
|
65 | + // Store in cache |
|
66 | + if ($fileToCompile->cached) |
|
67 | + { |
|
68 | + File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
69 | + } |
|
70 | + else |
|
71 | + { |
|
72 | + File::put(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
|
73 | + File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
74 | + } |
|
75 | 75 | |
76 | - return $path; |
|
77 | - } |
|
76 | + return $path; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Add fields to the create view. |
|
81 | - * |
|
82 | - * @param $modelData |
|
83 | - * |
|
84 | - * @return $this |
|
85 | - */ |
|
86 | - private function addFields($modelData) |
|
87 | - { |
|
88 | - $fields = ''; |
|
89 | - $firstIteration = true; |
|
79 | + /** |
|
80 | + * Add fields to the create view. |
|
81 | + * |
|
82 | + * @param $modelData |
|
83 | + * |
|
84 | + * @return $this |
|
85 | + */ |
|
86 | + private function addFields($modelData) |
|
87 | + { |
|
88 | + $fields = ''; |
|
89 | + $firstIteration = true; |
|
90 | 90 | |
91 | - foreach ($modelData->fields as $field) |
|
92 | - { |
|
93 | - if ($firstIteration) |
|
94 | - { |
|
95 | - $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
|
96 | - $firstIteration = false; |
|
97 | - } |
|
98 | - else |
|
99 | - { |
|
100 | - $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
|
101 | - } |
|
102 | - } |
|
91 | + foreach ($modelData->fields as $field) |
|
92 | + { |
|
93 | + if ($firstIteration) |
|
94 | + { |
|
95 | + $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
|
96 | + $firstIteration = false; |
|
97 | + } |
|
98 | + else |
|
99 | + { |
|
100 | + $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
|
104 | + $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
|
105 | 105 | |
106 | - return $this; |
|
107 | - } |
|
106 | + return $this; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Replace the prefix. |
|
111 | - * |
|
112 | - * @param $prefix |
|
113 | - * |
|
114 | - * @return $this |
|
115 | - */ |
|
116 | - private function replaceRoutePrefix($prefix) |
|
117 | - { |
|
118 | - $this->stub = str_replace('{{route_prefix}}', $prefix, $this->stub); |
|
109 | + /** |
|
110 | + * Replace the prefix. |
|
111 | + * |
|
112 | + * @param $prefix |
|
113 | + * |
|
114 | + * @return $this |
|
115 | + */ |
|
116 | + private function replaceRoutePrefix($prefix) |
|
117 | + { |
|
118 | + $this->stub = str_replace('{{route_prefix}}', $prefix, $this->stub); |
|
119 | 119 | |
120 | - return $this; |
|
121 | - } |
|
120 | + return $this; |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
29 | 29 | { |
30 | - if (File::exists(base_path('scaffolder-config/cache/view_create_' . $hash . self::CACHE_EXT))) |
|
30 | + if (File::exists(base_path('scaffolder-config/cache/view_create_'.$hash.self::CACHE_EXT))) |
|
31 | 31 | { |
32 | 32 | return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
33 | 33 | } |
@@ -55,22 +55,22 @@ discard block |
||
55 | 55 | */ |
56 | 56 | protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
57 | 57 | { |
58 | - $folder = PathParser::parse($scaffolderConfig->generator->paths->views) . strtolower($modelName) ; |
|
58 | + $folder = PathParser::parse($scaffolderConfig->generator->paths->views).strtolower($modelName); |
|
59 | 59 | |
60 | 60 | // create folder directory |
61 | 61 | Directory::createIfNotExists($folder, 0755, true); |
62 | 62 | |
63 | - $path = $folder . '/create.blade.php'; |
|
63 | + $path = $folder.'/create.blade.php'; |
|
64 | 64 | |
65 | 65 | // Store in cache |
66 | 66 | if ($fileToCompile->cached) |
67 | 67 | { |
68 | - File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
68 | + File::copy(base_path('scaffolder-config/cache/view_create_'.$fileToCompile->hash.self::CACHE_EXT), $path); |
|
69 | 69 | } |
70 | 70 | else |
71 | 71 | { |
72 | - File::put(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
|
73 | - File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
72 | + File::put(base_path('scaffolder-config/cache/view_create_'.$fileToCompile->hash.self::CACHE_EXT), $compiled); |
|
73 | + File::copy(base_path('scaffolder-config/cache/view_create_'.$fileToCompile->hash.self::CACHE_EXT), $path); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | return $path; |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | { |
93 | 93 | if ($firstIteration) |
94 | 94 | { |
95 | - $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
|
95 | + $fields .= sprintf(self::getInputFor($field).PHP_EOL, $field->name); |
|
96 | 96 | $firstIteration = false; |
97 | 97 | } |
98 | 98 | else |
99 | 99 | { |
100 | - $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
|
100 | + $fields .= sprintf("\t".self::getInputFor($field).PHP_EOL, $field->name); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | if (File::exists(base_path('scaffolder-config/cache/view_create_' . $hash . self::CACHE_EXT))) |
31 | 31 | { |
32 | 32 | return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
33 | - } |
|
34 | - else |
|
33 | + } else |
|
35 | 34 | { |
36 | 35 | $this->stub = $stub; |
37 | 36 | |
@@ -66,8 +65,7 @@ discard block |
||
66 | 65 | if ($fileToCompile->cached) |
67 | 66 | { |
68 | 67 | File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
69 | - } |
|
70 | - else |
|
68 | + } else |
|
71 | 69 | { |
72 | 70 | File::put(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
73 | 71 | File::copy(base_path('scaffolder-config/cache/view_create_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
@@ -94,8 +92,7 @@ discard block |
||
94 | 92 | { |
95 | 93 | $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
96 | 94 | $firstIteration = false; |
97 | - } |
|
98 | - else |
|
95 | + } else |
|
99 | 96 | { |
100 | 97 | $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
101 | 98 | } |
@@ -11,136 +11,136 @@ |
||
11 | 11 | |
12 | 12 | class EditViewCompiler extends AbstractViewCompiler |
13 | 13 | { |
14 | - use InputTypeResolverTrait; |
|
15 | - |
|
16 | - /** |
|
17 | - * Compiles the edit view. |
|
18 | - * |
|
19 | - * @param $stub |
|
20 | - * @param $modelName |
|
21 | - * @param $modelData |
|
22 | - * @param $scaffolderConfig |
|
23 | - * @param $hash |
|
24 | - * @param null $extra |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
|
29 | - { |
|
30 | - if (File::exists(base_path('scaffolder-config/cache/view_edit_' . $hash . self::CACHE_EXT))) |
|
31 | - { |
|
32 | - return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
|
33 | - } |
|
34 | - else |
|
35 | - { |
|
36 | - $this->stub = $stub; |
|
37 | - |
|
38 | - return $this->replaceClassName($modelName) |
|
39 | - ->replaceBreadcrumb($modelName) |
|
40 | - ->addFields($modelData) |
|
41 | - ->replacePrimaryKey($modelData) |
|
42 | - ->replaceRoutePrefix($scaffolderConfig->generator->routing->prefix) |
|
43 | - ->store($modelName, $scaffolderConfig, $this->stub, new FileToCompile(false, $hash)); |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Store the compiled stub. |
|
49 | - * |
|
50 | - * @param $modelName |
|
51 | - * @param $scaffolderConfig |
|
52 | - * @param $compiled |
|
53 | - * @param FileToCompile $fileToCompile |
|
54 | - * |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
|
58 | - { |
|
59 | - $folder = PathParser::parse($scaffolderConfig->generator->paths->views) . strtolower($modelName) ; |
|
14 | + use InputTypeResolverTrait; |
|
15 | + |
|
16 | + /** |
|
17 | + * Compiles the edit view. |
|
18 | + * |
|
19 | + * @param $stub |
|
20 | + * @param $modelName |
|
21 | + * @param $modelData |
|
22 | + * @param $scaffolderConfig |
|
23 | + * @param $hash |
|
24 | + * @param null $extra |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
|
29 | + { |
|
30 | + if (File::exists(base_path('scaffolder-config/cache/view_edit_' . $hash . self::CACHE_EXT))) |
|
31 | + { |
|
32 | + return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
|
33 | + } |
|
34 | + else |
|
35 | + { |
|
36 | + $this->stub = $stub; |
|
37 | + |
|
38 | + return $this->replaceClassName($modelName) |
|
39 | + ->replaceBreadcrumb($modelName) |
|
40 | + ->addFields($modelData) |
|
41 | + ->replacePrimaryKey($modelData) |
|
42 | + ->replaceRoutePrefix($scaffolderConfig->generator->routing->prefix) |
|
43 | + ->store($modelName, $scaffolderConfig, $this->stub, new FileToCompile(false, $hash)); |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Store the compiled stub. |
|
49 | + * |
|
50 | + * @param $modelName |
|
51 | + * @param $scaffolderConfig |
|
52 | + * @param $compiled |
|
53 | + * @param FileToCompile $fileToCompile |
|
54 | + * |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
|
58 | + { |
|
59 | + $folder = PathParser::parse($scaffolderConfig->generator->paths->views) . strtolower($modelName) ; |
|
60 | 60 | |
61 | - // create folder directory |
|
62 | - Directory::createIfNotExists($folder, 0755, true); |
|
63 | - |
|
64 | - $path = $folder . '/edit.blade.php'; |
|
65 | - |
|
66 | - // Store in cache |
|
67 | - if ($fileToCompile->cached) |
|
68 | - { |
|
69 | - File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
70 | - } |
|
71 | - else |
|
72 | - { |
|
73 | - File::put(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
|
74 | - File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
75 | - } |
|
76 | - |
|
77 | - return $path; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Add fields to the edit view. |
|
82 | - * |
|
83 | - * @param $modelData |
|
84 | - * |
|
85 | - * @return $this |
|
86 | - */ |
|
87 | - private function addFields($modelData) |
|
88 | - { |
|
89 | - $fields = ''; |
|
90 | - $firstIteration = true; |
|
91 | - |
|
92 | - foreach ($modelData->fields as $field) |
|
93 | - { |
|
94 | - if ($firstIteration) |
|
95 | - { |
|
96 | - $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
|
97 | - $firstIteration = false; |
|
98 | - } |
|
99 | - else |
|
100 | - { |
|
101 | - $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
|
106 | - |
|
107 | - return $this; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Replace the prefix. |
|
112 | - * |
|
113 | - * @param $prefix |
|
114 | - * |
|
115 | - * @return $this |
|
116 | - */ |
|
117 | - private function replaceRoutePrefix($prefix) |
|
118 | - { |
|
119 | - $this->stub = str_replace('{{route_prefix}}', $prefix, $this->stub); |
|
120 | - |
|
121 | - return $this; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Replace the primary key. |
|
126 | - * |
|
127 | - * @param $modelData |
|
128 | - */ |
|
129 | - private function replacePrimaryKey($modelData) |
|
130 | - { |
|
131 | - $primaryKey = 'id'; |
|
132 | - |
|
133 | - foreach ($modelData->fields as $field) |
|
134 | - { |
|
135 | - if ($field->index == 'primary') |
|
136 | - { |
|
137 | - $primaryKey = $field->name; |
|
138 | - break; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - $this->stub = str_replace('{{primaryKey}}', $primaryKey, $this->stub); |
|
143 | - |
|
144 | - return $this; |
|
145 | - } |
|
61 | + // create folder directory |
|
62 | + Directory::createIfNotExists($folder, 0755, true); |
|
63 | + |
|
64 | + $path = $folder . '/edit.blade.php'; |
|
65 | + |
|
66 | + // Store in cache |
|
67 | + if ($fileToCompile->cached) |
|
68 | + { |
|
69 | + File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
70 | + } |
|
71 | + else |
|
72 | + { |
|
73 | + File::put(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
|
74 | + File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
75 | + } |
|
76 | + |
|
77 | + return $path; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Add fields to the edit view. |
|
82 | + * |
|
83 | + * @param $modelData |
|
84 | + * |
|
85 | + * @return $this |
|
86 | + */ |
|
87 | + private function addFields($modelData) |
|
88 | + { |
|
89 | + $fields = ''; |
|
90 | + $firstIteration = true; |
|
91 | + |
|
92 | + foreach ($modelData->fields as $field) |
|
93 | + { |
|
94 | + if ($firstIteration) |
|
95 | + { |
|
96 | + $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
|
97 | + $firstIteration = false; |
|
98 | + } |
|
99 | + else |
|
100 | + { |
|
101 | + $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + $this->stub = str_replace('{{fields}}', $fields, $this->stub); |
|
106 | + |
|
107 | + return $this; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Replace the prefix. |
|
112 | + * |
|
113 | + * @param $prefix |
|
114 | + * |
|
115 | + * @return $this |
|
116 | + */ |
|
117 | + private function replaceRoutePrefix($prefix) |
|
118 | + { |
|
119 | + $this->stub = str_replace('{{route_prefix}}', $prefix, $this->stub); |
|
120 | + |
|
121 | + return $this; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Replace the primary key. |
|
126 | + * |
|
127 | + * @param $modelData |
|
128 | + */ |
|
129 | + private function replacePrimaryKey($modelData) |
|
130 | + { |
|
131 | + $primaryKey = 'id'; |
|
132 | + |
|
133 | + foreach ($modelData->fields as $field) |
|
134 | + { |
|
135 | + if ($field->index == 'primary') |
|
136 | + { |
|
137 | + $primaryKey = $field->name; |
|
138 | + break; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + $this->stub = str_replace('{{primaryKey}}', $primaryKey, $this->stub); |
|
143 | + |
|
144 | + return $this; |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
29 | 29 | { |
30 | - if (File::exists(base_path('scaffolder-config/cache/view_edit_' . $hash . self::CACHE_EXT))) |
|
30 | + if (File::exists(base_path('scaffolder-config/cache/view_edit_'.$hash.self::CACHE_EXT))) |
|
31 | 31 | { |
32 | 32 | return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
33 | 33 | } |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | */ |
57 | 57 | protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
58 | 58 | { |
59 | - $folder = PathParser::parse($scaffolderConfig->generator->paths->views) . strtolower($modelName) ; |
|
59 | + $folder = PathParser::parse($scaffolderConfig->generator->paths->views).strtolower($modelName); |
|
60 | 60 | |
61 | 61 | // create folder directory |
62 | 62 | Directory::createIfNotExists($folder, 0755, true); |
63 | 63 | |
64 | - $path = $folder . '/edit.blade.php'; |
|
64 | + $path = $folder.'/edit.blade.php'; |
|
65 | 65 | |
66 | 66 | // Store in cache |
67 | 67 | if ($fileToCompile->cached) |
68 | 68 | { |
69 | - File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
69 | + File::copy(base_path('scaffolder-config/cache/view_edit_'.$fileToCompile->hash.self::CACHE_EXT), $path); |
|
70 | 70 | } |
71 | 71 | else |
72 | 72 | { |
73 | - File::put(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
|
74 | - File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
73 | + File::put(base_path('scaffolder-config/cache/view_edit_'.$fileToCompile->hash.self::CACHE_EXT), $compiled); |
|
74 | + File::copy(base_path('scaffolder-config/cache/view_edit_'.$fileToCompile->hash.self::CACHE_EXT), $path); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | return $path; |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | { |
94 | 94 | if ($firstIteration) |
95 | 95 | { |
96 | - $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
|
96 | + $fields .= sprintf(self::getInputFor($field).PHP_EOL, $field->name); |
|
97 | 97 | $firstIteration = false; |
98 | 98 | } |
99 | 99 | else |
100 | 100 | { |
101 | - $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
|
101 | + $fields .= sprintf("\t".self::getInputFor($field).PHP_EOL, $field->name); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | if (File::exists(base_path('scaffolder-config/cache/view_edit_' . $hash . self::CACHE_EXT))) |
31 | 31 | { |
32 | 32 | return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
33 | - } |
|
34 | - else |
|
33 | + } else |
|
35 | 34 | { |
36 | 35 | $this->stub = $stub; |
37 | 36 | |
@@ -67,8 +66,7 @@ discard block |
||
67 | 66 | if ($fileToCompile->cached) |
68 | 67 | { |
69 | 68 | File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
70 | - } |
|
71 | - else |
|
69 | + } else |
|
72 | 70 | { |
73 | 71 | File::put(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
74 | 72 | File::copy(base_path('scaffolder-config/cache/view_edit_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
@@ -95,8 +93,7 @@ discard block |
||
95 | 93 | { |
96 | 94 | $fields .= sprintf(self::getInputFor($field) . PHP_EOL, $field->name); |
97 | 95 | $firstIteration = false; |
98 | - } |
|
99 | - else |
|
96 | + } else |
|
100 | 97 | { |
101 | 98 | $fields .= sprintf("\t" . self::getInputFor($field) . PHP_EOL, $field->name); |
102 | 99 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
26 | 26 | { |
27 | - if (File::exists(base_path('scaffolder-config/cache/view_index_' . $hash . self::CACHE_EXT))) |
|
27 | + if (File::exists(base_path('scaffolder-config/cache/view_index_'.$hash.self::CACHE_EXT))) |
|
28 | 28 | { |
29 | 29 | return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
30 | 30 | } |
@@ -53,22 +53,22 @@ discard block |
||
53 | 53 | */ |
54 | 54 | protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
55 | 55 | { |
56 | - $folder = PathParser::parse($scaffolderConfig->generator->paths->views) . strtolower($modelName) ; |
|
56 | + $folder = PathParser::parse($scaffolderConfig->generator->paths->views).strtolower($modelName); |
|
57 | 57 | |
58 | 58 | // create folder directory |
59 | 59 | Directory::createIfNotExists($folder, 0755, true); |
60 | 60 | |
61 | - $path = $folder . '/index.blade.php'; |
|
61 | + $path = $folder.'/index.blade.php'; |
|
62 | 62 | |
63 | 63 | // Store in cache |
64 | 64 | if ($fileToCompile->cached) |
65 | 65 | { |
66 | - File::copy(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
66 | + File::copy(base_path('scaffolder-config/cache/view_index_'.$fileToCompile->hash.self::CACHE_EXT), $path); |
|
67 | 67 | } |
68 | 68 | else |
69 | 69 | { |
70 | - File::put(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
|
71 | - File::copy(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
|
70 | + File::put(base_path('scaffolder-config/cache/view_index_'.$fileToCompile->hash.self::CACHE_EXT), $compiled); |
|
71 | + File::copy(base_path('scaffolder-config/cache/view_index_'.$fileToCompile->hash.self::CACHE_EXT), $path); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | return $path; |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | { |
94 | 94 | if ($firstIteration) |
95 | 95 | { |
96 | - $fields .= sprintf("{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name); |
|
96 | + $fields .= sprintf("{ data: '%s', name: '%s' },".PHP_EOL, $field->name, $field->name); |
|
97 | 97 | $firstIteration = false; |
98 | 98 | } |
99 | 99 | else |
100 | 100 | { |
101 | - $fields .= sprintf("\t\t\t\t{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name); |
|
101 | + $fields .= sprintf("\t\t\t\t{ data: '%s', name: '%s' },".PHP_EOL, $field->name, $field->name); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | } |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | { |
128 | 128 | if ($firstIteration) |
129 | 129 | { |
130 | - $fields .= sprintf("<th>%s</th>" . PHP_EOL, ucfirst($field->name)); |
|
130 | + $fields .= sprintf("<th>%s</th>".PHP_EOL, ucfirst($field->name)); |
|
131 | 131 | $firstIteration = false; |
132 | 132 | |
133 | 133 | } |
134 | 134 | else |
135 | 135 | { |
136 | - $fields .= sprintf("\t\t\t<th>%s</th>" . PHP_EOL, ucfirst($field->name)); |
|
136 | + $fields .= sprintf("\t\t\t<th>%s</th>".PHP_EOL, ucfirst($field->name)); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | } |