Skip to content

Commit 556cc3b

Browse files
committed
Initial commit
0 parents  commit 556cc3b

19 files changed

+848
-0
lines changed

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[composer.json]
2+
indent_size = 4
3+
4+
[*.php]
5+
indent_size = 4
6+
ij_php_force_empty_methods_in_one_line = true
7+
ij_php_phpdoc_blank_lines_around_parameters = true
8+
ij_php_align_key_value_pairs = true
9+
ij_php_align_class_constants = true
10+
ij_php_align_enum_cases = true
11+
ij_php_align_multiline_parameters_in_calls = false
12+
ij_php_keep_rparen_and_lbrace_on_one_line = true
13+
ij_php_align_phpdoc_comments = true
14+
ij_php_align_phpdoc_param_names = true
15+
ij_php_phpdoc_wrap_long_lines = true
16+
17+
[*.xml]
18+
indent_size = 2
19+
tab_width = 2
20+
ij_continuation_indent_size = 4
21+
22+
[*.md]
23+
indent_size = 2

.github/workflows/tests.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: PHP Tests
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
run:
12+
runs-on: ${{ matrix.operating-system }}
13+
14+
strategy:
15+
matrix:
16+
operating-system: [ ubuntu-latest ]
17+
php-version: [ '8.0', '8.1', '8.2' ]
18+
19+
name: PHP ${{ matrix.php-version }} test on ${{ matrix.operating-system }}
20+
21+
steps:
22+
- name: Checkout Code
23+
uses: actions/checkout@v3
24+
25+
- name: Install PHP
26+
id: php
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: ${{ matrix.php-version }}
30+
31+
- name: Check PHP version
32+
run: php -v
33+
34+
- name: Cache Composer packages
35+
id: composer-cache
36+
uses: actions/cache@v3
37+
with:
38+
path: vendor
39+
key: ${{ runner.os }}-${{ matrix.operating-system }}-php-${{ steps.php.outputs.php-version }}
40+
restore-keys: |
41+
${{ runner.os }}-${{ matrix.operating-system }}-php-${{ steps.php.outputs.php-version }}
42+
43+
- if: steps.composer-cache.outputs.cache-hit != 'true'
44+
name: Install Composer dependencies
45+
run: composer install --prefer-dist --no-progress
46+
47+
- name: PHPUnit Tests
48+
run: vendor/bin/phpunit --coverage-clover ./tests/coverage.xml
49+
50+
- name: Upload coverage reports to Codecov
51+
uses: codecov/codecov-action@v3
52+
with:
53+
token: ${{ secrets.CODECOV_TOKEN }}
54+
files: ./tests/coverage.xml
55+
flags: os-${{ matrix.operating-system }}_php-${{ matrix.php-version }}
56+
verbose: true

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# IDEs
2+
.idea/
3+
4+
# Composer
5+
vendor/
6+
composer.lock
7+
8+
# PHPUnit
9+
.phpunit.result.cache
10+
tests/coverage/
11+
tests/tmp/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Okapi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!--suppress HtmlDeprecatedAttribute -->
2+
<h1 align="center">PHP Path</h1>
3+
4+
<!-- Main Badges -->
5+
<p align="center">
6+
<!-- License: MIT -->
7+
<a href="https://opensource.org/licenses/MIT" target="_blank">
8+
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-9C0000.svg?labelColor=ebdbb2&style=flat&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNCIgaGVpZ2h0PSIxNCI+PHBhdGggdmVjdG9yLWVmZmVjdD0ibm9uLXNjYWxpbmctc3Ryb2tlIiBkPSJNMCAyLjk5NWgxLjI4djguMDFIMHpNMi41NCAzaDEuMjh2NS4zNEgyLjU0em0yLjU1LS4wMDVoMS4yOHY4LjAxSDUuMDl6bTIuNTQuMDA3aDEuMjh2MS4zMzZINy42M3oiIGZpbGw9IiM5YzAwMDAiLz48cGF0aCB2ZWN0b3ItZWZmZWN0PSJub24tc2NhbGluZy1zdHJva2UiIGQ9Ik03LjYzIDUuNjZoMS4yOFYxMUg3LjYzeiIgZmlsbD0iIzdjN2Q3ZSIvPjxwYXRoIHZlY3Rvci1lZmZlY3Q9Im5vbi1zY2FsaW5nLXN0cm9rZSIgZD0iTTEwLjE3NyAzLjAwMmgzLjgyNnYxLjMzNmgtMy44MjZ6bS4wMDMgMi42NThoMS4yOFYxMWgtMS4yOHoiIGZpbGw9IiM5YzAwMDAiLz48L3N2Zz4="/>
9+
</a>
10+
11+
<!-- Twitter: @WalterWoshid -->
12+
<a href="https://twitter.com/WalterWoshid" target="_blank">
13+
<img alt="Twitter: @WalterWoshid" src="https://img.shields.io/badge/@WalterWoshid-Twitter?labelColor=ebdbb2&style=flat&logo=twitter&logoColor=458588&color=458588&label=Twitter"/>
14+
</a>
15+
16+
<!-- PHP: >=8.0 -->
17+
<a href="https://www.php.net" target="_blank">
18+
<img alt="PHP: >=8.0" src="https://img.shields.io/badge/PHP->=8.0-4C5789.svg?labelColor=ebdbb2&style=flat&logo=php&logoColor=4C5789"/>
19+
</a>
20+
21+
<!-- Packagist -->
22+
<a href="https://packagist.org/packages/okapi/filesystem" target="_blank">
23+
<img alt="Packagist" src="https://img.shields.io/packagist/v/okapi/filesystem?label=Packagist&labelColor=ebdbb2&style=flat&color=fe8019&logo=packagist"/>
24+
</a>
25+
26+
<!-- Build -->
27+
<!--suppress HtmlUnknownTarget -->
28+
<a href="../../actions/workflows/tests.yml" target="_blank">
29+
<img alt="Build" src="https://img.shields.io/github/actions/workflow/status/okapi-web/php-filesystem/tests.yml?label=Build&labelColor=ebdbb2&style=flat&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgdmlld0JveD0iMCAwIDUxMiA1MTIiIGhlaWdodD0iMTYiPjxwYXRoIGZpbGw9IiM2YWFiMjAiIGQ9Ik0zMy45MTQgNDEzLjYxMmgxNDkuNTV2MjcuNTk1SDI3LjQ5NGMtMjYuMzQ4IDAtMzQuMTM2LTEzLjE5NC0yMS43MjktMzQuMzFMMTM3LjkxIDE4Ny43NTNWNjEuOTc1aC0yNi4wNzVjLTE5LjUwNCAwLTE5LjUwNC0yNy41OTUgMC0yNy41OTVoMTg5LjkzYzE5LjUwNSAwIDE5LjUwNSAyNy41OTUgMCAyNy41OTVIMjc1LjY5djEzMi44MjhoLTI3Ljk2M1Y2MS45NzVoLTgxLjg1NHYxMzIuODI4TDMzLjkxNCA0MTMuNjEyem0xMzUuNi0xNjkuMTg3TDg0LjY5MiAzODYuNTc0aDcwLjYwMWwxMDQuMzc1LTExMi45MDctMTUuNTgyLTI5LjI0MmgtNzQuNTd6bTE0NS45OTYgOS43ODNMMjA5LjUgMzY3LjUwNmwxMDYuMDEgMTEwLjI4NiAzMy41MzgtMzMuNTM4LTgwLjY1LTc2Ljc0OCA4MC42NS03OS43Ni0zMy41MzgtMzMuNTM4em01Ni45NDMgMzMuNTM3IDgwLjY1IDc5Ljc2LTgwLjY1IDc2Ljc1IDMzLjUzOCAzMy41MzdMNTEyIDM2Ny41MDYgNDA1Ljk5IDI1NC4yMDhsLTMzLjUzNyAzMy41Mzd6Ii8+PC9zdmc+">
30+
</a>
31+
</p>
32+
33+
<!-- Coverage -->
34+
<p align="center">
35+
<!-- Coverage - PHP 8.0 -->
36+
<a href="https://app.codecov.io/gh/okapi-web/php-filesystem/flags" target="_blank">
37+
<img alt="Coverage - PHP 8.0" src="https://img.shields.io/codecov/c/github/okapi-web/php-filesystem?flag=os-ubuntu-latest_php-8.0&label=Coverage - PHP 8.0&labelColor=ebdbb2&style=flat&logo=codecov&logoColor=FFC107&color=FFC107"/>
38+
</a>
39+
40+
<!-- Coverage - PHP 8.1 -->
41+
<a href="https://app.codecov.io/gh/okapi-web/php-filesystem/flags" target="_blank">
42+
<img alt="Coverage - PHP 8.1" src="https://img.shields.io/codecov/c/github/okapi-web/php-filesystem?flag=os-ubuntu-latest_php-8.1&label=Coverage - PHP 8.1&labelColor=ebdbb2&style=flat&logo=codecov&logoColor=FFC107&color=FFC107"/>
43+
</a>
44+
45+
<!-- Coverage - PHP 8.2 -->
46+
<a href="https://app.codecov.io/gh/okapi-web/php-filesystem/flags" target="_blank">
47+
<img alt="Coverage - PHP 8.2" src="https://img.shields.io/codecov/c/github/okapi-web/php-filesystem?flag=os-ubuntu-latest_php-8.2&label=Coverage - PHP 8.2&labelColor=ebdbb2&style=flat&logo=codecov&logoColor=FFC107&color=FFC107"/>
48+
</a>
49+
</p>
50+
51+
<h2 align="center">PHP Filesystem is a PHP library that provides an abstraction layer for the filesystem.</h2>
52+
<h3 align="center">It is based on <a href="https://nodejs.org/api/fs.html">Node.js's filesystem module.</a></h3>
53+
54+
55+
56+
## Installation
57+
58+
```shell
59+
composer require okapi/filesystem
60+
```
61+
62+
63+
64+
# Usage
65+
66+
```php
67+
<?php
68+
69+
use Okapi\Filesystem\Filesystem;
70+
71+
// Write file
72+
Filesystem::writeFile('./path/to/file.txt', 'Hello World!');
73+
74+
75+
// Read file
76+
$contents = Filesystem::readFile('./path/to/file.txt');
77+
78+
79+
// Remove directory or file
80+
Filesystem::rm(
81+
'./path',
82+
recursive: true,
83+
force: true,
84+
);
85+
86+
// Create directory
87+
Filesystem::mkdir(
88+
'./path/to/directory',
89+
recursive: true,
90+
mode: 0777,
91+
);
92+
```
93+
94+
95+
96+
## Testing
97+
98+
- Run `composer run-script test`<br>
99+
or
100+
- Run `composer run-script test-coverage`
101+
102+
103+
104+
## Show your support
105+
106+
Give a ⭐ if this project helped you!
107+
108+
109+
110+
## 📝 License
111+
112+
Copyright © 2023 [Valentin Wotschel](https://github.com/WalterWoshid).<br>
113+
This project is [MIT](https://opensource.org/licenses/MIT) licensed.

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "okapi/filesystem",
3+
"description": "PHP Filesystem is a PHP library that provides an abstraction layer for the filesystem.",
4+
"version": "1.0.0",
5+
"type": "library",
6+
"homepage": "https://github.com/okapi-web/php-filesystem",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "WalterWoshid",
11+
"email": "[email protected]",
12+
"homepage": "https://github.com/WalterWoshid"
13+
}
14+
],
15+
"keywords": [
16+
"filesystem",
17+
"file",
18+
"directory",
19+
"folder",
20+
"php"
21+
],
22+
"scripts": {
23+
"test": "phpunit",
24+
"test-coverage": "phpunit --coverage-html tests/coverage"
25+
},
26+
"require": {
27+
"php": ">=8.0"
28+
},
29+
"require-dev": {
30+
"phpunit/phpunit": ">=9.0",
31+
"jetbrains/phpstorm-attributes": "^1.0"
32+
},
33+
"autoload": {
34+
"psr-4": {
35+
"Okapi\\Filesystem\\": "src/"
36+
}
37+
},
38+
"autoload-dev": {
39+
"psr-4": {
40+
"Okapi\\Filesystem\\Tests\\": "tests/"
41+
}
42+
}
43+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Tests">
9+
<directory>tests/</directory>
10+
</testsuite>
11+
</testsuites>
12+
13+
<coverage>
14+
<include>
15+
<directory suffix=".php">src/</directory>
16+
</include>
17+
</coverage>
18+
</phpunit>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Okapi\Filesystem\Exception;
4+
5+
/**
6+
* # Directory Not Empty Exception
7+
*
8+
* Thrown when a directory is not empty.
9+
*/
10+
class DirectoryNotEmptyException extends FilesystemException
11+
{
12+
/**
13+
* DirectoryNotEmptyException constructor.
14+
*
15+
* @param string $path
16+
*/
17+
public function __construct(string $path)
18+
{
19+
parent::__construct("Directory '$path' is not empty.");
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Okapi\Filesystem\Exception;
4+
5+
/**
6+
* # File exists exception
7+
*
8+
* Thrown when a file already exists.
9+
*/
10+
class FileExistsException extends FilesystemException
11+
{
12+
/**
13+
* FileExistsException constructor.
14+
*
15+
* @param string $path
16+
*/
17+
public function __construct(string $path)
18+
{
19+
parent::__construct("Cannot create directory '$path': File exists.");
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Okapi\Filesystem\Exception;
4+
5+
/**
6+
* # File Not Found Exception
7+
*
8+
* This exception is thrown when a file is not found.
9+
*/
10+
class FileNotFoundException extends FilesystemException
11+
{
12+
/**
13+
* FileNotFoundException constructor.
14+
*
15+
* @param string $path
16+
*/
17+
public function __construct(string $path)
18+
{
19+
parent::__construct("File '$path' not found.");
20+
}
21+
}

0 commit comments

Comments
 (0)