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

incompatible with php-parser v2.* #38

Closed
seancheung opened this issue Nov 8, 2016 · 7 comments
Closed

incompatible with php-parser v2.* #38

seancheung opened this issue Nov 8, 2016 · 7 comments
Milestone

Comments

@seancheung
Copy link

Please add support for php-parser v2.*

Problem 1
    - Installation request for gossi/php-code-generator ^0.3.2 -> satisfiable by gossi/php-code-generator[v0.3.2].
    - Conclusion: remove nikic/php-parser v2.1.1
    - Conclusion: don't install nikic/php-parser v2.1.1
    - gossi/php-code-generator v0.3.2 requires nikic/php-parser ~1 -> satisfiable by nikic/php-parser[v1.0.0, v1.0.1, v1.0.2, v1.1.0, v1.2.0, v1.2.1, v1.2.2, v1.3.0, v1.4.0, v1.4.1].
    - Can only install one of: nikic/php-parser[v1.2.1, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.2.2, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.3.0, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.4.0, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.4.1, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.0.0, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.0.1, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.0.2, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.1.0, v2.1.1].
    - Can only install one of: nikic/php-parser[v1.2.0, v2.1.1].
    - Installation request for nikic/php-parser (locked at v2.1.1) -> satisfiable by nikic/php-parser[v2.1.1].
@gossi
Copy link
Collaborator

gossi commented Nov 8, 2016

Unfortunately, because the lib requires sami in require-dev which itself requires the php-parser in version 1. So I'm going with that one so far (I recently tried to update to v2 last week). What would work though is to make "nikic/php-parser": "~1|~2". That would require that the API is consistent between these two major versions. I haven't checked this yet (despite realizing php-parser in v3 is coming soon). Do you know if this works?

@seancheung
Copy link
Author

unfortunately it doesn't work in my case. "nikic/php-parser": "^2.1.1" is a dependency of one of my major dependency.

So no chance to make it work with v2.* ?

@gossi
Copy link
Collaborator

gossi commented Nov 8, 2016

Well, I can do this:

  "require": {
    ...
    "nikic/php-parser": "~1|~2"
    ...
  }

which would install v1 for dev-mode (as composer install --dev would require v1) and would install v2 for you. That would work in regards to composer. The thing I am wondering about is wether v1 and v2 are API compatible. Like would php-parser v2 break the php-code-generator or not, that is the question. I would be happy to make the lib work with php-parser in both versions 😃

@seancheung
Copy link
Author

Man I did a test using composer's local repositories feature.

"require": {
        "gossi/php-code-generator": "*"
    },
"repositories": [
        {
            "type": "path",
            "url": "../php-code-generator"
        }
    ]

Then I changed your package's requirement of php-parser to

"require" : {
    "nikic/php-parser" : "~1|~2"
},

And it successfully installed.
image

The sample code runs correctly:

use gossi\codegen\generator\CodeGenerator;
use gossi\codegen\model\PhpClass;
use gossi\codegen\model\PhpMethod;
use gossi\codegen\model\PhpParameter;

$class = new PhpClass();
$class
    ->setQualifiedName('my\\cool\\Tool')
    ->setMethod(PhpMethod::create('__construct')
        ->addParameter(PhpParameter::create('target')
            ->setType('string')
            ->setDescription('Creates my Tool')
        )
    )
;

$generator = new CodeGenerator();
$code = $generator->generate($class);

=>

namespace my\cool;

class Tool {

    /**
     *
     * @param $target string Creates my Tool
     */
    public function __construct($target) {
    }
}

Except that I got a deprecated-error:

PHP error:  The Symfony\Component\OptionsResolver\OptionsResolver::setOptional method is deprecated since version 2.6 and will be removed in 3.0. Use the setDefined() method instead. in F:\Documents\workspace\eyesar-laravel\vendor\symfony\options-resolver\OptionsResolver.php on line 1126
PHP error:  Calling the Symfony\Component\OptionsResolver\OptionsResolver::setAllowedTypes method with an array of options is deprecated since version 2.6 and will be removed in 3.0. Use the new signature with a single option instead. in F:\Documents\workspace\eyesar-laravel\vendor\symfony\options-resolver\OptionsResolver.php on line 591

I think php-parser's v1 is mostly compatible with v2.

@gossi
Copy link
Collaborator

gossi commented Nov 15, 2016

I recently pushed to github. I set v1 or v2 for php-parser, so you can play around with dev-master version of this lib. If everything goes well, this will be version 0.4 which I'm about to release in the coming days.

@seancheung
Copy link
Author

Sure thanks.

@gossi
Copy link
Collaborator

gossi commented Nov 16, 2016

So, the parser instantiation is different between v1 and v2. I tested it today and it failed. So I made some customizations and now the right parser for the right version is being used. I'm about to release 0.4 now, which will work with php-parser v2.

@gossi gossi closed this as completed Nov 16, 2016
@gossi gossi added this to the Version 0.4 milestone Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants