honth / filehandler
This package allows reading and manipulating system files easy.
Requires
- php: ^5.6 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^5.4
This package is not auto-updated.
Last update: 2016-10-29 12:21:50 UTC
README
This package allows reading and manipulating system files easy.
How to install
This package uses Composer and to install it with Composer, simply execute this in you console at your project:
composer require honth/filehandler
If you don't have Composer that you can download it as a zip from Github.
Once you have it installed you will need to set the project root. It's not required but it is for when passing in an array of directories, the path created will be prepended with the project root.
How to use
The Filesystem
lets you manipulate your files within your system.
Remember that Filesystem
uses file_put_contents()
for writing to a file.
That means that it's better to collect all contents for the file and then write it all at once.
Example of using Filesystem and File
<?php use Honth\FileHandler\File; use Honth\FileHandler\Filesystem; use Honth\FileHandler\Path; require "vendor/autoload.php"; Path::setProjectRoot(__DIR__); Filesystem::mkdir(Path::make(__DIR__ . "/bin/log/")); // Both of these works but the second one requires that you have set the project root. Filesystem::mkdir(Path::make(["bin", "log"])); $file = new File(Path::make(["bin", "log"], "info.log")); $file->write("Hello World!"); $file->rename(__DIR__ . "/test.log");
Fileloader
This class lets you load php files easily. You can also pass in data that will be sent to the file when loading. This could be handy when dividing you tasks into different files when using a framework.
Fileloader::load("example.php", ["app" => $app]); // Meanwhile in example.php: $app->something();
JSON
This class lets you load and save JSON files.
$jsonData = JSON::load(__DIR__ . "/composer.json"); JSON::save($jsonData, __DIR__ . "/composer-copy.json");
Licence
This is open-sourced software is licensed under the MIT license.