-
-
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 f05c587
Showing
15 changed files
with
550 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,21 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 | ||
|
||
[*.bat] | ||
end_of_line = crlf |
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,9 @@ | ||
# .gitattributes | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore | ||
|
||
# Auto detect text files and perform LF normalization | ||
* text=auto |
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 @@ | ||
/vendor/ | ||
composer.lock | ||
.phplint-cache | ||
.phpcs-cache | ||
.phpunit.result.cache | ||
.idea/ |
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,5 @@ | ||
path: ./src/ | ||
extensions: | ||
- php | ||
exclude: | ||
- 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,26 @@ | ||
language: php | ||
|
||
notifications: | ||
email: | ||
on_success: never | ||
|
||
php: | ||
- 7.3 | ||
- 7.4 | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
- php: 7.3 | ||
env: dependencies=lowest | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
before_script: | ||
- composer install -n | ||
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest --prefer-stable -n; fi; | ||
|
||
script: | ||
- vendor/bin/phpunit |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 ncou | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
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. |
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,44 @@ | ||
# My Awesome Project | ||
|
||
This is the catchphrase: what does this project do and how is it unique? | ||
|
||
[![Build Status](https://img.shields.io/travis/org/PHP-DI/PHP-DI/master.svg?style=flat-square)](https://travis-ci.org/PHP-DI/PHP-DI) | ||
[![Latest Version](https://img.shields.io/github/release/PHP-DI/PHP-DI.svg?style=flat-square)](https://packagist.org/packages/PHP-DI/php-di) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/PHP-DI/PHP-DI.svg?style=flat-square)](https://packagist.org/packages/PHP-DI/php-di) | ||
|
||
Here is an additional quick introduction, if necessary. | ||
|
||
## Why? | ||
|
||
Why does this project exist? Come on, don't delete this part. Fill it. | ||
Yes it's hard, but it's perhaps the most important part of the README. | ||
|
||
As to why *this* project exist, it's to serve as a template for future open | ||
source PHP projects. Of course, feel free to fork it and make your own recipe. | ||
|
||
## Installation | ||
|
||
Describe how to install the project/library/framework/… | ||
|
||
Make sure your installation instructions work by testing them! | ||
|
||
## Usage | ||
|
||
Describe how to use the project. A gif or a short code example is the best | ||
way to show how it works. Also keep paragraphs short and sentences simple: not | ||
everybody speaks english well. | ||
|
||
For the sake of the example here is how you can use this project template | ||
as a basis for your own repository: | ||
|
||
```bash | ||
git clone https://github.com/ncou/project-template.git my-project | ||
cd my-project | ||
# Remove the git repository metadata | ||
rm -rf .git/ | ||
# Start a brand new repository | ||
git init | ||
git add . | ||
``` | ||
|
||
Easy peasy! Now you just have to code. |
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,35 @@ | ||
{ | ||
"name": "chiron/csrf", | ||
"description": "Give it a nice description!", | ||
"keywords": [], | ||
"license": "MIT", | ||
"type": "library", | ||
"autoload": { | ||
"psr-4": { | ||
"Chiron\\Csrf\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Chiron\\Csrf\\Test\\": "tests/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^7.2" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8.0", | ||
"phpstan/phpstan": "^0.12", | ||
"phpstan/phpstan-phpunit": "^0.12", | ||
"overtrue/phplint": "^2.0", | ||
"chiron/coding-standard": "^3.0" | ||
}, | ||
"scripts": { | ||
"phpunit": "phpunit --colors=always", | ||
"test-coverage": "phpunit --coverage-clover clover.xml", | ||
"phpstan": "phpstan analyse --ansi", | ||
"phplint": "phplint --ansi", | ||
"check-style": "phpcs src tests", | ||
"fix-style": "phpcbf src 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,25 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Project" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> | ||
<description>PHP Coding Standards</description> | ||
|
||
<arg name="basepath" value="."/> | ||
<arg name="cache" value=".phpcs-cache"/> | ||
<arg name="colors" /> | ||
<arg name="encoding" value="UTF-8"/> | ||
<arg name="extensions" value="php"/> | ||
<arg name="parallel" value="80"/> | ||
<arg name="report" value="code"/> | ||
<arg name="report-width" value="160"/> | ||
<!-- Show progress of the run --> | ||
<arg value="p"/> | ||
<!-- Do not print warning --> | ||
<arg value="n"/> | ||
<!-- Show sniff codes in all reports --> | ||
<arg value="s"/> | ||
|
||
<file>src/</file> | ||
<file>tests/</file> | ||
|
||
<!-- Load the ruleset.xml file from this folder --> | ||
<rule ref="Chiron"/> | ||
</ruleset> |
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,5 @@ | ||
parameters: | ||
level: max | ||
paths: | ||
- src | ||
- 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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit colors="true" | ||
bootstrap="./vendor/autoload.php"> | ||
|
||
<testsuites> | ||
<testsuite name="Test suite"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
</phpunit> |
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,130 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chiron\Csrf\Config; | ||
|
||
use Chiron\Config\AbstractInjectableConfig; | ||
use Chiron\Config\Helper\Validator; | ||
use Closure; | ||
use Nette\Schema\Expect; | ||
use Nette\Schema\Schema; | ||
use Twig\Cache\CacheInterface; | ||
|
||
final class CsrfConfig extends AbstractInjectableConfig | ||
{ | ||
protected const CONFIG_SECTION_NAME = 'csrf'; | ||
|
||
protected function getConfigSchema(): Schema | ||
{ | ||
// TODO : améliorer le typage des tableaux exemple : Expect::arrayOf(Expect::string(), Expect::type(CacheInterface::class)) | ||
return Expect::structure([ | ||
// general options settings | ||
'options' => Expect::structure([ | ||
'debug' => Expect::bool()->default(setting('debug')), | ||
'charset' => Expect::string()->default(setting('charset')), // TODO : il faudrait pas refaire un test sur la validité du Charset ? comme c'est fait pour le settingsConfig ? | ||
'strict_variables' => Expect::bool()->default(false), | ||
'autoescape' => Expect::anyOf(false, Expect::string(), Expect::callable())->default('name'), | ||
//'cache' => Expect::anyOf(false, Expect::string(), Expect::is(CacheInterface::class))->default(directory('@cache/twig/')), | ||
'cache' => Expect::anyOf(false, Expect::string(), Expect::object())->assert(Closure::fromCallable([$this, 'objectIsCacheInterface']), 'instanceof CacheInterface')->default(directory('@cache/twig/')), // TODO : on devrait peut etre ne pas gérer la possibilité de passer un objet Cache*Interface ca simplifierai le code non ???? | ||
'auto_reload' => Expect::bool()->default(setting('debug')), | ||
'optimizations' => Expect::anyOf(-1, 0)->default(-1), | ||
]), | ||
// date settings | ||
'date' => Expect::structure([ | ||
'format' => Expect::string()->default('F j, Y H:i'), | ||
'interval_format' => Expect::string()->default('%d days'), | ||
'timezone' => Expect::string()->nullable()->default(setting('timezone')), // TODO : il faudrait pas refaire un test sur la validité du TimeZone ? comme c'est fait pour le settingsConfig ? Si on ajoute ce controle il ne sera plus nécessaire de lever d'exception dans la méthode "setTimeZone()" de la factory car on sera sur que le format de la timezone est correct !!!! | ||
]), | ||
// number settings | ||
'number_format' => Expect::structure([ | ||
'decimals' => Expect::int()->default(0), | ||
'decimal_point' => Expect::string()->default('.'), | ||
'thousands_separator' => Expect::string()->default(','), | ||
]), | ||
// generic parameters | ||
// TODO : améliorer la vérification des tableaux pour bien vérifier le type d'objet qui sont autorisés dans ces tableaux !!! | ||
'extensions' => Expect::array(), // extension could be a string classename or an ExtensionInterface object. | ||
'functions' => Expect::array(), | ||
'filters' => Expect::array(), | ||
'globals' => Expect::arrayOf('string')->assert([Validator::class, 'isArrayAssociative'], 'associative array'), | ||
'facades' => Expect::array()->assert(Closure::fromCallable([$this, 'isValidFacadeArray']), 'facades array structure'), | ||
'lexer' => Expect::array(), | ||
]); | ||
} | ||
|
||
public function getOptions(): array | ||
{ | ||
return $this->get('options'); | ||
} | ||
|
||
public function getFacades(): array | ||
{ | ||
return $this->get('facades'); | ||
} | ||
|
||
public function getGlobals(): array | ||
{ | ||
return $this->get('globals'); | ||
} | ||
|
||
public function getFunctions(): array | ||
{ | ||
return $this->get('functions'); | ||
} | ||
|
||
public function getFilters(): array | ||
{ | ||
return $this->get('filters'); | ||
} | ||
|
||
public function getExtensions(): array | ||
{ | ||
return $this->get('extensions'); | ||
} | ||
|
||
public function getLexer(): array | ||
{ | ||
return $this->get('lexer'); | ||
} | ||
|
||
public function getDate(): array | ||
{ | ||
return $this->get('date'); | ||
} | ||
|
||
public function getNumberFormat(): array | ||
{ | ||
return $this->get('number_format'); | ||
} | ||
|
||
private function objectIsCacheInterface($value): bool | ||
{ | ||
if (! is_object($value)) { | ||
// if it's not an object we ignore this validation. | ||
return true; | ||
} | ||
|
||
return Validator::is($value, CacheInterface::class); | ||
} | ||
|
||
// The facades array structure should be : a string index (used as the facade name), and the value should be an array with at least an existing 'class' key. | ||
private function isValidFacadeArray(array $facades): bool | ||
{ | ||
foreach ($facades as $key => $value) { | ||
if (! is_string($key)) { | ||
return false; | ||
} | ||
|
||
if (! is_array($value)) { | ||
return false; | ||
} | ||
|
||
if (! isset($value['class'])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.