Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
update something. update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 4, 2018
1 parent bc332d1 commit 6871acd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 59 deletions.
47 changes: 0 additions & 47 deletions src/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,51 +357,4 @@ public static function delete($path, $delSelf = true): bool

return true;
}

/**
* 比较文件路径
* @param $newPath
* @param $oldPath
* @return string
*/
public static function comparePath($newPath, $oldPath): string
{
$oldDirName = basename(rtrim($oldPath, '/'));
$newPath_arr = explode('/', rtrim($newPath, '/'));
$oldPath_arr = explode('/', rtrim($oldPath, '/'));

$reOne = array_diff($newPath_arr, $oldPath_arr);
$numOne = \count((array)$reOne);//

/**
* 跟框架在同一个父目录[phpTest]下
* projectPath 'F:/www/phpTest/xxx/yyy/[zzz]'--应用目录 zzz,
* yzonePath 'F:/www/phpTest/[yzonefk]'---框架目录 [yzonefk]
* 从应用'F:/www/phpTest/xxx/yyy/[zzz]/'目录回滚到共同的父目录[这里是从zzz/web回滚到phpTest]
* 入口文件 在 zzz/web/index.php
*/
$dirStr = '__DIR__';

for ($i = 0; $i <= $numOne; $i++) {
$dirStr = 'dirname( ' . $dirStr . ' )';
}

$dirStr .= '.\'';

/**
* 跟框架在不同父目录下,在回滚到共同的父目录后,再加上到框架的路径
* newPath 'F:/www/otherDir/ddd/eee/xxx/yyy/[zzz]'--应用目录 zzz
* oldPath 'F:/www/phpTest/[yzonefk]'---框架目录[yzonefk]
*/
if (\dirname($newPath) !== \dirname($oldPath)) {
$reTwo = array_diff($oldPath_arr, $newPath_arr);
$reTwo = array_shift($reTwo);
// $numTwo = count($reTwo);// 从框架目录向上回滚,找到相同的父节点,得到相隔几层
$dirStr .= implode('/', (array)$reTwo);
}

$dirStr = $dirStr . '/' . $oldDirName . '/Gee.php\'';

return $dirStr;
}
}
10 changes: 5 additions & 5 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function info(string $filename, $check = true): array
*/
public static function getStat($filename): array
{
return stat($filename);
return \stat($filename);
}

/**
Expand All @@ -116,15 +116,15 @@ public static function getStat($filename): array
*/
public static function save(string $filename, string $data): bool
{
return file_put_contents($filename, $data) !== false;
return \file_put_contents($filename, $data) !== false;
}

/**
* @param $content
* @param $path
* @throws IOException
*/
public static function write($content, $path): void
public static function write($content, $path)
{
$handler = static::openHandler($path);

Expand Down Expand Up @@ -154,7 +154,7 @@ public static function openHandler(string $path)
* @param string $path The path to the file (for exception printing only).
* @throws IOException
*/
public static function writeToFile($handler, string $content, string $path = ''): void
public static function writeToFile($handler, string $content, string $path = '')
{
if (($result = @fwrite($handler, $content)) === false || ($result < \strlen($content))) {
throw new IOException('The file "' . $path . '" could not be written to. Check your disk space and file permissions.');
Expand All @@ -172,7 +172,7 @@ public static function writeToFile($handler, string $content, string $path = '')
* 'case.html' => 'content' ,
* );
**/
public static function createAndWrite(array $fileData = [], $append = false, $mode = 0664): void
public static function createAndWrite(array $fileData = [], $append = false, $mode = 0664)
{
foreach ($fileData as $file => $content) {
//检查目录是否存在,不存在就先创建(多级)目录
Expand Down
15 changes: 8 additions & 7 deletions src/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function pathFormat(string $dirName): string
}

/**
* @param string $path e.g phar://E:/workenv/php-dockerized/www/phplang/ugirls-social/social-uem/uem.phar/web
* @param string $path e.g phar://E:/workenv/xxx/yyy/app.phar/web
* @return string
*/
public function clearPharPath(string $path): string
Expand Down Expand Up @@ -116,7 +116,7 @@ public static function exists(string $file, $type = null)
* @throws FileNotFoundException
* @throws \InvalidArgumentException
*/
public static function check(string $file, $ext = null): void
public static function check(string $file, $ext = null)
{
if (!$file || !file_exists($file)) {
throw new FileNotFoundException("File {$file} not exists!");
Expand All @@ -142,7 +142,7 @@ public static function check(string $file, $ext = null): void
* @throws IOException When target file or directory already exists
* @throws IOException When origin cannot be renamed
*/
public static function rename(string $origin, string $target, bool $overwrite = false): void
public static function rename(string $origin, string $target, bool $overwrite = false)
{
// we check that target does not exist
if (!$overwrite && static::isReadable($target)) {
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function isReadable(string $filename): bool
* @param int $mode The directory mode
* @throws IOException On any directory creation failure
*/
public static function mkdir($dirs, $mode = 0777): void
public static function mkdir($dirs, $mode = 0777)
{
foreach (Arr::toIterator($dirs) as $dir) {
if (is_dir($dir)) {
Expand Down Expand Up @@ -207,7 +207,7 @@ public static function mkdir($dirs, $mode = 0777): void
* @param bool $recursive Whether change the mod recursively or not
* @throws IOException When the change fail
*/
public static function chmod($files, $mode, $umask = 0000, $recursive = false): void
public static function chmod($files, $mode, $umask = 0000, $recursive = false)
{
foreach (Arr::toIterator($files) as $file) {
if (true !== @chmod($file, $mode & ~$umask)) {
Expand All @@ -228,7 +228,7 @@ public static function chmod($files, $mode, $umask = 0000, $recursive = false):
* @param bool $recursive Whether change the owner recursively or not
* @throws IOException When the change fail
*/
public static function chown($files, string $user, $recursive = false): void
public static function chown($files, string $user, $recursive = false)
{
foreach (Arr::toIterator($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
Expand All @@ -251,11 +251,12 @@ public static function chown($files, string $user, $recursive = false): void
* @param string $srcDir
* @param callable $filter
* @return \RecursiveIteratorIterator
* @throws \InvalidArgumentException
*/
public static function getIterator(string $srcDir, callable $filter): \RecursiveIteratorIterator
{
if (!$srcDir || !file_exists($srcDir)) {
throw new \LogicException('Please provide a exists source directory.');
throw new \InvalidArgumentException('Please provide a exists source directory.');
}

$directory = new \RecursiveDirectoryIterator($srcDir);
Expand Down

0 comments on commit 6871acd

Please sign in to comment.