Skip to content

Commit

Permalink
Merge pull request #17 from WebFiori/dev
Browse files Browse the repository at this point in the history
Added PHP 8.3
  • Loading branch information
usernane committed Dec 3, 2023
2 parents fb98ded + 340fd96 commit 6517957
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 14 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/php83.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build PHP 8.3

on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [8.3]

name: PHP${{matrix.php}} - ${{matrix.os}}

steps:
- name: Clone Repo
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysqli, mbstring, sqlsrv
tools: phpunit:9.5.20, composer

- name: Shutdown Ubuntu MySQL
run: sudo service mysql stop

- name: Install Dependencies
run: composer install --prefer-dist --no-interaction

- name: Execute Tests
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
composer.lock
php-cs-fixer-v2.phar
.idea/*
php-cs-fixer.phar
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Basic class library to read, write and view files using PHP.

<p align="center">
<a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php82.yml">
<img src="https://github.com/WebFiori/file/workflows/Build%20PHP%208.2/badge.svg?branch=main">
<img src="https://github.com/WebFiori/file/actions/workflows/php82.yml/badge.svg?branch=main">
</a>
<a href="https://codecov.io/gh/WebFiori/file">
<img src="https://codecov.io/gh/WebFiori/file/branch/main/graph/badge.svg" />
Expand Down Expand Up @@ -35,14 +35,15 @@ Basic class library to read, write and view files using PHP.
## Supported PHP Versions
| Build Status |
|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php70.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%207.0/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php71.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%207.1/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php72.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%207.2/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php73.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%207.3/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php74.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%207.4/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php80.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%208.0/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php81.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%208.1/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php82.yml"><img src="https://github.com/WebFiori/file/workflows/Build%20PHP%208.2/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php70.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php70.yml?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php71.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php71.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php72.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php72.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php73.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php73.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php74.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php74.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php80.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php80.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php81.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php81.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php82.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php82.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/file/actions/workflows/php83.yml"><img src="https://github.com/WebFiori/file/actions/workflows/php83.yml/badge.svg?branch=main"></a> |

## Main Aim of The Library
The main aim of the library is to have an OOP abstraction that simplifies most common operations with files in PHP.
Expand Down
18 changes: 13 additions & 5 deletions webfiori/file/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function create(bool $createDirIfNotExist = false) {

if (!$this->isExist()) {
self::isDirectory($this->getDir(), $createDirIfNotExist);
$resource = $this->createResource('wb', $fPath);
$resource = self::createResource('wb', $fPath);

if (!is_resource($resource)) {
throw new FileException('Unable to create a file at \''.$fPath.'\'.');
Expand Down Expand Up @@ -847,7 +847,15 @@ private function checkNameAndPath(): string {
}
throw new FileException('File name cannot be empty string.');
}
private function createResource($mode, $path) {
/**
*
* @param string $mode
*
* @param string $path
*
* @return bool|resource
*/
public static function createResource(string $mode, string $path) {
set_error_handler(self::$errFunc);
$resource = fopen($path, $mode);
restore_error_handler();
Expand Down Expand Up @@ -929,7 +937,7 @@ private function readHelper($fPath,$from,$to) {
$fSize = filesize($fPath);
$this->setSize($fSize);
$bytesToRead = $to - $from > 0 ? $to - $from : $this->getSize();
$resource = $this->createResource('rb', $fPath);
$resource = self::createResource('rb', $fPath);

if ($bytesToRead > $this->getSize() || $to > $this->getSize()) {
throw new FileException('Reached end of file while trying to read '.$bytesToRead.' byte(s).');
Expand Down Expand Up @@ -1052,9 +1060,9 @@ private function writeHelper(string $fPath, bool $append, bool $encode = false)
throw new FileException("File not found: '$fPath'.");
} else {
if ($append) {
$resource = $this->createResource('ab', $fPath);
$resource = self::createResource('ab', $fPath);
} else {
$resource = $this->createResource('rb+', $fPath);
$resource = self::createResource('rb+', $fPath);
}
}

Expand Down

0 comments on commit 6517957

Please sign in to comment.