public function render() { if ($this->isRender) { return $this; } $this->isRender = true; // make sure clean all buffer $this->web->ob->clean('webStart'); $this->web->ob->start('webRender'); $this->web->registerRenderer($this); $this->rendering(); return $this; }
public function getWeb() { if (!isset($this->web)) { $this->web = Web::getWeb(); } return $this->web; }
protected function redirect($uri = null, $query = null) { if (!$this->web->isRender()) { $this->rendering(new Render\Redirection($this->web->uri($uri, $query)))->render(); } return $this; }
protected function onExecute($argv = null) { $path = $this->getPath(); if (is_file($path)) { throw new \Exception("The file {$path} is existing!"); } $content = $this->buildClass($this->class); $dir = dirname($path); if (!is_dir($dir)) { mkdir($dir, 0755, true); } if (file_put_contents($path, $content)) { $this->console->println("Add controller '{$this->class}' success!"); $action = $this->web->getDefaultAction(); $command = new NewAction(['', "{$this->name}#{$action}"]); $command->execute(); } else { $this->console->println("Add controller '{$this->class}' lost, please try again."); } }
protected function onPrepare($argv = null) { $this->web = Web::getWeb(); $dirs = $this->web->component->getScopeDirs('widget'); if (!isset($dirs['appComponent'])) { throw new \Exception("Unknown layout folder!"); } $this->dir = $dirs['appComponent']; if (is_file($this->getPath())) { throw new \Exception("File {$this->getPath()} is existing!"); } }
protected function onPrepare($argv = null) { $this->web = Web::getWeb(); $this->app = $this->web->app; $this->router = $this->web->getRouter(); $this->parse = $this->router->parseStr($this->name); if (empty($this->parse['controller'])) { throw new \Exception('Please specify controller, the right format should "controller#action"!'); } if (empty($this->parse['action'])) { throw new \Exception('Please specify action, the right format should "controller#action"!'); } $this->controller = $this->web->filterController($this->parse['controller']); $this->class = $this->web->makeControllerClass($this->controller); $this->view = $this->web->filterAction($this->parse['action']); $dirs = $this->web->component->getScopeDirs('view'); if (!isset($dirs['appView'])) { throw new \Exception("Unknown view folder!"); } $this->dir = $dirs['appView']; if (is_file($this->getPath())) { throw new \Exception("The file '{$this->getPath()}' is existing!"); } }
/** * * <code> * import('file', ['user' => new User()]); * import('file'); * import('file', 'wrapper', ['name' => 'Jack']); * import('file', 'wrapper'); * </code> * * @param $file * @param null $layout * @param array|null $vars * @param bool $isStrict * @return bool|string * @throws Exception */ public function loadComponent($file, $layout = null, array $vars = null, bool $isStrict = false) { if (!isset($layout) || is_array($layout) || is_object($layout)) { $vars = (array) $layout; $layout = false; } $content = ''; $filePath = $this->web->getComponentPath($file); if ($filePath === false) { $message = "Component {$file} not found!"; if ($isStrict) { throw new Exception($message); } $content = "<pre>{$message}</pre>"; } else { $content = $this->import($filePath, $vars); } if (!empty($layout)) { $content = $this->layout($content, $layout, $vars); } return $content; }
protected function onPrepare($argv = null) { $this->web = Web::getWeb(); $this->router = $this->web->getRouter(); $this->parse = $this->router->parseStr($this->name); if (empty($this->parse['controller'])) { throw new \Exception('Please specify controller, the right format should "controller#action"!'); } if (empty($this->parse['action'])) { throw new \Exception('Please specify action, the right format should "controller#action"!'); } $this->class = $this->web->makeControllerClass($this->parse['controller']); $this->method = $this->web->filterAction($this->parse['action']); if (!class_exists($this->class, true)) { throw new \Exception("The class '{$this->class}' not found!"); } if (!is_subclass_of($this->class, Controller::class)) { throw new \Exception("The class '{$this->class}' is exiting, but it's not a controller class!"); } $this->reflection = new \ReflectionClass($this->class); if ($this->reflection->hasMethod($this->method)) { throw new \Exception("The method '{$this->class}#{$this->method}' is defined!"); } }
public function paginate(Pagination $pagination = null, $attr = null) { if (!isset($pagination)) { return ''; } $linksCount = intval($this->pageLinks); $prevNext = !empty($this->pagePrevNext); $firstLast = !empty($this->pageFirstLast); $goto = $this->pageGoto; $field = $pagination->field; $pageTotal = $pagination->total; $pageCurrent = $pagination->current; $els = ['links' => '', 'prev' => '', 'next' => '', 'first' => '', 'last' => '', 'current' => '', 'total' => '', 'button' => '']; if ($pageTotal > $linksCount) { $half = (int) ($linksCount / 2); $start = $pageCurrent - $half; if ($start < 1) { $start = 1; } $over = $start + $linksCount; // $over = $start + $linksCount - ($firstLast ? ($start == 1 ? 2 : 3) : 1); if ($over > $pageTotal) { $over = $pageTotal; $start = $over - $linksCount; if ($start <= 1) { $start = 1; } } } else { $start = 1; $over = $pageTotal; } $uri = Web::getWeb()->http->newUri(); $ellipsis = $this->paginationLink(self::PAGE_ELLIPSIS, 0); if ($linksCount > 0) { if ($start > 1) { if (!$firstLast) { $els['links'] .= $this->paginationLink(self::PAGE_ITEM, 1, $uri, $field, false); $start += 1; if ($start > 2) { $els['links'] .= $ellipsis; } } else { $els['links'] .= $ellipsis; } } if (!$firstLast && $over < $pageTotal) { $over -= 1; } for ($i = $start; $i <= $over; $i++) { $els['links'] .= $this->paginationLink(self::PAGE_ITEM, $i, $uri, $field, $pageCurrent); } if ($over < $pageTotal) { if (!$firstLast) { if ($over < $pageTotal - 1) { $els['links'] .= $ellipsis; } $els['links'] .= $this->paginationLink(self::PAGE_ITEM, $pageTotal, $uri, $field, false); } else { $els['links'] .= $ellipsis; } } } if ($firstLast) { $els['first'] = $this->paginationLink(self::PAGE_FIRST, 1, $uri, $field, $pageCurrent); $els['last'] = $this->paginationLink(self::PAGE_LAST, $pageTotal, $uri, $field, $pageCurrent); } if ($prevNext) { $els['prev'] = $this->paginationLink(self::PAGE_PREV, $pageCurrent - 1, $uri, $field, 1 - 1); $els['next'] = $this->paginationLink(self::PAGE_NEXT, $pageCurrent + 1, $uri, $field, $pageTotal + 1); } if (!empty($goto)) { if ($goto === 'input') { $el = $this->input('number', $pageCurrent, ['step' => 1, 'min' => 1, 'max' => $pageTotal, 'name' => $field]); } else { $pages = range(1, $pageTotal); $el = $this->select(array_combine($pages, $pages), $pageCurrent, ['name' => $field]); } $els['current'] = $this->tag('page-span:input', sprintf($this->getText(self::PAGE_CUR), $el)); $els['button'] = $this->tag('page-button', $this->getText(self::PAGE_GOTO)); } else { $els['current'] = sprintf($this->getText(self::PAGE_CUR), $pageCurrent); } $els['total'] = sprintf($this->getText(self::PAGE_TOTAL), $pageTotal); $row = substitute($this->pageRow, $els); if (!empty($goto)) { $row .= $this->inputSet($uri->getQueryData(), 'hidden', [$field => 1]); $row = $this->tag('form', $row, ['action' => $uri, 'method' => 'get']); } return $this->tag('page-wrap', $row, $attr); }
public function getBaseUri() { if (!isset($this->baseUri)) { $web = Web::getWeb(); if (KE_HTTP_REWRITE) { $this->baseUri = $web->getBaseUri(); } else { $this->baseUri = new Uri(['scheme' => KE_REQUEST_SCHEME, 'host' => KE_REQUEST_HOST, 'uri' => dirname(KE_HTTP_BASE)]); } } return $this->baseUri; }
public function setWithWiki(bool $withWiki) { if ($this->withWiki !== $withWiki) { $this->withWiki = $withWiki; Web::updateRoute($this->routePath, $this->getRoutes()[$this->routePath]); } return $this; }