Skip to content

Commit 325226e

Browse files
committed
Merge branch 'release/1.0.0'
2 parents c874d67 + 1c7f63d commit 325226e

32 files changed

+3357
-0
lines changed

.coveralls.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage_clover: ./build/coverage.xml
2+
json_path: ./build/coverage.json

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea/
2+
/vendor/
3+
/bin/

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sudo: false
2+
3+
language: php
4+
5+
php:
6+
- 5.6
7+
- 7.0
8+
9+
cache:
10+
directories:
11+
- vendor
12+
- bin
13+
14+
before_script:
15+
- composer self-update
16+
- composer install
17+
- mkdir build/
18+
19+
script:
20+
- bin/phpcs
21+
- bin/phpspec run --config phpspec.travis.yml
22+
23+
after_script:
24+
- bin/coveralls -v

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 EcomDev B.V., Ivan Chepurnyi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Cache Key [![Build Status](https://travis-ci.org/EcomDev/cache-key.svg)](https://travis-ci.org/EcomDev/cache-key) [![Coverage Status](https://coveralls.io/repos/github/EcomDev/cache-key/badge.svg?branch=develop)](https://coveralls.io/github/EcomDev/cache-key?branch=develop)
2+
3+
Library that allows you to generate cache keys based on various data formats.
4+
5+
Main components:
6+
* **Key generator** Allows to generate a cache key based on different data input
7+
* **Key converters** Allows to convert various php data types into key friendly data type
8+
* **Key normalizer** Normalizes characters in generated string to match particular cache key sanity checks of your own cache adapter.
9+
10+
## Installation
11+
```bash
12+
composer require ecomdev/cache-key
13+
```
14+
15+
## Usage
16+
17+
### Automatic non alpha-num characters encoding
18+
```php
19+
use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
20+
use EcomDev\CacheKey\Generator;
21+
22+
$generator = new Generator(new EncodeNormalizer());
23+
$generator->generate('some_bad_#^.;:/\\_character'); // Generates "some_bad_235e2e3b3a2f5c_character"
24+
```
25+
26+
### Multiple normalizers
27+
```php
28+
use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
29+
use EcomDev\CacheKey\Normalizer\LengthNormalizer;
30+
use EcomDev\CacheKey\NormalizerChain;
31+
use EcomDev\CacheKey\Generator;
32+
33+
$normalizer = new NormalizerChain([
34+
new EncodeNormalizer(),
35+
new LengthNormalizer(16)
36+
]);
37+
38+
$generator = new Generator($normalizer);
39+
$generator->generate('some_bad_#^.;:/\\_character'); // Generates "some_bad_235e2e3b3a2f5c_character"
40+
```
41+
42+
### Using converter for key value map
43+
```php
44+
use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
45+
use EcomDev\CacheKey\Converter\KeyValueConverter;
46+
use EcomDev\CacheKey\Converter\ScalarConverter;
47+
use EcomDev\CacheKey\Generator;
48+
49+
$generator = new Generator(
50+
new EncodeNormalizer(),
51+
new KeyValueConverter(new ScalarConverter())
52+
);
53+
54+
$generator->generate([
55+
'some-key' => 'some-value',
56+
'another-key' => 'another-value'
57+
]); // Generates "some-key_some-value_another-key_another-value"
58+
```
59+
60+
### Cache Key Info Provider Usage
61+
62+
Your custom cache able model
63+
```php
64+
class YourCustomModel implements EcomDev\CacheKey\InfoProviderInterface
65+
{
66+
public function getCacheKeyInfo()
67+
{
68+
return [
69+
'some-key' => 'some-value',
70+
'another-key' => 'another-value'
71+
];
72+
}
73+
}
74+
```
75+
76+
Usage in key generation
77+
78+
```php
79+
use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
80+
use EcomDev\CacheKey\Converter\KeyValueConverter;
81+
use EcomDev\CacheKey\Converter\ScalarConverter;
82+
use EcomDev\CacheKey\Generator;
83+
84+
$object = new YourCustomModel();
85+
86+
$generator = new Generator(
87+
new EncodeNormalizer(),
88+
new KeyValueConverter(new ScalarConverter())
89+
);
90+
91+
$generator->generate($object); // Generates "some-key_some-value_another-key_another-value"
92+
```
93+
94+
95+
## Contribution
96+
Make a pull request based on develop branch

composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "ecomdev/cache-key",
3+
"description": "Library that allows you to generate cache keys based on various data formats.",
4+
"type": "library",
5+
"require": {
6+
"php": "^5.6|>=7.0"
7+
},
8+
"require-dev": {
9+
"phpspec/phpspec": "^2.4",
10+
"squizlabs/php_codesniffer": "*",
11+
"phpmd/phpmd": "^2.3",
12+
"satooshi/php-coveralls": "dev-master",
13+
"mikey179/vfsStream": "^1.6",
14+
"henrikbjorn/phpspec-code-coverage": "^2.0",
15+
"phpspec/nyan-formatters": "^1.0"
16+
},
17+
"license": "MIT",
18+
"authors": [
19+
{
20+
"name": "Ivan Chepurnyi",
21+
"email": "ivan@ecomdev.org"
22+
}
23+
],
24+
"minimum-stability": "stable",
25+
"autoload": {
26+
"psr-4": {
27+
"EcomDev\\CacheKey\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"spec\\EcomDev\\CacheKey\\": "spec/"
33+
}
34+
},
35+
"config": {
36+
"bin-dir": "bin/"
37+
}
38+
}

0 commit comments

Comments
 (0)