ride/lib-system

Ride框架的系统库

1.1.2 2020-11-09 09:18 UTC

This package is auto-updated.

Last update: 2024-09-09 17:33:01 UTC


README

PHP Ride框架的系统抽象库。

本库包含的内容

系统

System 类是对底层服务器系统的抽象。它提供了对底层文件系统的简单访问。您也可以使用它来执行命令或检查系统类型、连接客户端等。

文件系统

FileSystem 接口是对底层文件系统的抽象。Windows文件系统与Unix文件系统处理方式不同。此接口使得在两种系统上编程透明化成为可能。

文件

文件系统通过 File 对象工作。所有文件操作都应通过此类调用。

文件浏览器

FileBrowser 接口用于创建透明文件结构。您可以使用它请求相对文件而无需了解文件的组织方式。此外,您还可以请求应用程序和公共目录。

权限转换器

您可以使用 PermissionConverter 将权限转换为不同的格式。

代码示例

查看此代码示例,了解本库的用途

<?php

use ride\library\system\System;

$system = new System();

// check the type of operating system
$system->isUnix();
$system->isWindows();

// check the client
$system->isCli();
$system->getClient(); // ip address or username when in cli

// execute a command
$output = $system->execute('whoami');

// file system abstraction
$fileSystem = $system->getFileSystem();

$dir = $fileSystem->getFile('/path/to/dir');
$dir->isDirectory();
$dir->isReadable();
$files = $dir->read();

$file = $fileSystem->getFile('/path/to/file');
$file->exists();
$file->getModificationTime();
$file->setLock(true);
$content = $file->read();

$destination = $dir->getChild($file->getName());
$destination = $destination->getCopyFile();

$file->copy($destination);

实现

有关更多示例,您可以查看本库的以下实现

安装

您可以使用 Composer 安装此库。

composer require ride/lib-system