From: <pan...@us...> - 2008-12-06 23:14:25
|
Revision: 436 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=436&view=rev Author: panzaboi Date: 2008-12-06 23:14:20 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Removed unneeded files; added firebug profiler; Added Paths: ----------- website/library/Ostacium/Db/Profiler/ website/library/Ostacium/Db/Profiler/Firebug.php website/library/Ostacium/View/Helper/Measure.php Removed Paths: ------------- website/library/Ostacium/Controller/Plugin/Router.php website/library/Ostacium/Form/Element/ Deleted: website/library/Ostacium/Controller/Plugin/Router.php =================================================================== --- website/library/Ostacium/Controller/Plugin/Router.php 2008-12-06 23:13:21 UTC (rev 435) +++ website/library/Ostacium/Controller/Plugin/Router.php 2008-12-06 23:14:20 UTC (rev 436) @@ -1,83 +0,0 @@ -<?php - -class Ostacium_Controller_Plugin_Router_Exception extends Zend_Controller_Exception {} - -class Ostacium_Controller_Plugin_Router extends Zend_Controller_Plugin_Abstract -{ - private $_acl; - private $_noauth = array( /*'module' => 'default',*/ - 'controller' => 'index', - 'action' => 'index' ); - - private $_noacl = array( 'module' => 'default', - 'controller' => 'error', - 'action' => 'error' ); - - public function __construct($acl, $noauth = null, $noacl = null) { - $this->_acl = $acl; - $this->_noauth = is_array($noauth) ? $noauth : $this->_noauth; - $this->_noacl = is_array($noacl) ? $noacl : $this->_noacl; - } - - public function preDispatch(Zend_Controller_Request_Abstract $request) { - $auth = Zend_Auth::getInstance(); - $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher(); - - if ($auth->hasIdentity()) { - $role = $this->_acl->getRoleById($auth->getIdentity()->roleid) ? $this->_acl->getRoleById($auth->getIdentity()->roleid) : 'guest'; - } else { - $role = 'guest'; - } - - $controller = $request->getControllerName(); - $action = $request->getActionName(); - $module = $request->getModuleName(); - $resource = ($module != 'default' ? $module . ':' . $controller : $controller); - - if (!$this->_acl->has($resource) || !$dispatcher->isDispatchable($request) || !$this->isProperAction($dispatcher, $request)) - { - $e = new Zend_Controller_Dispatcher_Exception("Resource doesn't exist", 404); - - $response = $this->getResponse(); - $response->setException($e); - } - elseif (!$this->_acl->isAllowed($role, $resource, $action)) { - if (!$auth->hasIdentity()) { - //$module = $this->_noauth['module']; - $controller = $this->_noauth['controller']; - $action = $this->_noauth['action']; - - $request->setParam('error_message', 'nologin'); - } else { - $module = $this->_noacl['module']; - $controller = $this->_noacl['controller']; - $action = $this->_noacl['action']; - - $request->setParam('error_message', 'noallowed'); - } - } - - $request->setModuleName($module); - $request->setControllerName($controller); - $request->setActionName($action); - } - - public function isProperAction($dispatcher, $request) - { - $className = $dispatcher->loadClass($dispatcher->getControllerClass($request)); - $actionName = $request->getActionName(); - - if (empty($actionName)) { - $actionName = $dispatcher->getDefaultAction(); - } - - $methodName = $dispatcher->formatActionName($actionName); - $class = new ReflectionClass($className); - - if ($class->hasMethod($methodName)) { - return true; - } - - return false; - } -} \ No newline at end of file Property changes on: website/library/Ostacium/Db/Profiler ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/library/Ostacium/Db/Profiler/Firebug.php =================================================================== --- website/library/Ostacium/Db/Profiler/Firebug.php (rev 0) +++ website/library/Ostacium/Db/Profiler/Firebug.php 2008-12-06 23:14:20 UTC (rev 436) @@ -0,0 +1,63 @@ +<?php + +class Ostacium_Db_Profiler_Firebug extends Zend_Db_Profiler_Firebug +{ + /** + * The longest query + * @var Zend_Db_Profiler_Query + */ + protected $_longestQuery = null; + + /** + * Constructor + * + * @param string $label OPTIONAL Label for the profiling info. + * @return void + */ + public function __construct($label = null) + { + $this->_label = $label; + if(!$this->_label) { + $this->_label = 'Ostacium_Db_Profiler_Firebug'; + } + } + + public function setLabel($label) + { + $this->_label = $label; + } + + /** + * Intercept the query end and find out longest query + * + * @param integer $queryId + * @throws Zend_Db_Profiler_Exception + * @return void + */ + public function queryEnd($queryId) + { + parent::queryEnd($queryId); + + $profile = $this->getQueryProfile($queryId); + + if ($this->_longestQuery == null || $profile->getElapsedSecs() > $this->_longestQuery->getElapsedSecs()) + { + $this->_longestQuery = $profile; + $this->updateMessageLabel(); + } + } + + /** + * Update the label of the message holding the profile info. + * + * @return void + */ + protected function updateMessageLabel() + { + if (!$this->_message) { + return; + } + + $this->_message->setLabel($this->_label . ' (' . round($this->_totalElapsedTime,5) . ' sec)' . ($this->_longestQuery ? '[Longest('.round($this->_longestQuery->getElapsedSecs(), 5).' sec): ' . $this->_longestQuery->getQuery() . ']' : '')); + } +} \ No newline at end of file Added: website/library/Ostacium/View/Helper/Measure.php =================================================================== --- website/library/Ostacium/View/Helper/Measure.php (rev 0) +++ website/library/Ostacium/View/Helper/Measure.php 2008-12-06 23:14:20 UTC (rev 436) @@ -0,0 +1,22 @@ +<?php + +class Ostacium_View_Helper_Measure extends Zend_View_Helper_Abstract +{ + public function measure($measure, $amount, $type = null, $convert = null, $round = 2, $locale = null) + { + try + { + $measure = 'Zend_Measure_'.$measure; + $m = new $measure($amount, $type, $locale); + + if ($convert) + $m->setType($convert, 2); + + return $m->toString($round); + } + catch (Exception $e) + { + return false; + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |