PHP library for handling cookies.
- Requirements
- Installation
- Available Methods
- Quick Start
- Usage
- Tests
- TODO
- Contribute
- Repository
- License
- Copyright
This library is supported by PHP versions 5.6 or higher.
The preferred way to install this extension is through Composer.
To install PHP Cookie library, simply:
$ composer require Josantonius/Cookie
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
$ composer require Josantonius/Cookie --prefer-source
You can also clone the complete repository with Git:
$ git clone https://github.com/Josantonius/PHP-Cookie.git
Or install it manually:
$ wget https://raw.githubusercontent.com/Josantonius/PHP-Cookie/master/src/Cookie.php
Available methods in this library:
Cookie::set($key, $value, $time);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$key | Cookie name. | string | Yes | |
$value | The data to save. | string | Yes | |
$time | Expiration time in days. | string | No | 365 |
# Return (boolean)
Cookie::get($key);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$key | Cookie name. | string | No | '' |
# Return (mixed|false) → returns cookie value, cookies array or false
Cookie::pull($key);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$key | Cookie name. | string | Yes |
# Return (string|false) → item or false when key does not exists
Cookie::destroy($key);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$key | Cookie name to destroy. Not set to delete all. | string | No | '' |
# Return (boolean)
Cookie::setPrefix($prefix);
Attribute | Description | Type | Required | Default |
---|---|---|---|---|
$prefix | Cookie prefix. | string | Yes |
# Return (boolean)
Cookie::getPrefix();
# Return (string) → cookie prefix
To use this class with Composer:
require __DIR__ . '/vendor/autoload.php';
use Josantonius\Cookie\Cookie;
Or If you installed it manually, use it:
require_once __DIR__ . '/Cookie.php';
use Josantonius\Cookie\Cookie;
Example of use for this library:
Cookie::set('cookie_name', 'value', 365);
Cookie::get('cookie_name');
Cookie::get();
Cookie::pull('cookie_name');
Cookie::destroy('cookie_name');
Cookie::destroy();
Cookie::setPrefix('prefix_');
Cookie::getPrefix();
To run tests you just need composer and to execute the following:
$ git clone https://github.com/Josantonius/PHP-Cookie.git
$ cd PHP-Cookie
$ composer install
Run unit tests with PHPUnit:
$ composer phpunit
Run PSR2 code standard tests with PHPCS:
$ composer phpcs
Run PHP Mess Detector tests to detect inconsistencies in code style:
$ composer phpmd
Run all previous tests:
$ composer tests
- Add new feature.
- Improve tests.
- Improve documentation.
- Refactor code for disabled code style rules. See phpmd.xml and .php_cs.dist.
If you would like to help, please take a look at the list of issues or the To Do checklist.
Pull requests
- Fork and clone.
- Run the command
composer install
to install the dependencies. This will also install the dev dependencies. - Run the command
composer fix
to excute code standard fixers. - Run the tests.
- Create a branch, commit, push and send me a pull request.
The file structure from this repository was created with PHP-Skeleton.
This project is licensed under MIT license. See the LICENSE file for more info.
2016 - 2018 Josantonius, josantonius.com
If you find it useful, let me know 😉