예제 #1
0
파일: NewWidget.php 프로젝트: janpoem/kephp
 public function getTemplatePath() : string
 {
     $tpl = '/Templates/' . $this->template;
     $scopes = $this->console->getAppCommandScopes();
     foreach ($scopes as $ns => $dir) {
         if (real_file($path = $dir . $tpl)) {
             return $path;
         }
     }
     return __DIR__ . $tpl;
 }
예제 #2
0
 public function __construct(string $file, bool $autoImport = false)
 {
     $this->path = real_file($file);
     if (!is_file($this->path)) {
         throw new \Error('Please input a valid file!');
     }
     $this->autoImport = $autoImport;
     if ($autoImport && array_search($this->path, get_included_files()) === false) {
         require $this->path;
     }
 }
예제 #3
0
파일: Console.php 프로젝트: janpoem/kephp
 /**
  * @param Argv|null $argv
  * @return Command
  * @throws Exception
  */
 public function seekCommand(Argv $argv = null)
 {
     if (!isset($argv)) {
         $argv = $this->getArgv();
     }
     if (empty($argv[0])) {
         throw new Exception('No command found in argv.');
     }
     $cmd = $this->getAliasCommand($argv[0]);
     $class = null;
     $path = null;
     $scopes = $this->getGlobalCommandScopes();
     $commands = $this->makeCommands($cmd);
     foreach ($scopes as $ns => $dir) {
         foreach ($commands as $command) {
             $path = real_file($dir . DS . $command . '.php');
             if ($path !== false) {
                 $class = str_replace('/', '\\', $command);
                 if (!empty($ns)) {
                     $class = $ns . '\\' . $class;
                 }
                 break;
             }
         }
         if (!empty($class)) {
             break;
         }
     }
     if (empty($class)) {
         throw new Exception("No command detected with \"{$argv[0]}\"!");
     }
     require $path;
     if (!class_exists($class, false)) {
         throw new Exception("Undefined command class {$class}");
     }
     if (!is_subclass_of($class, Command::class)) {
         throw new Exception("Command class {$class} doest not extend with " . Command::class . '!');
     }
     /** @var Command $cmd */
     return new $class($argv);
 }
예제 #4
0
파일: Command.php 프로젝트: janpoem/kephp
 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;
     }
 }
예제 #5
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;
 }