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

Should Model class implement the magic setter/getter methods for protected properties? #720

Closed
gustavojm opened this issue Sep 14, 2017 · 5 comments

Comments

@gustavojm
Copy link
Contributor

for example to get the table name from the model

$model->getTable()

without having to declare $table as public in the model.

@lonnieezell
Copy link
Member

Why do you need the table outside of the model? Isn't that the point of the model - to separate out the persistence from the rest of the app?

@gustavojm
Copy link
Contributor Author

gustavojm commented Sep 15, 2017

Yes, that's the point of the model, but...

I'm trying to achieve something like what you did in SprintPHP

https://github.com/ci-bonfire/Sprint/blob/develop/myth/_generators/Controller/ControllerGenerator.php#L280-L288

And when I say "something like" I mean "exactly that" ;-). Is it there a better way?
Thanks in advance

@lonnieezell
Copy link
Member

:) In that case, use Reflection and you can get protected/private properties.

However, you could also contribute to vulcan which is a code generation suite I've worked on a bit. it's not complete just yet, but has a pretty good start.

@lonnieezell
Copy link
Member

CI4 already has a ReflectionHelper trait that provides a couple of methods for reading/writing protected fields.

@gustavojm
Copy link
Contributor Author

Awesome thing! I didn't know about "vulcan". I'm gonna give it a look and see if I can cooperate in some way, considering that my coding skills are not that great and are definitely outdated.
Thanks!

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