Skip to content

Commit

Permalink
Resolve Hesto#147. Problem on Laravel 6 (String Helper)
Browse files Browse the repository at this point in the history
  • Loading branch information
alaminfirdows committed Oct 12, 2019
1 parent fcdb4ea commit 2950903
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
30 changes: 15 additions & 15 deletions src/Commands/MultiAuthInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Hesto\MultiAuth\Commands\Traits\OverridesGetArguments;
use Hesto\MultiAuth\Commands\Traits\ParsesServiceInput;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use SplFileInfo;
use Symfony\Component\Console\Input\InputOption;

Expand Down Expand Up @@ -36,7 +37,7 @@ class MultiAuthInstallCommand extends InstallAndReplaceCommand
*/
public function fire()
{
if ($this->option('lucid') && ! $this->getParsedServiceInput()) {
if ($this->option('lucid') && !$this->getParsedServiceInput()) {
$this->error('You must pass a Service name with the `--lucid` option.');

return true;
Expand Down Expand Up @@ -65,7 +66,7 @@ public function fire()
'--force' => true
]);

if(!$this->option('model')) {
if (!$this->option('model')) {
Artisan::call('multi-auth:model', [
'name' => $name,
'--lucid' => $lucid,
Expand All @@ -76,7 +77,7 @@ public function fire()
$this->installPasswordResetMigration();
}

if(!$this->option('views')) {
if (!$this->option('views')) {
Artisan::call('multi-auth:views', [
'name' => $name,
'service' => $service,
Expand All @@ -85,7 +86,7 @@ public function fire()
]);
}

if(!$this->option('routes')) {
if (!$this->option('routes')) {
$this->installWebRoutes();
}

Expand All @@ -111,21 +112,21 @@ public function installWebRoutes()
$service = $this->getParsedServiceInput();

if ($lucid) {
$stub = ! $domain
$stub = !$domain
? __DIR__ . '/../stubs/Lucid/routes/web.stub'
: __DIR__ . '/../stubs/Lucid/domain-routes/web.stub';

$lucidPath = base_path() . '/src/Services/' . studly_case($service) . '/Http/routes.php';
$lucidStub = ! $domain
$lucidStub = !$domain
? __DIR__ . '/../stubs/Lucid/routes/map-method.stub'
: __DIR__ . '/../stubs/Lucid/domain-routes/map-method.stub';

if ( ! $this->contentExists($lucidPath, $lucidStub)) {
if (!$this->contentExists($lucidPath, $lucidStub)) {
$lucidFile = new SplFileInfo($lucidStub);
$this->appendFile($lucidPath, $lucidFile);
}

if( ! $this->contentExists($lucidPath, $stub)) {
if (!$this->contentExists($lucidPath, $stub)) {
$file = new SplFileInfo($stub);
$this->appendFile($lucidPath, $file);

Expand All @@ -141,15 +142,14 @@ public function installWebRoutes()
$stub = __DIR__ . '/../stubs/domain-routes/web.stub';
}

if( ! $this->contentExists($path, $stub)) {
if (!$this->contentExists($path, $stub)) {
$file = new SplFileInfo($stub);
$this->appendFile($path, $file);

return true;
}

return false;

}

/**
Expand All @@ -162,13 +162,13 @@ public function installMigration()
$name = $this->getParsedNameInput();

$migrationDir = base_path() . '/database/migrations/';
$migrationName = 'create_' . str_plural(snake_case($name)) .'_table.php';
$migrationName = 'create_' . Str::plural(Str::snake($name)) . '_table.php';
$migrationStub = new SplFileInfo(__DIR__ . '/../stubs/Model/migration.stub');

$files = $this->files->allFiles($migrationDir);

foreach ($files as $file) {
if(str_contains($file->getFilename(), $migrationName)) {
if (Str::contains($file->getFilename(), $migrationName)) {
$this->putFile($file->getPathname(), $migrationStub);

return true;
Expand All @@ -191,13 +191,13 @@ public function installPasswordResetMigration()
$name = $this->getParsedNameInput();

$migrationDir = base_path() . '/database/migrations/';
$migrationName = 'create_' . str_singular(snake_case($name)) .'_password_resets_table.php';
$migrationName = 'create_' . Str::singular(Str::snake($name)) . '_password_resets_table.php';
$migrationStub = new SplFileInfo(__DIR__ . '/../stubs/Model/PasswordResetMigration.stub');

$files = $this->files->allFiles($migrationDir);

foreach ($files as $file) {
if(str_contains($file->getFilename(), $migrationName)) {
if (Str::contains($file->getFilename(), $migrationName)) {
$this->putFile($file->getPathname(), $migrationStub);

return true;
Expand Down Expand Up @@ -226,4 +226,4 @@ public function getOptions()
['routes', null, InputOption::VALUE_NONE, 'Exclude routes'],
];
}
}
}
36 changes: 19 additions & 17 deletions src/Commands/Traits/OverridesCanReplaceKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Hesto\MultiAuth\Commands\Traits;

use Illuminate\Support\Str;

trait OverridesCanReplaceKeywords
{
/**
Expand All @@ -11,7 +13,7 @@ trait OverridesCanReplaceKeywords
*/
protected function getParsedNameInput()
{
return mb_strtolower(str_singular($this->getNameInput()));
return mb_strtolower(Str::singular($this->getNameInput()));
}

/**
Expand All @@ -35,7 +37,7 @@ public function replaceNames($template)
$name = $this->getParsedNameInput();
$service = $this->getParsedServiceInput();

$name = str_plural($name);
$name = Str::plural($name);

$plural = [
'{{pluralCamel}}',
Expand All @@ -57,30 +59,30 @@ public function replaceNames($template)
];

$replacePlural = [
camel_case($name),
str_slug($name),
snake_case($name),
ucfirst(camel_case($name)),
Str::camel($name),
Str::slug($name),
Str::snake($name),
ucfirst(Str::camel($name)),
];

$replaceSingular = [
str_singular(camel_case($name)),
str_singular(str_slug($name)),
str_singular(snake_case($name)),
str_singular(ucfirst(camel_case($name))),

camel_case($service),
str_slug($service),
snake_case($service),
ucfirst(camel_case($service)),
Str::singular(Str::camel($name)),
Str::singular(Str::slug($name)),
Str::singular(Str::snake($name)),
Str::singular(ucfirst(Str::camel($name))),

Str::camel($service),
Str::slug($service),
Str::snake($service),
ucfirst(Str::camel($service)),
];



$template = str_replace($plural, $replacePlural, $template);
$template = str_replace($singular, $replaceSingular, $template);
$template = str_replace('{{Class}}', ucfirst(camel_case($name)), $template);
$template = str_replace('{{Class}}', ucfirst(Str::camel($name)), $template);

return $template;
}
}
}
4 changes: 3 additions & 1 deletion src/Commands/Traits/ParsesServiceInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Hesto\MultiAuth\Commands\Traits;

use Illuminate\Support\Str;

trait ParsesServiceInput
{
/**
Expand All @@ -11,7 +13,7 @@ trait ParsesServiceInput
*/
protected function getParsedServiceInput()
{
return mb_strtolower(str_singular($this->getServiceInput()));
return mb_strtolower(Str::singular($this->getServiceInput()));
}

/**
Expand Down

0 comments on commit 2950903

Please sign in to comment.