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

Explicit type declarations is not handled! #24

Closed
Hubbitus opened this issue Dec 8, 2021 · 5 comments · Fixed by #25
Closed

Explicit type declarations is not handled! #24

Hubbitus opened this issue Dec 8, 2021 · 5 comments · Fixed by #25

Comments

@Hubbitus
Copy link
Contributor

Hubbitus commented Dec 8, 2021

Since PHP 7.4 type declarations were introduced.

But php-avro-schema-generator does not look in it.

Steps to reproduce:

// in ../DAO/DemoNotification.php
class DemoNotification {
    private string $content;

    public function __construct(string $content) {
        $this->content = $content;
    }

    public function getContent(): string {
        return $this->content;
    }
}

$data = new DemoNotification("Hello");
$registry = (new ClassRegistry())
    ->addClassDirectory(__DIR__ . '/../DAO')
    ->load();
$generator = new SchemaGenerator($registry, '');
$schemas = $generator->generate();
echo(current($schemas)); // Out: {"type":"record","name":"DemoNotification","namespace":"App.DAO","fields":[{"name":"content","type":""}]}

Actual behavior

Despite explicit type declaration:

private string $content;

Script outputs:

{"type":"record","name":"DemoNotification","namespace":"App.DAO","fields":[{"name":"content","type":""}]}

Expected behavior

{"type":"record","name":"DemoNotification","namespace":"App.DAO","fields":[{"name":"content","type":"string"}]}
@nick-zh
Copy link
Member

nick-zh commented Dec 8, 2021

Heya, thanks for the report. Absolutely correct, i'll look into it ✌️

Hubbitus pushed a commit to Hubbitus/php-avro-schema-generator that referenced this issue Dec 8, 2021
@Hubbitus
Copy link
Contributor Author

Hubbitus commented Dec 8, 2021

@nick-zh, please review pull-request addressing that issue #25

@nick-zh
Copy link
Member

nick-zh commented Dec 8, 2021

Many thanks, i made small adjustments and also opened #26 for the next major, since i never liked that class to begin with 😄

nick-zh added a commit that referenced this issue Dec 8, 2021
…claration first (#25)

* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first

* Apply suggestions from code review

Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
Co-authored-by: Nick <nickjobszh@gmail.com>
@Hubbitus
Copy link
Contributor Author

Hubbitus commented Dec 8, 2021

Thank you very much! Could you please release a new version to do not hack that in my application?

@nick-zh
Copy link
Member

nick-zh commented Dec 8, 2021

Sure thing, i am on it, i need to fix the stan error, so i already merged your changes ✌️
Edit: Backported for both 1.x and 2.x
Thanks again 👍

nick-zh added a commit that referenced this issue Dec 8, 2021
…claration first (#25)

* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first

* Apply suggestions from code review

Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
Co-authored-by: Nick <nickjobszh@gmail.com>
nick-zh added a commit that referenced this issue Dec 8, 2021
* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first (#25)

* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first

* Apply suggestions from code review

Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
Co-authored-by: Nick <nickjobszh@gmail.com>

* fix stan (#27)

* fix import

Co-authored-by: Pavel Alexeev aka Pahan-Hubbitus <pahan@hubbitus.info>
Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
nick-zh added a commit that referenced this issue Dec 8, 2021
…claration first (#25)

* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first

* Apply suggestions from code review

Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
Co-authored-by: Nick <nickjobszh@gmail.com>
nick-zh added a commit that referenced this issue Dec 8, 2021
* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first (#25)

* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first

* Apply suggestions from code review

Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
Co-authored-by: Nick <nickjobszh@gmail.com>

* fix stan (#27)

* fix import

Co-authored-by: Pavel Alexeev aka Pahan-Hubbitus <pahan@hubbitus.info>
Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants