mulertech/file-manipulation
Composer 安装命令:
composer require mulertech/file-manipulation
包简介
This package manipulates and organizes files and path
关键字:
README 文档
README
This package manipulates files and paths
Requirements
- PHP
^8.4 symfony/yaml^8.1
Installation
Two methods to install FileManipulation package with composer :
Add to your "composer.json" file into require section :
"mulertech/file-manipulation": "^1.0"
and run the command :
php composer.phar update
Run the command :
php composer.phar require mulertech/file-manipulation "^1.0"
Usage
Open env file : (return content of file)
$envFile = new Env('path/to/envFile');
$content = $envFile->open();
// key1=value1
Parse env file : (return parsed content of file)
$envFile = new Env('path/to/envFile');
$content = $envFile->parseFile();
// ['key' => 'value', 'key2' => 'value2']
Load env file : (load env file in environment variables)
$envFile = new Env('path/to/envFile');
$content = $envFile->parseFile();
Open json file : (return content of file)
$jsonFile = new Json('path/to/file.json');
$content = $jsonFile->open();
// ['key' => 'value', 'key2' => 'value2']
Open php file : (return content of file)
$phpFile = new Php('path/to/file.php');
$content = $phpFile->open();
// ['key' => 'value', 'key2' => 'value2']
Open yaml file : (return content of file)
$yamlFile = new Yaml('path/to/file.yaml'); // or .yml
$content = $yamlFile->open();
// ['key' => 'value', 'key2' => 'value2']
Open other file : (return content of file)
$otherFile = new FileManipulation('path/to/file.other');
$content = $otherFile->open();
// ['key' => 'value', 'key2' => 'value2']
Save env/json/php/yaml file :
$envFile = new Env('path/to/envFile');
$content = $envFile->saveFile('content to save');
Save other file :
$otherFile = new FileManipulation('path/to/file.other');
$content = $otherFile->saveFile('content to save');
Php file class name :
$phpFile = new Php('path/to/file.php');
$className = $phpFile->getClassName();
// ClassName
Php get class names :
$phpFile = new Php('path/to/file.php');
$classNames = $phpFile->getClassNames();
// ['ClassName', 'ClassName2']
Php get class attribute named "Attribute::class" :
$phpFile = new Php('path/to/file.php');
$attribute = Php::getClassAttributeNamed(Class::class, Attribute::class);
// return ReflectionAttribute of Attribute::class
Php get instance of class attribute named "Attribute::class" :
$phpFile = new Php('path/to/file.php');
$attribute = Php::getInstanceOfClassAttributeNamed(Class::class, Attribute::class);
// return instance of Attribute::class
Php get properties attributes :
$phpFile = new Php('path/to/file.php');
$propertiesAttributes = Php::getPropertiesAttributes(Class::class);
// return array of ReflectionProperty of properties
Php get instance of properties attributes named "Attribute::class" :
$phpFile = new Php('path/to/file.php');
$propertiesAttributes = Php::getInstanceOfPropertiesAttributesNamed(Class::class, Attribute::class);
// return array of property name => instances of Attribute::class
Php get methods attributes :
$phpFile = new Php('path/to/file.php');
$methodsAttributes = Php::getMethodsAttributes(Class::class);
// return array of ReflectionMethod of methods
Php get instance of methods attributes named "Attribute::class" :
$phpFile = new Php('path/to/file.php');
$methodsAttributes = Php::getInstanceOfMethodsAttributesNamed(Class::class, Attribute::class);
// return array of method name => instances of Attribute::class
Get first occurrence of a string in a file :
$file = new FileManipulation('path/to/file'); // if for example php file : new Php('path/to/file.php')
$firstOccurrence = $file->getFirstOccurrence('string');
// return line of first occurrence (int)
Get last occurrence of a string in a file :
$file = new FileManipulation('path/to/file'); // if for example php file : new Php('path/to/file.php')
$lastOccurrence = $file->getLastOccurrence('string');
// return line of last occurrence (int)
Get line number :
$file = new FileManipulation('path/to/file'); // if for example php file : new Php('path/to/file.php')
$lineNumber = $file->getLine(number);
// return content of line (string)
Convert file :
$jsonFile = new Json('path/to/file.json');
$yamlFile = new Yaml('path/to/file.yaml');
$jsonFile->convertFile($yamlFile);
// convert json file to yaml file
Count lines :
$file = new FileManipulation('path/to/file'); // if for example php file : new Php('path/to/file.php')
$lines = $file->countLines();
// return number of lines of file (int)
Insert content at line number :
$file = new FileManipulation('path/to/file'); // if for example php file : new Php('path/to/file.php')
$file->insertContentAtLineNumber('content', 2);
// insert content (one or more lines) at line number 2 and move other lines after
Date path :
$dateStorage = new DateStorage('path');
$datePath = $dateStorage->datePath();
// return path of path/year/month (example : path/2022/02)
Date filename :
DateStorage::dateFilename('suffix');
// return filename with date (example : 20220201-suffix)
Date time filename :
DateStorage::dateTimeFilename('suffix');
// return filename with date and time (example : 20220201-1200-suffix)
mulertech/file-manipulation 适用场景与选型建议
mulertech/file-manipulation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 377 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「file」 「path」 「filesystem」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mulertech/file-manipulation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mulertech/file-manipulation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mulertech/file-manipulation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
JSONPath implementation for querying and updating JSON objects with support for json flattening into a table
The InstantConfigurationCopy module provides easy way to copy configuration field information for admin in back office Magento 2.
Laravel Media Popup to upload/view the files
simple agnostic package for IO releted (files, dir, etc..)
PMVC Plugin for File information
统计信息
- 总下载量: 377
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-29