public function createApplication($namespace = 'Staq\\Core\\Ground', $baseUri = NULL, $platform = NULL) { if (empty($baseUri)) { $baseUri = $this->getDefaultBaseUri(); } if (empty($platform)) { $platform = 'prod'; if (\Staq\Util::isCli()) { if (!isset($argv[1])) { echo 'You must specify a platform.' . PHP_EOL; echo 'Ex: ' . $argv[0] . ' local' . PHP_EOL; die; } $platform = $argv[1]; } } $extensions = $this->findExtensions($namespace); if (!is_null(static::$autoloader)) { spl_autoload_unregister(array(static::$autoloader, 'autoload')); } static::$autoloader = new \Staq\Autoloader($extensions); spl_autoload_register(array(static::$autoloader, 'autoload')); static::$application = new \Stack\Application($extensions, $baseUri, $platform); static::$application->initialize(); return static::$application; }
public function test_existing_class__complex() { $app = \Staq\App::create($this->projectNamespace)->setPlatform('local'); $stack = new \Stack\Existing\Coco\Des\Bois(); $this->assertEquals(1, \Staq\Util::getStackHeight($stack)); $this->assertTrue(is_a($stack, $this->getProjectStackClass('Existing\\Coco'))); }
protected function createView($action = 'view') { $controller = \Staq\Util::getStackSubQuery($this); $view = (new \Stack\View())->byName($action, $controller); $view['controller'] = $controller; $view['controllerAction'] = $action; return $view; }
public function __construct() { $this->settings = (new \Stack\Setting())->parse($this); $this->name = strtolower(\Staq\Util::getStackSubQuery($this, '_')); $this->table = $this->settings->get('database.table', $this->name); $this->idField = $this->settings['database.idField']; $this->fields = $this->settings->getAsArray('database.fields'); }
public function __construct() { $settings = (new \Stack\Setting())->parse($this); $this->name = \Staq\Util::getStackSubQuery($this, '_'); $this->folder = '/data/' . $this->name; if (isset($settings['idField'])) { $this->idField = $settings['idField']; } }
public function actionLogout() { $redirect = '/'; if (isset($_GET['redirect'])) { $redirect = $_GET['redirect']; } $this->logout(); Notif::info(static::MSG_LOGOUT_VALID); \Staq\Util::httpRedirectUri($redirect); }
protected function render($view) { $view = parent::render($view); if (!\Staq\Util::isStack($view, 'Stack\\View')) { $page = new \Stack\View(); $page['content'] = $view; $view = $page; } return $view->render(); }
public function __construct($message = NULL, $code = NULL, \Exception $previous = NULL) { if (is_null($message)) { $message = $this->defaultMessage; } if (is_null($message)) { $message = \Staq\Util::getStackSubQueryText($this); } if (is_null($code)) { $code = $this->defaultCode; } parent::__construct($message, $code, $previous); }
public function actionView($id) { $query = strtolower($id); $article = (new \Stack\Entity\Article())->fetchById($query); if (!$article->exists()) { return null; } if ($id != $article->id) { \Staq\Util::httpRedirect(\Staq\Util::getModelControllerUrl($article), 301); } $view = $this->createView(); $view['article'] = $article; return $view; }
public function actionSiteMap() { $siteMap = new \Feedify\Writer(); $siteMap->addItems($this->getAllPages()); $siteMap->addItems(array(array('url' => 'http://' . $_SERVER['SERVER_NAME'] . \Staq\Util::getControllerUrl($this, 'archive')))); $siteMap->addItems($this->getAllArticles()); $siteMap->addAttributeFormatter('url', function ($article) { if (isset($article->id)) { $path = $article->id; if ($path == 'index') { $path = ''; } return 'http://' . $_SERVER['SERVER_NAME'] . \Staq\Util::getPublicUrl($path); } if (isset($article['url'])) { return $article['url']; } }); $siteMap->addAttribute('date'); $siteMap->output(\Feedify\Writer::SITEMAP_FORMAT); return TRUE; }
public function set($model) { if (empty($model)) { $model = $this->getRemoteModel(); } else { if (is_numeric($model)) { $model = $this->getRemoteModel()->entity->fetchById($model); } else { if (!\Staq\Util::isStack($model, $this->getRemoteClass())) { $message = 'Input of type "' . $this->getRemoteClass() . '", but "' . gettype($model) . '" given.'; throw new \Stack\Exception\NotRightInput($message); } } } if ($model && $model->exists()) { $this->remoteModel = $model; $this->seed = $model->id; } else { $this->seed = NULL; $this->remoteModel = NULL; } return $this; }
public function set($remoteModels) { $this->remoteModels = []; $this->changed = TRUE; \UArray::doConvertToArray($remoteModels); if ($this->uniqueRemote) { $remoteModels = array_slice($remoteModels, 0, 1); } foreach ($remoteModels as $model) { if (is_numeric($model)) { $model = $this->getRemoteModel()->entity->fetchById($model); } else { if (!\Staq\Util::isStack($model, $this->getRemoteClass())) { $message = 'Input of type "' . $this->getRemoteClass() . '", but "' . gettype($model) . '" given.'; throw new \Stack\Exception\NotRightInput($message); } } if ($model && $model->exists()) { $this->remoteModels[] = $model; } } return $this; }
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); }
public function initialize() { $this->settings = (new \Stack\Setting())->clearCache()->parse($this); // Display errors $displayErrors = 0; if ($this->settings->getAsBoolean('error.display_errors') || \Staq\Util::isCli()) { $displayErrors = 1; } ini_set('display_errors', $displayErrors); // Level reporting if (\Staq\Util::isCli()) { $level = E_ALL & ~E_STRICT; } else { $level = $this->settings->get('error.error_reporting'); if (!is_numeric($level)) { $level = 0; } } error_reporting($level); // Timezone $timezone = $this->settings->get('service.timezone'); date_default_timezone_set($timezone); $this->initialized = TRUE; return $this; }
protected function extendTwig() { $publicFilter = new \Twig_SimpleFilter('public', ['Staq\\Util', 'getPublicUrl']); $this->twig->addFilter($publicFilter); $publicFunction = new \Twig_SimpleFunction('public', ['Staq\\Util', 'getPublicUrl']); $this->twig->addFunction($publicFunction); $assetFunction = new \Twig_SimpleFunction('asset', ['Staq\\Util', 'getAssetUrl']); $this->twig->addFunction($assetFunction); $routeFunction = new \Twig_SimpleFunction('route', ['Staq\\Util', 'getControllerUrl']); $this->twig->addFunction($routeFunction); $routeFunction = new \Twig_SimpleFunction('route_model_*', function ($action, $model) { return \Staq\Util::getModelControllerUrl($model, $action); }); $this->twig->addFunction($routeFunction); $routeFunction = new \Twig_SimpleFunction('route_model', ['Staq\\Util', 'getModelControllerUrl']); $this->twig->addFunction($routeFunction); $findFunction = new \Twig_SimpleFunction('find_template', array(get_class($this), 'findTemplate')); $this->twig->addFunction($findFunction); if ($this->debug) { $this->twig->addExtension(new \Twig_Extension_Debug()); } }
protected function getModelName() { return \Staq\Util::getStackSubSubQuery($this); }
public function offsetSet($index, $newVal) { $attribute = $this->getAttribute($index); if (\Staq\Util::isStack($attribute, 'Stack\\Attribute')) { $attribute->set($newVal); } else { parent::offsetSet($index, $newVal); } }
protected function loadStackParentClass($class) { $queryExtension = \Staq\Util::getStackableExtension($class); $query = \Staq\Util::getParentStackQuery($class); $ready = FALSE; while ($query) { foreach (array_keys($this->extensions) as $extensionNamespace) { if ($ready) { if ($realClass = $this->getRealClass($query, $extensionNamespace)) { $this->createClassAlias($class, $realClass); return TRUE; } } else { if ($queryExtension === $extensionNamespace) { $ready = TRUE; } } } $query = \Staq\Util::popStackQuery($query); $ready = TRUE; } $this->createClassEmpty($class); }
protected function preventExceptionLoop($exception) { if (\Staq\Util::isStack($exception)) { $name = \Staq\Util::getStackQuery($exception); } else { $name = get_class($exception); } if (in_array($name, $this->exceptionNames, TRUE)) { throw new \Exception('Uncatched exception "' . $exception->getMessage() . '"'); } $this->exceptionNames[] = $name; }
protected function getModel() { $modelClass = 'Stack\\Model\\' . \Staq\Util::getStackSubQuery($this); return new $modelClass(); }
protected function getSettingFileNameFromStack($stack) { $settingFileName = \Staq\Util::getStackQuery($stack); return \Staq\Util::convertNamespaceToPath($settingFileName); }
public function __toString() { $str = 'Route( ' . $this->uri . ' => '; if (is_array($this->callable)) { $controller = $this->callable[0]; if (\Staq\Util::isStack($controller)) { $str .= \Staq\Util::getStackSubQuery($controller); } else { $str .= \UObject::convertToClass($controller); } $str .= '::' . $this->callable[1]; } else { $str .= 'anonymous'; } return $str . ' )'; }