From c497c1d2503247b98fe5d6643b9a8fda131c30ed Mon Sep 17 00:00:00 2001 From: bidi Date: Fri, 5 Apr 2024 16:12:34 +0300 Subject: [PATCH 1/7] updated docs, workflow --- .github/workflows/continuous-integration.yml | 11 +++++ .github/workflows/cs-tests.yml | 47 -------------------- .github/workflows/docs-build.yml | 16 +++++++ .github/workflows/static-analysis.yml | 47 -------------------- .github/workflows/unit-tests.yml | 47 -------------------- README.md | 12 ++--- SECURITY.md | 36 +++++++++++++++ composer.json | 3 +- docs/book/index.md | 1 + docs/book/v5/configuration.md | 8 ++++ docs/book/v5/installation.md | 5 +++ docs/book/v5/usage.md | 6 +++ docs/book/v5/usage/factory.md | 36 +++++++++++++++ docs/book/v5/usage/injection.md | 23 ++++++++++ mkdocs.yml | 21 +++++++++ 15 files changed, 171 insertions(+), 148 deletions(-) create mode 100644 .github/workflows/continuous-integration.yml delete mode 100644 .github/workflows/cs-tests.yml create mode 100644 .github/workflows/docs-build.yml delete mode 100644 .github/workflows/static-analysis.yml delete mode 100644 .github/workflows/unit-tests.yml create mode 100644 SECURITY.md create mode 100644 docs/book/index.md create mode 100644 docs/book/v5/configuration.md create mode 100644 docs/book/v5/installation.md create mode 100644 docs/book/v5/usage.md create mode 100644 docs/book/v5/usage/factory.md create mode 100644 docs/book/v5/usage/injection.md create mode 100644 mkdocs.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..26c5802 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,11 @@ +name: "Continuous Integration" + +on: + pull_request: + push: + branches: + tags: + +jobs: + ci: + uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml deleted file mode 100644 index e8bbade..0000000 --- a/.github/workflows/cs-tests.yml +++ /dev/null @@ -1,47 +0,0 @@ -on: - - push - -name: Run phpcs checks - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - "8.3" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run phpcs checks - run: vendor/bin/phpcs diff --git a/.github/workflows/docs-build.yml b/.github/workflows/docs-build.yml new file mode 100644 index 0000000..1a7aa24 --- /dev/null +++ b/.github/workflows/docs-build.yml @@ -0,0 +1,16 @@ +name: docs-build + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + build-deploy: + runs-on: ubuntu-latest + steps: + - name: Build Docs + uses: dotkernel/documentation-theme/github-actions/docs@main + env: + DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index 6f7452d..0000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,47 +0,0 @@ -on: - - push - -name: Run static analysis - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - "8.3" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run static analysis - run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 8f6f990..0000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,47 +0,0 @@ -on: - - push - -name: Run PHPUnit tests - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - "8.3" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run PHPUnit tests - run: vendor/bin/phpunit --colors=always diff --git a/README.md b/README.md index 4a59c5b..34a7101 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ [![SymfonyInsight](https://insight.symfony.com/projects/f6038340-d76b-4da8-9016-0472d4899f0a/big.svg)](https://insight.symfony.com/projects/f6038340-d76b-4da8-9016-0472d4899f0a) - DotKernel session component extending and customizing [laminas-session](https://github.com/laminas/laminas-session) ## Installation @@ -22,22 +21,22 @@ Run the following command in your project folder composer require dotkernel/dot-session - ## Configuration + Register `SessionMiddleware` in your application's pipeline by adding the following line to `config/pipeline.php`: $app->pipe(Dot\Session\SessionMiddleware::class); - Register `dot-session`'s ConfigProvider in your application's configurations by adding the following line to `config/config.php`: \Dot\Session\ConfigProvider::class, - ## Usage + Basic usage to access and use the session object in your services: ### Method #1 - Factory + #### Step 1: Create a factory that retrieves the SessionManger from the container ```php @@ -69,11 +68,12 @@ class ExampleService $this->session = $session; } - //you methods + //your methods } ``` -### Method 2 - Injection +### Method #2 - Injection + If you use annotated injection you can inject the Session Manager in your services. ```php diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..90d6095 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,36 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | PHP Version | +|---------|--------------------|-------------------------------------------------------------------------------------------------------------| +| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-session/5.4.2) | +| <= 4.x | :x: | | + +## Reporting Potential Security Issues + +If you have encountered a potential security vulnerability in this project, +please report it to us at . We will work with you to +verify the vulnerability and patch it. + +When reporting issues, please provide the following information: + +- Component(s) affected +- A description indicating how to reproduce the issue +- A summary of the security vulnerability and impact + +We request that you contact us via the email address above and give the +project contributors a chance to resolve the vulnerability and issue a new +release prior to any public exposure; this helps protect the project's +users, and provides them with a chance to upgrade and/or update in order to +protect their applications. + +## Policy + +If we verify a reported security vulnerability, our policy is: + +- We will patch the current release branch, as well as the immediate prior minor + release branch. + +- After patching the release branches, we will immediately issue new security + fix releases for each patched release branch. diff --git a/composer.json b/composer.json index 77b25c5..e8c4ef6 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "laminas/laminas-dependency-plugin": false } } } diff --git a/docs/book/index.md b/docs/book/index.md new file mode 100644 index 0000000..ae42a26 --- /dev/null +++ b/docs/book/index.md @@ -0,0 +1 @@ +../../README.md diff --git a/docs/book/v5/configuration.md b/docs/book/v5/configuration.md new file mode 100644 index 0000000..456624c --- /dev/null +++ b/docs/book/v5/configuration.md @@ -0,0 +1,8 @@ +# Configuration +Register `SessionMiddleware` in your application's pipeline by adding the following line to `config/pipeline.php`: + + $app->pipe(Dot\Session\SessionMiddleware::class); + +Register `dot-session`'s ConfigProvider in your application's configurations by adding the following line to `config/config.php`: + + \Dot\Session\ConfigProvider::class, diff --git a/docs/book/v5/installation.md b/docs/book/v5/installation.md new file mode 100644 index 0000000..31c68dd --- /dev/null +++ b/docs/book/v5/installation.md @@ -0,0 +1,5 @@ +# Installation + +Run the following command in your project folder + + composer require dotkernel/dot-session diff --git a/docs/book/v5/usage.md b/docs/book/v5/usage.md new file mode 100644 index 0000000..740e550 --- /dev/null +++ b/docs/book/v5/usage.md @@ -0,0 +1,6 @@ +# Usage + +Basic usage to access and use the session object in your services: + +* [Method #1 - Factory](usage/factory.md) +* [Method #2 - Injection](usage/injection.md) diff --git a/docs/book/v5/usage/factory.md b/docs/book/v5/usage/factory.md new file mode 100644 index 0000000..c838f9d --- /dev/null +++ b/docs/book/v5/usage/factory.md @@ -0,0 +1,36 @@ +# Method #1 - Factory + +## Step 1: Create a factory that retrieves the SessionManger from the container + +```php +class ExampleFactory +{ + // code + + public function __invoke(ContainerInterface $container) + { + return new ExampleService( + $container->get(SessionManager::class) + ) + } +} +``` + +Register the factory in any mode you register factories on your project. + +## Step 2: Access through your Service + +```php + +class ExampleService +{ + private SessionManager $session; + + public function __construct(SessionManager $session) + { + $this->session = $session; + } + + //your methods +} +``` diff --git a/docs/book/v5/usage/injection.md b/docs/book/v5/usage/injection.md new file mode 100644 index 0000000..dcad32e --- /dev/null +++ b/docs/book/v5/usage/injection.md @@ -0,0 +1,23 @@ +# Method #2 - Injection + +If you use annotated injection you can inject the Session Manager in your services. + +```php +use Dot\AnnotatedServices\Annotation\Inject; +use Laminas\Session\SessionManager; + +class ExampleService +{ + private SessionManager $session; + + /** + * @Inject({SessionManager::class}) + */ + public function __construct(SessionManager $session) + { + $this->session = $session; + } + + //your methods +} +``` diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..58dab10 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,21 @@ +docs_dir: docs/book +site_dir: docs/html +extra: + project: Packages + current_version: v5 + versions: + - v5 +nav: + - Home: index.md + - v5: + - Overview: v5/installation.md + - Installation: v5/configuration.md + - Usage: v5/usage.md + - Reference: + - "Inject class dependencies": v5/usage/factory.md + - "Inject entity repositories": v5/usage/injection.md +site_name: dot-session +site_description: "DotKernel's session component" +repo_url: "https://github.com/dotkernel/dot-session" +plugins: + - search From 87682e37a4d1309de22dbd4856809ebdc3c5ccd4 Mon Sep 17 00:00:00 2001 From: bidi Date: Fri, 5 Apr 2024 20:16:44 +0300 Subject: [PATCH 2/7] updated docs --- README.md | 6 ++++++ docs/book/v5/configuration.md | 1 + 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 34a7101..54d11d5 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,23 @@ DotKernel session component extending and customizing [laminas-session](https:// Run the following command in your project folder +```bash composer require dotkernel/dot-session +``` ## Configuration Register `SessionMiddleware` in your application's pipeline by adding the following line to `config/pipeline.php`: +```php $app->pipe(Dot\Session\SessionMiddleware::class); +``` Register `dot-session`'s ConfigProvider in your application's configurations by adding the following line to `config/config.php`: +```php \Dot\Session\ConfigProvider::class, +``` ## Usage diff --git a/docs/book/v5/configuration.md b/docs/book/v5/configuration.md index 456624c..3393342 100644 --- a/docs/book/v5/configuration.md +++ b/docs/book/v5/configuration.md @@ -1,4 +1,5 @@ # Configuration + Register `SessionMiddleware` in your application's pipeline by adding the following line to `config/pipeline.php`: $app->pipe(Dot\Session\SessionMiddleware::class); From d783ef21f0bf6bdb5c1d6d8783634ddc62d64b7a Mon Sep 17 00:00:00 2001 From: bidi Date: Mon, 8 Apr 2024 12:15:08 +0300 Subject: [PATCH 3/7] updated tests --- test/Factory/ContainerAbstractServiceFactoryTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Factory/ContainerAbstractServiceFactoryTest.php b/test/Factory/ContainerAbstractServiceFactoryTest.php index cb4a6ad..d89d075 100644 --- a/test/Factory/ContainerAbstractServiceFactoryTest.php +++ b/test/Factory/ContainerAbstractServiceFactoryTest.php @@ -43,8 +43,9 @@ public function testInstantiate(): void $this->container->expects($this->once()) ->method('get') - ->with(ManagerInterface::class) - ->willReturnMap([ManagerInterface::class]); + ->willReturnMap([ + [ManagerInterface::class => ManagerInterface::class] + ]); $factory = (new ContainerAbstractServiceFactory())($this->container, 'dot-session.test'); $this->assertInstanceOf(Container::class, $factory); From 325fe1f21d383e17b97c476a4c3c80e466a10dc5 Mon Sep 17 00:00:00 2001 From: bidi Date: Mon, 8 Apr 2024 12:27:17 +0300 Subject: [PATCH 4/7] updated tests --- test/Factory/ContainerAbstractServiceFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Factory/ContainerAbstractServiceFactoryTest.php b/test/Factory/ContainerAbstractServiceFactoryTest.php index d89d075..b76f22f 100644 --- a/test/Factory/ContainerAbstractServiceFactoryTest.php +++ b/test/Factory/ContainerAbstractServiceFactoryTest.php @@ -44,7 +44,7 @@ public function testInstantiate(): void $this->container->expects($this->once()) ->method('get') ->willReturnMap([ - [ManagerInterface::class => ManagerInterface::class] + [ManagerInterface::class => ManagerInterface::class], ]); $factory = (new ContainerAbstractServiceFactory())($this->container, 'dot-session.test'); From a33f3293ee1fcbd0afebdfccbf16bc97d39339f3 Mon Sep 17 00:00:00 2001 From: bidi Date: Mon, 8 Apr 2024 16:31:38 +0300 Subject: [PATCH 5/7] updated documentation --- docs/book/v5/usage/factory.md | 37 ++++++++++++++++++++++++-- docs/book/v5/usage/injection.md | 47 +++++++++++++++++++++++++++++---- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/docs/book/v5/usage/factory.md b/docs/book/v5/usage/factory.md index c838f9d..dbc5f4c 100644 --- a/docs/book/v5/usage/factory.md +++ b/docs/book/v5/usage/factory.md @@ -16,8 +16,6 @@ class ExampleFactory } ``` -Register the factory in any mode you register factories on your project. - ## Step 2: Access through your Service ```php @@ -34,3 +32,38 @@ class ExampleService //your methods } ``` + +## Step 3: Register the factory + +Open the ConfigProvider of the module where your repository resides. + +Add a new entry under `factories`, where the key is your service's FQCN and the value is your factory's FQCN. + +See below example for a better understanding of the file structure. + +```php + $this->getDependencies(), + ]; + } + + public function getDependencies(): array + { + return [ + 'factories' => [ + ExampleService::class => ExampleFactory::class, + ], + ]; + } +} +``` diff --git a/docs/book/v5/usage/injection.md b/docs/book/v5/usage/injection.md index dcad32e..cf3b68c 100644 --- a/docs/book/v5/usage/injection.md +++ b/docs/book/v5/usage/injection.md @@ -1,17 +1,19 @@ # Method #2 - Injection -If you use annotated injection you can inject the Session Manager in your services. +If you are using [dot-annotated-services](https://github.com/dotkernel/dot-annotated-services/) in your project, you don't need to create a separate factory, just follow the below steps. + +## Step 1: Access through your Service ```php -use Dot\AnnotatedServices\Annotation\Inject; -use Laminas\Session\SessionManager; class ExampleService { private SessionManager $session; - /** - * @Inject({SessionManager::class}) + /** + * @Dot\AnnotatedServices\Annotation\Inject({ + * SessionManager::class, + * }) */ public function __construct(SessionManager $session) { @@ -21,3 +23,38 @@ class ExampleService //your methods } ``` + +## Step 2: Register your service + +Open the ConfigProvider of the module where your repository resides. + +Add a new entry under `factories`, where the key is your service's FQCN and the value is `Dot\AnnotatedServices\Factory\AbstractAnnotatedFactory`. + +See below example for a better understanding of the file structure. + +```php + $this->getDependencies(), + ]; + } + + public function getDependencies(): array + { + return [ + 'factories' => [ + ExampleService::class => AbstractAnnotatedFactory::class, + ], + ]; + } +} +``` From 99829d132efaca369486664007f7464237cba91f Mon Sep 17 00:00:00 2001 From: bidi Date: Tue, 9 Apr 2024 12:05:34 +0300 Subject: [PATCH 6/7] updated documentation --- mkdocs.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 58dab10..1e0d7a0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -8,12 +8,12 @@ extra: nav: - Home: index.md - v5: - - Overview: v5/installation.md - - Installation: v5/configuration.md + - Installation: v5/installation.md + - Configuration: v5/configuration.md - Usage: v5/usage.md - Reference: - - "Inject class dependencies": v5/usage/factory.md - - "Inject entity repositories": v5/usage/injection.md + - "Inject using a factory": v5/usage/factory.md + - "Inject using dot-annotated-services": v5/usage/injection.md site_name: dot-session site_description: "DotKernel's session component" repo_url: "https://github.com/dotkernel/dot-session" From 8097a72b0aa3e1987ade85e8b89ab33c684fb8cc Mon Sep 17 00:00:00 2001 From: bidi Date: Thu, 11 Apr 2024 15:01:15 +0300 Subject: [PATCH 7/7] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54d11d5..41b8f74 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-session)](https://github.com/dotkernel/dot-session/stargazers) [![GitHub license](https://img.shields.io/github/license/dotkernel/dot-session)](https://github.com/dotkernel/dot-session/blob/5.0/LICENSE.md) -[![Build Static](https://github.com/dotkernel/dot-session/actions/workflows/static-analysis.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-session/actions/workflows/static-analysis.yml) +[![Build Static](https://github.com/dotkernel/dot-session/actions/workflows/continuous-integration.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-session/actions/workflows/continuous-integration.yml) [![codecov](https://codecov.io/gh/dotkernel/dot-session/graph/badge.svg?token=DCHKH0R4AA)](https://codecov.io/gh/dotkernel/dot-session) [![SymfonyInsight](https://insight.symfony.com/projects/f6038340-d76b-4da8-9016-0472d4899f0a/big.svg)](https://insight.symfony.com/projects/f6038340-d76b-4da8-9016-0472d4899f0a)