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..41b8f74 100644 --- a/README.md +++ b/README.md @@ -8,36 +8,41 @@ [![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) - DotKernel session component extending and customizing [laminas-session](https://github.com/laminas/laminas-session) ## Installation 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 + 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 +74,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..3393342 --- /dev/null +++ b/docs/book/v5/configuration.md @@ -0,0 +1,9 @@ +# 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..dbc5f4c --- /dev/null +++ b/docs/book/v5/usage/factory.md @@ -0,0 +1,69 @@ +# 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) + ) + } +} +``` + +## Step 2: Access through your Service + +```php + +class ExampleService +{ + private SessionManager $session; + + public function __construct(SessionManager $session) + { + $this->session = $session; + } + + //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 new file mode 100644 index 0000000..cf3b68c --- /dev/null +++ b/docs/book/v5/usage/injection.md @@ -0,0 +1,60 @@ +# Method #2 - Injection + +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 + +class ExampleService +{ + private SessionManager $session; + + /** + * @Dot\AnnotatedServices\Annotation\Inject({ + * SessionManager::class, + * }) + */ + public function __construct(SessionManager $session) + { + $this->session = $session; + } + + //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, + ], + ]; + } +} +``` diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..1e0d7a0 --- /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: + - Installation: v5/installation.md + - Configuration: v5/configuration.md + - Usage: v5/usage.md + - Reference: + - "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" +plugins: + - search diff --git a/test/Factory/ContainerAbstractServiceFactoryTest.php b/test/Factory/ContainerAbstractServiceFactoryTest.php index cb4a6ad..b76f22f 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);