Source

Apmgr / library / ZFHistory / Plugin / History.php

<?php
/**
 * Keep a record of the visitor's steps on our application
 * Push elements into the session stack and pop them out when we hit back
 */

class ZFHistory_Plugin_History extends Zend_Controller_Plugin_Abstract {

    /**
     * (non-PHPdoc)
     * @see library/Zend/Controller/Plugin/Zend_Controller_Plugin_Abstract#preDispatch($request)
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        $trace = new Zend_Session_Namespace('wulfStorageTrace');
        $url = Zend_Controller_Front :: getInstance()->getBaseUrl() ? Zend_Controller_Front :: getInstance()->getBaseUrl() : "/";

        //Yield the url
        //TODO can't work well with exceptions
        foreach( $request->getUserParams() as $id=>$x ) {
            $url .=$x.DIRECTORY_SEPARATOR;
        }


        if( isset($trace->history) ) {
            $found = false;
            //	If we find it, then do not add it into the stack
            foreach($trace->history as $key=>$value) {
                if($value==$url) {
                    $found = true;
                    break;
                }
            }
            if($found==false) {
                $trace->history[] = $url;
            }
        } else {
            $trace->history = array();
            foreach( $request->getUserParams() as $id=>$x ) {
                $url .=$x.DIRECTORY_SEPARATOR;
            }
            $trace->history[] = $url;
        }
    }
}