Skip to content

Commit

Permalink
Make it compatible with Laravel 6+
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Nov 4, 2019
1 parent 2259e94 commit 95e95db
Show file tree
Hide file tree
Showing 31 changed files with 65 additions and 57 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ApiDocs/CreateApiDocsControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 5 additions & 5 deletions src/Commands/ApiDocs/CreateApiDocsViewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Bases/ControllerCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/Bases/ControllerRequestCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 ');
}

/**
Expand Down Expand Up @@ -212,7 +213,7 @@ protected function getCustomRuleShortName($rule)
*/
protected function canHaveUsingCommand($fullname)
{
return !starts_with($fullname, '\\');
return !Str::startsWith($fullname, '\\');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Bases/ResourceFileCreatorCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/Framework/CreateFormRequestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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';
}

/**
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Commands/Framework/CreateMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Framework/CreateModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Resources/ResourceFileDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Resources/ResourceFileFromDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Resources/ResourceFileReduceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/Views/CreateCreateViewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CrestApps\CodeGenerator\Commands\Bases\ViewsCommandBase;
use CrestApps\CodeGenerator\Models\Resource;
use CrestApps\CodeGenerator\Support\Str;

class CreateCreateViewCommand extends ViewsCommandBase
{
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}
}
5 changes: 3 additions & 2 deletions src/Commands/Views/CreateEditViewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CrestApps\CodeGenerator\Commands\Bases\ViewsCommandBase;
use CrestApps\CodeGenerator\Models\Resource;
use CrestApps\CodeGenerator\Support\Str;

class CreateEditViewCommand extends ViewsCommandBase
{
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}
}
4 changes: 2 additions & 2 deletions src/DatabaseParsers/MysqlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DatabaseParsers/ParserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected function makeModelName($tableName)
{
$name = Str::singular($tableName);

return ucfirst(camel_case($name));
return ucfirst(Str::camel($name));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/HtmlGenerators/LaravelCollectiveHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/HtmlGenerators/StandardHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[]';
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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|');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ForeignConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ForeignRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,6 @@ public static function makeRelationName($fieldName)
{
$modelName = self::extractModelName($fieldName);

return camel_case($modelName);
return Str::camel($modelName);
}
}
3 changes: 2 additions & 1 deletion src/Models/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/FieldTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
16 changes: 8 additions & 8 deletions src/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -97,9 +97,9 @@ public static function getAppName()
public static function fixNamespace($path)
{
$path = self::convertSlashToBackslash($path);

$path = rtrim(Str::eliminateDuplicates($path, '\\'), '\\');

return $path;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\\');
}
}
Loading

0 comments on commit 95e95db

Please sign in to comment.