Пример #1
0
 public function handle()
 {
     $action = $this->url->get("action", "default");
     $whoops = new \Whoops\Run();
     if ($this->url->get("ajax", false)) {
         $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
     } else {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     }
     $whoops->register();
     $result = null;
     if (method_exists($this, "handle_" . $action)) {
         $result = call_user_func(array($this, "handle_" . $action));
     } else {
         throw new Exception("Unknown action");
     }
     $output = "";
     if (is_string($result)) {
         $newResult = array('type' => 'transclude', 'content' => $result);
         $result = $newResult;
     }
     switch ($result['type']) {
         case "template":
             $output = $this->twig->renderTemplateToString($result['template'], $result['data']);
             break;
         case "json":
             $this->app->setJsonResponse(true);
             $data = $result['data'];
             $data['flashbag'] = FlashBag::getFlashes();
             $output = json_encode($data);
             break;
         case "redirect":
             $this->app->_requestRedirect($result['url']);
             return;
             break;
         case "transclude":
             $pageMap = [];
             /** @var BasePage $pageItem */
             foreach ($this->app->getPages() as $pageItem) {
                 $pageMap[] = array('id' => $pageItem->getId(), 'name' => $pageItem->getName());
             }
             ValueBag::set("flashbag", FlashBag::getFlashes());
             $data = array('valueBag' => json_encode(ValueBag::getValues()), 'staticRoot' => $this->app->getStaticRoot(), 'pageMap' => $pageMap, 'defaultUrl' => $this->routeGen->defaultRoute(), 'title' => $this->app->getAppName(), 'userParams' => $this->app->getUserParams(), 'pageTitle' => '');
             if ($this->page !== null) {
                 $data['page'] = $this->page;
                 $data['currentId'] = $this->page->getId();
                 $data['pageTitle'] = $this->page->getName();
             } else {
                 $data['currentId'] = -1;
             }
             $data['page_content'] = $result['content'];
             $data['dev'] = false;
             // change to true to load unminified js
             $output = $this->twig->renderTemplateToString("main_page.twig", $data);
             break;
         default:
             throw new Exception("Unknown result type");
     }
     return $output;
 }
Пример #2
0
 public static function enableDebug()
 {
     // 设置 PHP 调试环境
     ini_set('display_errors', 1);
     error_reporting(E_ALL | E_STRICT);
     // 开启 debug log
     BzfDebug::startDebugLogCollector();
     // 当前目录 autoload
     \Core\Plugin\SystemHelper::addAutoloadPath(realpath(dirname(__FILE__)));
     $handler = new \Whoops\Handler\PrettyPageHandler();
     // 增加额外的日志输出
     $handler->addDataTableCallback('LOGS', function () {
         // 取得 logCollector
         $logCollector = BzfDebug::startDebugLogCollector();
         $logArray = $logCollector->getLogArray();
         // 由于 debug 只支持 key-->value 显示,我们只能简单一点了
         $displayArray = array();
         $index = 0;
         foreach ($logArray as $logItem) {
             $displayArray['' . sprintf('%02d', $index) . '|' . str_pad($logItem['level'], 10, ' ', STR_PAD_LEFT) . '|' . $logItem['source']] = $logItem['msg'];
             $index++;
         }
         return $displayArray;
     });
     $run = new \Whoops\Run();
     $run->pushHandler($handler);
     $run->register();
 }
