Esempio n. 1
0
 public function test_anonymous_controller__conditionnal_controller()
 {
     \Staq::App()->addController('/*', function () {
         if (\Staq::App()->getCurrentUri() == '/coco') {
             return NULL;
         }
     })->run();
     $this->expectOutputHtmlContent('error 404');
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 protected function tearDown()
 {
     (new \Stack\Storage\Database\Request())->loadMysqlFile(\Staq::App()->getPath('dataset/reset.sql'));
 }
Esempio n. 7
0
 protected function redirectList($type)
 {
     $params = [];
     $params['type'] = $type;
     \Staq\Util::httpRedirectUri(\Staq::App()->getUri($this, 'list', $params));
 }
Esempio n. 8
0
 protected function getPublicPath()
 {
     return \Staq::App()->getCurrentUri();
 }
Esempio n. 9
0
 protected function getRedirectUri()
 {
     if (isset($_POST['redirect'])) {
         return $_POST['redirect'];
     }
     if (isset($_GET['redirect'])) {
         return $_GET['redirect'];
     }
     return \Staq::App()->getCurrentUri();
 }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 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);
 }