-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4ad51d4
Showing
11 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file is for unifying the coding style for different editors and IDEs | ||
# editorconfig.org | ||
|
||
# PHP PSR-2 Coding Standards | ||
# http://www.php-fig.org/psr/psr-2/ | ||
|
||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[*.php] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.travis.yml export-ignore | ||
Makefile export-ignore | ||
phpunit.xml.dist export-ignore | ||
tests/ export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
composer.lock | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $COMPOSER_CACHE_DIR | ||
- $HOME/.composer/cache | ||
- $TRAVIS_BUILD_DIR/build | ||
|
||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
|
||
before_script: | ||
- if [[ $TRAVIS_PHP_VERSION != "5.6" ]]; then phpenv config-rm xdebug.ini; fi | ||
|
||
script: | ||
- if [[ $TRAVIS_PHP_VERSION == "5.6" ]]; then make test-coveralls; else make test; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
The olvlvl/symfony-validator-companion package is free software. | ||
It is released under the terms of the following BSD License. | ||
|
||
Copyright (c) 2017 by Olivier Laviale | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of Olivier Laviale nor the names of its | ||
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# customization | ||
|
||
PACKAGE_NAME = olvlvl/symfony-validator-companion | ||
PACKAGE_VERSION = 0.1 | ||
PHPUNIT_VERSION = phpunit-5.7.phar | ||
PHPUNIT_FILENAME = build/$(PHPUNIT_VERSION) | ||
PHPUNIT = php $(PHPUNIT_FILENAME) | ||
|
||
# do not edit the following lines | ||
|
||
all: $(PHPUNIT_FILENAME) vendor | ||
|
||
usage: | ||
@echo "test: Runs the test suite.\ndoc: Creates the documentation.\nclean: Removes the documentation, the dependencies and the Composer files." | ||
|
||
vendor: | ||
@COMPOSER_ROOT_VERSION=$(PACKAGE_VERSION) composer install | ||
|
||
update: | ||
@COMPOSER_ROOT_VERSION=$(PACKAGE_VERSION) composer update | ||
|
||
autoload: vendor | ||
@composer dump-autoload | ||
|
||
$(PHPUNIT_FILENAME): | ||
mkdir -p build | ||
wget https://phar.phpunit.de/$(PHPUNIT_VERSION) -O $(PHPUNIT_FILENAME) | ||
|
||
test: all | ||
@$(PHPUNIT) | ||
|
||
test-coverage: all | ||
@mkdir -p build/coverage | ||
@$(PHPUNIT) --coverage-html build/coverage | ||
|
||
test-coveralls: all | ||
@mkdir -p build/logs | ||
COMPOSER_ROOT_VERSION=$(PACKAGE_VERSION) composer require satooshi/php-coveralls | ||
@$(PHPUNIT) --coverage-clover build/logs/clover.xml | ||
php vendor/bin/coveralls -v | ||
|
||
doc: vendor | ||
@mkdir -p build/docs | ||
@apigen generate \ | ||
--source lib \ | ||
--destination build/docs/ \ | ||
--title "$(PACKAGE_NAME) v$(PACKAGE_VERSION)" \ | ||
--template-theme "bootstrap" | ||
|
||
clean: | ||
@rm -fR build | ||
@rm -fR vendor | ||
@rm -f composer.lock | ||
|
||
.PHONY: all autoload doc clean test test-coverage test-coveralls update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Symfony Validator Companion | ||
|
||
[![Packagist](https://img.shields.io/packagist/v/olvlvl/symfony-validator-companion.svg)](https://packagist.org/packages/olvlvl/symfony-validator-companion) | ||
[![Build Status](https://img.shields.io/travis/olvlvl/symfony-validator-companion.svg)](http://travis-ci.org/olvlvl/symfony-validator-companion) | ||
[![Code Quality](https://img.shields.io/scrutinizer/g/olvlvl/symfony-validator-companion.svg)](https://scrutinizer-ci.com/g/olvlvl/symfony-validator-companion) | ||
[![Code Coverage](https://img.shields.io/coveralls/olvlvl/symfony-validator-companion.svg)](https://coveralls.io/r/olvlvl/symfony-validator-companion) | ||
[![Downloads](https://img.shields.io/packagist/dt/olvlvl/symfony-validator-companion.svg)](https://packagist.org/packages/olvlvl/symfony-validator-companion/stats) | ||
|
||
__olvlvl/symfony-validator-companion__ provides companion feature for | ||
[Symfony's validator component](http://symfony.com/components/Validator), albeit right now it's | ||
only adding an adaptor for [PSR-16 Simple Cache](http://www.php-fig.org/psr/psr-16/). | ||
|
||
|
||
|
||
|
||
|
||
---------- | ||
|
||
|
||
|
||
|
||
|
||
## Requirements | ||
|
||
The package requires PHP 5.6 or later. | ||
|
||
|
||
|
||
|
||
|
||
## Installation | ||
|
||
The recommended way to install this package is through [Composer](http://getcomposer.org/): | ||
|
||
$ composer require olvlvl/symfony-validator-companion | ||
|
||
|
||
|
||
|
||
|
||
### Cloning the repository | ||
|
||
The package is [available on GitHub][], its repository can be cloned with the following Message | ||
line: | ||
|
||
$ git clone https://github.com/olvlvl/symfony-validator-companion.git | ||
|
||
|
||
|
||
|
||
|
||
## Testing | ||
|
||
The test suite is ran with the `make test` Message. [PHPUnit](https://phpunit.de/) and | ||
[Composer](http://getcomposer.org/) need to be globally available to run the suite. The Message | ||
installs dependencies as required. The `make test-coverage` Message runs test suite and also creates | ||
an HTML coverage report in `build/coverage`. The directory can later be cleaned with the `make | ||
clean` Message. | ||
|
||
The package is continuously tested by [Travis CI](http://about.travis-ci.org/). | ||
|
||
[![Build Status](https://img.shields.io/travis/olvlvl/symfony-validator-companion.svg)](http://travis-ci.org/olvlvl/symfony-validator-companion) | ||
[![Code Coverage](https://img.shields.io/coveralls/olvlvl/symfony-validator-companion.svg)](https://coveralls.io/r/olvlvl/symfony-validator-companion) | ||
|
||
|
||
|
||
|
||
|
||
## License | ||
|
||
**olvlvl/symfony-validator-companion** is licensed under the New BSD License - See the [LICENSE](LICENSE) file for details. | ||
|
||
|
||
|
||
|
||
|
||
[available on GitHub]: https://github.com/olvlvl/symfony-validator-companion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "olvlvl/symfony-validator-companion", | ||
"type": "library", | ||
"description": "A companion package for Symfony's validator", | ||
"keywords": [ | ||
"validator", | ||
"cache" | ||
], | ||
"license": "BSD-3-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Olivier Laviale", | ||
"email": "olivier.laviale@gmail.com", | ||
"homepage": "https://olvlvl.com/", | ||
"role": "Developer" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/olvlvl/symfony-validator-companion/issues", | ||
"source": "https://github.com/olvlvl/symfony-validator-companion" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"prefer-dist": true, | ||
"require": { | ||
"php": ">=5.6", | ||
"symfony/validator": "^2.7", | ||
"psr/simple-cache": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"olvlvl\\SymfonyValidatorCompanion\\": "lib/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"olvlvl\\SymfonyValidatorCompanion\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the olvlvl/symfony-validator-companion package. | ||
* | ||
* (c) Olivier Laviale <olivier.laviale@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace olvlvl\SymfonyValidatorCompanion; | ||
|
||
use Symfony\Component\Validator\Mapping\Cache\CacheInterface as ValidatorCache; | ||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
use Psr\SimpleCache\CacheInterface as SimpleCache; | ||
|
||
class SimpleCacheAdaptor implements ValidatorCache | ||
{ | ||
/** | ||
* @param string $class | ||
* | ||
* @return string | ||
*/ | ||
public static function normalizeKey($class) | ||
{ | ||
return strtr($class, '\\', '.'); | ||
} | ||
|
||
/** | ||
* @var SimpleCache | ||
*/ | ||
private $cache; | ||
|
||
/** | ||
* @param SimpleCache $cache | ||
*/ | ||
public function __construct(SimpleCache $cache) | ||
{ | ||
$this->cache = $cache; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function has($class) | ||
{ | ||
return $this->cache->has(self::normalizeKey($class)); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function read($class) | ||
{ | ||
$result = $this->cache->get(self::normalizeKey($class)); | ||
|
||
return $result ? $result : false; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function write(ClassMetadata $metadata) | ||
{ | ||
$this->cache->set(self::normalizeKey($metadata->getClassName()), $metadata); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
bootstrap="./vendor/autoload.php" | ||
> | ||
<testsuites> | ||
<testsuite name="olvlvl/symfony-validator-companion"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./lib</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.