From 07252d09f40af27cc04494ea7081a41fe0fe2ede Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Wed, 27 Nov 2024 18:22:18 +0300 Subject: [PATCH 1/5] chore: Updated Dependencies Versions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b0708ead4..5fb65799b 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-mbstring": "*", "ext-fileinfo": "*", "ext-openssl": "*", - "webfiori/http": "v3.3.15", + "webfiori/http": "v3.4.0", "webfiori/file": "v1.3.6", "webfiori/jsonx": "v3.3.0", "webfiori/ui": "v2.6.3", From 434fd726657d7e4967681933bd718d60f68f2a76 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Wed, 27 Nov 2024 18:48:19 +0300 Subject: [PATCH 2/5] feat: Added Ability to Enable or Disable Cache --- webfiori/framework/cache/Cache.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/webfiori/framework/cache/Cache.php b/webfiori/framework/cache/Cache.php index f5d1bf861..5075685e9 100644 --- a/webfiori/framework/cache/Cache.php +++ b/webfiori/framework/cache/Cache.php @@ -19,6 +19,7 @@ class Cache { * @var Storage */ private $driver; + private $isEnabled; private static $inst; /** * Removes an item from the cache given its unique identifier. @@ -28,6 +29,15 @@ class Cache { public static function delete(string $key) { self::getDriver()->delete($key); } + /** + * Enable or disable caching. + * + * @param bool $enable If set to true, caching will be enabled. Other than + * that, caching will be disabled. + */ + public static function setEnabled(bool $enable) { + self::getInst()->isEnabled = $enable; + } /** * Removes all items from the cache. */ @@ -61,8 +71,11 @@ public static function get(string $key, callable $generator = null, int $ttl = 6 return null; } $newData = call_user_func_array($generator, $params); - $item = new Item($key, $newData, $ttl, defined('CACHE_SECRET') ? CACHE_SECRET : ''); - self::getDriver()->cache($item); + + if (self::isEnabled()) { + $item = new Item($key, $newData, $ttl, defined('CACHE_SECRET') ? CACHE_SECRET : ''); + self::getDriver()->cache($item); + } return $newData; } @@ -122,10 +135,20 @@ public static function set(string $key, $data, int $ttl = 60, bool $override = f if (!self::has($key) || $override === true) { $item = new Item($key, $data, $ttl, defined('CACHE_SECRET') ? CACHE_SECRET : ''); self::getDriver()->cache($item); + + return true; } return false; } + /** + * Checks if caching is enabled or not. + * + * @return bool True if enabled. False otherwise. + */ + public static function isEnabled() : bool { + return self::getInst()->isEnabled; + } /** * Sets storage engine which is used to store, read, update and delete items * from the cache. @@ -165,6 +188,7 @@ private static function getInst() : Cache { if (self::$inst === null) { self::$inst = new Cache(); self::setDriver(new FileStorage()); + self::setEnabled(true); } return self::$inst; From 277fed8f40ca247f7855a80517ad0a9496e61c9c Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Wed, 27 Nov 2024 18:48:36 +0300 Subject: [PATCH 3/5] test: Added More Tests to Cache --- phpunit.xml | 2 +- .../framework/test/cache/CacheTest.php | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 0ed2e9860..6d4c4976c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -29,7 +29,7 @@ ./webfiori/framework/router/Router.php ./webfiori/framework/cache/AbstractCacheStore.php - ./webfiori/framework/cache/FileCacheStore.php + ./webfiori/framework/cache/FileStorage.php ./webfiori/framework/cache/Cache.php ./webfiori/framework/session/Session.php diff --git a/tests/webfiori/framework/test/cache/CacheTest.php b/tests/webfiori/framework/test/cache/CacheTest.php index f65ef6645..1ce12410e 100644 --- a/tests/webfiori/framework/test/cache/CacheTest.php +++ b/tests/webfiori/framework/test/cache/CacheTest.php @@ -11,6 +11,7 @@ class CacheTest extends TestCase { */ public function test00() { $key = 'first'; + $this->assertTrue(Cache::isEnabled()); $data = Cache::get($key, function () { return 'This is a test.'; }); @@ -84,4 +85,62 @@ public function test05() { $this->assertFalse(Cache::has($key)); } } + /** + * @test + */ + public function test06() { + $key = 'bbuu'; + $this->assertTrue(Cache::isEnabled()); + Cache::setEnabled(false); + $data = Cache::get($key, function () { + return 'This is a test.'; + }); + $this->assertEquals('This is a test.', $data); + $this->assertNull(Cache::get($key)); + $this->assertFalse(Cache::isEnabled()); + } + /** + * @test + */ + public function testSet00() { + $key = 'new_cool_key'; + Cache::setEnabled(true); + $this->assertTrue(Cache::isEnabled()); + $this->assertTrue(Cache::set($key, 'This is a test.', 60, false)); + $this->assertEquals('This is a test.', Cache::get($key)); + $item = Cache::getItem($key); + $this->assertEquals(60, $item->getTTL()); + + $this->assertFalse(Cache::set($key, 'This is a test.', 60, false)); + $this->assertEquals('This is a test.', Cache::get($key)); + $item = Cache::getItem($key); + $this->assertEquals(60, $item->getTTL()); + + $this->assertTrue(Cache::set($key, 'This is a test 2.', 660, true)); + $this->assertEquals('This is a test 2.', Cache::get($key)); + $item = Cache::getItem($key); + $this->assertEquals(660, $item->getTTL()); + } + /** + * @test + */ + public function testSetTTL00() { + $key = 'new_cool_key2'; + Cache::setEnabled(true); + $this->assertTrue(Cache::isEnabled()); + $this->assertTrue(Cache::set($key, 'This is a test.', 60, false)); + $item = Cache::getItem($key); + $this->assertEquals(60, $item->getTTL()); + Cache::setTTL($key, 700); + + $item = Cache::getItem($key); + $this->assertEquals(700, $item->getTTL()); + } + /** + * @test + */ + public function testSetTTL01() { + $key = 'not exist cool'; + $this->assertFalse(Cache::setTTL($key, 700)); + } } From 6996f207c80f9883157c7f5cb1a5170bd327cd52 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Wed, 27 Nov 2024 18:52:08 +0300 Subject: [PATCH 4/5] ci: Added PHP 8.4 --- .github/workflows/php84.yml | 122 ++++++++++++++++++++++++++++++++++++ README.md | 5 +- 2 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/php84.yml diff --git a/.github/workflows/php84.yml b/.github/workflows/php84.yml new file mode 100644 index 000000000..3117109d9 --- /dev/null +++ b/.github/workflows/php84.yml @@ -0,0 +1,122 @@ +name: Build PHP 8.2 + +on: + push: + branches: [ master, dev ] + pull_request: + branches: [ master ] + +jobs: + + test: + runs-on: ${{ matrix.os }} + services: + sql.data: + image: mcr.microsoft.com/mssql/server:2019-latest + env: + SA_PASSWORD: 1234567890@Eu + ACCEPT_EULA: Y + MSSQL_PID: Express + ports: + - "1433:1433" + strategy: + fail-fast: true + matrix: + os: [ ubuntu-latest ] + php: [8.4] + + name: PHP${{matrix.php}} - ${{matrix.os}} + + steps: + - name: Clone Repo + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mysqli, mbstring, sqlsrv + tools: phpunit:9.5.20, composer, symplify/easy-coding-standard:12.0.6, phpbench/phpbench:1.2.14 + + - name: Shutdown Ubuntu MySQL + run: sudo service mysql stop + + - name: Set up MySQL + uses: mirromutth/mysql-action@v1.1 + with: + mysql version: '5.7' + mysql database: 'testing_db' + mysql root password: 123456 + mysql user: 'root' + mysql password: 123456 + + - name: Wait for MySQL + run: | + while ! mysqladmin ping --host=127.0.0.1 --password=123456 --silent; do + sleep 1 + done + + - name: Setup MSSQL + run: sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db' + + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction --no-dev + + - name: Execute Tests + run: phpunit + + - name: CodeCov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + coding_standards_check: + name: "Coding Standards Check" + needs: + - "test" + + runs-on: "ubuntu-latest" + steps: + - name: "Set up PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "8.1" + extensions: "mbstring" + tools: composer, symplify/easy-coding-standard:12.0.6 + + - name: "Checkout code" + uses: "actions/checkout@v3" + + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction --no-dev + + - name: "Check Style" + run: "ecs check" + + benchmarking: + needs: + - "test" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ ubuntu-latest ] + php: [8.0,8.1,8.2,8.3,8.4] + steps: + - name: Clone Repo + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring + tools: composer, phpbench/phpbench + + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction --no-dev + + - name: Benchmarking + run: phpbench run tests/webfiori/benchmark --report=default + + diff --git a/README.md b/README.md index cb26e3e53..6272d3c73 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

