Closed seancheung closed 7 years ago
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?
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.*
?
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 😃
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.
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.
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.
Sure thanks.
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.
Please add support for php-parser v2.*