public function getWeb() { if (!isset($this->web)) { $this->web = Web::getWeb(); } return $this->web; }
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!"); } }
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!"); } }
protected function onPrepare($argv = null) { $this->web = Web::getWeb(); $this->name = $this->web->filterController($this->name); $this->class = $this->web->makeControllerClass($this->name); }
public function __construct() { $this->web = Web::getWeb(); }
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 final function __construct() { $this->web = Web::getWeb(); $this->http = $this->web->http; $this->onConstruct(); }
public function __construct() { $this->web = Web::getWeb(); $this->context = $this->web->getContext(); }