Beispiel #1
0
 public function __construct(string $dir, string $export)
 {
     $this->source = real_dir($dir);
     if (empty($this->source)) {
         throw new \Error("Please input a valid source directory!");
     }
     if (empty($export)) {
         throw new \Error('Export directory can not be empty!');
     }
     $this->export = $export;
     if (!is_dir($this->export)) {
         mkdir($this->export, 0755, true);
     }
     $this->source = $this->addDir($this->source);
     $this->export = DocMen::convertUnixPath($this->export);
 }
Beispiel #2
0
 public function setDirs(array $dirs)
 {
     foreach ($dirs as $name => $dir) {
         // 不为空,必须是字符串,不允许'kephp'和'root'两个关键字的写入
         if (empty($name) || !is_string($name) || $name === 'kephp' || $name === 'root') {
             continue;
         }
         // dir如果为:null false,表示删除掉这个目录
         if ($dir === null || $dir === false) {
             unset($this->dirs[$name]);
             continue;
         } elseif (empty($dir) || !is_string($dir)) {
             // 目录也必须是字符串类型
             // todo: 以后要增加对Object和Array类型的识别
             continue;
         }
         // 这里其实有些尴尬,realpath,是基于当前执行的脚本为基础入口的,所以这里可能还有一些问题
         if (($real = real_dir($dir)) !== false) {
             $this->dirs[$name] = $real;
         } else {
             $this->aliases[$name] = $dir;
         }
     }
     return $this;
 }
Beispiel #3
0
 /**
  * 基于范围搜索相关的文件,返回这个文件的完整路径,如果搜索不到,则范围false
  *
  * @param string|null $scope
  * @param string      $file
  * @param bool        $isAll
  * @return array|bool|string
  */
 public function seek(string $scope = null, string $file, bool $isAll = false)
 {
     if (empty($file)) {
         return false;
     }
     $scope = $this->filterScope($scope);
     if (!empty($this->extension)) {
         $file = ext($file, $this->extension);
     }
     if (!KE_IS_WIN && strpos($file, KE_DS_CLS) !== false) {
         $file = str_replace(KE_DS_CLS, KE_DS_UNIX, $file);
     }
     $dir = DIRECTORY_SEPARATOR;
     if (!empty($this->scopeRewrites[$scope])) {
         $dir .= $this->scopeRewrites[$scope] . DIRECTORY_SEPARATOR;
     }
     $result = null;
     foreach ($this->getScopeDirs($scope) as $name => $base) {
         if (($base = real_dir($base)) === false) {
             continue;
         }
         if (($path = real_file($base . $dir . $file)) === false) {
             continue;
         }
         if (!$isAll) {
             return $path;
         }
         $result[] = $path;
     }
     return empty($result) ? false : $result;
 }
Beispiel #4
0
 public static function verifyValue($type, $value = null, array $column = [])
 {
     if ($type === KE_STR) {
         return (string) $value;
     } elseif ($type === KE_BOOL || $type === 'bool' || $type === 'single') {
         if ($value === 'false' || $value === '0' || $value === 0 || $value === 0.0) {
             return false;
         }
         if (strtolower($value) === 'off') {
             return false;
         }
         if ($type === 'single' && $value === '') {
             return !$column['default'];
         }
         return (bool) $value;
     } elseif ($type === KE_INT || $type === 'int') {
         return (int) $value;
     } elseif ($type === KE_FLOAT) {
         return (double) $value;
     } elseif ($type === 'array') {
         if (is_string($value)) {
             if (strpos($value, ',') > 0) {
                 $result = [];
                 foreach (explode(',', $value) as $item) {
                     $result[] = trim($item);
                 }
                 return $result;
             }
         }
         return (array) $value;
     } elseif ($type === 'dir') {
         if (empty($value)) {
             return false;
         }
         return real_dir($value);
     } elseif ($type === 'file') {
         if (empty($value)) {
             return false;
         }
         return real_file($value);
     } elseif ($type === 'realpath') {
         if (empty($value)) {
             return KE_SCRIPT_DIR;
         }
         return real_path($value);
     } elseif ($type === 'json') {
         $decode = json_decode($value, true);
         return $decode;
     } elseif ($type === 'dirs' || $type === 'files') {
         if (empty($value)) {
             return [];
         }
         $value = static::verifyValue('array', $value, $column);
         if ($type === 'dirs') {
             foreach ($value as $index => $item) {
                 $value[$index] = static::verifyValue('dir', $item, $column);
             }
         } elseif ($type === 'files') {
             foreach ($value as $index => $item) {
                 $value[$index] = static::verifyValue('file', $item, $column);
             }
         }
         return $value;
     } else {
         if ($value === 'false') {
             return false;
         }
         if ($value === 'true') {
             return true;
         }
         if ($value === 'null') {
             return null;
         }
         if (is_float($value)) {
             return (double) $value;
         }
         if (is_int($value)) {
             return (int) $value;
         }
         return $value;
     }
 }
Beispiel #5
0
 public function getWikiDir()
 {
     if (!$this->isWithWiki()) {
         return false;
     }
     return real_dir($this->docDir . DS . '/wiki');
 }