public static function shutDown() { chdir(APP_PATH); $error = error_get_last(); if ($error !== null) { ini_set('memory_limit', memory_get_usage() + 16 * 1024 * 1024); //in case it was an memory limit error make sure we have enough memory for error handling $ignore = false; if (preg_match('#^include\\(\\).*Failed opening \'[^\']*cache/setup\\d+.php\' for inclusion#', $error['message'])) { //ignore error that can happen before creating setup the first time $ignore = true; } if (defined('E_STRICT') && $error["type"] == E_STRICT) { $ignore = true; } if (defined('E_DEPRECATED') && $error["type"] == E_DEPRECATED) { $ignore = true; } if (!$ignore) { $e = new ErrorException($error["message"], 0, $error["type"], $error["file"], $error["line"]); Kwf_Debug::handleException($e); } } Kwf_Benchmark::shutDown(); }
public function testChildPage1() { $root = Kwf_Component_Data_Root::getInstance(); $c = $root->getComponentById('root-en'); Kwf_Debug::enable(); $c = $c->getChildComponent('_1'); $this->assertEquals('root-en_1', $c->componentId); }
protected function _renderHtml($exception, $msg) { if ($this->getComponentClass() && Kwf_Component_Data_Root::getComponentClass() && isset($_SERVER['REQUEST_URI']) && isset($_SERVER['HTTP_HOST'])) { $uri = $_SERVER['REQUEST_URI']; $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; $data = null; while (!$data && $uri) { $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . $uri, $acceptLanguage); $uri = substr($uri, 0, strrpos($uri, '/')); } if (!$data) { $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . '/', $acceptLanguage); } if (!$data) { $data = Kwf_Component_Data_Root::getInstance(); } $notFound = Kwf_Component_Data_Root::getInstance()->getComponentByClass($this->getComponentClass(), array('limit' => 1, 'subroot' => $data)); if ($notFound) { return str_replace('{logId}', $this->_logId, $notFound->render(null, true)); } } class_exists('Kwf_Trl'); //eventually trigger autoloader $view = Kwf_Debug::getView(); $view->exception = $msg; $view->message = $exception->getMessage(); $view->requestUri = isset($_SERVER['REQUEST_URI']) ? htmlspecialchars($_SERVER['REQUEST_URI']) : ''; $view->debug = Kwf_Exception::isDebug(); try { if (Kwf_Registry::get('userModel') && Kwf_Registry::get('userModel')->getAuthedUserRole() == 'admin') { $view->debug = true; } } catch (Exception $e) { } if (Kwf_Component_Data_Root::getComponentClass()) { $data = null; if (isset($_SERVER['HTTP_HOST'])) { //try to get the page of current domain to get correct language $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; try { $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . '/', $acceptLanguage); } catch (Exception $e) { } } if (!$data) { $data = Kwf_Component_Data_Root::getInstance(); } $view->data = $data; //can be used for trl } else { //no components used, use Kwf_Trl object that also has trl() methods //HACK, but will work if only trl is used in template $view->data = Kwf_Trl::getInstance(); } $template = $this->getTemplate(); $template = strtolower(Zend_Filter::filterStatic($template, 'Word_CamelCaseToDash') . '.tpl'); return $view->render($template); }
private function _processException($exception) { if (!$exception instanceof Kwf_Exception_Abstract) { $exception = new Kwf_Exception_Other($exception); } $view = new Kwf_Exception_TestView(); Kwf_Debug::setView($view); $exception->render(true); return $view; }
public function testPages() { $c = $this->_root->getChildComponent('-1')->getChildComponents(); $this->assertEquals(count($c), 1); $c = $this->_root->getChildComponent('-1')->getChildComponents(array('filename' => 'bar')); $this->assertEquals(count($c), 1); $c = $this->_root->getChildComponent('-1'); Kwf_Debug::enable(); $c = $c->getChildComponents(array('filename' => 'bar')); $this->assertEquals(count($c), 1); $this->assertEquals(current($c)->componentId, 'root-1_1'); $c = $this->_root->getRecursiveChildComponents(array('filename' => 'bar')); $this->assertEquals(count($c), 1); $this->assertEquals(current($c)->componentId, 'root-1_1'); }
public function render($ignoreCli = false) { try { if (isset($_SERVER['REQUEST_URI']) && Kwf_Setup::hasDb() && Kwf_Registry::get('dao')->getDbConfig()) { $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; $target = Kwf_Model_Abstract::getInstance('Kwf_Util_Model_Redirects')->findRedirectUrl('path', $_SERVER['REQUEST_URI'], $host); if ($target) { header('Location: ' . $target, true, 301); exit; } } } catch (Exception $e) { Kwf_Debug::handleException($e); } parent::render($ignoreCli); }
public static function fireEvent($event) { $logger = Kwf_Events_Log::getInstance(); if ($logger && $logger->indent == 0) { $logger->info('----'); $logger->resetTimer(); } $class = $event->class; $eventClass = get_class($event); $cacheId = '-ev-lst-' . Kwf_Component_Data_Root::getComponentClass() . '-' . $eventClass . '-' . $class; $callbacks = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($callbacks === false) { $listeners = self::getAllListeners(); $callbacks = array(); if ($class && isset($listeners[$eventClass][$class])) { $callbacks = $listeners[$eventClass][$class]; } if (isset($listeners[$eventClass]['all'])) { $callbacks = array_merge($callbacks, $listeners[$eventClass]['all']); } Kwf_Cache_SimpleStatic::add($cacheId, $callbacks); } if ($logger) { $logger->info($event->__toString() . ':'); $logger->indent++; } static $callbackBenchmark = array(); foreach ($callbacks as $callback) { $ev = call_user_func(array($callback['class'], 'getInstance'), $callback['class'], $callback['config']); if ($logger) { $msg = '-> ' . $callback['class'] . '::' . $callback['method'] . '(' . Kwf_Debug::_btArgsString($callback['config']) . ')'; $logger->info($msg . ':'); $start = microtime(true); } $ev->{$callback['method']}($event); if ($logger) { if (!isset($callbackBenchmark[$callback['class'] . '::' . $callback['method']])) { $callbackBenchmark[$callback['class'] . '::' . $callback['method']] = array('calls' => 0, 'time' => 0); } $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['calls']++; $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['time'] += (microtime(true) - $start) * 1000; //ATM includes everything which is missleading } } if ($logger) { $logger->indent--; if ($logger->indent == 0) { foreach ($callbackBenchmark as $cb => $i) { $logger->info(sprintf("% 3d", $i['calls']) . "x " . sprintf("%3d", round($i['time'], 0)) . " ms: {$cb}"); } $callbackBenchmark = array(); } } self::$eventsCount++; }
public static function bt($file = false) { if (!Kwf_Debug::isEnabled()) { return; } if (php_sapi_name() == 'cli' || $file) { $ret = self::btString(); if ($file) { $ret = str_repeat("=", 45) . "\n" . php_sapi_name() . ' ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "\n" . $ret; file_put_contents('backtrace', $ret, FILE_APPEND); } else { echo $ret; } } else { $bt = debug_backtrace(); unset($bt[0]); $out = array(array('File', 'Line', 'Function', 'Args')); foreach ($bt as $i) { $out[] = array(isset($i['file']) ? $i['file'] : '', isset($i['line']) ? $i['line'] : '', isset($i['function']) ? $i['function'] : null, self::_btArgsString($i['args'])); } p(array('Backtrace for ' . self::_btString($bt[1]), $out), 'TABLE'); } }
private static function _countArray(&$counter, $name, $value, $backtrace = false) { if (!isset($counter[$name])) { if (!is_null($value)) { $counter[$name] = array(); } else { $counter[$name] = 0; } } if (!is_null($value)) { if (!is_array($counter[$name])) { throw new Kwf_Exception("Missing value for counter '{$name}'"); } $bt = false; if ($backtrace) { $b = debug_backtrace(); unset($b[0]); unset($b[1]); $bt = ''; foreach ($b as $i) { $bt .= (isset($i['file']) ? $i['file'] : 'Unknown file') . ':' . (isset($i['line']) ? $i['line'] : '?') . ' - ' . (isset($i['object']) && $i['object'] instanceof Kwf_Component_Data ? $i['object']->componentId . '->' : '') . (isset($i['function']) ? $i['function'] : '') . '(' . Kwf_Debug::_btArgsString($i['args']) . ')' . "<br />"; } } $counter[$name][] = array('value' => $value, 'bt' => $bt); } else { if (is_array($counter[$name])) { throw new Kwf_Exception("no value possible for counter '{$name}'"); } $counter[$name]++; } }
public function render($ignoreCli = false) { try { $exception = $this->getException(); $msg = $exception->__toString(); if ($exception instanceof Zend_Db_Adapter_Exception) { try { foreach (Kwf_Registry::get('config')->database as $db) { $msg = str_replace($db->password, 'xxxxxx', $msg); } } catch (Exception $e) { } } if (!$ignoreCli && PHP_SAPI == 'cli') { $this->log(); file_put_contents('php://stderr', $msg . "\n"); exit(1); } class_exists('Kwf_Trl'); //eventually trigger autoloader $view = Kwf_Debug::getView(); $view->exception = $msg; $view->message = $exception->getMessage(); $view->requestUri = isset($_SERVER['REQUEST_URI']) ? htmlspecialchars($_SERVER['REQUEST_URI']) : ''; $view->debug = Kwf_Exception::isDebug() || !Kwf_Registry::get('config')->setupFinished; try { if (Kwf_Registry::get('userModel') && Kwf_Registry::get('userModel')->getAuthedUserRole() == 'admin') { $view->debug = true; } } catch (Exception $e) { } if (Kwf_Component_Data_Root::getComponentClass()) { $data = null; if (isset($_SERVER['HTTP_HOST'])) { //try to get the page of current domain to get correct language $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; try { $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl('http://' . $_SERVER['HTTP_HOST'] . '/', $acceptLanguage); } catch (Exception $e) { } } if (!$data) { $data = Kwf_Component_Data_Root::getInstance(); } $view->data = $data; //can be used for trl } else { //no components used, use Kwf_Trl object that also has trl() methods //HACK, but will work if only trl is used in template $view->data = Kwf_Trl::getInstance(); } $header = $this->getHeader(); $template = $this->getTemplate(); $template = strtolower(Zend_Filter::filterStatic($template, 'Word_CamelCaseToDash') . '.tpl'); $this->log(); if (!headers_sent()) { header($header); header('Content-Type: text/html; charset=utf-8'); } echo $view->render($template); } catch (Exception $e) { echo '<pre>'; echo $this->getException()->__toString(); echo "\n\n\nError happened while handling exception:"; echo $e->__toString(); echo '</pre>'; } }
public function toDebug() { $out = ''; foreach ($this->_parts as $type => $p) { if (is_array($p)) { $out .= "\n"; $out .= "{$type} => array(\n"; foreach ($p as $k => $i) { $out .= ' '; if ($i instanceof Kwf_Model_Select_Expr_Interface) { if (!is_int($k)) { $out .= $k . ' => '; } $out .= _pArray($i, ' '); } else { $out .= $k . ' => ' . Kwf_Debug::_btArgString($i); } $out .= ",\n"; } $out .= "),\n"; } else { $out .= "\n"; $out .= "{$type} => " . Kwf_Debug::_btArgString($p) . ", "; } } $out = trim($out, ', '); $ret = '<pre>' . get_class($this) . '(' . $out . "\n)</pre>"; return $ret; }
public function testNewlineInIndex() { $fnf = new Kwf_Model_Proxycache_TestFnF(array('uniqueIdentifier' => 'unique')); $fnf->setData(array(array('id' => 1, 'en' => "foo\nbar", 'de' => "foo\\nbar"))); $proxy = new Kwf_Model_ProxyCache(array('proxyModel' => $fnf, 'cacheSettings' => array(array('index' => array('en'), 'columns' => array()), array('index' => array('de'), 'columns' => array())))); Kwf_Debug::enable(); $proxy->clearCache(); $row = $proxy->getRow($proxy->select()->whereEquals('en', "foo\nbar")); $this->assertEquals(1, $fnf->getRowsCalled); $row = $proxy->getRow($proxy->select()->whereEquals('en', "foo\nbar")); $this->assertEquals(1, $row->id); $this->assertEquals(1, $fnf->getRowsCalled); $row = $proxy->getRow($proxy->select()->whereEquals('de', "foo\\nbar")); $this->assertEquals(2, $fnf->getRowsCalled); $row = $proxy->getRow($proxy->select()->whereEquals('de', "foo\\nbar")); $this->assertEquals(1, $row->id); $this->assertEquals(2, $fnf->getRowsCalled); }
public function indexAction() { self::initForTests(); if (!Kwf_Registry::get('config')->server->domain) { throw new Kwf_Exception_Client("Can't run tests; server.domain is not set. Please set in tests/config.local.ini"); } $arguments = array(); $arguments['colors'] = true; $arguments['filter'] = false; if ($this->_getParam('filter')) { $arguments['filter'] = $this->_getParam('filter'); } $arguments['groups'] = array(); if ($this->_getParam('group')) { $arguments['groups'] = explode(',', $this->_getParam('group')); } $arguments['excludeGroups'] = array(); if ($this->_getParam('exclude-group')) { $arguments['excludeGroups'] = explode(',', $this->_getParam('exclude-group')); } $arguments['verbose'] = false; if ($this->_getParam('verbose')) { $arguments['verbose'] = $this->_getParam('verbose'); } if ($this->_getParam('stop-on-failure')) { $arguments['stopOnFailure'] = $this->_getParam('stop-on-failure'); } if ($this->_getParam('log-xml')) { $arguments['xmlLogfile'] = $this->_getParam('log-xml'); } if ($this->_getParam('log-pmd')) { $arguments['pmdXML'] = $this->_getParam('log-pmd'); } if ($this->_getParam('log-metrics')) { $arguments['metricsXML'] = $this->_getParam('log-metrics'); } if ($this->_getParam('coverage-xml')) { $arguments['coverageClover'] = $this->_getParam('coverage-xml'); } if ($this->_getParam('retry-on-error')) { $arguments['retryOnError'] = $this->_getParam('retry-on-error'); } if ($this->_getParam('coverage')) { if (!extension_loaded('tokenizer') || !extension_loaded('xdebug')) { throw new Kwf_ClientException('tokenizer and xdebug extensions must be loaded'); } if (!is_string($this->_getParam('coverage'))) { $arguments['reportDirectory'] = './report'; } else { $arguments['reportDirectory'] = $this->_getParam('coverage'); } } Kwf_Registry::set('testDomain', Kwf_Registry::get('config')->server->domain); Kwf_Registry::set('testServerConfig', Kwf_Registry::get('config')); if ($this->_getParam('report')) { $resultLogger = new Kwf_Test_ResultLogger(true); $arguments['listeners'][] = $resultLogger; } if ($this->_getParam('testdox')) { $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text(); $arguments['noProgress'] = true; } else { if ($this->_getParam('no-progress')) { $arguments['noProgress'] = true; } } if ($this->_getParam('disable-debug')) { Kwf_Debug::disable(); } //nur temporär deaktiviert, damit ich selenium-verbindungs-probleme besser debuggen kann // PHPUnit_Util_Filter::setFilter(false); $runner = new Kwf_Test_TestRunner(); $suite = new Kwf_Test_TestSuite(); Kwf_Model_Abstract::clearInstances(); $result = $runner->doRun($suite, $arguments); if ($this->_getParam('report')) { $resultLogger->printResult($result); $reportData = array('tests' => $result->count(), 'failures' => $result->failureCount() + $result->errorCount(), 'skipped' => $result->skippedCount(), 'not_implemented' => $result->notImplementedCount(), 'kwf_version' => Kwf_Util_Git::kwf()->getActiveBranch() . ' (' . Kwf_Util_Git::kwf()->revParse('HEAD') . ')'); if (Kwf_Registry::get('config')->application->id != 'kwf') { $reportData['web_version'] = Kwf_Util_Git::web()->getActiveBranch() . ' (' . Kwf_Util_Git::web()->revParse('HEAD') . ')'; } echo "===REPORT==="; echo serialize($reportData); echo "===/REPORT==="; } Kwf_Benchmark::shutDown(); if ($result->wasSuccessful()) { exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); } else { if ($result->errorCount() > 0) { exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } else { exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } } $this->_helper->viewRenderer->setNoRender(true); }