UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

110 lines (100 loc) 2.97 kB
--- layout: page title: "JavaScript ob_get_status function" comments: true sharing: true footer: true alias: - /functions/view/ob_get_status:899 - /functions/view/ob_get_status - /functions/view/899 - /functions/ob_get_status:899 - /functions/899 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's ob_get_status {% codeblock outcontrol/ob_get_status.js lang:js https://raw.github.com/kvz/phpjs/master/functions/outcontrol/ob_get_status.js raw on github %} function ob_get_status (full_status) { // http://kevin.vanzonneveld.net // + original by: Brett Zamir (http://brett-zamir.me) // * example 1: ob_get_status(true); // * returns 1: [{chunk_size:4096, name:myCallback, del:true, type:1,status:0}] var i = 0, retObj = {}, ob = {}, retArr = [], name = ''; var getFuncName = function (fn) { var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn); if (!name) { return '(Anonymous)'; } return name[1]; }; this.php_js = this.php_js || {}; var phpjs = this.php_js, ini = phpjs.ini, obs = phpjs.obs; if (!obs || !obs.length) { if (ini && ini.output_buffering && (typeof ini.output_buffering.local_value !== 'string' || ini.output_buffering.local_value.toLowerCase() !== 'off')) { // handler itself is stored in 'output_handler' ini retObj = { type: 1, status: 0, name: 'default output handler', del: true }; if (full_status) { retObj.chunk_size = 4096; return [retObj]; } else { retObj.level = 1; return retObj; } } return retArr; } if (full_status) { for (i = 0; i < obs.length; i++) { ob = obs[i]; name = ob.callback && getFuncName(ob.callback) ? (getFuncName(ob.callback) === 'URLRewriter' ? 'URL-Rewriter' : getFuncName(ob.callback)) : undefined; retObj = { chunk_size: ob.chunk_size, name: name, del: ob.erase, type: ob.type, status: ob.status }; if (ob.size) { retObj.size = ob.size; } if (ob.block_size) { retObj.block_size = ob.block_size; } retArr.push(retObj); } return retArr; } ob = obs[phpjs.obs.length - 1]; name = getFuncName(ob.callback); return { level: phpjs.obs.length, name: name, del: ob.erase, type: ob.type, status: ob.status }; } {% endcodeblock %} - [view on github](https://github.com/kvz/phpjs/blob/master/functions/outcontrol/ob_get_status.js) - [edit on github](https://github.com/kvz/phpjs/edit/master/functions/outcontrol/ob_get_status.js) ### Example 1 This code {% codeblock lang:js example %} ob_get_status(true); {% endcodeblock %} Should return {% codeblock lang:js returns %} [{chunk_size:4096, name:myCallback, del:true, type:1,status:0}] {% endcodeblock %} ### Other PHP functions in the outcontrol extension {% render_partial _includes/custom/outcontrol.html %}