Пример #3
0
 private function readyErrorHandler()
 {
     if (empty(DEBUG)) {
         return false;
     }
     $whoops_run = new \Whoops\Run();
     $whoops_pretty_page_handler = new \Whoops\Handler\PrettyPageHandler();
     $whoops_json_response_handler = new \Whoops\Handler\JsonResponseHandler();
     $whoops_json_response_handler->onlyForAjaxRequests(true);
     $whoops_run->pushHandler($whoops_pretty_page_handler);
     $whoops_run->pushHandler(function ($exception, $inspector, $whoops_run) {
         $inspector->getFrames()->map(function ($frame) {
             $frame_function = $frame->getFunction();
             $frame_class = $frame->getClass();
             $frame_args = $frame->getArgs();
             if (!empty($frame_function)) {
                 $frame->addComment($frame_function, 'Function');
             }
             if (!empty($frame_class)) {
                 $frame->addComment($frame_class, 'Class');
             }
             if (!empty($frame_args)) {
                 $frame->addComment(print_r($frame_args, true), 'Args');
             }
             return $frame;
         });
     });
     $whoops_run->pushHandler($whoops_json_response_handler);
     $whoops_run->register();
     $whoops_pretty_page_handler->addDataTable('Willer Contants', array('URL_PREFIX' => URL_PREFIX, 'REQUEST_URI' => REQUEST_URI, 'ROOT_PATH' => ROOT_PATH, 'DATABASE_PATH' => DATABASE_PATH, 'DATABASE' => DATABASE));
 }
Пример #4
0
 public function __construct()
 {
     spl_autoload_register(array($this, 'loadClass'));
     GlizyErrorHandler::unregister();
     $whoops = new \Whoops\Run();
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $whoops->pushHandler($handler);
     $whoops->register();
 }
Пример #5
0
 /**
  * Render an exception using Whoops.
  * 
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 protected function renderExceptionWithWhoops(Exception $e)
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     var_dump($e);
     exit;
     return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
 }
Пример #6
0
 public function init()
 {
     if (APP_DEBUG) {
         // 注册错误页面
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         $whoops->register();
     }
 }
Пример #7
0
 public function register(Application $app)
 {
     $whoops = new \Whoops\Run();
     $whoops->allowQuit(false);
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $handler->setPageTitle("Whoops! There was a problem.");
     $whoops->pushHandler($handler);
     $whoops->register();
     $app->set('Whoops', $whoops);
 }
Пример #8
0
 /**
  * Report or log an exception.
  *
  * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  *
  * @param  \Exception  $e
  * @return void
  */
 public function report(Exception $e)
 {
     if ($e instanceof \PHPUnit_Framework_Exception) {
         echo $e->getMessage();
         echo $e->getTraceAsString();
     }
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     return parent::report($e);
 }
Пример #9
0
 private static function openWhoops()
 {
     if (self::$config['DEBUG'] === true) {
         error_reporting(E_ALL);
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         $whoops->register();
     } else {
         error_reporting(0);
     }
 }
 public function __construct()
 {
     // Setup whoops exception handler
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     // Initialize services
     $this->setUpServices();
     // Create the lazy service container
     $this->container = new DependencyInjector($this->services);
 }
Пример #11
0
 /**
  * Init Whoops based on App conditional rule.
  */
 public function init()
 {
     if (TIGA_DEBUG == true && !$this->app->isConsole()) {
         $whoops = new \Whoops\Run();
         if ($this->app['request']->isJson()) {
             $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
         } else {
             $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         }
         $whoops->register();
     }
 }
 /**
  *
  */
 public function loadConfig()
 {
     if (!empty($this->config['type']) && $this->config['type'] == 'development') {
         ini_set("display_errors", "On");
         ini_set("error_reporting", E_ALL & ~E_NOTICE);
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         $whoops->register();
     } else {
         ini_set("display_errors", "Off");
         ini_set("error_reporting", E_ALL & ~E_DEPRECATED);
     }
 }
Пример #13
0
 public function initializeErrorHandler()
 {
     $whoops = new \Whoops\Run();
     if ($this->config->get('debug', false) === true) {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     } else {
         $template = $this->template;
         $whoops->pushHandler(function ($exception, $inspector, $run) use($template) {
             $template->output('common/error');
         });
     }
     $whoops->register();
 }
Пример #14
0
 /**
  * This method will load and register a new autoloader for the system
  * multiple autoloader instances may be used.
  */
 public static function registerAutoloaders()
 {
     require_once 'Autoloader.php';
     $autoloader = new Autoloader(__NAMESPACE__, BASE);
     $autoloader->register();
     /**
      * Override Basic error handling with Whoops
      */
     $whoopsload = new Autoloader('Whoops', BASE . 'vendor' . DS . 'filp' . DS . 'whoops' . DS . 'src' . DS . '');
     $whoopsload->register();
     $wh = new \Whoops\Run();
     $wh->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $wh->register();
 }
