kegi/netscape-cookie-file-handler

View on GitHub
README.md

Summary

Maintainability
Test Coverage
# Netscape Cookie File Handler
[![Build Status](https://travis-ci.org/kegi/netscape-cookie-file-handler.svg?branch=master)](https://travis-ci.org/kegi/netscape-cookie-file-handler)
[![Latest Stable Version](https://img.shields.io/packagist/v/kegi/netscape-cookie-file-handler.svg?style=flat)](https://packagist.org/packages/kegi/netscape-cookie-file-handler)
[![Test Coverage](https://codeclimate.com/github/kegi/netscape-cookie-file-handler/badges/coverage.svg)](https://codeclimate.com/github/kegi/netscape-cookie-file-handler/coverage)

[![Issue Count](https://codeclimate.com/github/kegi/netscape-cookie-file-handler/badges/issue_count.svg)](https://codeclimate.com/github/kegi/netscape-cookie-file-handler)
[![Code Climate](https://codeclimate.com/github/kegi/netscape-cookie-file-handler/badges/gpa.svg)](https://codeclimate.com/github/kegi/netscape-cookie-file-handler)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/9ecd72f2-a463-4eca-9c55-4733d936753f/mini.png)](https://insight.sensiolabs.com/projects/9ecd72f2-a463-4eca-9c55-4733d936753f)

This library allows you to manipulate Netscape Cookie File (eg. Cookies generated by CURL).

----------

## Requirements
This is library is only available for **PHP7+**
There is no other dependencies

## Installation
This library is available on packagist (**Composer**)
```shell
composer require kegi/netscape-cookie-file-handler
```

## What are Cookies Files ?
The Netscape cookie files are widely used. Curl, by example, allows you to select a file (called the cookie jar) to save and read the cookies using this format. This library will help you to manipulate and read those cookies.

## Example
Simple example of reading + writing cookies

```php
/*Open and parse the cookie file*/

$configuration = (new Configuration())->setCookieDir('cookies/');
$cookieJar = (new CookieFileHandler($configuration))->parseFile('my_cookie_file');

/*Add (and save) a cookie*/

$cookieJar->add(
    (new Cookie())
        ->setHttpOnly(true)
        ->setPath('/foo')
        ->setSecure(true)
        ->setExpire(new DateTime('2020-02-20 20:20:02'))
        ->setName('foo')
        ->setValue('bar')
)->persist();
```

## Documentation

Learn how to use the library here : [documentation](/docs/README.md).

## Contribution

Feel free to contact me or send pull requests !