lazarusphp/openhandler
最新稳定版本:1.0.1
Composer 安装命令:
composer require lazarusphp/openhandler
包简介
FileManager and Data Writer.
README 文档
README
Version Information Build version : v1.0.0 Date Of Build : 31/12/2025
Index
2 Open FileHandler Permissions Manager
3 Usage
4 Helpers
What is OpenHandler
Open Handler (OH) is a standalone File and Directory Handling Library, OFH is designed to control and comminicate with the Server file structure, set permissions and manage files and directories.
Open File handler Permissions manager
Along side the FileWriter and File handler the Library will also feature a permissions manager. The Permissions manager will give the FileHandler library the ability to set permissions relating to the files and directories.
Usage
Installation
composer install lazarusphp/openhandler
Creating a new Instantiation.*
// Setting a path within the methods parameters will set the directory root. // Leaving it blank will default to the folder root. $filehandler = OpenHandler::create("/var/www/OpenHandler/Structure");
Creating a Directory
if a root is not generated but required, the root directory will have to be passed for the following methods.
upon creating a Directory Helper methods such as hasDirectory and writable are also called these methods are required to make sure the correct permissions and structure access are put in place click here for more informtion on helpers.
// Make Sure path exists $filehandler->directory("/Apps/Login");
Generating Files
Open Handler has the ability to Generate files with Additional Customisation read more about FileWriter commands.
Listing Files and Folders
the code below can be used to list directories and the files, it is recommended to list them in a loop but can also be apploed to the var_dump or print_r methods for debugging purposes.
$filehandler->list("/Apps"); foreach($filehandler->list("/Apps") as $item => $folders) { // List code goes here. }
Deleting Directory and files
OpenHandler has the ability to delete a single file or directory.
Passing a single filename will Remove the specific file.
$filehandler->delete("/Apps/Home/users.env");
Passing a directory will Delete the specified directory along with any files inside.
$filehandler->delete("/Apps");
Setting a prefix
Using a prefix gives the ability to group methods into a specific directory making and can be done like so.
$filehandler->prefix("/App/Users",function($handler){ // Use handler at this point to call methods $handler->directory("/Uploads"); if(isset($_POST["file"]) && $_SERVER["REQUEST_METHOD"] === "POST") { // Set the path and the Form Name value. $handler->upload("Uploads","file"); } })
Uploading FIles
if(isset($_POST["file"]) && $_SERVER["REQUEST_METHOD"] === "POST") { $filehandler->upload("/uploads/Path","file"); }
Helpers
importing
Add Under Namspace
use LazarusPhp\OpenHandler\CoreFiles\Traits\Structure;
Add Within the classname
use Structure;
OpenHandler utilisies a trait called Structure which contants helper functions for ease of access when Handling Data.
hasFile
Check if the file is a valid file this uses the built in is_file() method and returns a true or false boolean.
if($this->hasFile("/App/Home/test.php")) { echo "this is a valid File"; }
fileExists
file Exists utilises the file_exist() method and checks if the file Exists.
if($this->fileExists("App/Home/test.php")) { echo "file Exists"; }
hasDirectory
Has directory is used to validate if the path is a valid directory hasDirectory uses the is_dir() built in method and returns a true or false boolean.
if($this->hasDirectory("/Apps/Home")) { echo "directory Exists"; } else { echo "Directory doesnt exist"; }
reflection
The Reflection helper is used to call a new Reflection class instance.
$class = $this->reflection(__CLASS__); $class->getShortName();
getExtension
the getExtension helper gives the ability obtain the file extension type which can be used with other helper methods.
$this->getExtension("/App/Home/Users.php");
hasExtension
The hasExtension helper is used to validate and limit what file extentions can be used when writing or opening data.
if($this->hasExtension("/App/Home/test.php","php")) { echo "FIle is a valid type"; }
WhitelistExtention
The Whitelist Extension helper can be used in conjunction with the hasExtension helper and getExtensions helper when creating a custom method.
function myCustommFileMethod($file) { $extention = $this->getExtension($file); if($this->whitelistExtension($extension,["php","js","txt"])) { echo "We can Continue"; } } $filemethod = new CustomClass(); $filemethod->myCustomFileMethod("App/Home/Users.php");
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-31