Skip to content

Commit

Permalink
Cleanup (yiisoft#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Nov 4, 2020
1 parent d318c40 commit 1605ff8
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 151 deletions.
File renamed without changes.
25 changes: 0 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
tests:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
env:
extensions: curl, mbstring, dom, intl, json, libxml, xml, xmlwriter
key: cache-v1

runs-on: ${{ matrix.os }}
Expand All @@ -27,30 +26,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov
tools: composer:v2

- name: Determine composer cache directory on Linux
if: matrix.os == 'ubuntu-latest'
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fcookies%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/cookies/master)
[![static analysis](https://github.com/yiisoft/cookies/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/cookies/actions?query=workflow%3A%22static+analysis%22)

The package ...
The package helps in working with HTTP cookies in a [PSR-7](https://www.php-fig.org/psr/psr-7/) environment:

- provides a handy abstraction representing a cookie
- allows dealing with many cookies at once
- forms and adds `Set-Cookie` headers to response

## Installation

Expand All @@ -26,6 +30,36 @@ composer install yiisoft/cookies

## General usage

Adding a cookie to response:

```php
$cookie = (new \Yiisoft\Cookies\Cookie('cookieName', 'value'))
->withPath('/')
->withDomain('yiiframework.com')
->withHttpOnly(true)
->withSecure(true)
->withSameSite(\Yiisoft\Cookies\Cookie::SAME_SITE_STRICT)
->withMaxAge(new \DateInterval('P7D'));

$response = $cookie->addToResponse($response);
```

Modifying response cookies to be sent:

```php
$cookies = \Yiisoft\Cookies\CookieCollection::fromResponse($response);
$cookies->expire('login');
$response = $cookies->setToResponse($response);
```

Getting request cookies:

```php
$cookies = \Yiisoft\Cookies\CookieCollection::fromArray($request->getCookieParams());
```

See [Yii guide to cookies](https://github.com/yiisoft/docs/blob/master/guide/en/runtime/cookies.md) for more info.

## Unit testing

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "yiisoft/cookies",
"type": "library",
"description": "_____",
"description": "Convenient way to use cookies with PSR-7",
"keywords": [
"cookies",
"cookie"
"cookie",
"psr-7"
],
"homepage": "https://www.yiiframework.com/",
"license": "BSD-3-Clause",
Expand All @@ -15,19 +16,17 @@
"irc": "irc:https://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/cookies"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.4|^8.0",
"psr/http-message": "^1.0",
"psr/http-message-implementation": "1.0",
"yiisoft/http": "^1.0"
},
"require-dev": {
"infection/infection": "^0.16.3",
"infection/infection": "^0.20.1",
"nyholm/psr7": "^1.3",
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "^3.15"
"phpunit/phpunit": "^9.4",
"vimeo/psalm": "^4.1"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<psalm
errorLevel="6"
resolveFromConfigFile="true"
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
Loading

0 comments on commit 1605ff8

Please sign in to comment.