Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SDK to support Illuminate/support 7.x branch (and Laravel 7.x) #217

Closed
JBtje opened this issue Mar 12, 2020 · 15 comments
Closed

Update SDK to support Illuminate/support 7.x branch (and Laravel 7.x) #217

JBtje opened this issue Mar 12, 2020 · 15 comments

Comments

@JBtje
Copy link
Contributor

JBtje commented Mar 12, 2020

Given a clean Laravel 7.x project, adding the myparcel SDK will result in the errors below.

Cause of the problem: Laravel 7.x is using the Illuminate/support 7.x branch, whilst MyParcel is using a version of branch 5.6

>> composer require myparcelnl/sdk

  - Installing myparcelnl/sdk (v3.1.7): Loading from cache
Package anahkiasen/underscore-php is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
PHP Warning:  Uncaught ErrorException: Declaration of MyParcelNL\Sdk\src\Support\Collection::push($value) should be compatible with Illuminate\Support\Collection::push(...$values) in Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php:38
Stack trace:
#0 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php(38): Composer\Util\ErrorHandler::handle(2, 'Declaration of ...', 'Z:\\Mega\\Webserv...', 38, Array)
#1 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\AutoLoader.php(4): require_once('Z:\\Mega\\Webserv...')
#2 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\composer\autoload_real.php(66): require('Z:\\Mega\\Webserv...')
#3 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\composer\autoload_real.php(56): composerRequire34f4fcc12f3a0b623a324cdd55cde51f('3480d8f702c8d1d...', 'Z:\\Mega\\Webserv...')
#4 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\autoload.php(7): ComposerAutoloaderInit34f4fcc12f3a0b623a324cdd55cde51f::getLoader()
#5 Z:\Me in Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php on line 38

Warning: Uncaught ErrorException: Declaration of MyParcelNL\Sdk\src\Support\Collection::push($value) should be compatible with Illuminate\Support\Collection::push(...$values) in Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php:38
Stack trace:
#0 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php(38): Composer\Util\ErrorHandler::handle(2, 'Declaration of ...', 'Z:\\Mega\\Webserv...', 38, Array)
#1 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\AutoLoader.php(4): require_once('Z:\\Mega\\Webserv...')
#2 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\composer\autoload_real.php(66): require('Z:\\Mega\\Webserv...')
#3 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\composer\autoload_real.php(56): composerRequire34f4fcc12f3a0b623a324cdd55cde51f('3480d8f702c8d1d...', 'Z:\\Mega\\Webserv...')
#4 Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\autoload.php(7): ComposerAutoloaderInit34f4fcc12f3a0b623a324cdd55cde51f::getLoader()
#5 Z:\Me in Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php on line 38
PHP Fatal error:  Declaration of MyParcelNL\Sdk\src\Support\Collection::sort(?callable $callback = NULL) must be compatible with Illuminate\Support\Collection::sort($callback = NULL) in Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php on line 38

Fatal error: Declaration of MyParcelNL\Sdk\src\Support\Collection::sort(?callable $callback = NULL) must be compatible with Illuminate\Support\Collection::sort($callback = NULL) in Z:\Mega\Webserver\www\Laravel\DiagnOSAS\vendor\myparcelnl\sdk\src\Support\Collection.php on line 38

Quick and dirty solution:
https://github.com/myparcelnl/sdk/blob/master/src/Support/Collection.php#L1238

    public function push( ...$values )
    {
        foreach( $values AS $value ) {
            $this->items[] = $value;
        }

        return $this;
    }

https://github.com/myparcelnl/sdk/blob/master/src/Support/Collection.php#L1445

    public function sort( $callback = NULL )

For me, this solves the problem and the SDK is still working... Better would be to implement the new Collection.php

@Cannonb4ll
Copy link

Having this issue as well.

@JBtje
Copy link
Contributor Author

JBtje commented Mar 17, 2020

My current solution is terrible and ugly as ... but it works for the time being.

