Open augustinewafula opened 5 years ago
a Few amendments helped me work out php artisan commands, not sure if that will help. use Illuminate\Support\Str; and change str_<> to Str::<>, Str:snake. I am still testing if that works.
almost all the Traits has this bug for laravel 6.01 release. see if this helps....
Regards Manish
<?php
namespace Hesto\MultiAuth\Commands\Traits;
use Illuminate\Support\Str;
trait ParsesServiceInput { /**
@return mixed|string */ protected function getParsedServiceInput() { return mb_strtolower(Str::singular($this->getServiceInput())); }
/**
<?php
namespace Hesto\Core\Commands;
use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Hesto\Core\Traits\CanReplaceKeywords; use Illuminate\Support\Str;
abstract class InstallAndReplaceCommand extends InstallCommand { use CanReplaceKeywords;
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The console command name.
*
* @var string
*/
protected $name;
/**
* The console command description.
*
* @var string
*/
protected $description;
/**
* Compile content.
*
* @param $content
* @return mixed
*/
protected function compile($content)
{
$content = $this->replaceNames($content);
return $content;
}
/**
* Get info message output
*
* @param $filePath
* @return mixed
*/
protected function getInfoMessage($filePath)
{
return $this->info('Content changed in: ' . $filePath);
}
/**
* Get the desired class name from the input.
*
* @return string
*/
protected function getParsedNameInput()
{
return mb_strtolower(Str::singular($this->getNameInput()));
}
/**
* Get the desired class name from the input.
*
* @return string
*/
protected function getNameInput()
{
return trim($this->argument('name'));
}
/**
* Get the console command arguments.
*
* @return array
*/
public function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the class'],
];
}
/**
* Check if stub's content exists in given file (path)
*
* @param $path
* @param $stub
* @return bool
*/
public function contentExists($path, $stub)
{
$originalContent = $this->files->get($path);
$content = $this->replaceNames($this->files->get($stub));
if (Str::contains(trim($originalContent), trim($content))) {
return true;
}
return false;
}
}
<?php
namespace Hesto\MultiAuth\Commands;
use Hesto\Core\Commands\InstallAndReplaceCommand; use Hesto\MultiAuth\Commands\Traits\OverridesCanReplaceKeywords; use Hesto\MultiAuth\Commands\Traits\OverridesGetArguments; use Hesto\MultiAuth\Commands\Traits\ParsesServiceInput; use Illuminate\Support\Facades\Artisan; use SplFileInfo; use Symfony\Component\Console\Input\InputOption; use Illuminate\Support\Str;
class MultiAuthInstallCommand extends InstallAndReplaceCommand { use OverridesCanReplaceKeywords, OverridesGetArguments, ParsesServiceInput;
/**
* The console command name.
*
* @var string
*/
protected $name = 'multi-auth:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install Multi Auth into Laravel 5.3 project';
/**
* Execute the console command.
*
* @return bool|null
*/
public function handle()
{
if ($this->option('lucid') && !$this->getParsedServiceInput()) {
$this->error('You must pass a Service name with the `--lucid` option.');
return true;
}
if ($this->option('force')) {
$name = $this->getParsedNameInput();
$domain = $this->option('domain');
$lucid = $this->option('lucid');
$service = $this->getParsedServiceInput() ?: null;
Artisan::call('multi-auth:settings', [
'name' => $name,
'service' => $service,
'--domain' => $domain,
'--lucid' => $lucid,
'--force' => true
]);
Artisan::call('multi-auth:files', [
'name' => $name,
'service' => $service,
'--domain' => $domain,
'--lucid' => $lucid,
'--force' => true
]);
if (!$this->option('model')) {
Artisan::call('multi-auth:model', [
'name' => $name,
'--lucid' => $lucid,
'--force' => true
]);
$this->installMigration();
$this->installPasswordResetMigration();
}
if (!$this->option('views')) {
Artisan::call('multi-auth:views', [
'name' => $name,
'service' => $service,
'--lucid' => $lucid,
'--force' => true
]);
}
if (!$this->option('routes')) {
$this->installWebRoutes();
}
$this->info('Multi Auth with ' . ucfirst($name) . ' guard successfully installed.');
return true;
}
$this->info('Use `-f` flag first.');
return true;
}
/**
* Install Web Routes.
*
* @return bool
*/
public function installWebRoutes()
{
$lucid = $this->option('lucid');
$domain = $this->option('domain');
$service = $this->getParsedServiceInput();
if ($lucid) {
$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
? __DIR__ . '/../stubs/Lucid/routes/map-method.stub'
: __DIR__ . '/../stubs/Lucid/domain-routes/map-method.stub';
if (!$this->contentExists($lucidPath, $lucidStub)) {
$lucidFile = new SplFileInfo($lucidStub);
$this->appendFile($lucidPath, $lucidFile);
}
if (!$this->contentExists($lucidPath, $stub)) {
$file = new SplFileInfo($stub);
$this->appendFile($lucidPath, $file);
return true;
}
return false;
}
$path = base_path() . '/routes/web.php';
$stub = __DIR__ . '/../stubs/routes/web.stub';
if ($domain) {
$stub = __DIR__ . '/../stubs/domain-routes/web.stub';
}
if (!$this->contentExists($path, $stub)) {
$file = new SplFileInfo($stub);
$this->appendFile($path, $file);
return true;
}
return false;
}
/**
* Install Migration.
*
* @return bool
*/
public function installMigration()
{
$name = $this->getParsedNameInput();
$migrationDir = base_path() . '/database/migrations/';
$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)) {
$this->putFile($file->getPathname(), $migrationStub);
return true;
}
}
$path = $migrationDir . date('Y_m_d_His') . '_' . $migrationName;
$this->putFile($path, $migrationStub);
return true;
}
/**
* Install PasswordResetMigration.
*
* @return bool
*/
public function installPasswordResetMigration()
{
$name = $this->getParsedNameInput();
$migrationDir = base_path() . '/database/migrations/';
$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)) {
$this->putFile($file->getPathname(), $migrationStub);
return true;
}
}
$path = $migrationDir . date('Y_m_d_His', strtotime('+1 second')) . '_' . $migrationName;
$this->putFile($path, $migrationStub);
return true;
}
/**
* Get the console command options.
*
* @return array
*/
public function getOptions()
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Force override existing files'],
['domain', false, InputOption::VALUE_NONE, 'Install in a subdomain'],
['lucid', false, InputOption::VALUE_NONE, 'Lucid architecture'],
['model', null, InputOption::VALUE_NONE, 'Exclude model and migration'],
['views', null, InputOption::VALUE_NONE, 'Exclude views'],
['routes', null, InputOption::VALUE_NONE, 'Exclude routes'],
];
}
}
<?php
namespace Hesto\Core\Commands;
use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Illuminate\Support\Str;
abstract class AppendContentCommand extends InstallAndReplaceCommand { /**
@var \Illuminate\Filesystem\Filesystem */ protected $files;
/**
@var string */ protected $name;
/**
@var string */ protected $description;
/**
@return array */ abstract function getSettings();
/**
@return bool|null */ public function handle() { $settings = $this->getSettings();
foreach ($settings as $setting) {
$path = $setting['path'];
$fullPath = base_path() . $path;
if ($this->putContent($fullPath, $this->compileContent($fullPath, $setting))) {
$this->getInfoMessage($fullPath);
}
}
return true;
}
/**
@return mixed */ protected function compileContent($path, $setting) //It should be compile method instead { $originalContent = $this->files->get($path); $content = $this->replaceNames($this->files->get($setting['stub']));
if (!Str::contains(trim($originalContent), trim($content))) {
if ($setting['prefix']) {
$stub = $content . $setting['search'];
} else {
$stub = $setting['search'] . $content;
}
$originalContent = str_replace($setting['search'], $stub, $originalContent);
}
return $originalContent;
} }
<?php
namespace Hesto\MultiAuth\Commands\Traits;
use Illuminate\Support\Str;
trait OverridesCanReplaceKeywords { /**
@return string */ protected function getParsedNameInput() { return mb_strtolower(Str::singular($this->getNameInput())); }
/**
@return string */ protected function getNameInput() { return trim($this->argument('name')); }
/**
@return $this */ public function replaceNames($template) { $name = $this->getParsedNameInput(); $service = $this->getParsedServiceInput();
$name = str::plural($name);
$plural = [
'{{pluralCamel}}',
'{{pluralSlug}}',
'{{pluralSnake}}',
'{{pluralClass}}',
];
$singular = [
'{{singularCamel}}',
'{{singularSlug}}',
'{{singularSnake}}',
'{{singularClass}}',
'{{singularServiceCamel}}',
'{{singularServiceSlug}}',
'{{singularServiceSnake}}',
'{{singularServiceClass}}',
];
$replacePlural = [
Str::camel($name),
Str::slug($name),
Str::snake($name),
ucfirst(Str::camel($name)),
];
$replaceSingular = [
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(Str::camel($name)), $template);
return $template;
} }
) Create a new Helper Directory inside app folder and create a helpers.php file and put all this function https://github.com/ajay-ag/blog/commit/e32425323e1722fc01158c0e09925b80cb010cfd Note : only string relented function
2.) put this code in service provider
foreach (glob(app_path().'/Helpers/*.php') as $filename){ require_once($filename); }
For string related issues: run composer require laravel/helpers
.
https://laravel.com/docs/6.x/upgrade#helpers
The current package isn't compatible with laravel 6.
I've replaced all the string functions by Str
Helper.
You may check my repo: alaminfirdows/laravel-multi-auth
The current package isn't compatible with laravel 6. I've replaced all the string functions by
Str
Helper.You may check my repo: alaminfirdows/multi-auth
How to use the package with ur modifications?
Updated...
You may like this package, works on Laravel 6.* alaminfirdows/laravel-multi-auth
I didn't create any package yet. Just download/clone my repo and paste it on your vendor folder.
i did not change in package file , i have create separate file put the necessary functions
I didn't create any package yet. Just download/clone my repo and paste it on your vendor folder.
Hello. Hesto/multi-auth can't be downloaded with Laravel 6. 1) How can I download it on Laravel 6? 2) How can I download ur modifications? Regards
Hello. Hesto/multi-auth can't be downloaded with Laravel 6.
- How can I download it on Laravel 6?
- How can I download ur modifications? Regards
Updated...
You may like this package, works on Laravel 6.* alaminfirdows/laravel-multi-auth
Step 1: Install Through Composer
composer require hesto/multi-auth
Step 2: Download my modification from alaminfirdows/multi-auth
Step 3: Go to vendor folder of your project and past the files.
Thanks.
I think you can try this All str and array helpers have been moved to the new laravel/helpers Composer package and removed from the framework. If desired, you may update all calls to these helpers to use the Illuminate\Support\Str and Illuminate\Support\Arr classes. Alternatively, you can add the new laravel/helpers package to your application to continue using these helpers: composer require laravel/helpers
Then install hesto
I think you can try this All str and array helpers have been moved to the new laravel/helpers Composer package and removed from the framework. If desired, you may update all calls to these helpers to use the Illuminate\Support\Str and Illuminate\Support\Arr classes. Alternatively, you can add the new laravel/helpers package to your application to continue using these helpers: composer require laravel/helpers
Then install hesto
I'll try it if the previous way didnt work. Thanks
Hello. Hesto/multi-auth can't be downloaded with Laravel 6.
- How can I download it on Laravel 6?
- How can I download ur modifications? Regards
Step 1: Install Through Composer
composer require hesto/multi-auth
Step 2: Download my modification from alaminfirdows/multi-auth
Step 3: Go to vendor folder of your project and past the files.
Thanks.
Copy files to which folder? plz Is there a direct way to send u some details with u, email for example? Regards
Updated...
Dear all, You may like this package, works on Laravel 6.* alaminfirdows/laravel-multi-auth
What was the actual actual problem
On Thu, 24 Oct, 2019, 2:03 PM Al-Amin Firdows, notifications@github.com wrote:
Updated...
Dear all, You may like this package https://github.com/alaminfirdows/laravel-multi-auth, works on Laravel 6.* alaminfirdows/laravel-multi-auth https://github.com/alaminfirdows/laravel-multi-auth
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Hesto/multi-auth/issues/147?email_source=notifications&email_token=AKO74MHQWEQA6LGJDGSEPODQQFMWLA5CNFSM4IUMOTMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECEGGHI#issuecomment-545809181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKO74MHEUPBKCS4Q3IO55LLQQFMWLANCNFSM4IUMOTMA .
The actual problem was string functions not exist on Laravel 6, I replaced it by Str Helper. On my package, customized folders, and namespaces also.
I have already mentioned step by step in comments
On Thu, 24 Oct, 2019, 11:39 PM Al-Amin Firdows, notifications@github.com wrote:
The actual problem was string functions not exist on Laravel 6, I replaced it by Str Helper. On my package, customized folders, and namespaces also.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Hesto/multi-auth/issues/147?email_source=notifications&email_token=AKO74MGKOJZPLJFQU6OSNBLQQHQGLA5CNFSM4IUMOTMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECF53CY#issuecomment-546037131, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKO74MBJGUHBL2CIHERYRZDQQHQGLANCNFSM4IUMOTMA .
This is no fix for this particular package.
But I have a similar multi-auth package that supports Laravel versions 5.3 to 6.x
https://github.com/mtvbrianking/multi-auth
You might wanna try it.
its not working with laravel 6.0