Example #1
0
 public function __construct($data = null)
 {
     parent::__construct($data);
 }
Example #2
0
 public final function __construct(string $root = null, array $dirs = null)
 {
     if (isset(self::$app)) {
         throw new PhpException('Create App repeated instances!');
     }
     self::$app = $this;
     // 检查根目录
     if (($this->root = real_dir($root)) === false) {
         throw new PhpException('App directory (root) does not exist or is not a directory!');
     }
     /** App的根目录的绝对路径 */
     define('KE_APP_ROOT', $this->root);
     /** App的目录名 */
     define('KE_APP_DIR', basename($this->root));
     // 后注册,让后继承的App类,可以以声明属性的方式来添加
     if (!isset($this->aliases['web'])) {
         $this->aliases['web'] = 'public';
     }
     /** @var string $kephp kephp的根目录 */
     $this->dirs['kephp'] = dirname(__DIR__);
     if (!empty($dirs)) {
         $this->setDirs($dirs);
     }
     // CLI模式加载特定的环境配置文件
     if (KE_APP_MODE === KE_CLI) {
         // 先尝试加载环境配置文件,这个文件以后会扩展成为json格式,以装载更多的信息
         $envFile = $this->root . '/env';
         if (is_file($envFile) && is_readable($envFile)) {
             $_SERVER['SERVER_NAME'] = trim(file_get_contents($envFile));
         } else {
             $_SERVER['SERVER_NAME'] = 'localhost';
         }
     }
     // 绑定servers
     $this->servers += self::$knownServers;
     // 匹配当前的运行环境
     $env = $this->detectEnv();
     // 不是开发模式或者测试模式,就必然是发布模式,确保在未知的模式下,返回发布模式
     if ($env !== KE_DEV && $env !== KE_TEST) {
         $env = KE_PRO;
     }
     /** App当前的运行环境 */
     define('KE_APP_ENV', $env);
     /** @var string $appSrc App的src目录 */
     $appSrc = $this->path('src');
     // 项目的基础的类、命名空间和命名空间对应的路径
     $appClass = static::class;
     $appNs = null;
     $appNsPath = $appSrc;
     if ($appClass !== __CLASS__) {
         list($appNs) = parse_class($appClass);
         if (!empty($appNs)) {
             $appNsPath .= DS . $appNs;
         }
         if (!KE_IS_WIN) {
             $appNsPath = str_replace('\\', '/', $appNsPath);
         }
     }
     /** 记录下全局的App的类名称 */
     define('KE_APP_CLASS', $appClass);
     /** 当前的App类名的namespace */
     define('KE_APP_NS', $appNs);
     /** 当前App类的Namespace指向的绝对路径 */
     define('KE_APP_NS_PATH', $appNsPath);
     $this->dirs['appNs'] = $appNsPath;
     $this->loader = new Loader(['dirs' => ['appSrc' => [$appSrc, 100, Loader::CLS], 'appHelper' => ["{$appNsPath}/Helper", 100, Loader::HELPER], 'keHelper' => ["{$this->dirs['kephp']}/Ke/Helper", 1000, Loader::HELPER]], 'classes' => import("{$this->dirs['kephp']}/classes.php"), 'prepend' => true]);
     $this->loader->start();
     if (!empty($this->helpers)) {
         $this->loader->loadHelper(...$this->helpers);
     }
     // Uri准备
     Uri::prepare();
     $this->onConstruct($this->loader);
 }
Example #3
0
 public function paginationLink(string $item, int $number, Uri $uri = null, string $field = 'page', $compare = false)
 {
     $attr = [];
     $text = $item;
     if (isset($this->texts[$item])) {
         $text = sprintf($this->texts[$item], $number);
     }
     if ($item === self::PAGE_ELLIPSIS) {
         $tag = 'page-span:ellipsis';
     } elseif (isset($uri) && ($compare === false || !equals($compare, $number))) {
         $tag = 'page-link';
         //
         $attr['href'] = $uri->setQuery([$field => $number <= 1 ? null : $number]);
     } else {
         if ($item === self::PAGE_ITEM) {
             $tag = 'page-span:active';
         } else {
             $tag = 'page-span';
         }
     }
     return $this->tag($tag, $text, $attr);
 }