Description

Add the possibility of including functions and native javascripts expressions to be encoded by Zend_Json, generating right syntax in the outputted json. The main idea is follow the Zend_Db_Expr pattern, so to include a Javascript Expression to be encoded in an object/array, will be enough to uses something similar to Zend_Json_Expr('javascript expression').

Comments

Posted by Benjamin Eberlei (beberlei) on 2009-03-20T07:51:21.000+0000

Moved from incubator to trunk in r14399, scheduled for 1.8 release

Posted by Oscar Reales (oreales) on 2009-03-20T10:17:33.000+0000

Benjamin, checking the actual implementation of this, I find the next problem:

Using Zend_Action_Helper_Json, or Zend_View_Helper_Json it is not possible to pass the $options['enableJsonExprFinder'=>true] up to Zend_Json::encode method, making this Helpers unuseful if you want to encode expressions. I mean, I am using the Zend_Action_Helper_Json::sendJson method because it is quite direct way of sending Json as response to an Ajax frontend. This Helpers chain the next actions until arrives to Zend_Json:

1.- Zend_Action_Helper_Json::sendJson($data, $keeplayouts) this calls to ->
2.- Zend_Action_Helper_Json::encodeJson($data, $keepLayouts) this calls to ->
3.- Zend_View_Helper_Json::json($data, $keepLayouts) this->calls to ->
4.- Zend_Json::encode($data) without other params as cycleCheck and options for encode method.

It would be useful to allow enabling Json Expr Finder from Helpers. I find 2 ways of doing this:

1.- Including an optional 3rd param in the Helpers: Zend_Action_Helper_Json::sendJson($data, $keepLayouts, $optionsForEncodeMethod) and the same in Zend_View_Helper_Json, so Zend_Json::encode can receive it. This will suppose to change a few methods and classes

2.- Doing enableJsonExprFinder a static prop in Zend_Json, so before using Helpers, if you want to enable Expr Finder, can include Zend_Json::enableExprFinder = true

Let's go with option one. I'd change this slightly, however, and overload the second parameter to the helper. If a boolean, then it sets the keepLayouts flag; if an array, then it uses that array to set options (and allows passing the keepLayouts option via that array).

Posted by Oscar Reales (oreales) on 2009-03-26T04:27:31.000+0000

Time Worked: 1 hour

Recode of Zend_Controller_Action_Helper_Json and Zend_View_Helper_Json to allow pass options up to Zend_Json::encode (as enableJsonExprFinder=>true) is done.

I have tried to do a Test of it, but including Zend_View_Helper_Json "breaks" my unitTesting, so I couldn´t do it.