ez projects / ezjscore / forum / general / feat. request: improving th...
You need to be logged in to post messages in the forums. New users may register here.
|
Member since: Posts: 265 |
Thursday 05 November 2009 7:45:25 pm the current template operators used for ecoding are a bit too opaque imho:
json_encode => works on arrays, but probably unexpected results on template objects xml_encode => same as above node_encode => too hardcoded in php plus they seem not to take their params via the pipe, which is imho the best thing about template operators, $value | transform ( $trandformationdetails ) being the guiding pattern having played around extensively with transforming objects to json/xml (see the ggxmlview extension), I think we can come up with something more useful, general and simple at the same time: $value | obj_encode( $style='json', $depth=1, $attributes_filter=array() ) - $style mandates the type of output - the recursive descent is done the same way that the 'attribute' operator does: iterating over $value's attribute() methods, ie. it does not iterate over the object as it is seen from php but it iterates over the object as it is seen from template code - $depth works as limiter, the same way that the 'attribute' operator does - the 'attributes' array allows the user to cherry pick the attributes he wants to have in the output. If not specified, all attributes are shown, otherwise only the attributes whose name appears in the list - if $value is an array or a scalar value, the encoding is done properly, unlike the current 'attribute' template operator With this simple operator we can - encode all template objects we want, not just nodes, not just objects - allow encodings that only show a bit of data and not all of it - allow js objects to be built at 0 cost that are specular images of template objects, which is excellent for developers (no new api to be learned) - ... - profit! Principal Consultant International Business |
|
|
Member since: Posts: 265 |
Saturday 20 March 2010 1:03:39 am At long last, the 'generic encodder for template obejcts' has landed, as part of the ggxmlview extension. All hail the "to_array" operator!
http://projects.ez.no/ggxmlview/news/ggxmlview_0_2_released It merely turns template objects to arrays, which can then be encoded via json_encode / xml_encode. Principal Consultant International Business |
You need to be logged in to post messages in the forums. New users may register here.