Пример #15
0
 private function boot()
 {
     if (ENVIRONMENT == 'development') {
         $run = new \Whoops\Run();
         $handler = new PrettyPageHandler();
         $handler->setPageTitle("We're all going to be fired!");
         $handler->setEditor('textmate');
         $run->pushHandler($handler);
         $handler = new JsonResponseHandler();
         $handler->onlyForAjaxRequests(true);
         $run->pushHandler($handler);
         $run->register();
     }
 }
Пример #16
0
 public static function run()
 {
     //初始化session
     session_start();
     //初始化配置文件
     Config::getInstance();
     $appConfig = Config::get('app');
     //初始化主题
     $public = $appConfig['public'] ? $appConfig['public'] : 'public';
     Filesystem::mkdir($public, 444);
     if (!empty($appConfig['theme'])) {
         defined("APP_THEME") or define("APP_THEME", $public . '/' . $appConfig['theme']);
     } else {
         defined("APP_THEME") or define("APP_THEME", $public);
     }
     //初始化应用名字
     if (!empty($appConfig['name'])) {
         defined("APP_NAME") or define("APP_NAME", $appConfig['name']);
     } else {
         defined("APP_NAME") or define("APP_NAME", 'Simpla');
     }
     //初始化应用URL域名
     defined("BASE_URL") or define("BASE_URL", $appConfig['url']);
     //是否开启错误提示
     if ($appConfig['debug'] == 1) {
         error_reporting(E_ALL);
     } else {
         error_reporting(0);
     }
     //初始化数据库
     Model::getInstance();
     //初始化缓存
     ICache::getInstance();
     Cache::getInstance();
     //初始化whoops
     $run = new \Whoops\Run();
     $handler = new PrettyPageHandler();
     // 设置错误页面的标题
     $handler->setPageTitle("Whoops! 出现了一个错误.");
     $run->pushHandler($handler);
     //设置ajax错误提示.
     if (\Whoops\Util\Misc::isAjaxRequest()) {
         $run->pushHandler(new JsonResponseHandler());
     }
     // 注册handler
     $run->register();
     //路由处理
     Route::check();
 }
Пример #17
0
 /**
  * Registering the debugger to log exceptions locally or transfer them to 
  * external services
  * 
  * Depends on the settings in config/env.php:
  *
  * + 0: Shows "Something went wrong" message ambiguously (handled locally)
  *
  * + 1:	Shows simple error message, file and the line occured (handled 
  *			locally)
  *
  * + 2: Shows advanced debugging with code snippet, stack frames, and 
  *			envionment details, handled by Flip\Whoops 
  *
  * @static
  * @access public
  * @since Method available since Release 0.1.0
  */
 static function start()
 {
     if (getenv('DEBUG') === '0' || getenv('DEBUG') === '1') {
         register_shutdown_function('Core\\Debugger::error_handler');
     } else {
         if (getenv('DEBUG') === '2') {
             $whoops = new \Whoops\Run();
             $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
             $whoops->register();
         } else {
             if (getenv('DEBUG') === '-1') {
             }
         }
     }
 }
 public function register($app)
 {
     /**
      * Error handler
      */
     $whoops = new \Whoops\Run();
     if (getenv('MODE') === 'dev') {
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     } else {
         $whoops->pushHandler(function () {
             Response::create('Something broke', Response::HTTP_INTERNAL_SERVER_ERROR)->send();
         });
     }
     $whoops->register();
 }
Пример #19
0
 public function register()
 {
     if (C('phpunit')) {
         return;
     }
     $whoops = new \Whoops\Run();
     $pretty = new \Whoops\Handler\PrettyPageHandler();
     $whoops->pushHandler($pretty);
     $jsonHandler = new \Whoops\Handler\JsonResponseHandler();
     $jsonHandler->onlyForAjaxRequests(true);
     $whoops->pushHandler($jsonHandler);
     $whoops->register();
     restore_error_handler();
     spl_autoload_register(array($this, 'autoload'));
 }
Пример #20
0
 static function reload()
 {
     $run = new Whoops\Run();
     $handler = new PrettyPageHandler();
     $CI =& get_instance();
     $handler->setEditor("sublime");
     // Set the editor used for the "Open" link
     $handler->addDataTable("Extra Info", array("Name" => 'Forhad Ahmed', "email" => "*****@*****.**"));
     // Set the title of the error page:
     $handler->setPageTitle("Whoops! There was a problem.");
     $run->pushHandler($handler);
     $CI =& load_class('Input');
     if ($CI->is_ajax_request() == true) {
         $run->pushHandler(new JsonResponseHandler());
     }
     // Register the handler with PHP, and you're set!
     $run->register();
 }
Пример #21
0
 public static function init()
 {
     error_reporting(E_ALL);
     if (Config\Config::get('WHOOPS_ERROR', FALSE) || Config\Config::get('DEBUG', FALSE)) {
         $whoops = new \Whoops\Run();
         $request = \Biome\Biome::getService('request');
         if ($request->acceptHtml()) {
             $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         } else {
             if (\Whoops\Util\Misc::isCommandLine()) {
                 $whoops->pushHandler(new \Whoops\Handler\PlainTextHandler());
             } else {
                 $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
             }
         }
         $whoops->register();
     }
 }
Пример #22
0
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     if ($catch) {
         try {
             return $this->app->handle($request, $type, $catch);
         } catch (\Exception $e) {
             $method = \Whoops\Run::EXCEPTION_HANDLER;
             ob_start();
             $whoops->{$method}($e);
             $output = ob_get_clean();
             $code = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
             return new Response($output, $code);
         }
     } else {
         return $this->app->handle($request, $type, $catch);
     }
 }
Пример #23
0
 public function __construct()
 {
     parent::__construct();
     $_ENV['environment'] = $this->config['environment'];
     // Setup Whoops if we're in development
     if ($_ENV['environment'] == 'development') {
         $whoops = new \Whoops\Run();
         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
         $whoops->register();
     }
     // Make the request class a little easier to access.
     class_alias('Unf\\Request', 'Request');
     // Setup database and templating
     $this->setupDatabaseConnection();
     $this->setupViewEngine();
     // Set current language
     // TODO: allow changing of this via the AdminCP and UserCP
     Language::register('EnglishAu', new EnglishAu());
     Language::setCurrent('EnglishAu');
     require __DIR__ . '/common.php';
     $this->getCurrentUser();
 }
Пример #24
0
 public static function invoke($app_class, $app_root_dir, $env, Handler $handler = null)
 {
     $app = new $app_class($app_root_dir, $env);
     $dispatcher = new static($app);
     $dispatcher->boot();
     if ($app->isDebug()) {
         if (is_null($handler)) {
             $handler = new \Whoops\Handler\PrettyPageHandler();
         }
         $whoops = new \Whoops\Run();
         $whoops->pushHandler($handler);
         $whoops->register();
     }
     try {
         $response = $dispatcher->handleRequest();
     } catch (\Exception $e) {
         if ($app->isDebug()) {
             throw $e;
         }
         $response = $dispatcher->handleError($e);
     }
 }
 public function __construct()
 {
     $CI =& get_instance();
     $_env = ENVIRONMENT;
     require_once __DIR__ . '/../../vendor/autoload.php';
     $whoops = new Whoops\Run();
     // Configure the PrettyPageHandler:
     $errorPage = new Whoops\Handler\PrettyPageHandler();
     $errorPage->setPageTitle("Oh No, It's broken!");
     // Set the page's title
     $errorPage->setEditor("sublime");
     // Set the editor used for the "Open" link
     $errorPage->addDataTable("Extra Info", array("route" => $CI->uri->uri_string()));
     $whoops->pushHandler($errorPage);
     if ($CI->input->is_ajax_request() == true) {
         $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler());
     }
     // Debug true in env development
     if ($_env == 'development') {
         $whoops->register();
         $this->whoops = $whoops;
     }
 }
Пример #26
0
 public static function ini($root = "")
 {
     require $root . "../core/Associates/Whoops/vendor/autoload.php";
     //
     if (Config::get('loggin.debug')) {
         $whoops = new \Whoops\Run();
         $errorPage = new \Whoops\Handler\PrettyPageHandler();
         //
         $errorPage->setPageTitle(Config::get('loggin.msg'));
         // Set the page's title
         $errorPage->setEditor("sublime");
         //
         $whoops->pushHandler($errorPage);
         $whoops->register();
     } else {
         $whoops = new \Whoops\Run();
         $errorPage = new \Whoops\Handler\PlainTextHandler();
         $errorPage->msg = Config::get('loggin.msg');
         $errorPage->bg_color = Config::get('loggin.bg');
         $errorPage->handle();
         $whoops->pushHandler($errorPage);
         $whoops->register();
     }
 }
Пример #27
0
 public function onError(ErrorEvent $event)
 {
     if (php_sapi_name() == "cli") {
         return;
     }
     header('X-Error-Message: ' . $event->getException()->getMessage(), true, 500);
     $whoops = new \Whoops\Run();
     $request = $event->getContext()->getRequest();
     $handler = new \Whoops\Handler\PrettyPageHandler();
     $event->getContext()->getActionName();
     $prev = $event->getException()->getPrevious();
     $fwkTable = array('Application name' => $event->getApplication()->getName(), 'Action name' => $event->getContext()->getActionName(), 'Context state' => $event->getContext()->getState(), 'Context error' => $event->getContext()->getError());
     $parents = $this->getParentExceptionsMessage($event->getException());
     if (!is_array($parents)) {
         $parents = array();
     }
     foreach ($parents as $idx => $exp) {
         $fwkTable['Parent Exception #' . $idx] = $exp;
     }
     $handler->addDataTable('Fwk\\Core Informations', $fwkTable);
     $handler->addDataTable('Request Informations', array('URI' => $request->getUri(), 'Request URI' => $request->getRequestUri(), 'Path Info' => $request->getPathInfo(), 'Query String' => $request->getQueryString() ?: '<none>', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getScriptName(), 'Base Path' => $request->getBasePath(), 'Base URL' => $request->getBaseUrl(), 'Scheme' => $request->getScheme(), 'Port' => $request->getPort(), 'Host' => $request->getHost()));
     $whoops->pushHandler($handler);
     $whoops->register();
 }
Пример #28
0
 /**
  * Core constructor.
  *
  * @param ResourceMap|null $map system resources
  */
 public function __construct(ResourceMap $map = null)
 {
     if (!isset($map)) {
         // Get correct web-application path
         $this->system_path = __SAMSON_CWD__;
         // Get web-application resource map
         $this->map = ResourceMap::get($this->system_path, false, array('src/'));
     } else {
         // Use data from passed map
         $this->map = $map;
         $this->system_path = $map->entryPoint;
     }
     // Connect static collection with this dynamic field to avoid duplicates
     $this->module_stack =& Module::$instances;
     // Temporary add template worker
     $this->subscribe('core.rendered', array($this, 'generateTemplate'));
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
     $whoops->register();
     // Fire core creation event
     Event::fire('core.created', array(&$this));
     // Signal core configure event
     Event::signal('core.configure', array($this->system_path . __SAMSON_CONFIG_PATH));
 }
Пример #29
0
// $environment = 'production';
error_reporting(E_ALL);
require '../vendor/autoload.php';
$injector = (include 'Dependencies.php');
/**
 * Register the error handler
 */
$whoops = new \Whoops\Run();
if ($environment !== 'production') {
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
} else {
    $whoops->pushHandler(function ($e) {
        echo 'Friendly error page and send an email to the developer';
    });
}
$whoops->register();
$routeDefinitionCallback = function (\FastRoute\RouteCollector $r) {
    $routes = (include 'Routes.php');
    foreach ($routes as $route) {
        $r->addRoute($route[0], $route[1], $route[2]);
    }
};
$dispatcher = \FastRoute\simpleDispatcher($routeDefinitionCallback);
$routeInfo = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
switch ($routeInfo[0]) {
    case \FastRoute\Dispatcher::NOT_FOUND:
        $response->setContent('404 - Page not found');
        $response->setStatusCode(404);
        break;
    case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
        $response->setContent('405 - Method not allowed');
Пример #30
0
 public function run($path = '/')
 {
     if ($this->kirby->option('patterns.lock') && !$this->kirby->site()->user()) {
         go($this->kirby->option('error'));
     }
     // error handling
     $whoops = new \Whoops\Run();
     $whoops->pushHandler(function ($e) {
         throw $e;
         return \Whoops\Handler\Handler::QUIT;
     });
     $whoops->register();
     tpl::$data = ['site' => $this->kirby->site(), 'pages' => $this->kirby->site()->children(), 'page' => $this->kirby->site()->find($this->kirby->option('home')), 'lab' => $this];
     $router = new Router();
     $router->register([['pattern' => '/', 'action' => function () {
         $readme = $this->root() . DS . 'readme.md';
         if (!is_dir($this->root())) {
             $modal = $this->view('modals/folder');
         } else {
             $modal = null;
         }
         if (is_file($readme)) {
             $markdown = kirbytext(f::read($readme));
         } else {
             $markdown = null;
         }
         return $this->view('layouts/main', ['title' => $this->title(), 'menu' => $this->menu(), 'content' => $this->view('views/dashboard', ['markdown' => $markdown]), 'modal' => $modal]);
     }], ['pattern' => 'assets/(:any)', 'action' => function ($file) {
         switch ($file) {
             case 'index.js':
             case 'index.min.js':
                 $mime = 'text/javascript';
                 break;
             case 'index.css':
             case 'index.min.css':
                 $mime = 'text/css';
                 break;
             default:
                 return new Response('Not found', 'text/html', 404);
                 break;
         }
         // build the root for the file
         $file = dirname(__DIR__) . DS . 'assets/dist/' . $file;
         return new Response(f::read($file), $mime);
     }], ['pattern' => '(:all)/preview', 'action' => function ($path) {
         lab::$mode = 'preview';
         $pattern = new Pattern($path);
         $config = $pattern->config();
         try {
             $html = $pattern->render();
         } catch (Exception $e) {
             $html = '';
         }
         return $this->view('views/preview', ['pattern' => $pattern, 'html' => $html, 'background' => a::get($config, 'background', $this->kirby->option('patterns.preview.background')), 'css' => $this->kirby->option('patterns.preview.css', 'assets/css/index.css'), 'js' => $this->kirby->option('patterns.preview.js', 'assets/js/index.js')]);
     }], ['pattern' => '(:all)', 'action' => function ($path) {
         $pattern = new Pattern($path);
         $file = null;
         if (!$pattern->exists()) {
             $filename = basename($path);
             $path = dirname($path);
             if ($path == '.') {
                 $preview = $this->view('previews/error', ['error' => 'The pattern could not be found']);
             } else {
                 $pattern = new Pattern($path);
                 $file = $pattern->files()->get($filename);
                 if ($file) {
                     $preview = $this->preview($pattern, $file);
                 } else {
                     $preview = $this->view('previews/error', ['error' => 'The file could not be found']);
                 }
             }
         } else {
             if ($file = $pattern->files()->get($pattern->name() . '.html.php')) {
                 go($pattern->url() . '/' . $file->filename());
             } else {
                 if ($file = $pattern->files()->first()) {
                     go($pattern->url() . '/' . $file->filename());
                 } else {
                     $preview = $this->view('previews/empty');
                 }
             }
         }
         if ($pattern->isHidden()) {
             go($this->url());
         }
         return $this->view('layouts/main', ['title' => $this->title() . ' / ' . $pattern->title(), 'menu' => $this->menu(null, $path), 'content' => $this->view('views/pattern', ['preview' => $preview, 'info' => $this->view('snippets/info', ['pattern' => $pattern, 'file' => $file])])]);
     }]]);
     if ($route = $router->run($path ? $path : '/')) {
         return new Response(call($route->action(), $route->arguments()));
     } else {
         go('error');
     }
 }