@@ -26,8 +26,7 @@ discard block |
||
| 26 | 26 | if (File::exists(base_path('scaffolder-config/cache/view_index_' . $hash . self::CACHE_EXT))) |
| 27 | 27 | { |
| 28 | 28 | return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash)); |
| 29 | - } |
|
| 30 | - else |
|
| 29 | + } else |
|
| 31 | 30 | { |
| 32 | 31 | $this->stub = $stub; |
| 33 | 32 | |
@@ -58,8 +57,7 @@ discard block |
||
| 58 | 57 | if ($fileToCompile->cached) |
| 59 | 58 | { |
| 60 | 59 | File::copy(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
| 61 | - } |
|
| 62 | - else |
|
| 60 | + } else |
|
| 63 | 61 | { |
| 64 | 62 | File::put(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $compiled); |
| 65 | 63 | File::copy(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $path); |
@@ -89,8 +87,7 @@ discard block |
||
| 89 | 87 | { |
| 90 | 88 | $fields .= sprintf("{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name); |
| 91 | 89 | $firstIteration = false; |
| 92 | - } |
|
| 93 | - else |
|
| 90 | + } else |
|
| 94 | 91 | { |
| 95 | 92 | $fields .= sprintf("\t\t\t\t{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name); |
| 96 | 93 | } |
@@ -124,8 +121,7 @@ discard block |
||
| 124 | 121 | $fields .= sprintf("<th>%s</th>" . PHP_EOL, ucfirst($field->name)); |
| 125 | 122 | $firstIteration = false; |
| 126 | 123 | |
| 127 | - } |
|
| 128 | - else |
|
| 124 | + } else |
|
| 129 | 125 | { |
| 130 | 126 | $fields .= sprintf("\t\t\t<th>%s</th>" . PHP_EOL, ucfirst($field->name)); |
| 131 | 127 | } |
@@ -16,8 +16,7 @@ |
||
| 16 | 16 | if ($fieldData->type->ui == 'text') |
| 17 | 17 | { |
| 18 | 18 | return '{!! Form::text(\'%s\', (isset($model)) ? $model->' . $fieldData->name . ' : null) !!}'; |
| 19 | - } |
|
| 20 | - elseif ($fieldData->type->ui == 'textarea') |
|
| 19 | + } elseif ($fieldData->type->ui == 'textarea') |
|
| 21 | 20 | { |
| 22 | 21 | return '{!! Form::textarea(\'%s\', (isset($model)) ? $model->' . $fieldData->name . ' : null) !!}'; |
| 23 | 22 | } |
@@ -18,33 +18,26 @@ |
||
| 18 | 18 | if (head($path) == 'app') |
| 19 | 19 | { |
| 20 | 20 | $path = app_path(last($path)); |
| 21 | - } |
|
| 22 | - elseif (head($path) == 'base') |
|
| 21 | + } elseif (head($path) == 'base') |
|
| 23 | 22 | { |
| 24 | 23 | $path = base_path(last($path)); |
| 25 | - } |
|
| 26 | - elseif (head($path) == 'config') |
|
| 24 | + } elseif (head($path) == 'config') |
|
| 27 | 25 | { |
| 28 | 26 | $path = config_path(last($path)); |
| 29 | - } |
|
| 30 | - elseif (head($path) == 'database') |
|
| 27 | + } elseif (head($path) == 'database') |
|
| 31 | 28 | { |
| 32 | 29 | $path = database_path(last($path)); |
| 33 | - } |
|
| 34 | - elseif (head($path) == 'public') |
|
| 30 | + } elseif (head($path) == 'public') |
|
| 35 | 31 | { |
| 36 | 32 | $path = public_path(last($path)); |
| 37 | - } |
|
| 38 | - elseif (head($path) == 'storage') |
|
| 33 | + } elseif (head($path) == 'storage') |
|
| 39 | 34 | { |
| 40 | 35 | $path = storage_path(last($path)); |
| 41 | - } |
|
| 42 | - else |
|
| 36 | + } else |
|
| 43 | 37 | { |
| 44 | 38 | $path = head($path); |
| 45 | 39 | } |
| 46 | - } |
|
| 47 | - else |
|
| 40 | + } else |
|
| 48 | 41 | { |
| 49 | 42 | $path = head($path); |
| 50 | 43 | } |
@@ -43,19 +43,19 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function show($id) |
| 46 | - { |
|
| 47 | - return 'Not implemented'; |
|
| 48 | - } |
|
| 46 | + { |
|
| 47 | + return 'Not implemented'; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | public function edit($id) |
| 51 | - { |
|
| 52 | - $model = {{class_name}}::find($id); |
|
| 51 | + { |
|
| 52 | + $model = {{class_name}}::find($id); |
|
| 53 | 53 | |
| 54 | 54 | return view('{{class_name_lw}}.edit')->with('model', $model); |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | public function update($id, Request $request) |
| 58 | - { |
|
| 58 | + { |
|
| 59 | 59 | $this->validate($request, [ |
| 60 | 60 | |
| 61 | 61 | {{validations}} |
@@ -63,13 +63,13 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | {{class_name}}::find($id)->fill($request->all())->save(); |
| 65 | 65 | |
| 66 | - return response()->json(['message' => 'ok']); |
|
| 67 | - } |
|
| 66 | + return response()->json(['message' => 'ok']); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | public function destroy($id) |
| 70 | - { |
|
| 70 | + { |
|
| 71 | 71 | {{class_name}}::destroy($id); |
| 72 | 72 | |
| 73 | - return response()->json(['message' => 'ok']); |
|
| 74 | - } |
|
| 73 | + return response()->json(['message' => 'ok']); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -27,8 +27,11 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | array_walk_recursive($models, function (&$item) |
| 29 | 29 | { |
| 30 | - if ($item == 'true') $item = true; |
|
| 31 | - elseif ($item == 'false') $item = false; |
|
| 30 | + if ($item == 'true') { |
|
| 31 | + $item = true; |
|
| 32 | + } elseif ($item == 'false') { |
|
| 33 | + $item = false; |
|
| 34 | + } |
|
| 32 | 35 | }); |
| 33 | 36 | |
| 34 | 37 | // Generate app.json |
@@ -51,8 +54,11 @@ discard block |
||
| 51 | 54 | |
| 52 | 55 | array_walk_recursive($models, function (&$item) |
| 53 | 56 | { |
| 54 | - if ($item == 'true') $item = true; |
|
| 55 | - elseif ($item == 'false') $item = false; |
|
| 57 | + if ($item == 'true') { |
|
| 58 | + $item = true; |
|
| 59 | + } elseif ($item == 'false') { |
|
| 60 | + $item = false; |
|
| 61 | + } |
|
| 56 | 62 | }); |
| 57 | 63 | |
| 58 | 64 | // Generate app.json |
@@ -10,68 +10,68 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ScaffolderServiceProvider extends ServiceProvider |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Bootstrap the application services. |
|
| 15 | - */ |
|
| 16 | - public function boot() |
|
| 17 | - { |
|
| 18 | - // Scaffolder config |
|
| 19 | - $this->publishes([ |
|
| 20 | - __DIR__ . '/../../config/' => base_path('scaffolder-config/') |
|
| 21 | - ], 'config'); |
|
| 13 | + /** |
|
| 14 | + * Bootstrap the application services. |
|
| 15 | + */ |
|
| 16 | + public function boot() |
|
| 17 | + { |
|
| 18 | + // Scaffolder config |
|
| 19 | + $this->publishes([ |
|
| 20 | + __DIR__ . '/../../config/' => base_path('scaffolder-config/') |
|
| 21 | + ], 'config'); |
|
| 22 | 22 | |
| 23 | - // Generator views |
|
| 24 | - //$this->loadViewsFrom(__DIR__ . '/../../views', 'scaffolder'); |
|
| 23 | + // Generator views |
|
| 24 | + //$this->loadViewsFrom(__DIR__ . '/../../views', 'scaffolder'); |
|
| 25 | 25 | |
| 26 | - // Generator routes |
|
| 27 | - if (!$this->app->routesAreCached()) |
|
| 28 | - { |
|
| 29 | - require __DIR__ . '/../../routes/generator.php'; |
|
| 30 | - } |
|
| 31 | - } |
|
| 26 | + // Generator routes |
|
| 27 | + if (!$this->app->routesAreCached()) |
|
| 28 | + { |
|
| 29 | + require __DIR__ . '/../../routes/generator.php'; |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Register the service provider. |
|
| 35 | - * |
|
| 36 | - * @return void |
|
| 37 | - */ |
|
| 38 | - public function register() |
|
| 39 | - { |
|
| 40 | - $this->app->singleton('scaffolder.command.generate', function ($app) |
|
| 41 | - { |
|
| 42 | - return new GeneratorCommand(); |
|
| 43 | - }); |
|
| 33 | + /** |
|
| 34 | + * Register the service provider. |
|
| 35 | + * |
|
| 36 | + * @return void |
|
| 37 | + */ |
|
| 38 | + public function register() |
|
| 39 | + { |
|
| 40 | + $this->app->singleton('scaffolder.command.generate', function ($app) |
|
| 41 | + { |
|
| 42 | + return new GeneratorCommand(); |
|
| 43 | + }); |
|
| 44 | 44 | |
| 45 | - $this->app->singleton('scaffolder.command.cache.clear', function () |
|
| 46 | - { |
|
| 47 | - return new ClearCacheCommand(); |
|
| 48 | - }); |
|
| 45 | + $this->app->singleton('scaffolder.command.cache.clear', function () |
|
| 46 | + { |
|
| 47 | + return new ClearCacheCommand(); |
|
| 48 | + }); |
|
| 49 | 49 | |
| 50 | - $this->app->singleton('scaffolder.command.build', function () |
|
| 51 | - { |
|
| 52 | - return new BuildCommand(); |
|
| 53 | - }); |
|
| 50 | + $this->app->singleton('scaffolder.command.build', function () |
|
| 51 | + { |
|
| 52 | + return new BuildCommand(); |
|
| 53 | + }); |
|
| 54 | 54 | |
| 55 | - $this->app->singleton('scaffolder.command.serve', function () |
|
| 56 | - { |
|
| 57 | - return new ServeCommand(); |
|
| 58 | - }); |
|
| 55 | + $this->app->singleton('scaffolder.command.serve', function () |
|
| 56 | + { |
|
| 57 | + return new ServeCommand(); |
|
| 58 | + }); |
|
| 59 | 59 | |
| 60 | - $this->commands([ |
|
| 61 | - 'scaffolder.command.generate', |
|
| 62 | - 'scaffolder.command.cache.clear', |
|
| 63 | - 'scaffolder.command.build', |
|
| 64 | - 'scaffolder.command.serve' |
|
| 65 | - ]); |
|
| 66 | - } |
|
| 60 | + $this->commands([ |
|
| 61 | + 'scaffolder.command.generate', |
|
| 62 | + 'scaffolder.command.cache.clear', |
|
| 63 | + 'scaffolder.command.build', |
|
| 64 | + 'scaffolder.command.serve' |
|
| 65 | + ]); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get the services provided by the provider. |
|
| 70 | - * |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - public function provides() |
|
| 74 | - { |
|
| 75 | - return ['scaffolder.command.generate', 'scaffolder.command.cache.clear', 'scaffolder.command.serve', 'scaffolder.command.build']; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get the services provided by the provider. |
|
| 70 | + * |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + public function provides() |
|
| 74 | + { |
|
| 75 | + return ['scaffolder.command.generate', 'scaffolder.command.cache.clear', 'scaffolder.command.serve', 'scaffolder.command.build']; |
|
| 76 | + } |
|
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -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 | } |
@@ -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 |
@@ -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 | |
@@ -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 |
@@ -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 | } |