From 95e95dbaa203a588da14d7900fdadaef5fdfce5f Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Sun, 3 Nov 2019 17:38:35 -0800 Subject: [PATCH] Make it compatible with Laravel 6+ --- composer.json | 2 +- .../ApiDocs/CreateApiDocsControllerCommand.php | 2 +- .../ApiDocs/CreateApiDocsViewCommand.php | 10 +++++----- src/Commands/Bases/ControllerCommandBase.php | 4 ++-- .../Bases/ControllerRequestCommandBase.php | 5 +++-- .../Bases/ResourceFileCreatorCommandBase.php | 2 +- .../Framework/CreateFormRequestCommand.php | 5 +++-- .../Framework/CreateMigrationCommand.php | 3 ++- src/Commands/Framework/CreateModelCommand.php | 2 +- .../Resources/ResourceFileDeleteCommand.php | 2 +- .../ResourceFileFromDatabaseCommand.php | 2 +- .../Resources/ResourceFileReduceCommand.php | 2 +- src/Commands/Views/CreateCreateViewCommand.php | 5 +++-- src/Commands/Views/CreateEditViewCommand.php | 5 +++-- src/DatabaseParsers/MysqlParser.php | 4 ++-- src/DatabaseParsers/ParserBase.php | 2 +- src/HtmlGenerators/LaravelCollectiveHtml.php | 2 +- src/HtmlGenerators/StandardHtml.php | 2 +- src/Models/Field.php | 2 +- src/Models/ForeignConstraint.php | 2 +- src/Models/ForeignRelationship.php | 2 +- src/Models/Resource.php | 3 ++- src/Support/FieldTransformer.php | 2 +- src/Support/Helpers.php | 16 ++++++++-------- src/Support/Str.php | 2 +- src/Support/ValidationParser.php | 2 +- src/Traits/ApiResourceTrait.php | 4 ++-- src/Traits/CommonCommand.php | 8 ++++---- src/Traits/GeneratorReplacers.php | 10 +++++----- src/Traits/Migration.php | 4 ++-- src/Traits/ScaffoldTrait.php | 4 +++- 31 files changed, 65 insertions(+), 57 deletions(-) diff --git a/composer.json b/composer.json index 3cd7f34..e3748b0 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "crestapps/laravel-code-generator", "license": "MIT", "description": "An intelligent code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages and/or form-requests! It is extremely flexible and customizable to cover many on the use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.", - "version": "v2.3.3", + "version": "2.4.0", "keywords": [ "laravel","crud","crud generator", "laravel crud generator","laravel crud builder", diff --git a/src/Commands/ApiDocs/CreateApiDocsControllerCommand.php b/src/Commands/ApiDocs/CreateApiDocsControllerCommand.php index 885e048..5368b30 100644 --- a/src/Commands/ApiDocs/CreateApiDocsControllerCommand.php +++ b/src/Commands/ApiDocs/CreateApiDocsControllerCommand.php @@ -261,7 +261,7 @@ protected function getCommandInput() { $modelName = trim($this->argument('model-name')); $cName = trim($this->option('controller-name')); - $controllerName = $cName ? str_finish($cName, Config::getControllerNamePostFix()) : Helpers::makeControllerName($modelName); + $controllerName = $cName ? Str::finish($cName, Config::getControllerNamePostFix()) : Helpers::makeControllerName($modelName); $prefix = ($this->option('routes-prefix') == 'default-form') ? Helpers::makeRouteGroup($modelName) : $this->option('routes-prefix'); $resourceFile = trim($this->option('resource-file')) ?: Helpers::makeJsonFileName($modelName); $force = $this->option('force'); diff --git a/src/Commands/ApiDocs/CreateApiDocsViewCommand.php b/src/Commands/ApiDocs/CreateApiDocsViewCommand.php index 9ca1eb3..27da053 100644 --- a/src/Commands/ApiDocs/CreateApiDocsViewCommand.php +++ b/src/Commands/ApiDocs/CreateApiDocsViewCommand.php @@ -319,22 +319,22 @@ protected function getValidationRules(Field $field) continue; } - if ($hasString && starts_with($rule, 'min:')) { + if ($hasString && Str::startsWith($rule, 'min:')) { $rules[] = 'Minimum Length: ' . Str::trimEnd($rule, 'min:'); continue; } - if ($hasString && starts_with($rule, 'max:')) { + if ($hasString && Str::startsWith($rule, 'max:')) { $rules[] = 'Maximum Length: ' . Str::trimEnd($rule, 'max:'); continue; } - if ($hasNumber && starts_with($rule, 'min:')) { + if ($hasNumber && Str::startsWith($rule, 'min:')) { $rules[] = 'Minimum Value: ' . Str::trimEnd($rule, 'min:'); continue; } - if ($hasNumber && starts_with($rule, 'max:')) { + if ($hasNumber && Str::startsWith($rule, 'max:')) { $rules[] = 'Maximum Value: ' . Str::trimEnd($rule, 'max:'); continue; } @@ -548,7 +548,7 @@ protected function getCommandInput() { $modelName = trim($this->argument('model-name')); $cName = trim($this->option('controller-name')); - $controllerName = $cName ? str_finish($cName, Config::getControllerNamePostFix()) : Helpers::makeControllerName($modelName); + $controllerName = $cName ? Str::finish($cName, Config::getControllerNamePostFix()) : Helpers::makeControllerName($modelName); $controllerDirectory = trim($this->option('controller-directory')); $viewsDirectory = trim($this->option('views-directory')); $layoutName = trim($this->option('layout-name')); diff --git a/src/Commands/Bases/ControllerCommandBase.php b/src/Commands/Bases/ControllerCommandBase.php index 26523f3..0f75c83 100644 --- a/src/Commands/Bases/ControllerCommandBase.php +++ b/src/Commands/Bases/ControllerCommandBase.php @@ -183,7 +183,7 @@ protected function getCommandInput() { $modelName = trim($this->argument('model-name')); $cName = trim($this->option('controller-name')); - $controllerName = $cName ? str_finish($cName, Config::getControllerNamePostFix()) : Helpers::makeControllerName($modelName); + $controllerName = $cName ? Str::finish($cName, Config::getControllerNamePostFix()) : Helpers::makeControllerName($modelName); $prefix = ($this->option('routes-prefix') == 'default-form') ? Helpers::makeRouteGroup($modelName) : $this->option('routes-prefix'); $perPage = intval($this->option('models-per-page')); $resourceFile = trim($this->option('resource-file')) ?: Helpers::makeJsonFileName($modelName); @@ -486,7 +486,7 @@ protected function getRelationCollections(array $fields, $view) protected function getRequestsNamespace($name, $path) { if (!empty($path)) { - $path = str_finish($path, '\\'); + $path = Str::finish($path, '\\'); } $path = Helpers::getAppNamespace() . Config::getRequestsPath($path); diff --git a/src/Commands/Bases/ControllerRequestCommandBase.php b/src/Commands/Bases/ControllerRequestCommandBase.php index b2ab6f6..6f8b628 100644 --- a/src/Commands/Bases/ControllerRequestCommandBase.php +++ b/src/Commands/Bases/ControllerRequestCommandBase.php @@ -8,6 +8,7 @@ use CrestApps\CodeGenerator\Traits\CommonCommand; use CrestApps\CodeGenerator\Traits\GeneratorReplacers; use Illuminate\Console\Command; +use CrestApps\CodeGenerator\Support\Str; class ControllerRequestCommandBase extends Command { @@ -174,7 +175,7 @@ protected function extractCustomValidationRules(array $rules) */ protected function isCustomRule($rule) { - return starts_with(trim($rule), 'new '); + return Str::startsWith(trim($rule), 'new '); } /** @@ -212,7 +213,7 @@ protected function getCustomRuleShortName($rule) */ protected function canHaveUsingCommand($fullname) { - return !starts_with($fullname, '\\'); + return !Str::startsWith($fullname, '\\'); } /** diff --git a/src/Commands/Bases/ResourceFileCreatorCommandBase.php b/src/Commands/Bases/ResourceFileCreatorCommandBase.php index 9a21170..4409750 100644 --- a/src/Commands/Bases/ResourceFileCreatorCommandBase.php +++ b/src/Commands/Bases/ResourceFileCreatorCommandBase.php @@ -34,7 +34,7 @@ protected function getCommandInput() { $modelName = trim($this->argument('model-name')); $filename = trim($this->option('resource-filename')); - $file = $filename ? str_finish($filename, '.json') : Helpers::makeJsonFileName($modelName); + $file = $filename ? Str::finish($filename, '.json') : Helpers::makeJsonFileName($modelName); $translationFor = array_unique(Arr::fromString($this->option('translation-for'))); $fieldNames = array_unique(Arr::fromString($this->option('fields'))); $relations = Arr::fromString($this->option('relations')); diff --git a/src/Commands/Framework/CreateFormRequestCommand.php b/src/Commands/Framework/CreateFormRequestCommand.php index 4a60a66..0bacb31 100644 --- a/src/Commands/Framework/CreateFormRequestCommand.php +++ b/src/Commands/Framework/CreateFormRequestCommand.php @@ -6,6 +6,7 @@ use CrestApps\CodeGenerator\Models\Resource; use CrestApps\CodeGenerator\Support\Config; use CrestApps\CodeGenerator\Support\Helpers; +use CrestApps\CodeGenerator\Support\Str; class CreateFormRequestCommand extends ControllerRequestCommandBase { @@ -184,7 +185,7 @@ protected function isConvertEmptyStringsToNullRegistered() */ protected function getDestenationFile($name, $path) { - return str_finish(app_path(Config::getRequestsPath($path)), '/') . $name . '.php'; + return Str::finish(app_path(Config::getRequestsPath($path)), '/') . $name . '.php'; } /** @@ -196,7 +197,7 @@ protected function getDestenationFile($name, $path) */ protected function getRequestsNamespace($path) { - $path = str_finish($path, '\\'); + $path = Str::finish($path, '\\'); $path = Helpers::getAppNamespace() . Config::getRequestsPath($path); diff --git a/src/Commands/Framework/CreateMigrationCommand.php b/src/Commands/Framework/CreateMigrationCommand.php index 61eb18c..346f14d 100644 --- a/src/Commands/Framework/CreateMigrationCommand.php +++ b/src/Commands/Framework/CreateMigrationCommand.php @@ -12,6 +12,7 @@ use CrestApps\CodeGenerator\Models\MigrationTrackerCapsule; use CrestApps\CodeGenerator\Models\Resource; use CrestApps\CodeGenerator\Support\Arr; +use CrestApps\CodeGenerator\Support\Str; use CrestApps\CodeGenerator\Support\Config; use CrestApps\CodeGenerator\Support\Helpers; use CrestApps\CodeGenerator\Support\MigrationHistoryTracker; @@ -211,7 +212,7 @@ protected function getMigrationFullName($name) $folder = $this->tableName; } - return str_finish($this->getMigrationPath($folder) . DIRECTORY_SEPARATOR . $name, '.php'); + return Str::finish($this->getMigrationPath($folder) . DIRECTORY_SEPARATOR . $name, '.php'); } /** diff --git a/src/Commands/Framework/CreateModelCommand.php b/src/Commands/Framework/CreateModelCommand.php index 7438cb4..80e4c9c 100644 --- a/src/Commands/Framework/CreateModelCommand.php +++ b/src/Commands/Framework/CreateModelCommand.php @@ -818,7 +818,7 @@ protected function replaceMutators(&$stub, $mutators) protected function replaceFieldName(&$stub, $name) { $stub = $this->strReplace('field_name', $name, $stub); - $stub = $this->strReplace('field_name_cap', ucwords(camel_case($name)), $stub); + $stub = $this->strReplace('field_name_cap', ucwords(Str::camel($name)), $stub); return $this; } diff --git a/src/Commands/Resources/ResourceFileDeleteCommand.php b/src/Commands/Resources/ResourceFileDeleteCommand.php index f95d540..fe9a4da 100644 --- a/src/Commands/Resources/ResourceFileDeleteCommand.php +++ b/src/Commands/Resources/ResourceFileDeleteCommand.php @@ -59,7 +59,7 @@ protected function getCommandInput() { $modelName = trim($this->argument('model-name')); $filename = trim($this->option('resource-filename')); - $file = $filename ? str_finish($filename, '.json') : Helpers::makeJsonFileName($modelName); + $file = $filename ? Str::finish($filename, '.json') : Helpers::makeJsonFileName($modelName); return (object) compact('modelName', 'file'); } diff --git a/src/Commands/Resources/ResourceFileFromDatabaseCommand.php b/src/Commands/Resources/ResourceFileFromDatabaseCommand.php index 982cff5..8957fcd 100644 --- a/src/Commands/Resources/ResourceFileFromDatabaseCommand.php +++ b/src/Commands/Resources/ResourceFileFromDatabaseCommand.php @@ -152,7 +152,7 @@ protected function getNewFilename() { $filename = trim($this->option('resource-filename')) ?: Helpers::makeJsonFileName($this->getModelName()); - return str_finish($filename, '.json'); + return Str::finish($filename, '.json'); } /** diff --git a/src/Commands/Resources/ResourceFileReduceCommand.php b/src/Commands/Resources/ResourceFileReduceCommand.php index 59576f9..bb67a62 100644 --- a/src/Commands/Resources/ResourceFileReduceCommand.php +++ b/src/Commands/Resources/ResourceFileReduceCommand.php @@ -176,7 +176,7 @@ protected function getCommandInput() { $modelName = trim($this->argument('model-name')); $filename = trim($this->option('resource-filename')); - $file = $filename ? str_finish($filename, '.json') : Helpers::makeJsonFileName($modelName); + $file = $filename ? Str::finish($filename, '.json') : Helpers::makeJsonFileName($modelName); $fieldNames = array_unique(Arr::fromString($this->generatorOption('fields'))); $relations = Arr::fromString(trim($this->option('relations'))); $indexes = Arr::fromString(trim($this->option('indexes'))); diff --git a/src/Commands/Views/CreateCreateViewCommand.php b/src/Commands/Views/CreateCreateViewCommand.php index 31a0dc0..7d9cc75 100644 --- a/src/Commands/Views/CreateCreateViewCommand.php +++ b/src/Commands/Views/CreateCreateViewCommand.php @@ -4,6 +4,7 @@ use CrestApps\CodeGenerator\Commands\Bases\ViewsCommandBase; use CrestApps\CodeGenerator\Models\Resource; +use CrestApps\CodeGenerator\Support\Str; class CreateCreateViewCommand extends ViewsCommandBase { @@ -75,7 +76,7 @@ protected function handleCreateView() */ protected function getFormName($modelName) { - return sprintf('create_%s_form', snake_case($modelName)); + return sprintf('create_%s_form', Str::snake($modelName)); } /** @@ -87,6 +88,6 @@ protected function getFormName($modelName) */ protected function getFormId($modelName) { - return sprintf('create_%s_form', snake_case($modelName)); + return sprintf('create_%s_form', Str::snake($modelName)); } } diff --git a/src/Commands/Views/CreateEditViewCommand.php b/src/Commands/Views/CreateEditViewCommand.php index 51cdeb5..a98718f 100644 --- a/src/Commands/Views/CreateEditViewCommand.php +++ b/src/Commands/Views/CreateEditViewCommand.php @@ -4,6 +4,7 @@ use CrestApps\CodeGenerator\Commands\Bases\ViewsCommandBase; use CrestApps\CodeGenerator\Models\Resource; +use CrestApps\CodeGenerator\Support\Str; class CreateEditViewCommand extends ViewsCommandBase { @@ -75,7 +76,7 @@ protected function handleCreateView() */ protected function getFormName($modelName) { - return sprintf('edit_%s_form', snake_case($modelName)); + return sprintf('edit_%s_form', Str::snake($modelName)); } /** @@ -87,6 +88,6 @@ protected function getFormName($modelName) */ protected function getFormId($modelName) { - return sprintf('edit_%s_form', snake_case($modelName)); + return sprintf('edit_%s_form', Str::snake($modelName)); } } diff --git a/src/DatabaseParsers/MysqlParser.php b/src/DatabaseParsers/MysqlParser.php index 1031a20..e59b6c0 100644 --- a/src/DatabaseParsers/MysqlParser.php +++ b/src/DatabaseParsers/MysqlParser.php @@ -202,10 +202,10 @@ protected function getRealtion($foreignTableName, $foreignColumn, $localColumn, $relationName = ($selfReferences ? 'child_' : ''); if ($this->isOneToMany($foreignTableName, $foreignColumn)) { - return new ForeignRelationship('hasMany', $params, camel_case($relationName . Str::plural($foreignTableName))); + return new ForeignRelationship('hasMany', $params, Str::camel($relationName . Str::plural($foreignTableName))); } - return new ForeignRelationship('hasOne', $params, camel_case($relationName . Str::singular($foreignTableName))); + return new ForeignRelationship('hasOne', $params, Str::camel($relationName . Str::singular($foreignTableName))); } /** diff --git a/src/DatabaseParsers/ParserBase.php b/src/DatabaseParsers/ParserBase.php index 1d2b2e3..94555a7 100644 --- a/src/DatabaseParsers/ParserBase.php +++ b/src/DatabaseParsers/ParserBase.php @@ -221,7 +221,7 @@ protected function makeModelName($tableName) { $name = Str::singular($tableName); - return ucfirst(camel_case($name)); + return ucfirst(Str::camel($name)); } /** diff --git a/src/HtmlGenerators/LaravelCollectiveHtml.php b/src/HtmlGenerators/LaravelCollectiveHtml.php index db638d6..41dadca 100644 --- a/src/HtmlGenerators/LaravelCollectiveHtml.php +++ b/src/HtmlGenerators/LaravelCollectiveHtml.php @@ -229,7 +229,7 @@ protected function getMultipleRawOptionValue($name, $value, $defaultValue) $modelVariable = $this->getSingularVariable($this->modelName); $valueString = 'null'; if (!is_null($value)) { - $valueString = starts_with($value, '$') ? sprintf("%s", $value) : sprintf("'%s'", $value); + $valueString = Str::startsWith($value, '$') ? sprintf("%s", $value) : sprintf("'%s'", $value); } $defaultValueString = '[]'; if (!empty($defaultValue)) { diff --git a/src/HtmlGenerators/StandardHtml.php b/src/HtmlGenerators/StandardHtml.php index 4d2b804..b8893a8 100644 --- a/src/HtmlGenerators/StandardHtml.php +++ b/src/HtmlGenerators/StandardHtml.php @@ -278,7 +278,7 @@ protected function getMultipleRawOptionValue($name, $value, $defaultValue) $valueString = 'null'; if (!is_null($value)) { - $valueString = starts_with($value, '$') ? sprintf("%s", $value) : sprintf("'%s'", $value); + $valueString = Str::startsWith($value, '$') ? sprintf("%s", $value) : sprintf("'%s'", $value); } $defaultValueString = '[]'; diff --git a/src/Models/Field.php b/src/Models/Field.php index 3c03496..d6ea079 100644 --- a/src/Models/Field.php +++ b/src/Models/Field.php @@ -1809,7 +1809,7 @@ public static function isValidHtmlType(array $properties) public static function isValidSelectRangeType(array $properties) { return Arr::isKeyExists($properties, 'html-type') - && starts_with($properties['html-type'], 'selectRange|'); + && Str::startsWith($properties['html-type'], 'selectRange|'); } /** diff --git a/src/Models/ForeignConstraint.php b/src/Models/ForeignConstraint.php index 7c9df83..ef78489 100644 --- a/src/Models/ForeignConstraint.php +++ b/src/Models/ForeignConstraint.php @@ -141,7 +141,7 @@ public function getForeignRelation() */ protected function getForeignModelName($prefix = '') { - return ucfirst(camel_case($prefix . Str::singular($this->references))); + return ucfirst(Str::camel($prefix . Str::singular($this->references))); } /** diff --git a/src/Models/ForeignRelationship.php b/src/Models/ForeignRelationship.php index 11c44b5..5adc816 100644 --- a/src/Models/ForeignRelationship.php +++ b/src/Models/ForeignRelationship.php @@ -542,6 +542,6 @@ public static function makeRelationName($fieldName) { $modelName = self::extractModelName($fieldName); - return camel_case($modelName); + return Str::camel($modelName); } } diff --git a/src/Models/Resource.php b/src/Models/Resource.php index 058d3f5..915e301 100644 --- a/src/Models/Resource.php +++ b/src/Models/Resource.php @@ -6,6 +6,7 @@ use CrestApps\CodeGenerator\Models\Index; use CrestApps\CodeGenerator\Models\Relation; use CrestApps\CodeGenerator\Support\Arr; +use CrestApps\CodeGenerator\Support\Str; use CrestApps\CodeGenerator\Support\Config; use CrestApps\CodeGenerator\Support\Contracts\JsonWriter; use CrestApps\CodeGenerator\Support\FieldTransformer; @@ -158,7 +159,7 @@ public function setProtection($name, $isProtected) */ protected function getProtectionKey($name) { - $key = str_is('is-*-protected', $name) ? $name : sprintf('is-%s-protected', $name); + $key = Str::is('is-*-protected', $name) ? $name : sprintf('is-%s-protected', $name); return $key; } diff --git a/src/Support/FieldTransformer.php b/src/Support/FieldTransformer.php index 3a67d67..15c6e31 100644 --- a/src/Support/FieldTransformer.php +++ b/src/Support/FieldTransformer.php @@ -89,7 +89,7 @@ public static function fromString($str, $localeGroup = 'generic', array $languag foreach ($fieldNames as $fieldName) { $field = []; - if (str_contains($fieldName, ':')) { + if (Str::contains($fieldName, ':')) { // Handle the following format // name:a;html-type:select;options:first|second|third|fourth if (!Str::is('*name*:*', $fieldName)) { diff --git a/src/Support/Helpers.php b/src/Support/Helpers.php index 62e4c0b..8e4d954 100644 --- a/src/Support/Helpers.php +++ b/src/Support/Helpers.php @@ -20,7 +20,7 @@ class Helpers public static function makeControllerName($modelName) { $name = Str::properSnake($modelName, 'controller-name'); - $case = ucfirst(camel_case($name)); + $case = ucfirst(Str::camel($name)); if (!empty($postfix = Config::getControllerNamePostFix())) { return Str::postfix($case, $postfix); @@ -39,7 +39,7 @@ public static function makeControllerName($modelName) public static function makeApiResourceName($modelName) { $name = Str::properSnake($modelName, 'api-resource-name'); - $case = ucfirst(camel_case($name)); + $case = ucfirst(Str::camel($name)); if (!empty($postfix = Config::getApiResourceNamePostFix())) { return Str::postfix($case, $postfix); @@ -58,7 +58,7 @@ public static function makeApiResourceName($modelName) public static function makeApiResourceCollectionName($modelName) { $name = Str::properSnake($modelName, 'api-resource-collection-name'); - $case = ucfirst(camel_case($name)); + $case = ucfirst(Str::camel($name)); if (!empty($postfix = Config::getApiResourceCollectionNamePostFix())) { return Str::postfix($case, $postfix); @@ -97,9 +97,9 @@ public static function getAppName() public static function fixNamespace($path) { $path = self::convertSlashToBackslash($path); - + $path = rtrim(Str::eliminateDuplicates($path, '\\'), '\\'); - + return $path; } @@ -158,10 +158,10 @@ public static function convertNameToLabel($name) public static function makeFormRequestName($modelName) { $name = Str::properSnake($modelName, 'request-form-name'); - $case = ucfirst(camel_case($name)); + $case = ucfirst(Str::camel($name)); if (!empty($postFix = Config::getFormRequestNamePostFix())) { - return str_finish($case, $postFix); + return Str::finish($case, $postFix); } return $case; @@ -202,7 +202,7 @@ public static function makeJsonFileName($modelName) { $snake = Str::properSnake($modelName, 'resource-file-name'); - return str_finish($snake, '.json'); + return Str::finish($snake, '.json'); } /** diff --git a/src/Support/Str.php b/src/Support/Str.php index a32b909..c341d6f 100644 --- a/src/Support/Str.php +++ b/src/Support/Str.php @@ -371,6 +371,6 @@ public static function extractClassFromString($string) */ public static function isQualifiedNamespace($name) { - return !empty($name) && !starts_with($name, '\\'); + return !empty($name) && !Str::startsWith($name, '\\'); } } diff --git a/src/Support/ValidationParser.php b/src/Support/ValidationParser.php index ebb186e..b02d8c4 100644 --- a/src/Support/ValidationParser.php +++ b/src/Support/ValidationParser.php @@ -336,7 +336,7 @@ protected function getFirst($key) protected function startsWith($key) { foreach ($this->rules as $rule) { - if (starts_with($rule, $key)) { + if (Str::startsWith($rule, $key)) { return true; } } diff --git a/src/Traits/ApiResourceTrait.php b/src/Traits/ApiResourceTrait.php index 355544a..bce9b7f 100644 --- a/src/Traits/ApiResourceTrait.php +++ b/src/Traits/ApiResourceTrait.php @@ -18,7 +18,7 @@ protected function getApiResourceClassName($modelName) { $cName = trim($this->option('api-resource-name')); - return $cName ? str_finish($cName, Config::getApiResourceNamePostFix()) : Helpers::makeApiResourceName($modelName); + return $cName ? Str::finish($cName, Config::getApiResourceNamePostFix()) : Helpers::makeApiResourceName($modelName); } /** @@ -49,7 +49,7 @@ protected function getApiResourceCollectionClassName($modelName) { $cName = trim($this->option('api-resource-collection-name')); - return $cName ? str_finish($cName, Config::getApiResourceCollectionNamePostFix()) : Helpers::makeApiResourceCollectionName($modelName); + return $cName ? Str::finish($cName, Config::getApiResourceCollectionNamePostFix()) : Helpers::makeApiResourceCollectionName($modelName); } /** diff --git a/src/Traits/CommonCommand.php b/src/Traits/CommonCommand.php index 7703ca5..b7f16cd 100644 --- a/src/Traits/CommonCommand.php +++ b/src/Traits/CommonCommand.php @@ -128,9 +128,9 @@ public function arguments() */ public function getPluralVariable($name) { - $snake = snake_case($name); + $snake = Str::snake($name); - $variableName = camel_case(Str::plural($snake)); + $variableName = Str::camel(Str::plural($snake)); if ($variableName == $this->getSingularVariable($name)) { $variableName .= 'Objects'; @@ -148,9 +148,9 @@ public function getPluralVariable($name) */ public function getSingularVariable($name) { - $snake = snake_case($name); + $snake = Str::snake($name); - return camel_case($snake); + return Str::camel($snake); } /** diff --git a/src/Traits/GeneratorReplacers.php b/src/Traits/GeneratorReplacers.php index a416558..b88ee58 100644 --- a/src/Traits/GeneratorReplacers.php +++ b/src/Traits/GeneratorReplacers.php @@ -22,9 +22,9 @@ protected function replaceModelName(&$stub, $modelName, $prefix = 'model_') $stub = $this->strReplace($prefix . 'name_sentence', ucfirst($englishSingle), $stub); $stub = $this->strReplace($prefix . 'name_plural', $plural, $stub); $stub = $this->strReplace($prefix . 'name_plural_title', Str::titleCase($plural), $stub); - $stub = $this->strReplace($prefix . 'name_snake', snake_case($modelName), $stub); - $stub = $this->strReplace($prefix . 'name_studly', studly_case($modelName), $stub); - $stub = $this->strReplace($prefix . 'name_slug', str_slug($englishSingle), $stub); + $stub = $this->strReplace($prefix . 'name_snake', Str::snake($modelName), $stub); + $stub = $this->strReplace($prefix . 'name_studly', Str::studly($modelName), $stub); + $stub = $this->strReplace($prefix . 'name_slug', Str::slug($englishSingle), $stub); $stub = $this->strReplace($prefix . 'name_kebab', Str::kebabCase($modelName), $stub); $stub = $this->strReplace($prefix . 'name_title', Str::titleCase($englishSingle), $stub); $stub = $this->strReplace($prefix . 'name_title_lower', strtolower($englishSingle), $stub); @@ -67,7 +67,7 @@ protected function replaceStandardLabels(&$stub, array $items) */ protected function modelNamePlainEnglish($modelName) { - return str_replace('_', ' ', snake_case($modelName)); + return str_replace('_', ' ', Str::snake($modelName)); } /** @@ -169,7 +169,7 @@ protected function getModelCapName($name) */ protected function getModelName($name) { - return snake_case($name); + return Str::snake($name); } /** diff --git a/src/Traits/Migration.php b/src/Traits/Migration.php index b465a13..e2fbcec 100644 --- a/src/Traits/Migration.php +++ b/src/Traits/Migration.php @@ -129,7 +129,7 @@ protected function getCreateMigrationName($name) */ protected function makeCreateTableClassName($tableName) { - return sprintf('Create%sTable', studly_case($tableName)); + return sprintf('Create%sTable', Str::studly($tableName)); } /** @@ -142,6 +142,6 @@ protected function makeCreateTableClassName($tableName) */ protected function makeAlterTableClassName($tableName, $id) { - return sprintf('Alter%s%sTable', studly_case($tableName), $id); + return sprintf('Alter%s%sTable', Str::studly($tableName), $id); } } diff --git a/src/Traits/ScaffoldTrait.php b/src/Traits/ScaffoldTrait.php index 434ceed..1c670de 100644 --- a/src/Traits/ScaffoldTrait.php +++ b/src/Traits/ScaffoldTrait.php @@ -2,6 +2,8 @@ namespace CrestApps\CodeGenerator\Traits; +use CrestApps\CodeGenerator\Support\Str; + trait ScaffoldTrait { /** @@ -27,6 +29,6 @@ protected function printInfo($message) */ protected function modelNamePlainEnglish($modelName) { - return str_replace('_', ' ', snake_case($modelName)); + return str_replace('_', ' ', Str::snake($modelName)); } }