Skip to content
This repository was archived by the owner on Aug 14, 2022. It is now read-only.
/ php-file Public archive

PHP library for file and directory management.

License

Notifications You must be signed in to change notification settings

josantonius/php-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7941597 · Oct 30, 2017

History

21 Commits
Oct 28, 2017
Oct 28, 2017
Mar 18, 2017
Oct 28, 2017
Oct 28, 2017
Oct 28, 2017
Oct 28, 2017
Mar 18, 2017
Mar 18, 2017
Oct 30, 2017
Oct 30, 2017
Sep 13, 2017
Oct 28, 2017
Mar 18, 2017
Oct 28, 2017
Oct 28, 2017

Repository files navigation

PHP File library

Latest Stable Version Latest Unstable Version License Codacy Badge Total Downloads Travis PSR2 PSR4 CodeCov

Versión en español

PHP library for file management.



Requirements

This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.

Installation

The preferred way to install this extension is through Composer.

To install PHP File library, simply:

$ composer require Josantonius/File

The previous command will only install the necessary files, if you prefer to download the entire source code you can use:

$ composer require Josantonius/File --prefer-source

You can also clone the complete repository with Git:

$ git clone https://github.com/Josantonius/PHP-File.git

Or install it manually:

Download File.php:

$ wget https://raw.githubusercontent.com/Josantonius/PHP-File/master/src/File.php

Available Methods

Available methods in this library:

- Check if a file exists in a path or url:

File::exists($file);
Attribute Description Type Required Default
$file Path or file url. string Yes

# Return (boolean)

- Delete file if exists:

File::delete($file);
Attribute Description Type Required Default
$file File path. string Yes

# Return (boolean)

- Create directory if not exists:

File::createDir($path);
Attribute Description Type Required Default
$path Path where to create directory. string Yes

# Return (boolean)

- Copy directory recursively:

File::copyDirRecursively($from, $to);
Attribute Description Type Required Default
$from Path from copy. string Yes
$to Path to copy. string Yes

# Return (boolean)

- Delete empty directory:

File::deleteEmptyDir($path);
Attribute Description Type Required Default
$path Path to delete. string Yes

# Return (boolean)

- Delete directory recursively:

File::deleteDirRecursively($path);
Attribute Description Type Required Default
$path Path to delete. string Yes

# Return (boolean)

- Get files from directory:

File::getFilesFromDir($path);
Attribute Description Type Required Default
$path Path where get file paths. string Yes

# Return (boolean)

Quick Start

To use this library with Composer:

require __DIR__ . '/vendor/autoload.php';

use Josantonius\File\File;

Or If you installed it manually, use it:

require_once __DIR__ . '/File.php';

use Josantonius\File\File;

Usage

Example of use for this library:

- Check if a local file exists:

<?php
File::exists('path/to/file.php');

- Check if a external file exists:

<?php
File::exists('https://raw.githubusercontent.com/Josantonius/PHP-File/master/composer.json');

- Delete a local file:

<?php
File::delete(__DIR__ . '/test.txt');

- Create directory:

<?php
File::createDir(__DIR__ . '/test/');

- Delete empty directory:

<?php
File::deleteEmptyDir(__DIR__ . '/test/');

- Delete directory recursively:

<?php
File::deleteDirRecursively(__DIR__ . '/test/');

- Copy directory recursively:

<?php
File::copyDirRecursively(__DIR__ . '/test/', __DIR__ . '/copy/');

- Get file paths from directory:

<?php
get_class(File::getFilesFromDir(__DIR__));

Tests

To run tests you just need Composer and to execute the following:

$ git clone https://github.com/Josantonius/PHP-File.git

$ cd PHP-File

$ composer install

Run unit tests with PHPUnit:

$ composer phpunit

Run PSR2 code standard tests with PHPCS:

$ composer phpcs

Run all previous tests:

$ composer tests

☑ TODO

  • Create tests
  • Improve documentation

Contribute

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.

This is intended for large and long-lived objects.

Repository

All files in this repository were created and uploaded automatically with Reposgit Creator.

License

This project is licensed under MIT license. See the LICENSE file for more info.

Copyright

2017 Josantonius, josantonius.com

If you find it useful, let me know 😉

You can contact me on Twitter or through my email.