ok, let’s look at them.
romans@miracle2 /www/agiletech.ie/txf.demo/atk4 $ find -name '*.php' | while read f; do grep -5 exit $f; done
================= version check
<?php
// This sets initial path for the include. Further includes will be initialized through PathFinder
set_include_path('.'.PATH_SEPARATOR.'.'.DIRECTORY_SEPARATOR.'lib'.PATH_SEPA RATOR.dirname(__FILE__).'/lib');
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
echo 'PHP 5.3.0 is required';
exit;
}
include 'static.php';
//include dirname(__FILE__).DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'static.php ';
?>
================= exit on ->execute();, has hook.
$x=$this->api->template->get('document_ready');
if(is_array($x))$x=join('',$x);
echo $this->_render();
$this->api->hook('post-js-execute');
exit;
}else return $this;
}
/* [private] used by custom json_encoding */
function _safe_js_string($str) {
$l=strlen($str);
============= EntityManager <- obsolete code
$g->js(null,$g->js()->univ()->successMessage('Record deleted'))->reload()->execute();
}
}
}
function page_edit(){
if(!$this->allow_edit)exit;
$this->form=$f=$this->add('MVCForm','form');
$c=$this->c;
if($_GET['id']){
if($this->edit_actual_fields)
========= Logger: outputing public error message when web/output = null
//$frame=$this->findFrame('warning',$shift);
$this->logCaughtException($e);
}
if(!$this->web_output){
echo $this->public_error_message;
exit;
}
if($_GET[$this->name.'_debug']=='rendertree'){
echo '<h2>Object Tree</h2>';
try{
$this->showRenderTree($e,$this->api);
============= Logger: caught exception
if(method_exists($e,'getMyFile'))echo '<p><font color=blue>' . $e->getMyFile() . ':' . $e->getMyLine() . '</font></p>';
if(method_exists($e,'getMyTrace'))echo $this->backtrace($e->shift,$e->getMyTrace());
else echo $this->backtrace($e->shift,$e->getTrace());
exit;
}
function print_r($key,$gs,$ge,$ls,$le,$ind=' '){
$o='';
if(strlen($ind)>3)return;
if(is_array($key)){
============ Output fatal (obsolete)
echo "Stack trace:\n";
echo $this->txtBacktrace('fatal');
}
}
exit;
}
function htmlLine($msg,$frame=array(),$prefix=null){
if(!$frame){
return "<font style='font-family: verdana; font-size:10px'><font color=blue>warning: </font> <font color=red><b>$msg</b></font></font><br>";
}else{
================ field upload: hack to talk with the parent frame after uploading
}
function uploadComplete($data=null){
echo "<html><head><script>window.top.$('#".
$_GET[$this->name.'_upload_action']."').atk4_uploader('uploadComplete',".
json_encode($data).");</script></head></html>";
exit;
}
function uploadFailed($message){
$d='';
if($this->debug)$d=','.json_encode($_FILES[$this->name]);
============= field upload: same but telling parent frame that upload failed
echo "<html><head><script>window.top.$('#".
$_GET[$this->name.'_upload_action']."').atk4_uploader('uploadFailed',".
json_encode($message).
$d.
");</script></head></html>";
exit;
}
function init(){
parent::init();
$this->owner->template->set('enctype', "enctype=\"multipart/form-data\"");
============= output file contents when you want to see file contents
if(!$_GET['view']){
header("Content-disposition: attachment; filename=\"$name\"");
}
print(file_get_contents($path));
}
exit;
$this->js()->_selector('[name='.$this->name.']')->atk4_uploader('removeFile s',array($id))->execute();
//$this->js(true,$this->js()->_selector('#'.$this->name.'_token')->val('')) ->_selectorRegion()->closest('tr')->remove()->execute();
}
}
=========== ApiWeb : when no logger is present and exception is caught.
/** This method is called when exception was caught in the application */
function caughtException($e){
$this->hook('caught-exception',array($e));
echo "<font color=red>",$e,"</font>";
echo "<p>Please use 'Logger' class for more sophisticated output<br>\$api->add('Logger');</p>";
exit;
}
/** @obsolete */
function outputWarning($msg,$shift=0){
if($this->hook('output-warning',array($msg,$shift)))return true;
======= implementaiton of $api->redirect() function
* Use this function instead of issuing header("Location") stuff
*/
$url=$this->url($page,$args);
if($this->api->isAjaxOutput())$this->api->js()->univ()->redirect($url)->exe cute();
header("Location: ".$url);
exit;
}
/** Called on all templates in the system, populates some system-wide tags */
function setTags($t){
// absolute path to base location
$t->trySet('atk_path',$q=
=========== obsolete backtrace function
// restricting output by X symbols
$x=4096; //4k
if(strlen($backtrace)>$x)$backtrace=substr($backtrace,0,$x).
"<br>... Backtrace is too long, trimmed to first $x symbols ...";
echo $backtrace;
exit;
}
};if(!function_exists('error_handler')){
function error_handler($errno, $errstr, $errfile, $errline){
$errorType = Array (
E_ERROR => "Error",
=========== ApiCli - default caughtException for command-line without logger.
}
/** Is executed if exception is raised during execution. Re-define to have custom handling of exceptions system-wide */
function caughtException($e){
$this->hook('caught-exception',array($e));
echo get_class($e),": ".$e->getMessage();
exit;
}
/** @obsolete */
function outputFatal($msg,$shift){
$this->hook('output-fatal',array($msg,$shift+1));
echo "Fatal: $msg\n";exit;
}
/** @obsolete */
function outputWarning($msg,$shift=0){
if($this->hook('output-warning',array($msg,$shift)))return true;
echo "warning: $msg\n";
======= Auth Basic this is unreachable exit, as loggedIn would call redirect().
$f=$this->form;
if($f->isSubmitted()){
if($this->verifyCredentials($f->get('username'), $f->get('password'))){
$this->login($f->get('username'));
$this->loggedIn($f->get('username'),$f->get('password'));
exit;
}
$f->getElement('password')->displayFieldError('Incorrect login information');
}
return $p;
}
====== auth basic - manual rendering of the login form
$this->api->hook('submitted');
}
$this->api->hook('post-submit');
$this->api->execute();
exit;
}
}
We have added error codes into the exception, possibly we can pass that code inside the relevant “exit” methods.
As for the redirect, it should probably add the status code too.
Thanks for tackling this problem.
> I've used those simple line commands to count how many calls of exit function there are...
> grep -ri "exit;" atk4-addons/ | wc -l
> 19
> grep -ri "exit;" atk4 | wc -l
> 18
> If i'd like adding an status code (HTTP status code) in each exit, I don't want to set the right header in a destructor. I'd like to use a hook.
> --
--
I am working with my team on a VERY URGENT project now. I apologize for the delay in answering your email(s).
Romans Malinovskis is the author of the revolutionary PHP Framework: the “Agile Toolkit” (www.agiletoolkit.org). Please show your support by raising awareness about Agile Toolkit.
Refer commercial web development projects towards our skilled developer team: http://www.agiletech.ie/company/
NEW: Get Agile Toolkit Book for your iPad: http://itunes.apple.com/us/book/web-development-agile-toolkit/id57434...
or in PDF: http://agiletoolkit.org/book.pdf