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

Improved template variable handling #20

Merged
merged 1 commit into from
Jun 30, 2014
Merged

Improved template variable handling #20

merged 1 commit into from
Jun 30, 2014

Conversation

anlutro
Copy link
Contributor

@anlutro anlutro commented Jun 29, 2014

PHP magic methods can be used to imitate getting/setting of public variables on objects. This gets rid of the ugly $internal property, which means $template->internal is no longer a reserved variable name, and the Template code is a lot clearer.

PHP magic methods can be used to imitate getting/setting of public variables
on objects. This gets rid of the ugly $internal property.

- Allows $template->internal = 'foo'
- Better code clarity
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.55%) when pulling 9a4656f on alprs:fix/variables into 8733232 on thephpleague:master.

@anlutro
Copy link
Contributor Author

anlutro commented Jun 29, 2014

Also, unless I'm missing something, this should make #9 trivial.

extract($this->variables, EXTR_REFS);
// render template
foreach (array_keys($this->variables) as $key) unset($key);

The unset bit is probably not even necessary.

@reinink
Copy link
Contributor

reinink commented Jun 30, 2014

At first glance this looks good. Unfortunately it doesn't help with issue #9—the challenge there isn't extracting the variable available before you render, but rather those created while rendering.

Nonetheless, this looks like an improvement. I'm going to have a closer look, and unless I find any issues I'll pull it in. Thanks for your interest and help on this project!

@anlutro
Copy link
Contributor Author

anlutro commented Jun 30, 2014

You mean in terms of <?php $this->title = 'foo'; ?> being available as $title?

@reinink
Copy link
Contributor

reinink commented Jun 30, 2014

Exactly, and those variables created while using sections.

@reinink
Copy link
Contributor

reinink commented Jun 30, 2014

@anlutro You have me thinking about this now. Some things have changed with Plates over the last year, and handling variables that way may actually now be possible.

Edit: I'm going to continue this discussion in #21.

reinink added a commit that referenced this pull request Jun 30, 2014
Improved template variable handling
@reinink reinink merged commit df82e89 into thephpleague:master Jun 30, 2014
@anlutro
Copy link
Contributor Author

anlutro commented Jun 30, 2014

I don't know why this didn't cross my mind until now, but because the include is being called inside a class method, the protected variables are still available as $this->engine etc. in the template file - which kinda makes this change more pointless than I assumed :(

@reinink
Copy link
Contributor

reinink commented Jun 30, 2014

Haha, yeah, I was going to say that earlier, but you actually led me to removing the need for $this before all template variables (see #21), so while this change isn't going to help Plates 2.x, it was the first step towards Plates 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants