ZF-4946: Refactor Zend_Json to add expression support

Issue Type: New Feature Created: 2008-11-14T02:50:33.000+0000 Last Updated: 2009-03-26T04:27:38.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Oscar Reales (oreales) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Json

Related issues: - ZF-4588



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').


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

What do you think?

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-20T10:42:41.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.