question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REQ][Slim4] Getter and setters for the models (or a not private visibility to properties)

See original GitHub issue

Is your feature request related to a problem? Please describe.

The php-slim4 generator generate models with private properties so they are not accessible from other classes nor extendable. Every time a models is instantiated the object results in an empty object (with null properties).

Describe the solution you’d like

The php-slim4 generator should generate models with either public properties or getters and setters (and maybe a constructor from associative arrays) like the php-symfony generator.

Describe alternatives you’ve considered

Currently I don’t use models at all… For the response I create associative arrays structured according to the OpenAPI config file.

Additional context

A generated model from the sample directory: https://github.com/OpenAPITools/openapi-generator/blob/3b9cb14025ac4ae90909ad5ba98f316ba5546986/samples/server/petstore/php-slim4/lib/Model/Pet.php The same model generated with php-symfony: https://github.com/OpenAPITools/openapi-generator/blob/3b9cb14025ac4ae90909ad5ba98f316ba5546986/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php

I found a mustache file with the private directive. https://github.com/OpenAPITools/openapi-generator/blob/8c6236b341c0e74c4cc18ea409f6fbf3d3dc114d/modules/openapi-generator/src/main/resources/php-slim4-server/model.mustache#L36 Could be the simplest solution change it to public?

Thank you for this beautiful project!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ybelenkocommented, Jun 12, 2020

It seems that your 1 to 4 proposals already wait for review in #5930.

  1. The models’ properties must have protected access for a more generic extension

Can’t quite follow you here… If I make properties protected, then I should disable __get and __set methods completely.

  1. No solutions for more complex models (enum strings, array, weird properties, breaking syntax…) yet

You mean if I set properties protected? My current BaseModel handles scalar types and weird properties OK, because of $dataContainer and general setData($data), getData(): mixed methods. It doesn’t validate and doesn’t convert data types yet, but I’m going to add it in next version.

In case you think your new classes are not stable enough a super simple first step could be adopt only 4. and 5. of the proposal to have in any case the 1. from the pros.

I’m pretty satisfied with my BaseModel already, it completely covered with unit tests which is more than enough for 1.0.0 version. It doesn’t support allOf/anyOf/oneOf keywords yet, that’s my next goal.

0reactions
ybelenkocommented, Jul 25, 2020

Closed in #5930

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property getters and setters - The Modern JavaScript Tutorial
Accessor properties are represented by “getter” and “setter” methods. ... (has get/set methods) or a data property (has a value ), not both....
Read more >
Python Property vs. Getters & Setters - DataCamp
Setters : These are the methods used in OOPS feature which helps to set the value to private attributes in a class. Private...
Read more >
Getters and Setters in Java Explained - freeCodeCamp
Getters and setters allow control over the values. You may validate the given value in the setter before actually setting the value.
Read more >
Changing the visibility of Associations does not have affect on ...
Visibility) from Public to Private does not have affect on IBM Rational ... For attributes you can specify the visibility private and the...
Read more >
Swift properties / getters setters | Apple Developer Forums
test if the passed value for lastName and/or firstName is empty or not ... a separate private stored property so the computed property's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found