Laravel-Lang / common

Easily connect the necessary language packs to the application
https://laravel-lang.com/packages-common.html
MIT License
93 stars 10 forks source link

[Bug]: Argument #1 ($plugin) must be of type string, array given #186

Closed robsonek closed 3 months ago

robsonek commented 3 months ago

Lang Package Name

laravel-lang/publisher

Lang Package Version

16.4

Laravel Framework Version

11.9.2

PHP Version

8.3.7

Dependencies

"require": {
    "php": "^8.2",
    "laravel/framework": "^11.9",
    "laravel/tinker": "^2.9",
    "lcobucci/jwt": "^5.3",
    "overtrue/laravel-versionable": "^5.2",
    "rappasoft/laravel-livewire-tables": "^3.2",
    "wire-elements/modal": "^2.0"
},
"require-dev": {
    "fakerphp/faker": "^1.23",
    "laravel-lang/lang": "^15.4",
    "laravel/breeze": "^2.0",
    "laravel/pint": "^1.13",
    "laravel/sail": "^1.26",
    "mockery/mockery": "^1.6",
    "nunomaduro/collision": "^8.0",
    "phpunit/phpunit": "^11.0.1"
},

Issue description

php artisan lang:update

   INFO  Collecting translations...  

   TypeError 

  LaravelLang\Publisher\Processors\Processor::LaravelLang\Publisher\Processors\{closure}(): Argument #1 ($plugin) must be of type string, array given

  at vendor/laravel-lang/publisher/src/Processors/Processor.php:150
    146▕     protected function plugins(): array
    147▕     {
    148▕         return collect($this->config->getPlugins())
    149▕             ->map(fn (array $plugins) => collect($plugins)
  ➜ 150▕                 ->map(static fn (string $plugin) => new $plugin())
    151▕                 ->filter(static fn (Plugin $plugin) => $plugin->has())
    152▕                 ->all()
    153▕             )
    154▕             ->filter()

      +1 vendor frames 

  2   [internal]:0
      LaravelLang\Publisher\Processors\Processor::LaravelLang\Publisher\Processors\{closure}([], "/Users/...")
      +18 vendor frames 

  21  artisan:13
      Illuminate\Foundation\Application::handleCommand(Object(Symfony\Component\Console\Input\ArgvInput))

Steps to reproduce

I don't know. On 16.3 the error don't appear.

andrey-helldar commented 3 months ago

Try deleting the config/localization.php file and try again.

I tried to reproduce the problem on a clean application, installing only your dependencies, and the error did not reproduce.

image

robsonek commented 3 months ago

Try deleting the config/localization.php file and try again.

I don't have that file

I tried to reproduce the problem on a clean application, installing only your dependencies, and the error did not reproduce.

Please try with pl language. php artisan lang:add pl

I have no errors with the older version of the package "laravel-lang/publisher": "16.3",

andrey-helldar commented 3 months ago

Hm...

image

Locales ......................................
Installed ......................... en, fr, pl
Protected ................................. en
LaravelLang\Lang\Plugin ............... 15.4.1
Locales Version ........................ 2.8.0
Publisher Version ..................... 16.4.0

The publisher versions 16.3 and 16.4 differ only in working with the configuration file.

I am not able to reproduce the problem, so I need your help.

Go to the vendor/laravel-lang/publisher/src/Processors/Processor.php file and add a try-catch to the plugins method, adding the output. It should work like this:

protected function plugins(): array
{
    try {
        return collect($this->config->getPlugins())
            ->map(fn (array $plugins) => collect($plugins)
                ->map(static fn (string $plugin) => new $plugin())
                ->filter(static fn (Plugin $plugin) => $plugin->has())
                ->all()
            )
            ->filter()
            ->all();
    } catch (\Throwable $e) {
        dd(
            $e->getMessage(),
            $this->config->getPlugins()
        );
    }
}

After that, run the console command php artisan lang:update. As soon as the code drops by error, it will show information about it: the text of the error itself, as well as a list of plugins that caused it.

This way, I can identify the problem spot and fix it.

And also run the console command php artisan about. It will have a section called Locales. Send a screenshot of it.

Like this one ![image](https://github.com/Laravel-Lang/common/assets/10347617/2b1aa419-dfef-417e-b6b1-eadefef4670a)
robsonek commented 3 months ago

"LaravelLang\Publisher\Processors\Processor::LaravelLang\Publisher\Processors{closure}(): Argument #1 ($plugin) must be of type string, array given" // vendor/laravel-lang/publisher/src/Processors/Processor.php:158 array:1 [ "/Users/..." => array:1 [ "us/vendor/laravel-lang/lang" => array:17 [ 0 => "LaravelLang\Lang\Plugins\Breeze\Master" 1 => "LaravelLang\Lang\Plugins\Breeze\V2" 2 => "LaravelLang\Lang\Plugins\Cashier\Stripe\Master" 3 => "LaravelLang\Lang\Plugins\Cashier\Stripe\V15" 4 => "LaravelLang\Lang\Plugins\Fortify\Master" 5 => "LaravelLang\Lang\Plugins\Fortify\V1" 6 => "LaravelLang\Lang\Plugins\Jetstream\Master" 7 => "LaravelLang\Lang\Plugins\Jetstream\V5" 8 => "LaravelLang\Lang\Plugins\Laravel\Master" 9 => "LaravelLang\Lang\Plugins\Laravel\V11" 10 => "LaravelLang\Lang\Plugins\Nova\DuskSuite\Main" 11 => "LaravelLang\Lang\Plugins\Nova\LogViewer\Main" 12 => "LaravelLang\Lang\Plugins\Nova\V4" 13 => "LaravelLang\Lang\Plugins\Spark\Paddle" 14 => "LaravelLang\Lang\Plugins\Spark\Stripe" 15 => "LaravelLang\Lang\Plugins\UI\Master" 16 => "LaravelLang\Lang\Plugins\UI\V4" ] ] ] // vendor/laravel-lang/publisher/src/Processors/Processor.php:158

robsonek commented 3 months ago

php artisan about on "laravel-lang/publisher": "16.4.0"

Screenshot 2024-06-04 at 11 33 29
andrey-helldar commented 3 months ago

Can you execute composer info laravel-lang/config console command? What do you see?

andrey-helldar commented 3 months ago

I realized that the problem with the private configuration file - https://github.com/Laravel-Lang/config/blob/main/config/private.php

But I can't find the problem. I have already created the second test project and it works. My OS is Windows.

robsonek commented 3 months ago

yes

name : laravel-lang/config descrip. : The Laravel-Lang config package keywords : Laravel-lang, Settings, config, lang, languages, laravel, locale, locales, localization, localizations, translation, translations versions : * 1.0.2 released : 2024-06-01, this week type : library license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText homepage : source : [git] https://github.com/Laravel-Lang/config.git 48e8efa965dac43984ccc3a4ddc211793c5335dd dist : [zip] https://api.github.com/repos/Laravel-Lang/config/zipball/48e8efa965dac43984ccc3a4ddc211793c5335dd 48e8efa965dac43984ccc3a4ddc211793c5335dd path : /Users/.../vendor/laravel-lang/config names : laravel-lang/config

support issues : https://github.com/Laravel-Lang/config/issues source : https://github.com/Laravel-Lang/config/tree/1.0.2

autoload psr-4 LaravelLang\Config\ => src/

requires archtechx/enums ^1.0 illuminate/config ^10.0 || ^11.0 illuminate/support ^10.0 || ^11.0 laravel-lang/locale-list ^1.4 php ^8.1

requires (dev) orchestra/testbench ^9.1 pestphp/pest ^2.34

robsonek commented 3 months ago

But I can't find the problem. I have already created the second test project and it works. My OS is Windows.

I`m using MacOS

robsonek commented 3 months ago

php artisan about on "laravel-lang/publisher": "16.3.0"

Screenshot 2024-06-04 at 11 37 07
robsonek commented 3 months ago

I realized that the problem with the private configuration file - https://github.com/Laravel-Lang/config/blob/main/config/private.php

But I can't find the problem. I have already created the second test project and it works. My OS is Windows.

Maybe try installing an older version like I did and update to the latest one once it's set up?

andrey-helldar commented 3 months ago

image

image

GitHub tests for MacOS is ok too...

image

https://github.com/Laravel-Lang/publisher/actions/runs/9364921609/job/25778975795

andrey-helldar commented 3 months ago

Publishers 16.3 differs from 16.4 in only one PR: https://github.com/Laravel-Lang/publisher/pull/356

andrey-helldar commented 3 months ago

Let's try this:

composer remove --dev laravel-lang/lang

rm -rf ./config/localization.php ./config/localization-private.php ./vendor/laravel-lang ./lang ./resources/lang

composer update -W
composer require --dev laravel-lang/lang

php artisan lang:update
robsonek commented 3 months ago

The same...

php artisan lang:update

INFO Collecting translations...

TypeError

LaravelLang\Publisher\Processors\Processor::LaravelLang\Publisher\Processors{closure}(): Argument #1 ($plugin) must be of type string, array given

andrey-helldar commented 3 months ago

It remains to be seen where the difference comes from:

Your result:

array:1 [
    "/Users/..." => array:1 [
        "us/vendor/laravel-lang/lang" => array:17 [
            0 => "LaravelLang\Lang\Plugins\Breeze\Master"
            1 => "LaravelLang\Lang\Plugins\Breeze\V2"
...

My result:

array:1 [
  "D:\domains\test2\vendor\laravel-lang\lang" => array:17 [
    0 => "LaravelLang\Lang\Plugins\Breeze\Master"
    1 => "LaravelLang\Lang\Plugins\Breeze\V2"
...
andrey-helldar commented 3 months ago

Can you check if there is a dot anywhere in the path to the vendor\laravel-lang\lang folder?

Maybe, /User/.../domain.com/vendor/laravel-lang/lang? (domain.com)

andrey-helldar commented 3 months ago

Yes, that's point.

Path is /Users/<you_hide_this_path>/some.us/vendor/laravel-lang/lang

robsonek commented 3 months ago

Yes, I have a dot in path!

andrey-helldar commented 3 months ago

Yeah!

I changed path to d:\domains\test2.test and get the error:

image

andrey-helldar commented 3 months ago

I'll fix that in the near future. Thank you!

robsonek commented 3 months ago

Thank you for your support!

andrey-helldar commented 3 months ago

Fixed and released: laravel-lang/config#1.0.3

You can update dependency:

composer update laravel-lang/config

Thank you for your report!

PS: Don't forget to undo the changes in vendor/laravel-lang/publisher/src/Processors/Processor.php file

Or just run the commands:

composer remove --dev laravel-lang/lang
composer require --dev laravel-lang/lang

image

robsonek commented 3 months ago

Everything works with new version. Thank you for the quick help!

andrey-helldar commented 3 months ago

You're welcome!