Implement the above changes to the Collection.php file. Store the file somewhere IN your project (i use resources/MyParcel/Collection.php)
Collection.txt

After deploy of your code to the server, overwrite the Collection.php file in the vendor folder

cp resources/MyParcel/Collection.txt ./vendor/myparcelnl/sdk/src/Support/Collection.php

@appelflap
Copy link

Saw that part of this is fixed by 648c7db. Except that Illuminati v7.5.2 is moving further and has changed the declaration of the when call:

Fatal error: Declaration of MyParcelNL\Sdk\src\Support\Collection::when($value, callable $callback, ?callable $default = NULL) must be compatible with Illuminate\Support\Collection::when($value, ?callable $callback = NULL, ?callable $default = NULL) in /app/vendor/myparcelnl/sdk/src/Support/Collection.php on line 38

Maybe make two tags when it gets merged into master to let people lock down a combination of myparcel+illuminate in their composer.json?

@reindert-vetter
Copy link
Contributor

This is resolved in version 4.0.0. @appelflap @JBtje @Cannonb4ll Can you test whether it works now?

@appelflap
Copy link

Tried to update, but the 4.x isn't on packagist yet @reindert-vetter

@RichardPerdaan
Copy link
Member

Hi @appelflap ,
When I look on packagist I see version 4.0.0 there, would you like to try again?

@appelflap
Copy link

Yes, see it now too. Page says: This package is not auto-updated. Last update: 2020-05-08 10:25:13 UTC

Looks good! Stable with:

illuminate/http (v5.6.0 => v7.10.3)
symfony/event-dispatcher (v4.2.12 => v5.0.8)

@RickJeroen
Copy link
Contributor

We are still having this issue on laravel/framework (v7.10.3) with myparcelnl/sdk (v4.0.0):

Fatal error: Declaration of MyParcelNL\Sdk\src\Support\Collection::when($value, callable $callback, ?callable $default = NULL) must be compatible with Illuminate\Support\Collection::when($value, ?callable $callback = NULL, ?callable $default = NULL) in /vendor/myparcelnl/sdk/src/Support/Collection.php on line 486

@appelflap
Copy link

@RickJeroen, do you also have illuminate/support v7.10.3? Because MyParcelNL\Sdk\src\Support\Collection (indirectly) implements the EnumerateValuesTrait from that package andhas function definition public function when($value, callable $callback = null, callable $default = null) without the optional '?' sign.

@reindert-vetter
Copy link
Contributor

reindert-vetter commented May 11, 2020

@appelflap @RickJeroen @JBtje Do you like or dislike the fact that we extend the standard laravel class? It does force us to stay up to date with the latest changes in Laravel collection

@appelflap
Copy link

No problems with it being extended, but the dependency is not in the project composer.json. So version compatibility is somewhat unclear.

@RickJeroen
Copy link
Contributor

No problems with it being extended, but the dependency is not in the project composer.json. So version compatibility is somewhat unclear.

I agree

@JBtje
Copy link
Contributor Author

JBtje commented May 11, 2020

No problems with it being extended, but the dependency is not in the project composer.json. So version compatibility is somewhat unclear.

agree as well

@JBtje
Copy link
Contributor Author

JBtje commented May 15, 2020

Just tested #230, it works for laravel 7.4-7.11 (latest). Though, as stated by Appelflap, adding dependency requirement in composer.json would be nice.

@Cannonb4ll
Copy link

Still having the same error, have not tried #230 but would be nice if that got merged.

PHP Fatal error:  Declaration of MyParcelNL\Sdk\src\Support\Collection::when($value, callable $callback, ?callable $default = NULL) must be compatible with Illuminate\Support\Collection::when($value, ?callable $callback = NULL, ?callable $default = NULL) in /Users/dennissmink/Workspace/package-dev/vendor/myparcelnl/sdk/src/Support/Collection.php on line 486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants