Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
exit method
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tommaso Allevi  
View profile  
 More options Nov 15 2012, 10:25 am
From: Tommaso Allevi <tomall...@gmail.com>
Date: Thu, 15 Nov 2012 07:25:10 -0800 (PST)
Local: Thurs, Nov 15 2012 10:25 am
Subject: exit method

Hi!
  As developer and atk4 user, I'd like to have the possibility to handle
the exit function through an hook.
I propose use $this->api->exit() function instead exit php function.

It could be better to avoid spaghetti programmation and to able to add an
hook on exit request.

For example
function exit ($code, $type='exit') {
  $this->hook('beforeExit', $code);
  exit($code);

}

where $type indicates the kind of the end (ajax, normal execution, auth...)

What do you think about?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romans Malinovskis  
View profile  
 More options Nov 15 2012, 10:38 am
From: Romans Malinovskis <rom...@agiletoolkit.org>
Date: Thu, 15 Nov 2012 15:38:33 +0000
Local: Thurs, Nov 15 2012 10:38 am
Subject: Re: [atk4] exit method

We use destructors to execute things on exit, they work pretty good.

There are also two hooks you might want to look into:

        $this->addHook('post-render-output',array($this,'_showExecutionTime'));
        $this->addHook('post-js-execute',array($this,'_showExecutionTimeJS'));

The first is executed after all HTML is being echoed. The second done when JavaScript output is being sent through execute().

It’s uncommon to use “exit” inside the Agile Toolkit code, instead user should use use StopInit / StopRender exceptions.

romans

--
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tommaso Allevi  
View profile  
 More options Nov 15 2012, 10:56 am
From: Tommaso Allevi <tomall...@gmail.com>
Date: Thu, 15 Nov 2012 07:56:56 -0800 (PST)
Local: Thurs, Nov 15 2012 10:56 am
Subject: Re: [atk4] exit method


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Romans Malinovskis  
View profile  
 More options Nov 15 2012, 11:43 am
From: Romans Malinovskis <rom...@agiletoolkit.org>
Date: Thu, 15 Nov 2012 16:43:26 +0000
Local: Thurs, Nov 15 2012 11:43 am
Subject: Re: [atk4] exit method

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-&gt;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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »