public function test_anonymous_controller__conditionnal_controller() { \Staq::App()->addController('/*', function () { if (\Staq::App()->getCurrentUri() == '/coco') { return NULL; } })->run(); $this->expectOutputHtmlContent('error 404'); }
protected function initialize() { if (\Staq::App() && \Staq::App()->isInitialized()) { static::$cacheFile = reset($this->extensions) . '/cache/autoload.php'; if (\is_file(static::$cacheFile)) { require_once static::$cacheFile; } static::$initialized = TRUE; } return $this; }
public function actionView($code) { parent::actionView($code); $message = ''; $exception = \Staq::App()->getLastException(); if ($exception && \Staq::App()->settings->getAsBoolean('error.display_errors')) { $message = $exception->getMessage() . HTML_EOL . $exception->getTraceAsString(); } $page = new \Stack\View\Error(); $page['code'] = $code; $page['message'] = $message; return $page; }
protected function getTwigEnvironmentParameters() { $params = []; $settings = (new \Stack\Setting())->parse('Application.ini'); if ($settings->getAsBoolean('cache.twig')) { if ($cachePath = \Staq::App()->getPath('cache/twig/', TRUE)) { $params['cache'] = $cachePath; } } if ($settings->getAsBoolean('error.display_errors')) { $this->debug = TRUE; $params['debug'] = TRUE; } return $params; }
protected function globDataFile($pattern, $asId = false) { $path = $this->folder; $folders = \Staq::App()->getExtensions(); array_walk($folders, function (&$a) use($path) { $a = realpath($a . $path); }); $folders = array_filter($folders, function ($a) { return !empty($a); }); $files = []; foreach ($folders as $folder) { $fullFolder = $folder . DIRECTORY_SEPARATOR . $pattern; foreach (glob($fullFolder . '\\.*') as $filename) { if ($asId) { $id = \UString::notStartWith($filename, $folder . '/'); \UString::doSubstrBeforeLast($id, '.'); $files[$id] = $id; } else { $files[] = $filename; } } } if ($asId) { array_values($files); } return array_reverse($files); }
protected function tearDown() { (new \Stack\Storage\Database\Request())->loadMysqlFile(\Staq::App()->getPath('dataset/reset.sql')); }
protected function redirectList($type) { $params = []; $params['type'] = $type; \Staq\Util::httpRedirectUri(\Staq::App()->getUri($this, 'list', $params)); }
protected function getPublicPath() { return \Staq::App()->getCurrentUri(); }
protected function getRedirectUri() { if (isset($_POST['redirect'])) { return $_POST['redirect']; } if (isset($_GET['redirect'])) { return $_GET['redirect']; } return \Staq::App()->getCurrentUri(); }
protected function getFilePaths($fullSettingFileName) { $fileNames = $this->getFileNames($fullSettingFileName); $platformName = \Staq::App()->getPlatform(); $filePaths = []; foreach (\Staq::App()->getExtensions() as $extension) { foreach ($fileNames as $fileName) { if ($platformName) { $fileName .= '.' . $platformName; } while ($fileName) { $path = realpath($extension . '/setting/' . $fileName . '.ini'); if ($path) { $filePaths[] = $path; } $fileName = \UString::substrBeforeLast($fileName, '.'); } } } return array_reverse($filePaths); }
public static function getModelControllerUrl($model, $action = 'view', $parameters = [], $absoluteURL = false) { $controllerName = \Staq\Util::getStackQuery($model); $controller = \Staq::Ctrl($controllerName); if ($controller) { $parameters = $controller->getRouteAttributes($model); } $uri = \Staq::App()->getUri($controller, $action, $parameters); return \Staq\Util::getPublicUrl($uri, $absoluteURL); }