mulertech/file-manipulation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mulertech/file-manipulation

Composer 安装命令:

composer require mulertech/file-manipulation

包简介

This package manipulates and organizes files and path

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub PHPStan Action Status Total Downloads Test Coverage

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 mulertech/file-manipulation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-29