定制 struam/dir-rotation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

struam/dir-rotation

最新稳定版本:1.0.0

Composer 安装命令:

composer require struam/dir-rotation

包简介

PHP library for directory rotation

README 文档

README

DirRotation — is a library for managing directories and files in PHP. It provides methods for creating, deleting, archiving, and changing the working directory.

Installation

To install the library, use Composer:

composer require struam/dir-rotation

Usage

Example of usage

require 'vendor/autoload.php';

use Struam\DirRotation\DirRotation;

try {

    // Initialization without specifying the working directory
    $dirRotation = new DirRotation();
    echo "Working Directory: " . $dirRotation->getWorkingDirectory();

    // Creating a subdirectory
    $subdirectoryPath = $dirRotation->createSubdirectory('dir/new/temp');
    echo "Subdirectory created at: " . $subdirectoryPath;

    // Archiving a subdirectory followed by deletion
    $archivePath = $dirRotation->archiveDirectory('dir/new/temp', true);
    echo "Directory archived at: " . $archivePath;

    // Changing the working directory
    $dirRotation->changeWorkingDirectory('/new/working/directory');
    echo "Working Directory changed to: " . $dirRotation->getWorkingDirectory();

} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}

Methods

__construct(string $workingDirectory = null)

Initializes the DirRotation object with the specified working directory. If the working directory is not specified, the current working directory is used.

  • $workingDirectory (string|null)

Example:

'../', '../dir', '/var/project/dir', 'dir'

getWorkingDirectory()

Returns the current working directory.

changeWorkingDirectory(string $workingDirectory)

Changes the current working directory to the specified one.

  • $workingDirectory (string)

Example:

'../', '../dir', '/var/project/dir', 'dir'

createSubdirectory(string $path)

Creates a subdirectory in the working directory.

  • $path (string)

Example:

'dir', '/dir/new-dir', '/dir/new-dir/some-dir'

deleteSubdirectory(string $path)

Deletes a subdirectory from the working directory.

  • $path (string)

Example:

'dir', '/dir/new-dir', '/dir/new-dir/some-dir'

archiveDirectory(string $path,bool $deleteAfterArchive = false)

Archives the specified directory and saves the archive in the parent directory.

Example:

Archive directory: '/dir/new-dir'

Current working directory: '/var/project/'

The archive will be saved in the directory: '/var/project/dir/new-dir.zip'

  • $path (string)

The path to the directory to be archived.

Example:

'dir', '/dir/new-dir', '/dir/new-dir/some-dir'

  • $deleteAfterArchive (bool)

If true, the directory will be deleted after archiving. Default is false.

License

This library is distributed under the MIT License. See the LICENSE file for details.

Contributing

Contributions and suggestions for improving the library are welcome. Please create an issue or pull request.

Author

Rustam Kadirov struam@gmail.com

Version History

1.0.0 First release

This README.md file provides essential information about the library, including installation, usage, testing, and licensing. You can adapt it to your needs by adding additional sections or modifying existing ones.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-01-17