This package manipulates files and paths
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"
$envFile = new Env('path/to/envFile');
$content = $envFile->open();
// key1=value1
$envFile = new Env('path/to/envFile');
$content = $envFile->parseFile();
// ['key' => 'value', 'key2' => 'value2']
$envFile = new Env('path/to/envFile');
$content = $envFile->parseFile();
$jsonFile = new Json('path/to/file.json');
$content = $jsonFile->open();
// ['key' => 'value', 'key2' => 'value2']
$phpFile = new Php('path/to/file.php');
$content = $phpFile->open();
// ['key' => 'value', 'key2' => 'value2']
$yamlFile = new Yaml('path/to/file.yaml'); // or .yml
$content = $yamlFile->open();
// ['key' => 'value', 'key2' => 'value2']
$otherFile = new FileManipulation('path/to/file.other');
$content = $otherFile->open();
// ['key' => 'value', 'key2' => 'value2']
$envFile = new Env('path/to/envFile');
$content = $envFile->saveFile('content to save');
$otherFile = new FileManipulation('path/to/file.other');
$content = $otherFile->saveFile('content to save');
$phpFile = new Php('path/to/file.php');
$className = $phpFile->getClassName();
// ClassName
$phpFile = new Php('path/to/file.php');
$classNames = $phpFile->getClassNames();
// ['ClassName', 'ClassName2']
$phpFile = new Php('path/to/file.php');
$attribute = Php::getClassAttributeNamed(Class::class, Attribute::class);
// return ReflectionAttribute of Attribute::class
$phpFile = new Php('path/to/file.php');
$attribute = Php::getInstanceOfClassAttributeNamed(Class::class, Attribute::class);
// return instance of Attribute::class
$phpFile = new Php('path/to/file.php');
$propertiesAttributes = Php::getPropertiesAttributes(Class::class);
// return array of ReflectionProperty of properties
$phpFile = new Php('path/to/file.php');
$propertiesAttributes = Php::getInstanceOfPropertiesAttributesNamed(Class::class, Attribute::class);
// return array of property name => instances of Attribute::class
$phpFile = new Php('path/to/file.php');
$methodsAttributes = Php::getMethodsAttributes(Class::class);
// return array of ReflectionMethod of methods
$phpFile = new Php('path/to/file.php');
$methodsAttributes = Php::getInstanceOfMethodsAttributesNamed(Class::class, Attribute::class);
// return array of method name => instances of Attribute::class
$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)
$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)
$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)
$jsonFile = new Json('path/to/file.json');
$yamlFile = new Yaml('path/to/file.yaml');
$jsonFile->convertFile($yamlFile);
// convert json file to yaml file
$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)
$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
$dateStorage = new DateStorage('path');
$datePath = $dateStorage->datePath();
// return path of path/year/month (example : path/2022/02)
DateStorage::dateFilename('suffix');
// return filename with date (example : 20220201-suffix)
DateStorage::dateTimeFilename('suffix');
// return filename with date and time (example : 20220201-1200-suffix)