Skip to content
Adrian Tilita edited this page Aug 11, 2017 · 8 revisions

Up-to-date information about the project can be found here.

1. Simple Usage

<?php
require_once dirname(__FILE__) . '/../vendor/autoload.php';

use NeedleProject\FileIo\File;
use NeedleProject\FileIo\Content\Content;

$filename = __DIR__ . DIRECTORY_SEPARATOR . 'my_first_file';

/**
 * Writing content to a file
 */
$content = new Content('Hello world!');
$file = new File(__DIR__ . DIRECTORY_SEPARATOR . 'my_first_file');
if (true === $file->write($content)) {
    echo "I wrote my first file!\n";
}

/**
 * Verifying file
 */
if (true === $file->exists()) {
    echo sprintf('File %s exists on disk!', $filename) . "\n";
}

if (true === $file->isWritable()) {
    echo sprintf('File %s can be written!', $filename) . "\n";
}

if (true === $file->isReadable()) {
    echo sprintf('File %s can be read!', $filename) . "\n";
}

/**
 * Read content from a file
 */
echo "File content:\n";
echo $file->getContent()->get();
echo "\nEnd of file content!\n";

/**
 * Delete the file
 */
if (true === $file->delete()) {
    echo "The file was successfully deleted!" . "\n";
}

2. Changelog

  • v0.4.0 (05/30/2017) - Adapted code to support PHP 5.5 as minimum platform requirment
  • v0.3.1 (03/30/2017) - Fixed path helper splitFilename bug
  • v0.3.0 (03/30/2017) - Added prepend / append content, added new getArray and getObject in content Api
  • v0.2.0 (03/28/2017) - Added YAML content support
  • v0.1.1 (02/06/2017) - Moved error-to-exception handler to external dependency
  • v0.1.0 (01/23/2017) - Initial release
Clone this wiki locally