From df7b7fb56be25df35163871800ed9a24a8ba1276 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Mon, 21 Aug 2023 20:26:35 +0300 Subject: [PATCH 1/3] Made Method File::createResource() Static --- webfiori/file/File.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/webfiori/file/File.php b/webfiori/file/File.php index 1c3d5fa..5f8b135 100644 --- a/webfiori/file/File.php +++ b/webfiori/file/File.php @@ -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.'\'.'); @@ -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(); @@ -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).'); @@ -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); } } From b41ae9640c4d650fd62af17e4c54cc77b984fe46 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Mon, 4 Dec 2023 00:18:49 +0300 Subject: [PATCH 2/3] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 807c441..73d1b1b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ composer.lock php-cs-fixer-v2.phar .idea/* +php-cs-fixer.phar From 340fd96370b8d97bc79fc985e7fad5bf58b59122 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Mon, 4 Dec 2023 00:23:23 +0300 Subject: [PATCH 3/3] Added PHP 8.3 --- .github/workflows/php83.yml | 42 +++++++++++++++++++++++++++++++++++++ README.md | 19 +++++++++-------- 2 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/php83.yml diff --git a/.github/workflows/php83.yml b/.github/workflows/php83.yml new file mode 100644 index 0000000..e201b68 --- /dev/null +++ b/.github/workflows/php83.yml @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index c5a187b..5999bf4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Basic class library to read, write and view files using PHP.

- + @@ -35,14 +35,15 @@ Basic class library to read, write and view files using PHP. ## Supported PHP Versions | Build Status | |:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| -| | -| | -| | -| | -| | -| | -| | -| | +| | +| | +| | +| | +| | +| | +| | +| | +| | ## 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.