- + @@ -37,7 +37,8 @@ WebFiori Framework is a mini web development framework which is built using PHP || || || -|
| +|| +|
| ## Key Features From 2808d71750067ff6662bfe7104d517ae5c218417 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Wed, 27 Nov 2024 18:58:08 +0300 Subject: [PATCH 5/5] ci: Fix Steps Names --- .github/workflows/php83.yml | 2 ++ .github/workflows/php84.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php83.yml b/.github/workflows/php83.yml index 19ce53ba7..b53391c3d 100644 --- a/.github/workflows/php83.yml +++ b/.github/workflows/php83.yml @@ -119,6 +119,7 @@ jobs: - name: Benchmarking run: phpbench run tests/webfiori/benchmark --report=default release_staging: + name: Publish Beta needs: - "test" - "coding_standards_check" @@ -134,6 +135,7 @@ jobs: manifest-file: .release-please-manifest.json token: ${{ secrets.GITHUB_TOKEN }} release_prod: + name: Publish Production needs: - "test" - "coding_standards_check" diff --git a/.github/workflows/php84.yml b/.github/workflows/php84.yml index 3117109d9..42ddd1e21 100644 --- a/.github/workflows/php84.yml +++ b/.github/workflows/php84.yml @@ -1,4 +1,4 @@ -name: Build PHP 8.2 +name: Build PHP 8.4 on: push: