-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add template logic for nested data #30
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* Used in place of ArrayList when preparing nested arrays for export for SS templates. | ||
* | ||
* var_export calls '__set_state' on classes, so it produces code like: | ||
* | ||
* ArrayList::__set_state(array('items' => [...])) | ||
* | ||
* And because ArrayList doens't implement '__set_state', executing the code throws errors. | ||
* So we work around this by using an ArrayListExportable to produce: | ||
* | ||
* ArrayListExportable::__set_state(array('items' => [...])) | ||
* | ||
* And implement '__set_state' to return a constructed ArrayList. | ||
*/ | ||
class ArrayListExportable | ||
{ | ||
public function __construct($array = array()) | ||
{ | ||
// need to store items for var_export to recurse | ||
$this->items = $array; | ||
} | ||
|
||
public static function __set_state ($array) | ||
{ | ||
// when executed, we naruto-style body-replace with in an ArrayList | ||
return new ArrayList($array['items']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% if $NestedData %> | ||
<% loop $NestedData %> | ||
<h2>$Title</h2> | ||
<% if $Children %> | ||
<ul> | ||
<% loop $Children %> | ||
<li> | ||
<h3>$Title</h3> | ||
<% if $Children %> | ||
<ul> | ||
<% loop $Children %> | ||
<li> | ||
<h4>$Title</h4> | ||
</li> | ||
<% end_loop %> | ||
</ul> | ||
<% end_if %> | ||
</li> | ||
<% end_loop %> | ||
</ul> | ||
<% end_if %> | ||
<% end_loop %> | ||
<% end_if %> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason this is static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be a method, but as a static function it's clear that it doesn't interact with
$this
at all, it takes nestsed data, recurses it, and spits back the output. Whilst I think this is technically better/clearer, I'm happy to change it if you prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, while I don't disagree, if we're going to make it static I would lean towards making it public so it can be accessed from outside the service class. But for consistency purposes, it should probably stay public and non-static. Happy to leave this one to your judgement, just let me know what you decide on :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My vote is:
$this
which is context I would find useful when navigating unfamiliar code, etc.But I'm the noob here, so happy to be overridden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed IRL, I can always see someone trying to access a private function, no matter how niche it is :) But I agree, private and static makes the most sense!