/** * Customized constructor * @param $mixed */ public function __construct($mixed) { $args = func_get_args(); if (AppKitStringUtil::detectFormatSyntax($mixed)) { $format = array_shift($args); parent::__construct(vsprintf($format, $args)); } else { call_user_func_array(array($this, 'Exception::__construct'), array($mixed, $this->getCode())); } }
/** * @dataProvider highlightSnippets */ public function testFoo($code) { $highlighted = AgaviException::highlightString($code); $highlighted = "<ol>\n<li><code>" . implode("</code></li>\n<li><code>", $highlighted) . "</code></li>\n</ol>"; $doc = new DOMDocument(); $luie = libxml_use_internal_errors(true); $doc->loadXML($highlighted); $errors = libxml_get_errors(); libxml_use_internal_errors($luie); $this->assertEquals(0, count($errors)); }
$lines = explode("\n", trim($e->getMessage())); foreach ($lines as $line) { ?> <?php echo $cols ? wordwrap($line, $cols - 2, "\n ", true) : $line; ?> <?php } ?> Stack Trace ----------- <?php $i = 0; $traceLines = AgaviException::getFixedTrace($e, isset($exceptions[$ei + 1]) ? $exceptions[$ei + 1] : null); $traceCount = count($traceLines); foreach ($traceLines as $trace) { $i++; echo sprintf(" %" . strlen($traceCount) . "s: ", $i); if (isset($trace['file'])) { $msg = $trace['file'] . (isset($trace['line']) ? ':' . $trace['line'] : ''); echo $cols ? wordwrap($msg, $cols - 4 - strlen($traceCount), "\n" . str_repeat(' ', 4 + strlen($traceCount)), true) : $msg; } else { echo "Unknown file"; } echo "\n"; } } ?>
/** * Startup the Agavi core * * @param string environment the environment to use for this session. * * @author David Zülke <*****@*****.**> * @since 0.11.0 */ public static function bootstrap($environment = null) { // set up our __autoload spl_autoload_register(array('AgaviAutoloader', 'loadClass')); try { if ($environment === null) { // no env given? let's read one from core.environment $environment = AgaviConfig::get('core.environment'); } elseif (AgaviConfig::has('core.environment') && AgaviConfig::isReadonly('core.environment')) { // env given, but core.environment is read-only? then we must use that instead and ignore the given setting $environment = AgaviConfig::get('core.environment'); } if ($environment === null) { // still no env? oh man... throw new AgaviException('You must supply an environment name to Agavi::bootstrap() or set the name of the default environment to be used in the configuration directive "core.environment".'); } // finally set the env to what we're really using now. AgaviConfig::set('core.environment', $environment, true, true); AgaviConfig::set('core.debug', false, false); if (!AgaviConfig::has('core.app_dir')) { throw new AgaviException('Configuration directive "core.app_dir" not defined, terminating...'); } // define a few filesystem paths AgaviConfig::set('core.cache_dir', AgaviConfig::get('core.app_dir') . '/cache', false, true); AgaviConfig::set('core.config_dir', AgaviConfig::get('core.app_dir') . '/config', false, true); AgaviConfig::set('core.system_config_dir', AgaviConfig::get('core.agavi_dir') . '/config/defaults', false, true); AgaviConfig::set('core.lib_dir', AgaviConfig::get('core.app_dir') . '/lib', false, true); AgaviConfig::set('core.model_dir', AgaviConfig::get('core.app_dir') . '/models', false, true); AgaviConfig::set('core.module_dir', AgaviConfig::get('core.app_dir') . '/modules', false, true); AgaviConfig::set('core.template_dir', AgaviConfig::get('core.app_dir') . '/templates', false, true); AgaviConfig::set('core.cldr_dir', AgaviConfig::get('core.agavi_dir') . '/translation/data', false, true); // autoloads first (will trigger the compilation of config_handlers.xml) $autoload = AgaviConfig::get('core.config_dir') . '/autoload.xml'; if (!is_readable($autoload)) { $autoload = AgaviConfig::get('core.system_config_dir') . '/autoload.xml'; } AgaviConfigCache::load($autoload); // load base settings AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/settings.xml'); // clear our cache if the conditions are right if (AgaviConfig::get('core.debug')) { AgaviToolkit::clearCache(); // load base settings AgaviConfigCache::load(AgaviConfig::get('core.config_dir') . '/settings.xml'); } $compile = AgaviConfig::get('core.config_dir') . '/compile.xml'; if (!is_readable($compile)) { $compile = AgaviConfig::get('core.system_config_dir') . '/compile.xml'; } // required classes for the framework AgaviConfigCache::load($compile); } catch (Exception $e) { AgaviException::render($e); } }
?> class="closed"<?php } ?> >at <?php if ($i > 1) { ?> <strong><?php if (isset($trace['class'])) { echo $trace['class'], htmlspecialchars($trace['type']); } echo $trace['function']; ?> (</strong><?php if (isset($trace['args'])) { echo AgaviException::buildParamList($trace['args']); ?> <strong>)</strong><?php } } else { ?> <em>exception origin</em><?php } ?> <br />in <?php if (isset($trace['file'])) { echo preg_replace(array_keys($filepaths), $filepaths, $trace['file']); ?> <a href="#frame<?php echo $i; ?>
/** * (re)Initialize the AgaviContext instance. * * @author Dominik del Bondio <*****@*****.**> * @author David Zülke <*****@*****.**> * @author Mike Vincent <*****@*****.**> * @since 0.10.0 */ public function initialize() { try { include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . '/factories.xml', $this->name); } catch (Exception $e) { AgaviException::render($e, $this); } register_shutdown_function(array($this, 'shutdown')); }
/** * Dispatch a request * * @param AgaviRequestDataHolder An optional request data holder object * with additional request data. * @param AgaviExecutionContainer An optional execution container that, * if given, will be executed right away, * skipping routing execution. * * @return AgaviResponse The response produced during this dispatch call. * * @author David Zülke <*****@*****.**> * @since 0.9.0 */ public function dispatch(AgaviRequestDataHolder $arguments = null, AgaviExecutionContainer $container = null) { try { $rq = $this->context->getRequest(); $rd = $rq->getRequestData(); if ($container === null) { // match routes and assign returned initial execution container $container = $this->context->getRouting()->execute(); } if ($container instanceof AgaviExecutionContainer) { // merge in any arguments given. they need to have precedence over what the routing found if ($arguments !== null) { $rd->merge($arguments); } // next, we have to see if the routing did anything useful, i.e. whether or not it was enabled. $moduleName = $container->getModuleName(); $actionName = $container->getActionName(); if (!$moduleName) { // no module has been specified; that means the routing did not run, as it would otherwise have the 404 action's module name // lets see if our request data has values for module and action $ma = $rq->getParameter('module_accessor'); $aa = $rq->getParameter('action_accessor'); if ($rd->hasParameter($ma) && $rd->hasParameter($aa)) { // yup. grab those $moduleName = $rd->getParameter($ma); $actionName = $rd->getParameter($aa); } else { // nope. then its time for the default action $moduleName = AgaviConfig::get('actions.default_module'); $actionName = AgaviConfig::get('actions.default_action'); } // so by now we hopefully have something reasonable for module and action names - let's set them on the container $container->setModuleName($moduleName); $container->setActionName($actionName); } if (!AgaviConfig::get('core.available', false)) { $container = $container->createSystemActionForwardContainer('unavailable'); } // create a new filter chain $filterChain = $this->getFilterChain(); $this->loadFilters($filterChain, 'global'); // register the dispatch filter $filterChain->register($this->filters['dispatch'], 'agavi_dispatch_filter'); // go, go, go! $filterChain->execute($container); $response = $container->getResponse(); } elseif ($container instanceof AgaviResponse) { // the routing returned a response! $response = $container; // set $container to null so AgaviException::render() won't think it is a container if an exception happens later! $container = null; } else { throw new AgaviException('AgaviRouting::execute() returned neither AgaviExecutionContainer nor AgaviResponse object.'); } $response->merge($this->response); if ($this->getParameter('send_response')) { $response->send(); } return $response; } catch (Exception $e) { AgaviException::render($e, $this->context, $container); } }