diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/vendor/param-processor |
first commit
Diffstat (limited to 'www/wiki/vendor/param-processor')
46 files changed, 5701 insertions, 0 deletions
diff --git a/www/wiki/vendor/param-processor/param-processor/.gitignore b/www/wiki/vendor/param-processor/param-processor/.gitignore new file mode 100644 index 00000000..11efe322 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/.gitignore @@ -0,0 +1,11 @@ +*~ +*.kate-swp + +!.* +.idea/ + +composer.phar +composer.lock + +vendor/ +build/
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/.scrutinizer.yml b/www/wiki/vendor/param-processor/param-processor/.scrutinizer.yml new file mode 100644 index 00000000..3e88d4fb --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/.scrutinizer.yml @@ -0,0 +1,22 @@ +inherit: true +build: true + +checks: + php: + code_rating: true + duplication: true + +tools: + external_code_coverage: true + php_code_sniffer: true + php_cpd: true + php_cs_fixer: true + php_loc: true + php_mess_detector: true + php_pdepend: true + php_analyzer: true + sensiolabs_security_checker: true + +filter: + excluded_paths: + - 'vendor/*' diff --git a/www/wiki/vendor/param-processor/param-processor/.travis.yml b/www/wiki/vendor/param-processor/param-processor/.travis.yml new file mode 100644 index 00000000..b773815d --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/.travis.yml @@ -0,0 +1,22 @@ +language: php + +php: + - 7.1 + - 7.2 + - 7.3 + +install: travis_retry composer install + +script: composer ci + +after_success: + - if [[ "`phpenv version-name`" != "7.3" ]]; then exit 0; fi + - vendor/bin/phpunit --coverage-clover coverage.clover + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover coverage.clover + +sudo: false + +cache: + directories: + - "$HOME/.composer/cache" diff --git a/www/wiki/vendor/param-processor/param-processor/COPYING b/www/wiki/vendor/param-processor/param-processor/COPYING new file mode 100644 index 00000000..ebba08a4 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/COPYING @@ -0,0 +1,347 @@ +The license text below "----" applies to all files within this distribution, other +than those that are in a directory which contains files named "LICENSE" or +"COPYING", or a subdirectory thereof. For those files, the license text contained in +said file overrides any license information contained in directories of smaller depth. +Alternative licenses are typically used for software that is provided by external +parties, and merely packaged with this software for convenience. +---- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/www/wiki/vendor/param-processor/param-processor/DefaultConfig.php b/www/wiki/vendor/param-processor/param-processor/DefaultConfig.php new file mode 100644 index 00000000..bae67a74 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/DefaultConfig.php @@ -0,0 +1,13 @@ +<?php + +/** + * @deprecated + */ +$GLOBALS['egValidatorSettings'] = [ + 'errorListMinSeverity' => 'minor', +]; + +/** + * @deprecated + */ +$GLOBALS['wgParamDefinitions'] = \ParamProcessor\ParameterTypes::getCoreTypes(); diff --git a/www/wiki/vendor/param-processor/param-processor/IdeHelper.php b/www/wiki/vendor/param-processor/param-processor/IdeHelper.php new file mode 100644 index 00000000..a5292e0d --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/IdeHelper.php @@ -0,0 +1,10 @@ +<?php + +namespace ParamProcessor; + +/** + * Deprecated since 1.0 - this class is for internal use only + */ +class Param extends PackagePrivate\Param { + +}
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/README.md b/www/wiki/vendor/param-processor/param-processor/README.md new file mode 100644 index 00000000..c3ec4ebf --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/README.md @@ -0,0 +1,449 @@ +# ParamProcessor + +ParamProcessor is a parameter processing library that provides a way to +declaratively define a set of parameters and how they should be processed. +It can take such declarations together with a list of raw parameters and +provide the processed values. For example, if one defines a parameter to +be an integer, in the range `[0, 100]`, then ParamProcessor will verify the +input is an integer, in the specified range, and return it as an actual +integer variable. + +Also see [ParserHooks](https://github.com/JeroenDeDauw/ParserHooks), a library +that builds on top of ParamProcessor and provides MediaWiki integration. + +[![Build Status](https://secure.travis-ci.org/JeroenDeDauw/ParamProcessor.png?branch=master)](http://travis-ci.org/JeroenDeDauw/ParamProcessor) +[![Code Coverage](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/?branch=master) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/?branch=master) + + +On [Packagist](https://packagist.org/packages/param-processor/param-processor): +[![Latest Stable Version](https://poser.pugx.org/param-processor/param-processor/version.png)](https://packagist.org/packages/param-processor/param-processor) +[![Download count](https://poser.pugx.org/param-processor/param-processor/d/total.png)](https://packagist.org/packages/param-processor/param-processor) + +## Installation + +The recommended way to use this library is via [Composer](http://getcomposer.org/). + +### Composer + +To add this package as a local, per-project dependency to your project, simply add a +dependency on `param-processor/param-processor` to your project's `composer.json` file. +Here is a minimal example of a `composer.json` file that just defines a dependency on +version 1.x of this package: + +```json +{ + "require": { + "param-processor/param-processor": "~1.0" + } +} +``` + +### Manual + +Get the code of this package, either via git, or some other means. Also get all dependencies. +You can find a list of the dependencies in the "require" section of the composer.json file. +Then take care of autoloading the classes defined in the src directory. + +## Concept + +The goal of the ParamProcessor library is to make parameter handling simple and consistent. + +In order to achieve this, a declarative API for defining parameters is provided. Passing in +such parameter definitions together with a list of raw input into the processor leads to +a processed list of parameters. Processing consists out of name and alias resolving, parsing, +validation, formatting and defaulting. + +If ones defines an "awesomeness" parameter of type "integer", one can be sure that at the end +of the processing, there will be an integer value for the awesomeness parameter. If the user did +not provide a value, or provided something that is invalid, while the parameter it is required, +processing will abort with a fatal error. If on the other hand there is a default, the default will +be set. If the value was invalid, a warning will be kept track of. In case the user provides a valid +value, for instance "42" (string), it will be turned in the appropriate 42 (int). + +## Implementation structure + +Parameters are defined using the `ParamProcessor\ParamDefinition` class. Users can also use the array +format to define parameters and not be bound to this class. At present, it is preferred to use this +array format as the class itself is not stable yet. + +Processing is done via `ParamProcessor\Processor`. + +## Defining parameters + +### Array definition schema + +These fields are supported: + +<table> + <tr> + <th>Name</th> + <th>Type</th> + <th>Default</th> + <th>Description</th> + </tr> + <tr> + <th>name</th> + <td>string</td> + <td><i>required</i></td> + <td></td> + </tr> + <tr> + <th>type</th> + <td>string (enum)</td> + <td>string</td> + <td></td> + </tr> + <tr> + <th>default</th> + <td>mixed</td> + <td>null</td> + <td>If this value is null, the parameter has no default and is required</td> + </tr> + <tr> + <th>aliases</th> + <td>array of string</td> + <td>empty array</td> + <td>Aliases for the name</td> + </tr> + <tr> + <th>trim</th> + <td>boolean</td> + <td><i>inherited from processor options</i></td> + <td>If the value should be trimmed</td> + </tr> + <tr> + <th>islist</th> + <td>boolean</td> + <td>false</td> + <td></td> + </tr> + <tr> + <th>delimiter</th> + <td>string</td> + <td>,</td> + <td>The delimiter between values if it is a list</td> + </tr> + <tr> + <th>manipulatedefault</th> + <td>boolean</td> + <td>true</td> + <td>If the default value should also be manipulated</td> + </tr> + <tr> + <th>values</th> + <td>array</td> + <td></td> + <td>Allowed values</td> + </tr> + <tr> + <th>message</th> + <td>string</td> + <td><i>required</i></td> + <td></td> + </tr> + <tr> + <th>post-format</th> + <td>callback</td> + <td><i>none</i></td> + <td>Takes the value as only parameter and returns the new value</td> + </tr> + +</table> + +The requires fields currently are: name and message + +### Core parameter types + +<table> + <tr> + <th>Name</th> + <th>PHP return type</th> + <th>Description</th> + </tr> + <tr> + <th>string</th> + <td>string</td> + <td> + Default type<br /> + Supported options: + <ul> + <li>length: int or false (overrides minlength and maxlength)</li> + <li>minlength: int or false</li> + <li>maxlength: int or false</li> + <li>regex: string</li> + </ul> + </td> + </tr> + <tr> + <th>boolean</th> + <td>boolean</td> + <td>Accepts "yes", "no", "on", "off", "true" and "false"</td> + </tr> + <tr> + <th>float</th> + <td>float</td> + <td> + Supported options: + <ul> + <li>lowerbound: int, float or false</li> + <li>upperbound: int, float or false</li> + <li>range: [lowerbound, upperbound]</li> + <li>withinrange: [float $point, float $deviation]</li> + </ul> + </td> + </tr> + <tr> + <th>integer</th> + <td>integer</td> + <td> + Supported options: same as for float + </td> + </tr> + <tr> + <th>dimension</th> + <td>string</td> + <td> + Value for a width or height attribute in HTML<br /> + Supported options: + <ul> + <li>allowauto: bool</li> + <li>maxpercentage: int</li> + <li>minpercentage: int</li> + <li>units: array of string</li> + <li>defaultunit: string</li> + <li>lowerbound: int, float or false</li> + <li>upperbound: int, float or false</li> + </ul> + </td> + </tr> +</table> + +## Defining parameter types + +* <code>string-parser</code> Name of a class that implements the `ValueParsers\ValueParser` interface +* <code>validation-callback</code> Callback that gets the raw value as only parameter and returns a boolean +* <code>validator</code> Name of a class that implements the `ValueValidators\ValueValidator` interface + +As an example, the Maps MediaWiki extension defines a `coordinate` parameter type that turns the input into a `DataValues\LatLongValue` value object. + +## Usage example + +### Defining parameters + +```php +$parameterDefinitions = [ + 'username' => [ + 'minlength' => 1, + 'maxlength' => 20 + ], + 'job' => [ + 'default' => 'unknown', + 'values' => [ 'Developer', 'Designer', 'Peasant' ] + ], + 'favourite-numbers' => [ + 'type' => 'int', + 'islist' => true, + 'default' => [] + ] +] +``` + +### Processing input using defined parameters + +```php +$processor = ParamProcessor\Processor::newDefault(); + +$processor->setParameters( + [ + 'username' => 'Jeroen', + 'favourite-numbers' => '42, 1337, not a number', + ], + $paramDefinitions +); + +foreach ($processor->processParameters()->getParameters() $parameter) { + echo $parameter->getName(); + var_dump($parameter->getValue()); +}; + +// username: string(6) "Jeroen" +// job: string(7) "unknown" +// favourite-numbers: array(2) {[0]=>int(42), [1]=>int(1337)} +``` + +Alternative way to input parameters: + +```php +$processor->setFunctionParams( + [ + 'username = Jeroen', + 'favourite-numbers=42, 1337, not a number', + ], + $paramDefinitions +); +``` + +## Contributing + +* [File an issue](https://github.com/JeroenDeDauw/ParamProcessor/issues) +* [Submit a pull request](https://github.com/JeroenDeDauw/ParamProcessor/pulls) ([tasks for newcomers](https://github.com/JeroenDeDauw/ParamProcessor/issues?q=is%3Aissue+is%3Aopen+label%3Anewcomer)) + +## Authors + +ParamProcessor has been written by [Jeroen De Dauw](https://www.entropywins.wtf/) to +support the [Maps](https://github.com/JeroenDeDauw/Maps) and +[Semantic MediaWiki](https://semantic-mediawiki.org/) projects. + +## Release notes + +### 1.10.0 (2019-08-03) + +* Removed `DimensionParam` +* Fixed bug in parsing of parameters of type `dimension` + +### 1.9.0 (2019-08-03) + +* Added `ParamDefinitionFactory::newDefinitionsFromArrays` + +### 1.8.0 (2019-08-03) + +* Removed `ParamDefinitionFactory::getComponentForType` +* Added `ParamDefinitionFactory` constructor +* Added `ParameterTypes` constructor +* Added `ParameterTypes::addType` +* Added `ParameterTypes::newCoreTypes` +* Added `ProcessingResult::getParameterArray` + +### 1.7.0 (2019-08-02) + +* Added `ParameterTypes` public constants: `BOOLEAN`, `FLOAT`, `INTEGER`, `STRING`, `DIMENSION` +* Deprecated `ParamDefinition::getCleanDefinitions` in favour of `ParamDefinitionFactory` +* Deprecated `ParamDefinition::setDefault` in favour of constructor parameter +* Deprecated `Processor::getParameterValues` in favour of `processParameters` and `ProcessingResult` +* Deprecated `Processor::getErrors` in favour of `processParameters` and `ProcessingResult` +* Deprecated `Processor::getErrorMessages` in favour of `processParameters` and `ProcessingResult` +* Deprecated `Processor::hasErrors` in favour of `processParameters` and `ProcessingResult` +* Deprecated `Processor::hasFatalError` in favour of `processParameters` and `ProcessingResult` +* Deprecated parameter dependencies + * Deprecated `ParamDefinition::hasDependency` + * Deprecated `ParamDefinition::addDependencies` + * Deprecated `ParamDefinition::getDependencies` + * Deprecated `dependencies` key in `ParamDefinition::setArrayValues` parameter + * Deprecated `TopologicalSort` + * Deprecated `TSNode` +* Deprecated extending `ParamDefinition` +* Deprecated `StringParam` +* Deprecated `DimensionParam` +* Deprecated `ParamDefinition::setArrayValues` +* Deprecated `ParamDefinition::$acceptOverriding` +* Deprecated `ParamDefinition::$accumulateParameterErrors` +* Deprecated `Param::$accumulateParameterErrors` +* Deprecated `Settings` +* Deprecated `Options::setRawStringInputs` +* Deprecated `Options::isStringlyTyped` + +### 1.6.1 (2019-07-28) + +* Fixed message defaulting bug in `ParamDefinition` + +### 1.6.0 (2019-07-28) + +* Added `Processor::setParameterDefinitions` +* Deprecated second parameter of `Processor::setParameters` in favour of `setParameterDefinitions` +* Deprecated second parameter of `Processor::setFunctionParams` in favour of `setParameterDefinitions` +* Deprecated second parameter of `ParamDefinitionFactory::newDefinitionFromArray` +* Deprecated return value of `ParamDefinitionFactory::registerType` +* Deprecated `ParamDefinitionFactory::registerGlobals` +* Deprecated `typed-parser` key in parameter type definitions + +### 1.5.0 (2019-07-28) + +* Improved code comments and added extra type checks + +### 1.4.2 (2018-11-26) + +* Fixed defaulting behaviour of list parameters + +### 1.4.1 (2018-11-26) + +* List parameters are no longer set to their default when a single value is invalid + +### 1.4.0 (2018-11-25) + +* Dropped support for PHP older than 7.1 +* Added `ParameterTypes` to allow gradual migration away from the now deprecated `$wgParamDefinitions` +* Deprecated `$wgParamDefinitions` +* Deprecated `$egValidatorSettings` + +### 1.3.4 (2018-05-05) + +* Fixed deprecation notice occurring with PHP 7.2+ + +### 1.3.3 (2017-09-28) + +* Installation together with DataValues 2.x is now allowed +* Installation together with DataValues Common 0.4.x is now allowed + +### 1.3.2 (2017-03-26) + +* Fixed clearing of processing errors when making multiple processing calls to one `Processor` instance + +### 1.3.1 (2016-09-21) + +* Fixed `ParamDefinitionFactory` emitting a warning when initialized without the global `wgParamDefinitions` being set + +### 1.3.0 (2016-07-15) + +* Dropped support for PHP 5.3 and PHP 5.4. +* Fixed bug in `ParamDefinition::format` + +### 1.2.5 (2016-05-23) + +* Fixed bug in `Processor::newProcessingResult` + +### 1.2.4 (2016-05-15) + +* Fixed bug in `ParamDefinition::getAllowedValues` + +### 1.2.3 (2016-04-04) + +* Installation together with DataValues Interfaces 0.2.x is now allowed +* Installation together with DataValues Common 0.3.x is now allowed +* The component is now also tested against PHP 7 + +### 1.2.2 (2014-10-24) + +* Installation together with DataValues 1.x is now allowed. + +### 1.2.0 (2014-09-12) + +* Dropped dependency on DataValues Geo. + +### 1.1.0 (2014-05-07) + +* Dropped dependency on DataValues Time. +* Use PSR-4 based loading rather than PSR-0 based loading. +* Fixed Windows compatibility in PHPUnit bootstrap + +### 1.0.2 (2013-12-16) + +* Removed dependency on data-values/number +* Updated required version of data-values/common from ~0.1 to ~0.2. + +### 1.0.1 (2013-11-29) + +* Implemented ProcessingResult::hasFatal +* Added ProcessingResultTest + +### 1.0.0 (2013-11-21) + +First release as standalone PHP library. + +## Links + +* [ParamProcessor on Packagist](https://packagist.org/packages/param-processor/param-processor) +* [ParamProcessor on TravisCI](https://travis-ci.org/JeroenDeDauw/ParamProcessor) +* [ParamProcessor on ScrutinizerCI](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/) +* [MediaWiki extension "Validator"](https://www.mediawiki.org/wiki/Extension:Validator) - +a wrapper around this library for MediaWiki users diff --git a/www/wiki/vendor/param-processor/param-processor/composer.json b/www/wiki/vendor/param-processor/param-processor/composer.json new file mode 100644 index 00000000..df8036f1 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/composer.json @@ -0,0 +1,77 @@ +{ + "name": "param-processor/param-processor", + "type": "library", + "description": "Parameter processing library", + "keywords": [ + "ParamProcessor", + "Validator", + "MediaWiki", + "SMW", + "Semantic MediaWiki" + ], + "homepage": "https://github.com/JeroenDeDauw/ParamProcessor", + "license": "GPL-2.0-or-later", + "authors": [ + { + "name": "Jeroen De Dauw", + "email": "jeroendedauw@gmail.com", + "homepage": "https://www.entropywins.wtf", + "role": "Developer" + } + ], + "support": { + "irc": "irc://irc.freenode.net/mediawiki" + }, + "require": { + "php": "~7.1", + "data-values/data-values": "~2.0|~1.0", + "data-values/interfaces": "~0.2.0|~0.1.4", + "data-values/common": "~0.4.0|~0.3.0", + "data-values/validators": "~0.1.1" + }, + "require-dev": { + "phpunit/phpunit": "~7.4", + "squizlabs/php_codesniffer": "~3.3", + "phpmd/phpmd": "~2.6", + "ockcyp/covers-validator": "~1.0" + }, + "autoload": { + "psr-4": { + "ParamProcessor\\": "src" + }, + "files": [ + "DefaultConfig.php" + ] + }, + "autoload-dev": { + "psr-4": { + "ParamProcessor\\Tests\\": "tests" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "scripts": { + "test": [ + "composer validate --no-interaction", + "vendor/bin/phpunit", + "vendor/bin/covers-validator" + ], + "cs": [ + "@phpcs", + "@phpmd" + ], + "ci": [ + "@test", + "@cs" + ], + "phpcs": [ + "vendor/bin/phpcs src/* tests/* --standard=phpcs.xml --extensions=php -sp" + ], + "phpmd": [ + "vendor/bin/phpmd src/,tests/ text phpmd.xml --exclude TopologicalSort" + ] + } +} diff --git a/www/wiki/vendor/param-processor/param-processor/phpcs.xml b/www/wiki/vendor/param-processor/param-processor/phpcs.xml new file mode 100644 index 00000000..b9008d97 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/phpcs.xml @@ -0,0 +1,93 @@ +<?xml version="1.0"?> +<!-- + - https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml + - https://github.com/squizlabs/PHP_CodeSniffer/tree/master/CodeSniffer/Standards +--> +<ruleset name="MediaWiki"> + <rule ref="Generic.Classes" /> + <rule ref="Generic.CodeAnalysis" /> + <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"> + <severity>0</severity> + </rule> + <rule ref="Generic.ControlStructures" /> + + <rule ref="Generic.Files.ByteOrderMark" /> + <rule ref="Generic.Files.LineEndings" /> + <rule ref="Generic.Files.LineLength"> + <properties> + <property name="lineLimit" value="140" /> + <property name="absoluteLineLimit" value="140" /> + </properties> + </rule> + <rule ref="Generic.Files.OneClassPerFile" /> + + <rule ref="Generic.Formatting.DisallowMultipleStatements" /> + + <rule ref="Generic.Functions.CallTimePassByReference" /> + <rule ref="Generic.Functions.FunctionCallArgumentSpacing" /> + <rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" /> + + <rule ref="Generic.Metrics.NestingLevel"> + <properties> + <property name="nestingLevel" value="5" /> + <property name="absoluteNestingLevel" value="5" /> + </properties> + </rule> + + <rule ref="Generic.Metrics.CyclomaticComplexity"> + <properties> + <property name="complexity" value="10" /> + <property name="absoluteComplexity" value="10" /> + </properties> + </rule> + + <rule ref="Generic.NamingConventions" /> + <!-- TODO: create variation of this sniff that allows underscores in test methods --> + <rule ref="Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps"> + <severity>0</severity> + </rule> + + <rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" /> + <rule ref="Generic.PHP.DeprecatedFunctions" /> + <rule ref="Generic.PHP.DisallowShortOpenTag" /> + <rule ref="Generic.PHP.ForbiddenFunctions" /> + <rule ref="Generic.PHP.LowerCaseConstant" /> + <rule ref="Generic.PHP.LowerCaseKeyword" /> + <rule ref="Generic.PHP.SAPIUsage" /> + + <rule ref="Generic.WhiteSpace.DisallowSpaceIndent" /> + + <rule ref="PSR1" /> + <rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"> + <severity>0</severity> + </rule> + + <rule ref="PSR2.Classes.PropertyDeclaration" /> + <rule ref="PSR2.ControlStructures.ElseIfDeclaration" /> + <rule ref="PSR2.Namespaces" /> + + <rule ref="Squiz.Arrays.ArrayBracketSpacing" /> + <rule ref="Squiz.CSS.SemicolonSpacing" /> + <rule ref="Squiz.Classes.DuplicateProperty" /> + <rule ref="Squiz.Classes.SelfMemberReference" /> + <rule ref="Squiz.Classes.ValidClassName" /> + <rule ref="Squiz.Functions.FunctionDuplicateArgument" /> + <rule ref="Squiz.Functions.GlobalFunction" /> + <rule ref="Squiz.Scope" /> + <rule ref="Squiz.WhiteSpace.CastSpacing" /> + <rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" /> + <rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing" /> + + <!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/348 --> + <!--<rule ref="Squiz.WhiteSpace.OperatorSpacing" />--> + + <rule ref="Squiz.WhiteSpace.ScopeClosingBrace" /> + <rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing" /> + <rule ref="Squiz.WhiteSpace.SemicolonSpacing" /> + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" /> + <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines"> + <severity>0</severity> + </rule> + + <rule ref="Zend.Files.ClosingTag" /> +</ruleset> diff --git a/www/wiki/vendor/param-processor/param-processor/phpmd.xml b/www/wiki/vendor/param-processor/param-processor/phpmd.xml new file mode 100644 index 00000000..66bfad24 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/phpmd.xml @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<ruleset xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation=" http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <rule ref="rulesets/controversial.xml"> + <exclude name="CamelCaseMethodName" /> + <exclude name="Superglobals" /> + </rule> + + <rule ref="rulesets/design.xml" /> + + <rule ref="rulesets/naming.xml"> + <exclude name="ShortVariable" /> + <exclude name="LongVariable" /> + </rule> +</ruleset>
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/phpunit.xml.dist b/www/wiki/vendor/param-processor/param-processor/phpunit.xml.dist new file mode 100644 index 00000000..17835f15 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/phpunit.xml.dist @@ -0,0 +1,24 @@ +<phpunit backupGlobals="false" + backupStaticAttributes="false" + bootstrap="tests/bootstrap.php" + cacheTokens="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false" + verbose="true"> + <testsuites> + <testsuite name="ParamProcessor"> + <directory>tests</directory> + </testsuite> + </testsuites> + <filter> + <whitelist addUncoveredFilesFromWhitelist="true"> + <directory suffix=".php">src</directory> + </whitelist> + </filter> +</phpunit> diff --git a/www/wiki/vendor/param-processor/param-processor/src/Definition/StringParam.php b/www/wiki/vendor/param-processor/param-processor/src/Definition/StringParam.php new file mode 100644 index 00000000..3c74716d --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/Definition/StringParam.php @@ -0,0 +1,78 @@ +<?php + +namespace ParamProcessor\Definition; + +use ParamProcessor\ParamDefinition; +use ParamProcessor\IParam; + +/** + * Defines the string parameter type. + * Specifies the type specific validation and formatting logic. + * + * @deprecated since 1.7 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class StringParam extends ParamDefinition { + + /** + * Indicates if the parameter should be lowercased post validation. + * + * @since 1.0 + * + * @var boolean + */ + protected $toLower = false; + + /** + * Formats the parameter value to it's final result. + * @see ParamDefinition::formatValue + * + * @since 1.0 + * + * @param $value mixed + * @param $param IParam + * @param $definitions array of IParamDefinition + * @param $params array of IParam + * + * @return mixed + */ + protected function formatValue( $value, IParam $param, array &$definitions, array $params ) { + $value = (string)$value; + + if ( $this->toLower ) { + $value = strtolower( $value ); + } + + return $value; + } + + /** + * Sets the parameter definition values contained in the provided array. + * @see ParamDefinition::setArrayValues + * + * @since 1.0 + * + * @param array $param + */ + public function setArrayValues( array $param ) { + parent::setArrayValues( $param ); + + if ( array_key_exists( 'tolower', $param ) ) { + $this->toLower = $param['tolower']; + } + } + + /** + * Sets of the value should be lowercased. + * + * @since 1.0 + * + * @param boolean $toLower + */ + public function setToLower( $toLower ) { + $this->toLower = $toLower; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/IParam.php b/www/wiki/vendor/param-processor/param-processor/src/IParam.php new file mode 100644 index 00000000..ebb0a548 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/IParam.php @@ -0,0 +1,20 @@ +<?php + +namespace ParamProcessor; + +/** + * NOTE: as of version 1.0, this class is for internal use only! + * + * Interface for objects representing an "instance" of a parameter. + * + * @since 1.0 + * @deprecated since 1.0 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +interface IParam { + + + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/IParamDefinition.php b/www/wiki/vendor/param-processor/param-processor/src/IParamDefinition.php new file mode 100644 index 00000000..410b8096 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/IParamDefinition.php @@ -0,0 +1,287 @@ +<?php + +namespace ParamProcessor; + +use ValueParsers\ValueParser; +use ValueValidators\ValueValidator; + +/** + * Interface for parameter definition classes. + * + * @since 1.0 + * @deprecated since 1.0, use ParamDefinition + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +interface IParamDefinition { + + /** + * Adds one or more aliases for the parameter name. + * + * @since 1.0 + * + * @param string|string[] $aliases + */ + public function addAliases( $aliases ); + + /** + * Adds one or more dependencies. There are the names of parameters + * that need to be validated and formatted before this one. + * + * @since 1.0 + * + * @param string|string[] $dependencies + */ + public function addDependencies( $dependencies ); + + /** + * Formats the parameter value to it's final result. + * + * @since 1.0 + * + * @param $param IParam + * @param $definitions array of IParamDefinition + * @param $params array of IParam + */ + public function format( IParam $param, array &$definitions, array $params ); + + /** + * Returns the parameter name aliases. + * + * @since 1.0 + * + * @return string[] + */ + public function getAliases(): array; + + /** + * Returns the default value. + * + * @since 1.0 + * + * @return mixed + */ + public function getDefault(); + + /** + * Returns the delimiter to use to split the raw value in case the + * parameter is a list. + * + * @since 1.0 + * + * @return string + */ + public function getDelimiter(): string; + + /** + * Returns a list of dependencies the parameter has, in the form of + * other parameter names. + * + * @since 1.0 + * + * @return string[] + */ + public function getDependencies(): array; + + /** + * Returns a message that will act as a description message for the parameter. + * + * @since 1.0 + * + * @return string + */ + public function getMessage(): string; + + /** + * Returns the parameters main name. + * + * @since 1.0 + * + * @return string + */ + public function getName(): string; + + /** + * Returns an identifier for the type of the parameter. + * + * @since 1.0 + * + * @return string + */ + public function getType(): string; + + /** + * Returns if the parameter has a certain alias. + * + * @since 1.0 + * + * @param string $alias + * + * @return boolean + */ + public function hasAlias( string $alias ): bool; + + /** + * Returns if the parameter has a certain dependency. + * + * @since 1.0 + * + * @param string $dependency + * + * @return boolean + */ + public function hasDependency( string $dependency ): bool; + + /** + * Returns if the parameter is a list or not. + * + * @since 1.0 + * + * @return boolean + */ + public function isList(): bool; + + /** + * Returns if the parameter is a required one or not. + * + * @since 1.0 + * + * @return boolean + */ + public function isRequired(): bool; + + /** + * Sets the default parameter value. Null indicates no default, + * and therefore makes the parameter required. + * + * @since 1.0 + * + * @param mixed $default + * @param boolean $manipulate Should the default be manipulated or not? Since 0.4.6. + */ + public function setDefault( $default, $manipulate = true ); + + /** + * Sets the delimiter to use to split the raw value in case the + * parameter is a list. + * + * @since 1.0 + * + * @param $delimiter string + */ + public function setDelimiter( string $delimiter ); + + /** + * Set if the parameter manipulations should be applied to the default value. + * + * @since 1.0 + * + * @param boolean $manipulateDefault + */ + public function setDoManipulationOfDefault( bool $manipulateDefault ); + + /** + * Sets a message for the parameter that will act as description. + * + * + * @since 1.0 + * + * @param string $message + */ + public function setMessage( string $message ); + + /** + * Returns if the parameter manipulations should be applied to the default value. + * + * @since 1.0 + * + * @return boolean + */ + public function shouldManipulateDefault(): bool; + + /** + * Returns a message key for a message describing the parameter type. + * + * @since 1.0 + * + * @return string + */ + public function getTypeMessage(): string; + + /** + * Returns if the value should be trimmed before validation and any further processing. + * + * @since 1.0 + * + * @since boolean|null + */ + public function trimDuringClean(); + + /** + * Returns a ValueParser object to parse the parameters value. + * + * @since 1.0 + * + * @return ValueParser + */ + public function getValueParser(); + + /** + * Returns the ValueParser object to parse the parameters value. + * + * @since 1.0 + * + * @param ValueParser $parser + */ + public function setValueParser( ValueParser $parser ); + + /** + * Returns a ValueValidator that can be used to validate the parameters value. + * + * @since 1.0 + * + * @return ValueValidator + */ + public function getValueValidator(); + + /** + * Sets the ValueValidator that can be used to validate the parameters value. + * + * @since 1.0 + * + * @param ValueValidator $validator + */ + public function setValueValidator( ValueValidator $validator ); + + /** + * Sets a validation function that will be run before the ValueValidator. + * + * This can be used instead of a ValueValidator where validation is very + * trivial, ie checking if something is a boolean can be done with is_bool. + * + * @since 1.0 + * + * @param callable $validationFunction + */ + public function setValidationCallback( callable $validationFunction ); + + /** + * Sets the parameter definition values contained in the provided array. + * + * @since 1.0 + * + * @param array $options + */ + public function setArrayValues( array $options ); + + /** + * Returns a validation function that should be run before the ValueValidator. + * + * @since 1.0 + * + * @return callable|null + */ + public function getValidationCallback(); + +}
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/src/Options.php b/www/wiki/vendor/param-processor/param-processor/src/Options.php new file mode 100644 index 00000000..99e11b45 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/Options.php @@ -0,0 +1,96 @@ +<?php + +namespace ParamProcessor; + +/** + * Object for holding options affecting the behavior of a ParamProcessor object. + * + * @since 1.0 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class Options { + + private $name; + + // During setup + private $unknownInvalid = true; + private $lowercaseNames = true; + private $trimNames = true; + private $acceptOverriding = true; + + // During clean + private $trimValues = true; + private $lowercaseValues = false; + + // During validation + private $rawStringInputs = true; + + public function setName( string $name ) { + $this->name = $name; + } + + public function setUnknownInvalid( bool $unknownInvalid ) { + $this->unknownInvalid = $unknownInvalid; + } + + public function setLowercaseNames( bool $lowercase ) { + $this->lowercaseNames = $lowercase; + } + + /** + * @deprecated since 1.7 + */ + public function setRawStringInputs( bool $rawInputs ) { + $this->rawStringInputs = $rawInputs; + } + + public function setTrimNames( bool $trim ) { + $this->trimNames = $trim; + } + + public function setTrimValues( bool $trim ) { + $this->trimValues = $trim; + } + + public function setLowercaseValues( bool $lowercase ) { + $this->lowercaseValues = $lowercase; + } + + public function getName(): string { + return $this->name ?? ''; + } + + public function unknownIsInvalid(): bool { + return $this->unknownInvalid; + } + + public function lowercaseNames(): bool { + return $this->lowercaseNames; + } + + /** + * @deprecated since 1.7 + */ + public function isStringlyTyped(): bool { + return $this->rawStringInputs; + } + + public function trimNames(): bool { + return $this->trimNames; + } + + public function trimValues(): bool { + return $this->trimValues; + } + + public function lowercaseValues(): bool { + return $this->lowercaseValues; + } + + public function acceptOverriding(): bool { + return $this->acceptOverriding; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/DimensionParser.php b/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/DimensionParser.php new file mode 100644 index 00000000..06aa2ad5 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/DimensionParser.php @@ -0,0 +1,44 @@ +<?php + +namespace ParamProcessor\PackagePrivate; + +use ValueParsers\ParseException; +use ValueParsers\ParserOptions; +use ValueParsers\ValueParser; + +/** + * Package private + */ +class DimensionParser implements ValueParser { + + public const DEFAULT_UNIT = 'defaultunit'; + + public const PIXELS = 'px'; + + private $defaultUnit; + + public function __construct( ParserOptions $options = null ) { + $options = $options ?? new ParserOptions(); + + $this->defaultUnit = $options->hasOption( self::DEFAULT_UNIT ) ? $options->getOption( self::DEFAULT_UNIT ) : self::PIXELS; + } + + public function parse( $value ) { + if ( !is_string( $value ) ) { + throw new ParseException( 'Not a string' ); + } + + $value = $this->removeWhitespace( $value ); + + if ( preg_match( '/^(\d|\.)+$/', $value ) ) { + $value .= $this->defaultUnit; + } + + return $value; + } + + private function removeWhitespace( string $string ): string { + return preg_replace( '/\s+/', '', $string ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/Param.php b/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/Param.php new file mode 100644 index 00000000..49011579 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/Param.php @@ -0,0 +1,418 @@ +<?php + +namespace ParamProcessor\PackagePrivate; + +use DataValues\DataValue; +use Exception; +use ParamProcessor\IParam; +use ParamProcessor\IParamDefinition; +use ParamProcessor\Options; +use ParamProcessor\ParamDefinition; +use ParamProcessor\ParamDefinitionFactory; +use ParamProcessor\ProcessingError; +use ValueParsers\NullParser; +use ValueParsers\ParseException; +use ValueParsers\ValueParser; + +/** + * Package private! + * + * Parameter class, representing the "instance" of a parameter. + * Holds a ParamDefinition, user provided input (name & value) and processing state. + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class Param implements IParam { + + /** + * Indicates whether parameters not found in the criteria list + * should be stored in case they are not accepted. The default is false. + * + * @deprecated since 1.7 + */ + public static $accumulateParameterErrors = false; + + /** + * The original parameter name as provided by the user. This can be the + * main name or an alias. + * @var string + */ + protected $originalName; + + /** + * The original value as provided by the user. This is mainly retained for + * usage in error messages when the parameter turns out to be invalid. + * @var string + */ + protected $originalValue; + + /** + * @var mixed + */ + protected $value; + + /** + * Keeps track of how many times the parameter has been set by the user. + * This is used to detect overrides and for figuring out a parameter is missing. + * @var integer + */ + protected $setCount = 0; + + /** + * @var ProcessingError[] + */ + protected $errors = []; + + /** + * Indicates if the parameter was set to it's default. + * @var boolean + */ + protected $defaulted = false; + + /** + * @var ParamDefinition + */ + protected $definition; + + public function __construct( IParamDefinition $definition ) { + $this->definition = $definition; + } + + /** + * Sets and cleans the original value and name. + */ + public function setUserValue( string $paramName, $paramValue, Options $options ): bool { + if ( $this->setCount > 0 && !$options->acceptOverriding() ) { + // TODO + return false; + } + + $this->originalName = $paramName; + $this->originalValue = $paramValue; + + $this->cleanValue( $options ); + + $this->setCount++; + + return true; + } + + /** + * @param mixed $value + */ + public function setValue( $value ) { + $this->value = $value; + } + + /** + * Sets the $value to a cleaned value of $originalValue. + */ + protected function cleanValue( Options $options ) { + if ( $this->definition->isList() ) { + $this->value = explode( $this->definition->getDelimiter(), $this->originalValue ); + } + else { + $this->value = $this->originalValue; + } + + if ( $this->shouldTrim( $options ) ) { + $this->trimValue(); + } + + if ( $this->shouldLowercase( $options ) ) { + $this->lowercaseValue(); + } + } + + private function shouldTrim( Options $options ): bool { + $trim = $this->definition->trimDuringClean(); + + if ( $trim === true ) { + return true; + } + + return is_null( $trim ) && $options->trimValues(); + } + + private function trimValue() { + if ( is_string( $this->value ) ) { + $this->value = trim( $this->value ); + } + elseif ( $this->definition->isList() ) { + foreach ( $this->value as &$element ) { + if ( is_string( $element ) ) { + $element = trim( $element ); + } + } + } + } + + private function shouldLowercase( Options $options ): bool { + if ( $options->lowercaseValues() ) { + return true; + } + + $definitionOptions = $this->definition->getOptions(); + + return array_key_exists( 'tolower', $definitionOptions ) && $definitionOptions['tolower']; + } + + private function lowercaseValue() { + if ( $this->definition->isList() ) { + foreach ( $this->value as &$element ) { + if ( is_string( $element ) ) { + $element = strtolower( $element ); + } + } + } + elseif ( is_string( $this->value ) ) { + $this->value = strtolower( $this->value ); + } + } + + /** + * Parameter processing entry point. + * Processes the parameter. This includes parsing, validation and additional formatting. + * + * @param ParamDefinition[] $definitions + * @param Param[] $params + * @param Options $options + * + * @throws Exception + */ + public function process( array &$definitions, array $params, Options $options ) { + if ( $this->setCount == 0 ) { + if ( $this->definition->isRequired() ) { + // This should not occur, so throw an exception. + throw new Exception( 'Attempted to validate a required parameter without first setting a value.' ); + } + else { + $this->setToDefault(); + } + } + else { + $this->parseAndValidate( $options ); + } + + if ( !$this->hasFatalError() && ( $this->definition->shouldManipulateDefault() || !$this->wasSetToDefault() ) ) { + $this->definition->format( $this, $definitions, $params ); + } + } + + public function getValueParser( Options $options ): ValueParser { + $parser = $this->definition->getValueParser(); + + if ( !( $parser instanceof NullParser ) ) { + return $parser; + } + + // TODO: inject factory + $type = ParamDefinitionFactory::singleton()->getType( $this->definition->getType() ); + + $parserClass = $options->isStringlyTyped() ? $type->getStringParserClass() : $type->getTypedParserClass(); + + return new $parserClass( new \ValueParsers\ParserOptions( $this->definition->getOptions() ) ); + } + + protected function parseAndValidate( Options $options ) { + $parser = $this->getValueParser( $options ); + + if ( $this->definition->isList() ) { + $values = []; + + foreach ( $this->getValue() as $value ) { + $parsedValue = $this->parseAndValidateValue( $parser, $value ); + + if ( is_array( $parsedValue ) ) { + $values[] = $parsedValue[0]; + } + } + + $this->value = $values; + } + else { + $parsedValue = $this->parseAndValidateValue( $parser, $this->getValue() ); + + if ( is_array( $parsedValue ) ) { + $this->value = $parsedValue[0]; + } + } + + $this->setToDefaultIfNeeded(); + } + + /** + * Parses and validates the provided with with specified parser. + * The result is returned in an array on success. On fail, false is returned. + * The result is wrapped in an array since we need to be able to distinguish + * between the method returning false and the value being false. + * + * Parsing and validation errors get added to $this->errors. + * + * @since 1.0 + * + * @param ValueParser $parser + * @param mixed $value + * + * @return array|bool + */ + protected function parseAndValidateValue( ValueParser $parser, $value ) { + try { + $value = $parser->parse( $value ); + } + catch ( ParseException $parseException ) { + $this->registerProcessingError( $parseException->getMessage() ); + return false; + } + + if ( $value instanceof DataValue ) { + $value = $value->getValue(); + } + + $this->validateValue( $value ); + + return [ $value ]; + } + + protected function registerProcessingError( string $message ) { + $this->errors[] = $this->newProcessingError( $message ); + } + + protected function newProcessingError( string $message ): ProcessingError { + $severity = $this->isRequired() ? ProcessingError::SEVERITY_FATAL : ProcessingError::SEVERITY_NORMAL; + return new ProcessingError( $message, $severity ); + } + + /** + * @param mixed $value + */ + protected function validateValue( $value ) { + $validationCallback = $this->definition->getValidationCallback(); + + if ( $validationCallback !== null && $validationCallback( $value ) !== true ) { + $this->registerProcessingError( 'Validation callback failed' ); + } + else { + $validator = $this->definition->getValueValidator(); + if ( method_exists( $validator, 'setOptions' ) ) { + $validator->setOptions( $this->definition->getOptions() ); + } + $validationResult = $validator->validate( $value ); + + if ( !$validationResult->isValid() ) { + foreach ( $validationResult->getErrors() as $error ) { + $this->registerProcessingError( $error->getText() ); + } + } + } + } + + /** + * Sets the parameter value to the default if needed. + */ + protected function setToDefaultIfNeeded() { + if ( $this->shouldSetToDefault() ) { + $this->setToDefault(); + } + } + + private function shouldSetToDefault(): bool { + if ( $this->hasFatalError() ) { + return false; + } + + if ( $this->definition->isList() ) { + return $this->errors !== [] && $this->value === []; + } + + return $this->errors !== []; + } + + /** + * Returns the original use-provided name. + * + * @throws Exception + * @return string + */ + public function getOriginalName(): string { + if ( $this->setCount == 0 ) { + throw new Exception( 'No user input set to the parameter yet, so the original name does not exist' ); + } + return $this->originalName; + } + + /** + * Returns the original use-provided value. + * + * @throws Exception + * @return mixed + */ + public function getOriginalValue() { + if ( $this->setCount == 0 ) { + throw new Exception( 'No user input set to the parameter yet, so the original value does not exist' ); + } + return $this->originalValue; + } + + /** + * Returns all validation errors that occurred so far. + * + * @return ProcessingError[] + */ + public function getErrors(): array { + return $this->errors; + } + + /** + * Sets the parameter value to the default. + */ + protected function setToDefault() { + $this->defaulted = true; + $this->value = $this->definition->getDefault(); + } + + public function wasSetToDefault(): bool { + return $this->defaulted; + } + + public function hasFatalError(): bool { + foreach ( $this->errors as $error ) { + if ( $error->isFatal() ) { + return true; + } + } + + return false; + } + + /** + * Returns the ParamDefinition this Param was constructed from. + */ + public function getDefinition(): ParamDefinition { + return $this->definition; + } + + /** + * @return mixed + */ + public function &getValue() { + return $this->value; + } + + public function isRequired(): bool { + return $this->definition->isRequired(); + } + + public function getName(): string { + return $this->definition->getName(); + } + + /** + * @return string[] + */ + public function getAliases(): array { + return $this->definition->getAliases(); + } + +}
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/ParamType.php b/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/ParamType.php new file mode 100644 index 00000000..01022a1d --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/PackagePrivate/ParamType.php @@ -0,0 +1,58 @@ +<?php + +namespace ParamProcessor\PackagePrivate; + +use ParamProcessor\ParamDefinition; +use ValueParsers\NullParser; +use ValueValidators\NullValidator; + +/** + * Package private + */ +class ParamType { + + private $typeId; + + private $className; + private $stringParser; + private $typedParser; + private $validator; + private $validationCallback; + + private function __construct( string $typeId ) { + $this->typeId = $typeId; + } + + public static function newFromArray( string $typeId, array $spec ): self { + $type = new self( $typeId ); + + $type->className = array_key_exists( 'definition', $spec ) ? $spec['definition'] : ParamDefinition::class; + $type->stringParser = array_key_exists( 'string-parser', $spec ) ? $spec['string-parser'] : NullParser::class; + $type->typedParser = array_key_exists( 'typed-parser', $spec ) ? $spec['typed-parser'] : NullParser::class; + $type->validator = array_key_exists( 'validator', $spec ) ? $spec['validator'] : NullValidator::class; + $type->validationCallback = array_key_exists( 'validation-callback', $spec ) ? $spec['validation-callback'] : null; + + return $type; + } + + public function getClassName(): string { + return $this->className; + } + + public function getValidatorClass(): string { + return $this->validator; + } + + public function getValidationCallback(): ?callable { + return $this->validationCallback; + } + + public function getStringParserClass(): string { + return $this->stringParser; + } + + public function getTypedParserClass(): string { + return $this->typedParser; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/Param.php b/www/wiki/vendor/param-processor/param-processor/src/Param.php new file mode 100644 index 00000000..aa05c78c --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/Param.php @@ -0,0 +1,3 @@ +<?php + +class_alias(\ParamProcessor\PackagePrivate\Param::class, 'ParamProcessor\Param');
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/src/ParamDefinition.php b/www/wiki/vendor/param-processor/param-processor/src/ParamDefinition.php new file mode 100644 index 00000000..1f49bb4a --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/ParamDefinition.php @@ -0,0 +1,481 @@ +<?php + +namespace ParamProcessor; + +use Exception; +use ParamProcessor\PackagePrivate\Param; +use ValueParsers\NullParser; +use ValueParsers\ValueParser; +use ValueValidators\NullValidator; +use ValueValidators\ValueValidator; + +/** + * Specifies what kind of values are accepted, how they should be validated, + * how they should be formatted, what their dependencies are and how they should be described. + * + * Try to avoid using this interface outside of ParamProcessor for anything else than defining parameters. + * In particular, do not derive from this class to implement methods such as formatValue. + * + * @since 1.0 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +/* final */ class ParamDefinition implements IParamDefinition { + + /** + * Indicates whether parameters that are provided more then once should be accepted, + * and use the first provided value, or not, and generate an error. + * + * @deprected since 1.7 + * + * @var boolean + */ + public static $acceptOverriding = false; + + /** + * Indicates whether parameters not found in the criteria list + * should be stored in case they are not accepted. The default is false. + * + * @deprected since 1.7 + * + * @var boolean + */ + public static $accumulateParameterErrors = false; + + protected $type; + protected $name; + protected $default; + protected $isList; + + /** + * A message that acts as description for the parameter or false when there is none. + * Can be obtained via getMessage and set via setMessage. + * + * @var string + */ + protected $message; + + /** + * Indicates if the parameter value should trimmed during the clean process. + * @var boolean|null + */ + protected $trimValue = null; + + /** + * Indicates if the parameter manipulations should be applied to the default value. + * @var boolean + */ + protected $applyManipulationsToDefault = true; + + /** + * Dependency list containing parameters that need to be handled before this one. + * @var string[] + */ + protected $dependencies = []; + + /** + * @var string + */ + protected $delimiter = ','; + + /** + * List of aliases for the parameter name. + * + * @var string[] + */ + protected $aliases = []; + + /** + * Original array definition of the parameter + * @var array + */ + protected $options = []; + + /** + * @var ValueParser|null + */ + protected $parser = null; + + /** + * @var ValueValidator|null + */ + protected $validator = null; + + /** + * @var callable|null + */ + protected $validationFunction = null; + + /** + * @param string $type + * @param string $name + * @param mixed $default Use null for no default (which makes the parameter required) + * @param string $message + * @param boolean $isList + */ + public function __construct( string $type, string $name, $default = null, string $message = null, bool $isList = false ) { + $this->type = $type; + $this->name = $name; + $this->default = $default; + $this->message = $message ?? 'validator-message-nodesc'; + $this->isList = $isList; + + $this->postConstruct(); + } + + /** + * Allows deriving classed to do additional stuff on instance construction + * without having to get and pass all the constructor arguments. + * + * @since 1.0 + */ + protected function postConstruct() { + + } + + /** + * Returns if the value should be trimmed before validation and any further processing. + * - true: always trim + * - false: never trim + * - null: trim based on context settings + */ + public function trimDuringClean(): ?bool { + return $this->trimValue; + } + + /** + * Returns the parameter name aliases. + * @return string[] + */ + public function getAliases(): array { + return $this->aliases; + } + + public function hasAlias( string $alias ): bool { + return in_array( $alias, $this->getAliases() ); + } + + /** + * @deprecated since 1.7 + * Returns if the parameter has a certain dependency. + */ + public function hasDependency( string $dependency ): bool { + return in_array( $dependency, $this->getDependencies() ); + } + + /** + * Returns the list of allowed values, or an empty array if there is no such restriction. + */ + public function getAllowedValues(): array { + $allowedValues = []; + + if ( $this->validator !== null && method_exists( $this->validator, 'getWhitelistedValues' ) ) { + if ( method_exists( $this->validator, 'setOptions' ) ) { + $this->validator->setOptions( $this->options ); + } + + $allowedValues = $this->validator->getWhitelistedValues(); + + if ( $allowedValues === false ) { + $allowedValues = []; + } + } + + return $allowedValues; + } + + /** + * @deprecated since 1.7 + * + * @param mixed $default + * @param boolean $manipulate Should the default be manipulated or not? Since 0.4.6. + */ + public function setDefault( $default, $manipulate = true ) { + $this->default = $default; + $this->setDoManipulationOfDefault( $manipulate ); + } + + /** + * Returns the default value. + * @return mixed + */ + public function getDefault() { + return $this->default; + } + + /** + * Returns a message describing the parameter. + */ + public function getMessage(): string { + return $this->message; + } + + /** + * This should be a message key, ie something that can be passed + * to wfMsg. Not an actual text. + */ + public function setMessage( string $message ) { + $this->message = $message; + } + + /** + * Set if the parameter manipulations should be applied to the default value. + */ + public function setDoManipulationOfDefault( bool $doOrDoNotThereIsNoTry ) { + $this->applyManipulationsToDefault = $doOrDoNotThereIsNoTry; + } + + public function shouldManipulateDefault(): bool { + return $this->applyManipulationsToDefault; + } + + /** + * Adds one or more aliases for the parameter name. + * + * @param string|string[] $aliases + */ + public function addAliases( $aliases ) { + $args = func_get_args(); + $this->aliases = array_merge( $this->aliases, is_array( $args[0] ) ? $args[0] : $args ); + } + + /** + * Adds one or more dependencies. There are the names of parameters + * that need to be validated and formatted before this one. + * + * @param string|string[] $dependencies + */ + public function addDependencies( $dependencies ) { + $args = func_get_args(); + $this->dependencies = array_merge( $this->dependencies, is_array( $args[0] ) ? $args[0] : $args ); + } + + public function getName(): string { + return $this->name; + } + + /** + * Returns a message key for a message describing the parameter type. + */ + public function getTypeMessage(): string { + $message = 'validator-type-' . $this->getType(); + + if ( $this->isList() ) { + $message .= '-list'; + } + + return $message; + } + + /** + * @deprecated since 1.7 + * Returns a list of dependencies the parameter has, in the form of + * other parameter names. + * + * @return string[] + */ + public function getDependencies(): array { + return $this->dependencies; + } + + public function isRequired(): bool { + return is_null( $this->default ); + } + + public function isList(): bool { + return $this->isList; + } + + /** + * Returns the delimiter to use to split the raw value in case the + * parameter is a list. + */ + public function getDelimiter(): string { + return $this->delimiter; + } + + /** + * Sets the delimiter to use to split the raw value in case the + * parameter is a list. + */ + public function setDelimiter( string $delimiter ) { + $this->delimiter = $delimiter; + } + + /** + * Sets the parameter definition values contained in the provided array. + * + * @deprecated since 1.7 + * TODO: provide alternative in ParamDefinitionFactory + */ + public function setArrayValues( array $param ) { + if ( array_key_exists( 'aliases', $param ) ) { + $this->addAliases( $param['aliases'] ); + } + + if ( array_key_exists( 'dependencies', $param ) ) { + $this->addDependencies( $param['dependencies'] ); + } + + if ( array_key_exists( 'trim', $param ) ) { + $this->trimValue = $param['trim']; + } + + if ( array_key_exists( 'delimiter', $param ) ) { + $this->delimiter = $param['delimiter']; + } + + if ( array_key_exists( 'manipulatedefault', $param ) ) { + $this->setDoManipulationOfDefault( $param['manipulatedefault'] ); + } + + $this->options = $param; + } + + /** + * @see IParamDefinition::format + * + * @deprecated + * + * @param IParam $param + * @param IParamDefinition[] $definitions + * @param IParam[] $params + */ + public function format( IParam $param, array &$definitions, array $params ) { + /** + * @var Param $param + */ + + if ( $this->isList() && is_array( $param->getValue() ) ) { + // TODO: if isList returns true, the value should be an array. + // The second check here is to avoid a mysterious error. + // Should have logging that writes down the value whenever this occurs. + + $values = $param->getValue(); + + foreach ( $values as &$value ) { + $value = $this->formatValue( $value, $param, $definitions, $params ); + } + + $param->setValue( $values ); + $this->formatList( $param, $definitions, $params ); + } + else { + $param->setValue( $this->formatValue( $param->getValue(), $param, $definitions, $params ) ); + } + + // deprecated, deriving classes should not add array-definitions to the list + $definitions = self::getCleanDefinitions( $definitions ); + + if ( array_key_exists( 'post-format', $this->options ) ) { + $param->setValue( call_user_func( $this->options['post-format'], $param->getValue() ) ); + } + } + + /** + * Formats the parameters values to their final result. + * + * @since 1.0 + * @deprecated + * + * @param $param IParam + * @param $definitions array of IParamDefinition + * @param $params array of IParam + */ + protected function formatList( IParam $param, array &$definitions, array $params ) { + } + + /** + * Formats the parameter value to it's final result. + * + * @since 1.0 + * @deprecated + * + * @param mixed $value + * @param IParam $param + * @param IParamDefinition[] $definitions + * @param IParam[] $params + * + * @return mixed + */ + protected function formatValue( $value, IParam $param, array &$definitions, array $params ) { + return $value; + } + + /** + * Returns a cleaned version of the list of parameter definitions. + * This includes having converted all supported definition types to + * ParamDefinition classes and having all keys set to the names of the + * corresponding parameters. + * + * @deprecated since 1.7 - use ParamDefinitionFactory + * + * @param ParamDefinition[] $definitions + * + * @return ParamDefinition[] + * @throws Exception + */ + public static function getCleanDefinitions( array $definitions ): array { + return ParamDefinitionFactory::singleton()->newDefinitionsFromArrays( $definitions ); + } + + /** + * Returns an identifier for the type of the parameter. + */ + public function getType(): string { + return $this->type; + } + + /** + * Returns a ValueParser object to parse the parameters value. + */ + public function getValueParser(): ValueParser { + if ( $this->parser === null ) { + $this->parser = new NullParser(); + } + + return $this->parser; + } + + /** + * Returns a ValueValidator that can be used to validate the parameters value. + */ + public function getValueValidator(): ValueValidator { + if ( $this->validator === null ) { + $this->validator = new NullValidator(); + } + + return $this->validator; + } + + public function setValueParser( ValueParser $parser ) { + $this->parser = $parser; + } + + public function setValueValidator( ValueValidator $validator ) { + $this->validator = $validator; + } + + /** + * Sets a validation function that will be run before the ValueValidator. + * + * This can be used instead of a ValueValidator where validation is very + * trivial, ie checking if something is a boolean can be done with is_bool. + */ + public function setValidationCallback( ?callable $validationFunction ) { + $this->validationFunction = $validationFunction; + } + + /** + * @see setValidationCallback + */ + public function getValidationCallback(): ?callable { + return $this->validationFunction; + } + + public function getOptions(): array { + return $this->options; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/ParamDefinitionFactory.php b/www/wiki/vendor/param-processor/param-processor/src/ParamDefinitionFactory.php new file mode 100644 index 00000000..dcf72839 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/ParamDefinitionFactory.php @@ -0,0 +1,215 @@ +<?php + +namespace ParamProcessor; + +use Exception; +use OutOfBoundsException; +use ParamProcessor\PackagePrivate\ParamType; +use ValueValidators\NullValidator; + +/** + * Factory for ParamDefinition implementing objects. + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ParamDefinitionFactory { + + private $types; + + /** + * @since 1.8 + */ + public function __construct( ParameterTypes $types = null ) { + $this->types = $types ?? new ParameterTypes(); + } + + /** + * Returns a ParamDefinitionFactory that already has the core parameter types (@see ParameterTypes) registered. + * + * @since 1.6 + */ + public static function newDefault(): self { + return new self( ParameterTypes::newCoreTypes() ); + } + + /** + * @deprecated since 1.0 + */ + public static function singleton(): self { + static $instance = false; + + if ( $instance === false ) { + $instance = new self(); + $instance->registerGlobals(); + } + + return $instance; + } + + /** + * Registers the parameter types specified in the global $wgParamDefinitions. + * @deprecated since 1.6 + */ + public function registerGlobals() { + if ( array_key_exists( 'wgParamDefinitions', $GLOBALS ) ) { + foreach ( $GLOBALS['wgParamDefinitions'] as $type => $data ) { + if ( is_string( $data ) ) { + $data = [ 'definition' => $data ]; + } + + $this->registerType( $type, $data ); + } + } + } + + /** + * Registers a parameter type. + * + * The type is specified as a string identifier for the type, ie 'boolean', + * and an array containing further data. This data currently includes: + * + * - string-parser: the parser to use to transform string values + * This class needs to implement ValueParser. Default: NullParser + * - typed-parser: DEPRECATED since 1.6 - the parser to use to transform typed PHP values + * This class needs to implement ValueParser. Default: NullParser + * - validator: the validation object to use + * This class needs to implement ValueValidator. Default: NullValidator + * - validation-callback a callback to use for validation, called before the ValueValidator + * This callback needs to return a boolean indicating validity. + * + * @since 1.0 + * + * @param string $type + * @param array $data + * + * @return boolean DEPRECATED since 1.6 - Indicates if the type was registered + */ + public function registerType( $type, array $data ) { + if ( $this->types->hasType( $type ) ) { + return false; + } + + $this->types->addType( $type, $data ); + + return true; + } + + /** + * Creates a new instance of a ParamDefinition based on the provided type. + * + * @param string $typeName + * @param string $name + * @param mixed $default + * @param string $message + * @param boolean $isList + * + * @return ParamDefinition + * @throws OutOfBoundsException + */ + public function newDefinition( string $typeName, string $name, $default, string $message, bool $isList = false ): ParamDefinition { + if ( !$this->types->hasType( $typeName ) ) { + throw new OutOfBoundsException( 'Unknown parameter type "' . $typeName . '".' ); + } + + $type = $this->types->getType( $typeName ); + $class = $type->getClassName(); + + /** + * @var ParamDefinition $definition + */ + $definition = new $class( + $typeName, + $name, + $default, + $message, + $isList + ); + + $validator = $type->getValidatorClass(); + + if ( $validator !== NullValidator::class ) { + $definition->setValueValidator( new $validator() ); + } + + $validationCallback = $type->getValidationCallback(); + + if ( $validationCallback !== null ) { + $definition->setValidationCallback( $validationCallback ); + } + + return $definition; + } + + /** + * Package private + */ + public function getType( string $typeName ): ParamType { + return $this->types->getType( $typeName ); + } + + /** + * @param array $definitionArray + * @param bool $getMad DEPRECATED since 1.6 + * + * @return ParamDefinition|false + * @throws Exception + */ + public function newDefinitionFromArray( array $definitionArray, $getMad = true ) { + foreach ( [ 'name', 'message' ] as $requiredElement ) { + if ( !array_key_exists( $requiredElement, $definitionArray ) ) { + if ( $getMad ) { + throw new Exception( 'Could not construct a ParamDefinition from an array without ' . $requiredElement . ' element' ); + } + + return false; + } + } + + $definition = $this->newDefinition( + array_key_exists( 'type', $definitionArray ) ? $definitionArray['type'] : 'string', + $definitionArray['name'], + array_key_exists( 'default', $definitionArray ) ? $definitionArray['default'] : null, + $definitionArray['message'], + array_key_exists( 'islist', $definitionArray ) ? $definitionArray['islist'] : false + ); + + $definition->setArrayValues( $definitionArray ); + + return $definition; + } + + /** + * @since 1.9 + * + * @param array $definitionArrays Each element must either be + * - A definition array with "name" key + * - A name key pointing to a definition array + * - A ParamDefinition instance (discouraged) + * + * @return ParamDefinition[] + * @throws Exception + */ + public function newDefinitionsFromArrays( array $definitionArrays ): array { + $cleanList = []; + + foreach ( $definitionArrays as $key => $definitionArray ) { + if ( is_array( $definitionArray ) ) { + if ( !array_key_exists( 'name', $definitionArray ) && is_string( $key ) ) { + $definitionArray['name'] = $key; + } + + $definitionArray = $this->newDefinitionFromArray( $definitionArray ); + } + + if ( !( $definitionArray instanceof IParamDefinition ) ) { + throw new Exception( 'Parameter definition not an instance of IParamDefinition' ); + } + + $cleanList[$definitionArray->getName()] = $definitionArray; + } + + return $cleanList; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php b/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php new file mode 100644 index 00000000..4f984e51 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php @@ -0,0 +1,106 @@ +<?php + +declare( strict_types = 1 ); + +namespace ParamProcessor; + +use ParamProcessor\Definition\StringParam; +use ParamProcessor\PackagePrivate\DimensionParser; +use ParamProcessor\PackagePrivate\ParamType; +use ValueParsers\BoolParser; +use ValueParsers\FloatParser; +use ValueParsers\IntParser; +use ValueValidators\DimensionValidator; +use ValueValidators\RangeValidator; +use ValueValidators\StringValidator; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ParameterTypes { + + /** + * @since 1.7 + */ + public const BOOLEAN = 'boolean'; + public const FLOAT = 'float'; + public const INTEGER = 'integer'; + public const STRING = 'string'; + public const DIMENSION = 'dimension'; + + /** + * @var ParamType[] + */ + private $types = []; + + /** + * @param array[] $typeSpecs + */ + public function __construct( array $typeSpecs = [] ) { + foreach ( $typeSpecs as $typeName => $typeSpec ) { + $this->addType( $typeName, $typeSpec ); + } + } + + /** + * @since 1.8 + */ + public function addType( string $typeName, array $typeSpec ) { + $this->types[$typeName] = ParamType::newFromArray( $typeName, $typeSpec ); + } + + /** + * Package private + */ + public function hasType( string $typeName ): bool { + return array_key_exists( $typeName, $this->types ); + } + + /** + * Package private + */ + public function getType( string $typeName ): ParamType { + return $this->types[$typeName]; + } + + /** + * @since 1.8 + */ + public static function newCoreTypes(): self { + return new self( self::getCoreTypes() ); + } + + /** + * @since 1.4 + */ + public static function getCoreTypes(): array { + return [ + self::BOOLEAN => [ + 'string-parser' => BoolParser::class, + 'validation-callback' => 'is_bool', + ], + self::FLOAT => [ + 'string-parser' => FloatParser::class, + 'validation-callback' => function( $value ) { + return is_float( $value ) || is_int( $value ); + }, + 'validator' => RangeValidator::class, + ], + self::INTEGER => [ + 'string-parser' => IntParser::class, + 'validation-callback' => 'is_int', + 'validator' => RangeValidator::class, + ], + self::STRING => [ + 'validator' => StringValidator::class, + 'definition' => StringParam::class, + ], + self::DIMENSION => [ + 'string-parser' => DimensionParser::class, + 'validator' => DimensionValidator::class, + ], + ]; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/ProcessedParam.php b/www/wiki/vendor/param-processor/param-processor/src/ProcessedParam.php new file mode 100644 index 00000000..af87c32d --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/ProcessedParam.php @@ -0,0 +1,73 @@ +<?php + +namespace ParamProcessor; + +/** + * Object representing a parameter that has been processed. + * + * @since 1.0 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ProcessedParam { + + private $value; + private $name; + private $wasSetToDefault; + private $originalValue = null; + private $originalName = null; + + /** + * @param string $name + * @param mixed $value + * @param boolean $wasSetToDefault + * @param string|null $originalName + * @param mixed $originalValue + */ + public function __construct( string $name, $value, bool $wasSetToDefault, string $originalName = null, $originalValue = null ) { + $this->name = $name; + $this->value = $value; + $this->wasSetToDefault = $wasSetToDefault; + $this->originalName = $originalName; + $this->originalValue = $originalValue; + } + + public function setOriginalName( string $originalName ) { + $this->originalName = $originalName; + } + + /** + * @param mixed $originalValue + */ + public function setOriginalValue( $originalValue ) { + $this->originalValue = $originalValue; + } + + /** + * @return mixed + */ + public function getValue() { + return $this->value; + } + + public function getName(): string { + return $this->name; + } + + public function wasSetToDefault(): bool { + return $this->wasSetToDefault; + } + + /** + * @return null|mixed + */ + public function getOriginalValue() { + return $this->originalValue; + } + + public function getOriginalName(): ?string { + return $this->originalName; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/ProcessingError.php b/www/wiki/vendor/param-processor/param-processor/src/ProcessingError.php new file mode 100644 index 00000000..2e5cd51a --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/ProcessingError.php @@ -0,0 +1,182 @@ +<?php + +namespace ParamProcessor; + +/** + * @since 1.0 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ProcessingError { + + const SEVERITY_MINOR = 0; // Minor error. ie a deprecation notice + const SEVERITY_LOW = 1; // Lower-then-normal severity. ie an unknown parameter + const SEVERITY_NORMAL = 2; // Normal severity. ie an invalid value provided + const SEVERITY_HIGH = 3; // Higher-then-normal severity. ie an invalid value for a significant parameter + const SEVERITY_FATAL = 4; // Fatal error. Either a missing or an invalid required parameter + + const ACTION_IGNORE = 0; // Ignore the error + const ACTION_LOG = 1; // Log the error + const ACTION_WARN = 2; // Warn that there is an error + const ACTION_SHOW = 3; // Show the error + const ACTION_DEMAND = 4; // Show the error and don't render output + + public $message; + public $severity; + + /** + * List of 'tags' for the error. This is mainly meant for indicating an error + * type, such as 'missing parameter' or 'invalid value', but allows for multiple + * such indications. + * + * @since 0.4 + * + * @var string[] + */ + private $tags; + + /** + * Where the error occurred. + * + * @since 0.4 + * + * @var string|bool + */ + public $element; + + /** + * @param string $message + * @param integer $severity + * @param string|bool $element + * @param string[] $tags + */ + public function __construct( string $message, int $severity = self::SEVERITY_NORMAL, $element = false, array $tags = [] ) { + $this->message = $message; + $this->severity = $severity; + $this->element = $element; + $this->tags = $tags; + } + + /** + * Adds one or more tags. + * + * @since 0.4.1 + * + * @param string|string[] $criteria + */ + public function addTags() { + $args = func_get_args(); + $this->tags = array_merge( $this->tags, is_array( $args[0] ) ? $args[0] : $args ); + } + + public function getMessage(): string { + return $this->message; + } + + /** + * Returns the element this error occurred at, or 'unknown' when i's unknown. + */ + public function getElement(): string { + return ( $this->element === false || $this->element === '' ) ? 'unknown' : $this->element; + } + + /** + * Returns the severity of the error. + * @return integer Element of the self::SEVERITY_ enum + */ + public function getSeverity(): int { + return $this->severity; + } + + /** + * Returns if the severity is equal to or bigger then the provided one. + */ + public function hasSeverity( int $severity ): bool { + return $this->severity >= $severity; + } + + /** + * Returns if the error has a certain tag. + */ + public function hasTag( string $tag ): bool { + return in_array( $tag, $this->tags ); + } + + /** + * @return string[] + */ + public function getTags(): array { + return $this->tags; + } + + /** + * Returns the action associated with the errors severity. + * + * @return integer Element of the self::ACTION_ enum + * @throws \Exception + */ + public function getAction(): int { + // TODO: as option + $errorActions = [ + self::SEVERITY_MINOR => self::ACTION_LOG, + self::SEVERITY_LOW => self::ACTION_WARN, + self::SEVERITY_NORMAL => self::ACTION_SHOW, + self::SEVERITY_HIGH => self::ACTION_DEMAND, + ]; + + if ( $this->severity === self::SEVERITY_FATAL ) { + // This action should not be configurable, as lowering it would break in the Validator class. + return self::ACTION_DEMAND; + } + elseif ( array_key_exists( $this->severity, $errorActions ) ) { + return $errorActions[$this->severity]; + } + else { + throw new \Exception( "No action associated with error severity '$this->severity'" ); + } + } + + /** + * Returns if the action associated with the severity is equal to or bigger then the provided one. + */ + public function hasAction( int $action ): bool { + return $this->getAction() >= $action; + } + + /** + * Returns if the error is fatal. + */ + public function isFatal(): bool { + return $this->hasSeverity( self::SEVERITY_FATAL ); + } + + /** + * Returns if the error should be logged. + */ + public function shouldLog(): bool { + return $this->hasAction( self::ACTION_LOG ); + } + + /** + * Returns if there should be a warning that errors are present. + */ + public function shouldWarn(): bool { + return $this->hasAction( self::ACTION_WARN ); + } + + /** + * Returns if the error message should be shown. + */ + public function shouldShow(): bool { + return $this->hasAction( self::ACTION_SHOW ); + } + + /** + * Returns if the error message should be shown, and the output not be rendered. + */ + public function shouldDemand(): bool { + return $this->hasAction( self::ACTION_DEMAND ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/ProcessingErrorHandler.php b/www/wiki/vendor/param-processor/param-processor/src/ProcessingErrorHandler.php new file mode 100644 index 00000000..faa6fcea --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/ProcessingErrorHandler.php @@ -0,0 +1,59 @@ +<?php + +namespace ParamProcessor; + +/** + * Static class for error handling. + * + * @since 0.4 + * @deprecated since 1.0 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +final class ProcessingErrorHandler { + + /** + * @since 0.4 + * + * @var array of ProcessingError + */ + private static $errors = []; + + /** + * Adds a single ProcessingError. + * + * @since 0.4 + * + * @param string $errorMessage + * @param integer $severity + */ + public static function addError( ProcessingError $error ) { + self::$errors[$error->getElement()][] = $error; + } + + /** + * Adds a list of ProcessingError. + * + * @since 0.4 + * + * @param array $errors + */ + public static function addErrors( array $errors ) { + foreach ( $errors as $error ) { + self::addError( $error ); + } + } + + /** + * Returns a list of all registered errors. + * + * @since 0.4 + * + * @return array of ProcessingError + */ + public static function getErrors() { + return self::$errors; + } + +}
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/src/ProcessingResult.php b/www/wiki/vendor/param-processor/param-processor/src/ProcessingResult.php new file mode 100644 index 00000000..f184808f --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/ProcessingResult.php @@ -0,0 +1,62 @@ +<?php + +namespace ParamProcessor; + +/** + * @since 1.0 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ProcessingResult { + + private $parameters; + private $errors; + + /** + * @param ProcessedParam[] $parameters + * @param ProcessingError[] $errors + */ + public function __construct( array $parameters, array $errors = [] ) { + $this->parameters = $parameters; + $this->errors = $errors; + } + + /** + * @return ProcessedParam[] + */ + public function getParameters(): array { + return $this->parameters; + } + + /** + * @since 1.8 + */ + public function getParameterArray(): array { + $parameters = []; + + foreach ( $this->parameters as $parameter ) { + $parameters[$parameter->getName()] = $parameter->getValue(); + } + + return $parameters; + } + + /** + * @return ProcessingError[] + */ + public function getErrors(): array { + return $this->errors; + } + + public function hasFatal(): bool { + foreach ( $this->errors as $error ) { + if ( $error->isFatal() ) { + return true; + } + } + + return false; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/Processor.php b/www/wiki/vendor/param-processor/param-processor/src/Processor.php new file mode 100644 index 00000000..73a8d67a --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/Processor.php @@ -0,0 +1,484 @@ +<?php + +namespace ParamProcessor; + +use ParamProcessor\PackagePrivate\Param; + +/** + * Class for parameter validation of a single parser hook or other parametrized construct. + * + * @since 0.1 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + * @author Daniel Werner + */ +class Processor { + + /** + * Flag for unnamed default parameters used in Processor::setFunctionParams() to determine that + * a parameter should not have a named fallback. + * + * @since 0.4.13 + */ + const PARAM_UNNAMED = 1; + + /** + * @var Param[] + */ + private $params; + + /** + * Associative array containing parameter names (keys) and their user-provided data (values). + * This list is needed because additional parameter definitions can be added to the $parameters + * field during validation, so we can't determine in advance if a parameter is unknown. + * @var string[] + */ + private $rawParameters = []; + + /** + * Array containing the names of the parameters to handle, ordered by priority. + * @var string[] + */ + private $paramsToHandle = []; + + /** + * @var ParamDefinition[] + */ + private $paramDefinitions = []; + + /** + * @var ProcessingError[] + */ + private $errors = []; + + private $options; + + public function __construct( Options $options ) { + $this->options = $options; + } + + /** + * Constructs and returns a Validator object based on the default options. + */ + public static function newDefault(): self { + return new Processor( new Options() ); + } + + /** + * Constructs and returns a Validator object based on the provided options. + */ + public static function newFromOptions( Options $options ): self { + return new Processor( $options ); + } + + /** + * Returns the options used by this Validator object. + */ + public function getOptions(): Options { + return $this->options; + } + + /** + * Determines the names and values of all parameters. Also takes care of default parameters. + * After that the resulting parameter list is passed to Processor::setParameters + * + * @since 0.4 + * + * @param string[] $rawParams + * @param ParamDefinition[]|array[] $parameterDefinitions DEPRECATED! Use @see setParameterDefinitions instead + * @param array $defaultParams array of strings or array of arrays to define which parameters can be used unnamed. + * The second value in array-form is reserved for flags. Currently, Processor::PARAM_UNNAMED determines that + * the parameter has no name which can be used to set it. Therefore all these parameters must be set before + * any named parameter. The effect is, that '=' within the string won't confuse the parameter anymore like + * it would happen with default parameters that still have a name as well. + */ + public function setFunctionParams( array $rawParams, array $parameterDefinitions = [], array $defaultParams = [] ) { + $lastUnnamedDefaultNr = -1; + + /* + * Find last parameter with self::PARAM_UNNAMED set. Tread all parameters in front as + * the flag were set for them as well to ensure that there can't be any unnamed params + * after the first named param. Wouldn't be possible to determine which unnamed value + * belongs to which parameter otherwise. + */ + for( $i = count( $defaultParams ) - 1; $i >= 0; $i-- ) { + $dflt = $defaultParams[$i]; + if( is_array( $dflt ) && !empty( $dflt[1] ) && ( $dflt[1] | self::PARAM_UNNAMED ) ) { + $lastUnnamedDefaultNr = $i; + break; + } + } + + $parameters = []; + $nr = 0; + $defaultNr = 0; + + foreach ( $rawParams as $arg ) { + // Only take into account strings. If the value is not a string, + // it is not a raw parameter, and can not be parsed correctly in all cases. + if ( is_string( $arg ) ) { + $parts = explode( '=', $arg, ( $nr <= $lastUnnamedDefaultNr ? 1 : 2 ) ); + + // If there is only one part, no parameter name is provided, so try default parameter assignment. + // Default parameters having self::PARAM_UNNAMED set for having no name alias go here in any case. + if ( count( $parts ) == 1 ) { + // Default parameter assignment is only possible when there are default parameters! + if ( count( $defaultParams ) > 0 ) { + $defaultParam = array_shift( $defaultParams ); + if( is_array( $defaultParam ) ) { + $defaultParam = $defaultParam[0]; + } + $defaultParam = strtolower( $defaultParam ); + + $parameters[$defaultParam] = [ + 'original-value' => trim( $parts[0] ), + 'default' => $defaultNr, + 'position' => $nr + ]; + $defaultNr++; + } + } else { + $paramName = trim( strtolower( $parts[0] ) ); + + $parameters[$paramName] = [ + 'original-value' => trim( $parts[1] ), + 'default' => false, + 'position' => $nr + ]; + + // Let's not be evil, and remove the used parameter name from the default parameter list. + // This code is basically a remove array element by value algorithm. + $newDefaults = []; + + foreach( $defaultParams as $defaultParam ) { + if ( $defaultParam != $paramName ) { + $newDefaults[] = $defaultParam; + } + } + + $defaultParams = $newDefaults; + } + } + + $nr++; + } + + $this->setParameters( $parameters, $parameterDefinitions ); + } + + /** + * @since 1.6.0 + * @param ParamDefinition[] $paramDefinitions + */ + public function setParameterDefinitions( array $paramDefinitions ) { + $this->paramDefinitions = $paramDefinitions; + } + + /** + * Loops through a list of provided parameters, resolves aliasing and stores errors + * for unknown parameters and optionally for parameter overriding. + * + * @param array $parameters Parameter name as key, parameter value as value + * @param ParamDefinition[]|array[] $paramDefinitions DEPRECATED! Use @see setParameterDefinitions instead + */ + public function setParameters( array $parameters, array $paramDefinitions = [] ) { + $this->paramDefinitions = ParamDefinition::getCleanDefinitions( $paramDefinitions ); + + // Loop through all the user provided parameters, and distinguish between those that are allowed and those that are not. + foreach ( $parameters as $paramName => $paramData ) { + if ( $this->options->lowercaseNames() ) { + $paramName = strtolower( $paramName ); + } + + if ( $this->options->trimNames() ) { + $paramName = trim( $paramName ); + } + + $paramValue = is_array( $paramData ) ? $paramData['original-value'] : $paramData; + + $this->rawParameters[$paramName] = $paramValue; + } + } + + /** + * @param string $message + * @param string[] $tags + * @param integer $severity + */ + private function registerNewError( string $message, array $tags = [], int $severity = ProcessingError::SEVERITY_NORMAL ) { + $this->registerError( + new ProcessingError( + $message, + $severity, + $this->options->getName(), + (array)$tags + ) + ); + } + + private function registerError( ProcessingError $error ) { + $error->element = $this->options->getName(); + $this->errors[] = $error; + ProcessingErrorHandler::addError( $error ); + } + + /** + * Validates and formats all the parameters (but aborts when a fatal error occurs). + * + * @since 0.4 + * @deprecated since 1.0, use processParameters + */ + public function validateParameters() { + $this->doParamProcessing(); + } + + public function processParameters(): ProcessingResult { + $this->doParamProcessing(); + + if ( !$this->hasFatalError() && $this->options->unknownIsInvalid() ) { + // Loop over the remaining raw parameters. + // These are unrecognized parameters, as they where not used by any parameter definition. + foreach ( $this->rawParameters as $paramName => $paramValue ) { + $this->registerNewError( + $paramName . ' is not a valid parameter', // TODO + [ $paramName ] + ); + } + } + + return $this->newProcessingResult(); + } + + private function newProcessingResult(): ProcessingResult { + $parameters = []; + + if ( !is_array( $this->params ) ) { + $this->params = []; + } + + foreach ( $this->params as $parameter ) { + // TODO + $processedParam = new ProcessedParam( + $parameter->getName(), + $parameter->getValue(), + $parameter->wasSetToDefault() + ); + + // TODO: it is possible these values where set even when the value defaulted, + // so this logic is not correct and could be improved + if ( !$parameter->wasSetToDefault() ) { + $processedParam->setOriginalName( $parameter->getOriginalName() ); + $processedParam->setOriginalValue( $parameter->getOriginalValue() ); + } + + $parameters[$processedParam->getName()] = $processedParam; + } + + return new ProcessingResult( + $parameters, + $this->getErrors() + ); + } + + private function doParamProcessing() { + $this->errors = []; + + $this->getParamsToProcess( [], $this->paramDefinitions ); + + while ( $this->paramsToHandle !== [] && !$this->hasFatalError() ) { + $this->processOneParam(); + } + } + + private function processOneParam() { + $paramName = array_shift( $this->paramsToHandle ); + $definition = $this->paramDefinitions[$paramName]; + + $param = new Param( $definition ); + + $setUserValue = $this->attemptToSetUserValue( $param ); + + // If the parameter is required but not provided, register a fatal error and stop processing. + if ( !$setUserValue && $param->isRequired() ) { + $this->registerNewError( + "Required parameter '$paramName' is missing", // FIXME: i18n validator_error_required_missing + [ $paramName, 'missing' ], + ProcessingError::SEVERITY_FATAL + ); + return; + } + + $this->params[$param->getName()] = $param; + + $initialSet = $this->paramDefinitions; + + $param->process( $this->paramDefinitions, $this->params, $this->options ); + + foreach ( $param->getErrors() as $error ) { + $this->registerError( $error ); + } + + if ( $param->hasFatalError() ) { + return; + } + + $this->getParamsToProcess( $initialSet, $this->paramDefinitions ); + } + + /** + * Gets an ordered list of parameters to process. + * @throws \UnexpectedValueException + */ + private function getParamsToProcess( array $initialParamSet, array $resultingParamSet ) { + if ( $initialParamSet === [] ) { + $this->paramsToHandle = array_keys( $resultingParamSet ); + } + else { + if ( !is_array( $this->paramsToHandle ) ) { + $this->paramsToHandle = []; + } + + foreach ( $resultingParamSet as $paramName => $parameter ) { + if ( !array_key_exists( $paramName, $initialParamSet ) ) { + $this->paramsToHandle[] = $paramName; + } + } + } + + $this->paramsToHandle = $this->getParameterNamesInEvaluationOrder( $this->paramDefinitions, $this->paramsToHandle ); + } + + /** + * @param ParamDefinition[] $paramDefinitions + * @param string[] $paramsToHandle + * + * @return array + */ + private function getParameterNamesInEvaluationOrder( array $paramDefinitions, array $paramsToHandle ): array { + $dependencyList = []; + + foreach ( $paramsToHandle as $paramName ) { + $dependencies = []; + + if ( !array_key_exists( $paramName, $paramDefinitions ) ) { + throw new \UnexpectedValueException( 'Unexpected parameter name "' . $paramName . '"' ); + } + + if ( !is_object( $paramDefinitions[$paramName] ) || !( $paramDefinitions[$paramName] instanceof ParamDefinition ) ) { + throw new \UnexpectedValueException( 'Parameter "' . $paramName . '" is not a ParamDefinition' ); + } + + // Only include dependencies that are in the list of parameters to handle. + foreach ( $paramDefinitions[$paramName]->getDependencies() as $dependency ) { + if ( in_array( $dependency, $paramsToHandle ) ) { + $dependencies[] = $dependency; + } + } + + $dependencyList[$paramName] = $dependencies; + } + + $sorter = new TopologicalSort( $dependencyList, true ); + + return $sorter->doSort(); + } + + /** + * Tries to find a matching user provided value and, when found, assigns it + * to the parameter, and removes it from the raw values. Returns a boolean + * indicating if there was any user value set or not. + */ + private function attemptToSetUserValue( Param $param ): bool { + if ( array_key_exists( $param->getName(), $this->rawParameters ) ) { + $param->setUserValue( $param->getName(), $this->rawParameters[$param->getName()], $this->options ); + unset( $this->rawParameters[$param->getName()] ); + return true; + } + else { + foreach ( $param->getDefinition()->getAliases() as $alias ) { + if ( array_key_exists( $alias, $this->rawParameters ) ) { + $param->setUserValue( $alias, $this->rawParameters[$alias], $this->options ); + unset( $this->rawParameters[$alias] ); + return true; + } + } + } + + return false; + } + + /** + * @deprecated since 1.0 + * @return Param[] + */ + public function getParameters(): array { + return $this->params; + } + + /** + * @deprecated since 1.0 + */ + public function getParameter( string $parameterName ): Param { + return $this->params[$parameterName]; + } + + /** + * Returns an associative array with the parameter names as key and their + * corresponding values as value. + * @deprecated since 1.7 - use processParameters() return value + */ + public function getParameterValues(): array { + $parameters = []; + + foreach ( $this->params as $parameter ) { + $parameters[$parameter->getName()] = $parameter->getValue(); + } + + return $parameters; + } + + /** + * @deprecated since 1.7 - use processParameters() return value + * @return ProcessingError[] + */ + public function getErrors(): array { + return $this->errors; + } + + /** + * @deprecated since 1.7 - use processParameters() return value + * @return string[] + */ + public function getErrorMessages(): array { + $errors = []; + + foreach ( $this->errors as $error ) { + $errors[] = $error->getMessage(); + } + + return $errors; + } + + /** + * @deprecated since 1.7 - use processParameters() return value + */ + public function hasErrors(): bool { + return !empty( $this->errors ); + } + + /** + * @deprecated since 1.7 - use processParameters() return value + * @return ProcessingError|boolean false + */ + public function hasFatalError() { + foreach ( $this->errors as $error ) { + if ( $error->isFatal() ) { + return $error; + } + } + + return false; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/Settings.php b/www/wiki/vendor/param-processor/param-processor/src/Settings.php new file mode 100644 index 00000000..b38c59e6 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/Settings.php @@ -0,0 +1,65 @@ +<?php + +namespace ParamProcessor; + +/** + * File defining the settings for the ParamProcessor extension. + * More info can be found at https://www.mediawiki.org/wiki/Extension:Validator#Settings + * + * NOTICE: + * Changing one of these settings can be done by assigning to $egValidatorSettings, + * AFTER the inclusion of the extension itself. + * + * @deprecated since 1.7 + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +final class Settings { + + /** + * Constructs a new instance of the settings object from global state. + * + * @since 1.0 + * + * @param array $globalVariables + * + * @return Settings + */ + public static function newFromGlobals( array $globalVariables ) { + return new self( $globalVariables['egValidatorSettings'] ); + } + + /** + * @since 1.0 + * + * @var array + */ + private $settings; + + /** + * Constructor. + * + * @since 1.0 + * + * @param array $settings + */ + public function __construct( array $settings ) { + $this->settings = $settings; + } + + /** + * Returns the setting with the provided name. + * The specified setting needs to exist. + * + * @since 1.0 + * + * @param string $settingName + * + * @return mixed + */ + public function get( $settingName ) { + return $this->settings[$settingName]; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/src/TopologicalSort.php b/www/wiki/vendor/param-processor/param-processor/src/TopologicalSort.php new file mode 100644 index 00000000..ccb79eac --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/src/TopologicalSort.php @@ -0,0 +1,160 @@ +<?php + +namespace ParamProcessor; + +/** + * Sorts a series of dependency pairs in linear order. + * + * Based on http://blog.metafoundry.com/2007/09/topological-sort-in-php.html + * + * @deprecated since 1.7 + * @codingStandardsIgnoreFile + */ +class TopologicalSort { + + private $mNodes = []; + private $mNodeNames = []; + + /** + * Dependency pairs are a list of arrays in the form + * $name => $val where $key must come before $val in load order. + */ + public function __construct( array $dependencies = [], $parse = true ) { + $this->mNodeNames = array_keys( $dependencies ); + + if ( $parse ) { + $dependencies = $this->parseDependencyList( $dependencies ); + } + + // turn pairs into double-linked node tree + foreach ( $dependencies as $dpair ) { + $module = key( $dpair ); + $dependency = current( $dpair ); + if ( !isset( $this->mNodes[$module] ) ) $this->mNodes[$module] = new TSNode( $module ); + if ( !isset( $this->mNodes[$dependency] ) ) $this->mNodes[$dependency] = new TSNode( $dependency ); + if ( !in_array( $dependency, $this->mNodes[$module]->children ) ) $this->mNodes[$module]->children[] = $dependency; + if ( !in_array( $module, $this->mNodes[$dependency]->parents ) ) $this->mNodes[$dependency]->parents[] = $module; + } + } + + /** + * Perform Topological Sort. + * + * @return array Sorted array + */ + public function doSort() { + $nodes = $this->mNodes; + + // get nodes without parents + $root_nodes = array_values( $this->getRootNodes( $nodes ) ); + + // begin algorithm + $sorted = []; + while ( count( $nodes ) > 0 ) { + // check for circular reference + if ( $root_nodes === [] ) { + return []; + } + + + // remove this node from root_nodes + // and add it to the output + $n = array_pop( $root_nodes ); + $sorted[] = $n->name; + + // for each of its children + // queue the new node finally remove the original + for ( $i = count( $n->children ) - 1; $i >= 0; $i -- ) { + $childnode = $n->children[$i]; + // remove the link from this node to its + // children ($nodes[$n->name]->children[$i]) AND + // remove the link from each child to this + // parent ($nodes[$childnode]->parents[?]) THEN + // remove this child from this node + unset( $nodes[$n->name]->children[$i] ); + $parent_position = array_search ( $n->name, $nodes[$childnode]->parents ); + unset( $nodes[$childnode]->parents[$parent_position] ); + // check if this child has other parents + // if not, add it to the root nodes list + if ( !count( $nodes[$childnode]->parents ) ) { + array_push( $root_nodes, $nodes [$childnode] ); + } + } + + // nodes.Remove(n); + unset( $nodes[$n->name] ); + } + + $looseNodes = []; + + // Return the result with the loose nodes (items with no dependencies) appended. + foreach( $this->mNodeNames as $name ) { + if ( !in_array( $name, $sorted ) ) { + $looseNodes[] = $name; + } + } + + return array_merge( $sorted, $looseNodes ); + } + + /** + * Returns a list of node objects that do not have parents + * + * @param array $nodes array of node objects + * + * @return array of node objects + */ + private function getRootNodes( array $nodes ) { + $output = []; + + foreach ( $nodes as $name => $node ) { + if ( !count ( $node->parents ) ) { + $output[$name] = $node; + } + } + + return $output; + } + + /** + * Parses an array of dependencies into an array of dependency pairs + * + * The array of dependencies would be in the form: + * $dependency_list = array( + * "name" => array("dependency1","dependency2","dependency3"), + * "name2" => array("dependencyA","dependencyB","dependencyC"), + * ...etc + * ); + * + * @param array $dlist Array of dependency pairs for use as parameter in doSort method + * + * @return array + */ + private function parseDependencyList( array $dlist = [] ) { + $output = []; + + foreach ( $dlist as $name => $dependencies ) { + foreach ( $dependencies as $d ) { + $output[] = [ $d => $name ]; + } + } + + return $output; + } +} + +/** + * @deprecated since 1.7 + */ +class TSNode { + public $name; + public $children = []; + public $parents = []; + + public function __construct( $name = '' ) { + if ( !is_string( $name ) ) { + throw new \InvalidArgumentException( 'Name needs to be a string' ); + } + $this->name = $name; + } +}
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/BoolParamTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/BoolParamTest.php new file mode 100644 index 00000000..d8b23f06 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/BoolParamTest.php @@ -0,0 +1,72 @@ +<?php + +namespace ParamProcessor\Tests\Integration\Definitions; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class BoolParamTest extends ParamDefinitionTest { + + /** + * @see ParamDefinitionTest::getDefinitions + * @return array + */ + public function getDefinitions() { + $params = parent::getDefinitions(); + + return $params; + } + + /** + * @see ParamDefinitionTest::valueProvider + * + * @param boolean $stringlyTyped + * + * @return array + */ + public function valueProvider( $stringlyTyped = true ) { + $values = [ + 'empty' => [ + [ 'yes', true, true ], + [ 'on', true, true ], + [ '1', true, true ], + [ 'no', true, false ], + [ 'off', true, false ], + [ '0', true, false ], + [ 'foobar', false ], + [ '2', false ], + [ [], false ], + [ 42, false ], + ], + 'values' => [], +// 'values' => array( +// array( '1', true, true ), +// array( 'yes', true, true ), +// array( 'no', false ), +// array( 'foobar', false ), +// ), + ]; + + if ( !$stringlyTyped ) { + foreach ( $values as &$set ) { + foreach ( $set as &$value ) { + if ( in_array( $value[0], [ 'yes', 'on', '1', '0', 'off', 'no' ], true ) ) { + $value[0] = in_array( $value[0], [ 'yes', 'on', '1' ], true ); + } + } + } + } + + return $values; + } + + /** + * @see ParamDefinitionTest::getType + * @return string + */ + public function getType() { + return 'boolean'; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/FloatParamTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/FloatParamTest.php new file mode 100644 index 00000000..742f1342 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/FloatParamTest.php @@ -0,0 +1,72 @@ +<?php + +namespace ParamProcessor\Tests\Integration\Definitions; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class FloatParamTest extends NumericParamTest { + + /** + * @see ParamDefinitionTest::getDefinitions + * @return array + */ + public function getDefinitions() { + $params = parent::getDefinitions(); + + return $params; + } + + /** + * @see ParamDefinitionTest::valueProvider + * + * @param boolean $stringlyTyped + * + * @return array + */ + public function valueProvider( $stringlyTyped = true ) { + $values = [ + 'empty' => [ + [ 1, true, 1.0 ], + [ 1.0, true, 1.0 ], + [ 1.1, true, 1.1 ], + [ 0.2555, true, 0.2555 ], + [ '1.1.1', false ], + [ 'foobar', false ], + [ [], false ], + [ 'yes', false ], + [ false, false ], + ], + 'values' => [], +// 'values' => array( +// array( 1, true, 1 ), +// array( 'yes', false ), +// array( 'no', false ), +// array( 0.1, true, 0.1 ), +// array( 0.2555, false ), +// ), + ]; + + if ( $stringlyTyped ) { + foreach ( $values as &$set ) { + foreach ( $set as &$value ) { + if ( is_float( $value[0] ) || is_int( $value[0] ) ) { + $value[0] = (string)$value[0]; + } + } + } + } + + return $values; + } + + /** + * @see ParamDefinitionTest::getType + * @return string + */ + public function getType() { + return 'float'; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/IntParamTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/IntParamTest.php new file mode 100644 index 00000000..4e8872e8 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/IntParamTest.php @@ -0,0 +1,98 @@ +<?php + +namespace ParamProcessor\Tests\Integration\Definitions; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class IntParamTest extends NumericParamTest { + + /** + * @see ParamDefinitionTest::getDefinitions + * @return array + */ + public function getDefinitions() { + $params = parent::getDefinitions(); + + $params['count'] = [ + 'type' => 'integer', + ]; + + $params['amount'] = [ + 'type' => 'integer', + 'default' => 42, + 'upperbound' => 99, + ]; + + $params['number'] = [ + 'type' => 'integer', + 'upperbound' => 99, + ]; + + return $params; + } + + /** + * @see ParamDefinitionTest::valueProvider + * + * @param boolean $stringlyTyped + * + * @return array + */ + public function valueProvider( $stringlyTyped = true ) { + $values = [ + 'count' => [ + [ 42, true, 42 ], + [ 'foo', false ], + [ 4.2, false ], + [ [ 42 ], false ], + ], + 'amount' => [ + [ 0, true, 0 ], + [ 'foo', false, 42 ], + [ 100, false, 42 ], + [ 4.2, false, 42 ], + ], + 'number' => [ + [ 42, true, 42 ], + [ 'foo', false ], + [ 100, false ], + [ 4.2, false ], + ], + 'empty' => [ + [ 42, true, 42 ], + [ 4.2, false ], + [ [ 42 ], false ], + ], + 'values' => [ + [ 1, true, 1 ], + [ 'yes', false ], + [ true, false ], + [ 0.1, false ], + [ [], false ], + ], + ]; + + if ( $stringlyTyped ) { + foreach ( $values as &$set ) { + foreach ( $set as &$value ) { + if ( is_float( $value[0] ) || is_int( $value[0] ) ) { + $value[0] = (string)$value[0]; + } + } + } + } + + return $values; + } + + /** + * @see ParamDefinitionTest::getType + * @return string + */ + public function getType() { + return 'integer'; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/NumericParamTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/NumericParamTest.php new file mode 100644 index 00000000..2af9a2b0 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/NumericParamTest.php @@ -0,0 +1,69 @@ +<?php + +namespace ParamProcessor\Tests\Integration\Definitions; + +use ParamProcessor\Options; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +abstract class NumericParamTest extends ParamDefinitionTest { + + public function lowerBoundProvider() { + return [ + [ 42, 42, true ], + [ 42, 41, false ], + [ 42, 43, true ], + [ false, 43, true ], + [ false, 0, true ], + [ false, -100, true ], + [ -100, -100, true ], + [ -99, -100, false ], + [ -101, -100, true ], + ]; + } + + /** + * @dataProvider lowerBoundProvider + */ + public function testSetLowerBound( $bound, $testValue, $validity ) { + $definition = $this->getEmptyInstance(); + $definition->setArrayValues( [ 'lowerbound' => $bound ] ); + + $this->validate( $definition, (string)$testValue, $validity ); + + $options = new Options(); + $options->setRawStringInputs( false ); + $this->validate( $definition, $testValue, $validity, $options ); + } + + public function upperBoundProvider() { + return [ + [ 42, 42, true ], + [ 42, 41, true ], + [ 42, 43, false ], + [ false, 43, true ], + [ false, 0, true ], + [ false, -100, true ], + [ -100, -100, true ], + [ -99, -100, true ], + [ -101, -100, false ], + ]; + } + + /** + * @dataProvider upperBoundProvider + */ + public function testSetUpperBound( $bound, $testValue, $validity ) { + $definition = $this->getEmptyInstance(); + $definition->setArrayValues( [ 'upperbound' => $bound ] ); + + $this->validate( $definition, (string)$testValue, $validity ); + + $options = new Options(); + $options->setRawStringInputs( false ); + $this->validate( $definition, $testValue, $validity, $options ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/ParamDefinitionTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/ParamDefinitionTest.php new file mode 100644 index 00000000..64ac9004 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/ParamDefinitionTest.php @@ -0,0 +1,166 @@ +<?php + +namespace ParamProcessor\Tests\Integration\Definitions; + +use ParamProcessor\IParamDefinition; +use ParamProcessor\Options; +use ParamProcessor\PackagePrivate\Param; +use ParamProcessor\ParamDefinition; +use ParamProcessor\ParamDefinitionFactory; +use PHPUnit\Framework\TestCase; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +abstract class ParamDefinitionTest extends TestCase { + + /** + * Returns a list of arrays that hold values to test handling of. + * Each array holds the following unnamed elements: + * - value (mixed, required) + * - valid (boolean, required) + * - expected (mixed, optional) + * + * ie array( '42', true, 42 ) + * + * @since 0.1 + * + * @param boolean $stringlyTyped + * + * @return array + */ + public abstract function valueProvider( $stringlyTyped = true ); + + public abstract function getType(); + + public function getDefinitions() { + $params = []; + + $params['empty'] = []; + + $params['values'] = [ + 'values' => [ 'foo', '1', '0.1', 'yes', 1, 0.1 ] + ]; + + return $params; + } + + public function definitionProvider() { + $definitions = $this->getDefinitions(); + + foreach ( $definitions as &$definition ) { + $definition['type'] = $this->getType(); + } + + return $definitions; + } + + public function getEmptyInstance() { + return ParamDefinitionFactory::singleton()->newDefinitionFromArray( [ + 'name' => 'empty', + 'message' => 'test-empty', + 'type' => $this->getType(), + ] ); + } + + public function instanceProvider() { + $definitions = []; + + foreach ( $this->definitionProvider() as $name => $definition ) { + if ( !array_key_exists( 'message', $definition ) ) { + $definition['message'] = 'test-' . $name; + } + + $definition['name'] = $name; + $definitions[] = [ ParamDefinitionFactory::singleton()->newDefinitionFromArray( $definition ) ]; + } + + return $definitions; + } + + /** + * @dataProvider instanceProvider + */ + public function testGetType( IParamDefinition $definition ) { + $this->assertEquals( $this->getType(), $definition->getType() ); + } + + /** + * @dataProvider instanceProvider + */ + public function testValidate( IParamDefinition $definition ) { + foreach ( [ true, false ] as $stringlyTyped ) { + $values = $this->valueProvider( $stringlyTyped ); + $options = new Options(); + $options->setRawStringInputs( $stringlyTyped ); + + foreach ( $values[$definition->getName()] as $data ) { + list( $input, $valid, ) = $data; + + $param = new Param( $definition ); + $param->setUserValue( $definition->getName(), $input, $options ); + $definitions = []; + $param->process( $definitions, [], $options ); + + $this->assertEquals( + $valid, + $param->getErrors() === [], + 'The validation process should ' . ( $valid ? '' : 'not ' ) . 'pass' + ); + } + } + + $this->assertTrue( true ); + } + + /** + * @dataProvider instanceProvider + */ + public function testFormat( IParamDefinition $sourceDefinition ) { + $values = $this->valueProvider(); + $options = new Options(); + + foreach ( $values[$sourceDefinition->getName()] as $data ) { + $definition = clone $sourceDefinition; + + list( $input, $valid, ) = $data; + + $param = new Param( $definition ); + $param->setUserValue( $definition->getName(), $input, $options ); + + if ( $valid && array_key_exists( 2, $data ) ) { + $defs = []; + $param->process( $defs, [], $options ); + + $this->assertEquals( + $data[2], + $param->getValue() + ); + } + } + + $this->assertTrue( true ); + } + + protected function validate( ParamDefinition $definition, $testValue, $validity, Options $options = null ) { + $def = clone $definition; + $options = $options === null ? new Options() : $options; + + $param = new Param( $def ); + $param->setUserValue( $def->getName(), $testValue, $options ); + + $defs = []; + $param->process( $defs, [], $options ); + + $this->assertEquals( $validity, $param->getErrors() === [] ); + } + + public function testConstructingWithoutMessageLeadsToDefaultMessage() { + $this->assertSame( + 'validator-message-nodesc', + ( new ParamDefinition( 'type', 'name' ) )->getMessage() + ); + } + +}
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/StringParamTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/StringParamTest.php new file mode 100644 index 00000000..2fb31db1 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/Definitions/StringParamTest.php @@ -0,0 +1,45 @@ +<?php + +namespace ParamProcessor\Tests\Integration\Definitions; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class StringParamTest extends ParamDefinitionTest { + + /** + * @see ParamDefinitionTest::valueProvider + * + * @param boolean $stringlyTyped + * + * @return array + */ + public function valueProvider( $stringlyTyped = true ) { + return [ + 'empty' => [ + [ 'ohi there', true, 'ohi there' ], + [ 4.2, false ], + [ [ 42 ], false ], + ], + 'values' => [ + [ 'foo', true, 'foo' ], + [ '1', true, '1' ], + [ 'yes', true, 'yes' ], + [ 'bar', false ], + [ true, false ], + [ 0.1, false ], + [ [], false ], + ], + ]; + } + + /** + * @see ParamDefinitionTest::getType + * @return string + */ + public function getType() { + return 'string'; + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/DimensionTypeTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/DimensionTypeTest.php new file mode 100644 index 00000000..9fdac669 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/DimensionTypeTest.php @@ -0,0 +1,208 @@ +<?php + +declare( strict_types = 1 ); + +namespace ParamProcessor\Tests\Integration; + +use ParamProcessor\ParamDefinitionFactory; +use ParamProcessor\ParameterTypes; +use ParamProcessor\ProcessingResult; +use ParamProcessor\Processor; +use PHPUnit\Framework\TestCase; + +class DimensionTypeTest extends TestCase { + + /** + * @dataProvider widthProvider + */ + public function testWidth( string $input, string $expected ) { + $parameters = $this->process( + [ + 'width' => [ + 'type' => ParameterTypes::DIMENSION, + 'message' => 'test-message' + ] + ], + [ + 'width' => $input, + ] + )->getParameterArray(); + + $this->assertSame( $expected, $parameters['width'] ); + } + + public function widthProvider() { + yield [ '10', '10px' ]; + yield [ '10px', '10px' ]; + yield [ '10%', '10%' ]; + yield [ '10em', '10em' ]; + yield [ '10ex', '10ex' ]; + yield [ 'auto', 'auto' ]; + yield [ ' 10 ', '10px' ]; + yield [ ' 1 ', '1px' ]; + yield [ '1 px', '1px' ]; + yield [ '1 ex', '1ex' ]; + // TODO: make sure unit is after the value + // TODO: make sure only the unit is present + } + + private function process( array $definitionArrays, array $userInput ): ProcessingResult { + $processor = Processor::newDefault(); + + $processor->setParameters( $userInput ); + $processor->setParameterDefinitions( + ParamDefinitionFactory::newDefault()->newDefinitionsFromArrays( $definitionArrays ) + ); + + return $processor->processParameters(); + } + + /** + * @dataProvider heightProvider + */ + public function testHeight( string $input, string $expected ) { + $parameters = $this->process( + [ + 'height' => [ + 'type' => ParameterTypes::DIMENSION, + 'message' => 'test-message' + ] + ], + [ + 'height' => $input, + ] + )->getParameterArray(); + + $this->assertSame( $expected, $parameters['height'] ); + } + + public function heightProvider() { + yield [ '10', '10px' ]; + yield [ '10px', '10px' ]; + yield [ '10em', '10em' ]; + yield [ '10ex', '10ex' ]; + } + + public function testAlternateDefaultUnit() { + $parameters = $this->process( + [ + 'height' => [ + 'type' => ParameterTypes::DIMENSION, + 'defaultunit' => '%', + 'message' => 'test-message' + ] + ], + [ + 'height' => '2.5', + ] + )->getParameterArray(); + + $this->assertSame( '2.5%', $parameters['height'] ); + } + + /** + * @dataProvider invalidDimensionProvider + */ + public function testInvalidInputsDefault( string $invalidDimension ) { + $parameters = $this->process( + [ + 'height' => [ + 'type' => ParameterTypes::DIMENSION, + 'default' => '42%', + 'lowerbound' => 20, + 'upperbound' => 80, + 'minpercentage' => 30, + 'maxpercentage' => 70, + 'message' => 'test-message' + ] + ], + [ + 'height' => $invalidDimension, + ] + )->getParameterArray(); + + $this->assertSame( '42%', $parameters['height'] ); + } + + public function invalidDimensionProvider() { + yield [ 'invalid' ]; + yield [ 'px' ]; + yield [ '19' ]; + yield [ '81' ]; + yield [ '29%' ]; + yield [ '71%' ]; + yield 'auto not allowed' => [ 'auto' ]; + yield 'unit not allowed' => [ '1 wtf' ]; + } + + /** + * @dataProvider validBoundsInput + */ + public function testValidInputWithBounds( string $valid ) { + $parameters = $this->process( + [ + 'height' => [ + 'type' => ParameterTypes::DIMENSION, + 'default' => '42%', + 'lowerbound' => 20, + 'upperbound' => 80, + 'minpercentage' => 30, + 'maxpercentage' => 70, + 'message' => 'test-message' + ] + ], + [ + 'height' => $valid, + ] + )->getParameterArray(); + + $this->assertSame( $valid, $parameters['height'] ); + } + + public function validBoundsInput() { + yield [ '20px' ]; + yield [ '21px' ]; + yield [ '80px' ]; + yield [ '79px' ]; + // FIXME +// yield [ '30%' ]; +// yield [ '31%' ]; +// yield [ '70%' ]; +// yield [ '69%' ]; + } + + public function testAllowAuto() { + $parameters = $this->process( + [ + 'height' => [ + 'type' => ParameterTypes::DIMENSION, + 'allowauto' => true, + 'message' => 'test-message' + ] + ], + [ + 'height' => 'auto', + ] + )->getParameterArray(); + + $this->assertSame( 'auto', $parameters['height'] ); + } + + public function testCanUseSpecialUnit() { + $parameters = $this->process( + [ + 'height' => [ + 'type' => ParameterTypes::DIMENSION, + 'units' => [ 'wtf' ], + 'message' => 'test-message' + ] + ], + [ + 'height' => '4.2 wtf', + ] + )->getParameterArray(); + + $this->assertSame( '4.2wtf', $parameters['height'] ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Integration/ProcessorTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Integration/ProcessorTest.php new file mode 100644 index 00000000..cf1acde5 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Integration/ProcessorTest.php @@ -0,0 +1,486 @@ +<?php + +declare( strict_types = 1 ); + +namespace ParamProcessor\Tests\Integration; + +use ParamProcessor\Options; +use ParamProcessor\ParamDefinitionFactory; +use ParamProcessor\ProcessingResult; +use ParamProcessor\Processor; +use PHPUnit\Framework\TestCase; + +/** + * @covers \ParamProcessor\Processor + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ProcessorTest extends TestCase { + + public function newFromOptionsProvider() { + $options = []; + + $option = new Options(); + + $options[] = clone $option; + + $option->setName( 'foobar' ); + $option->setLowercaseNames( false ); + + $options[] = clone $option; + + return $this->arrayWrap( $options ); + } + + private function arrayWrap( array $elements ) { + return array_map( + function( $element ) { + return [ $element ]; + }, + $elements + ); + } + + public function testNewFromOptions() { + $this->assertEquals( new Options(), Processor::newFromOptions( new Options() )->getOptions() ); + } + + /** + * Simple parameter definitions and values that should all pass. + * + * @return array + */ + private function getSimpleParams() { + $params = [ + 'awesome' => 'yes', + 'Howmuch ' => '9001', + 'FLOAT' => '4.2', + ' page' => 'Ohi there!', + ' text ' => 'foo bar baz o_O', + ]; + + $definitions = [ + 'awesome' => [ + 'type' => 'boolean', + ], + 'howmuch' => [ + 'type' => 'integer', + ], + 'float' => [ + 'type' => 'float', + ], + 'page' => [ + 'type' => 'string', + 'hastoexist' => false, + ], + 'text' => [], + ]; + + $options = new Options(); + + $expected = [ + 'awesome' => true, + 'howmuch' => 9001, + 'float' => 4.2, + 'page' => 'Ohi there!', + 'text' => 'foo bar baz o_O', + ]; + + return [ $params, $definitions, $options, $expected ]; + } + + /** + * Simple parameter definitions with defaults and values + * that are invalid or missing and therefore default. + * + * @return array + */ + private function getDefaultingParams() { + $params = [ + 'awesome' => 'omg!', + 'howmuch' => 'omg!', + 'float' => 'omg!', + 'page' => 42, + 'whot?' => 'O_o', + 'integerr' => ' 9001 ', + ]; + + $definitions = [ + 'awesome' => [ + 'type' => 'boolean', + 'default' => true, + ], + 'howmuch' => [ + 'type' => 'integer', + 'default' => 9001, + ], + 'float' => [ + 'type' => 'float', + 'default' => 4.2, + ], + 'page' => [ + 'type' => 'string', + 'hastoexist' => false, + 'default' => 'Ohi there!', + ], + 'text' => [ + 'default' => 'foo bar baz o_O', + ], + 'integerr' => [ + 'type' => 'integer', + 'default' => 42, + ], + ]; + + $options = new Options(); + $options->setTrimValues( false ); + + $expected = [ + 'awesome' => true, + 'howmuch' => 9001, + 'float' => 4.2, + 'page' => 'Ohi there!', + 'text' => 'foo bar baz o_O', + 'integerr' => 42, + ]; + + return [ $params, $definitions, $options, $expected ]; + } + + /** + * Values and definitions in-system parameter handling. + * Options set to expect non-raw values. + * + * @return array + */ + private function getTypedParams() { + $params = [ + 'awesome' => true, + 'howmuch' => '42', + 'float' => 4.2, + 'page' => 'Ohi there!', + 'Text' => 'foo bar baz o_O', + 'text1 ' => 'foo bar baz o_O', + ' text2' => 'foo bar baz o_O', + ]; + + $definitions = [ + 'awesome' => [ + 'type' => 'boolean', + ], + 'howmuch' => [ + 'type' => 'integer', + 'default' => 9001, + ], + 'float' => [ + 'type' => 'float', + 'lowerbound' => 9001, + 'default' => 9000.1 + ], + 'page' => [ + 'type' => 'string', + 'hastoexist' => false, + ], + 'text' => [ + 'default' => 'some text', + ], + 'text1' => [ + 'default' => 'some text', + ], + 'text2' => [ + 'default' => 'some text', + ], + ]; + + $options = new Options(); + $options->setRawStringInputs( false ); + $options->setLowercaseNames( false ); + $options->setTrimNames( false ); + + $expected = [ + 'awesome' => true, + 'howmuch' => 9001, + 'float' => 9000.1, + 'page' => 'Ohi there!', + 'text' => 'some text', + 'text1' => 'some text', + 'text2' => 'some text', + ]; + + return [ $params, $definitions, $options, $expected ]; + } + + /** + * Values with capitalization and preceding/tailing spaces to test + * of the clean options work. + * + * @return array + */ + private function getUncleanParams() { + $params = [ + 'awesome' => ' yes ', + 'text' => ' FOO bar ', + 'integerr' => ' 9001 ', + ]; + + $definitions = [ + 'awesome' => [ + 'type' => 'boolean', + ], + 'text' => [ + 'default' => 'bar', + ], + 'integerr' => [ + 'type' => 'integer', + 'default' => 42, + ], + ]; + + $options = new Options(); + $options->setLowercaseValues( true ); + $options->setTrimValues( true ); + + $expected = [ + 'awesome' => true, + 'text' => 'foo bar', + 'integerr' => 9001, + ]; + + return [ $params, $definitions, $options, $expected ]; + } + + /** + * List parameters to test if list handling works correctly. + * + * @return array + */ + private function getListParams() { + $params = [ + 'awesome' => ' yes, no, on, off ', + 'float' => ' 9001 ; 42 ; 4.2;0', + ]; + + $definitions = [ + 'awesome' => [ + 'type' => 'boolean', + 'islist' => true, + ], + 'text' => [ + 'default' => [ 'bar' ], + 'islist' => true, + ], + 'float' => [ + 'type' => 'float', + 'islist' => true, + 'delimiter' => ';' + ], + ]; + + $options = new Options(); + $options->setLowercaseValues( true ); + $options->setTrimValues( true ); + + $expected = [ + 'awesome' => [ true, false, true, false ], + 'text' => [ 'bar' ], + 'float' => [ 9001.0, 42.0, 4.2, 0.0 ], + ]; + + return [ $params, $definitions, $options, $expected ]; + } + + public function parameterProvider() { + // $params, $definitions [, $options] + $argLists = []; + + $argLists[] = $this->getSimpleParams(); + + $argLists[] = $this->getDefaultingParams(); + + $argLists[] = $this->getTypedParams(); + + $argLists[] = $this->getUncleanParams(); + + $argLists[] = $this->getListParams(); + + foreach ( $argLists as &$argList ) { + foreach ( $argList[1] as $key => &$definition ) { + $definition['message'] = 'test-' . $key; + } + + if ( !array_key_exists( 2, $argList ) ) { + $argList[2] = new Options(); + } + } + + return $argLists; + } + + /** + * @dataProvider parameterProvider + */ + public function testSetParameters( array $params, array $definitions, Options $options ) { + $validator = Processor::newFromOptions( $options ); + + $validator->setParameters( $params, $definitions ); + + $this->assertTrue( true ); // TODO + } + + /** + * @dataProvider parameterProvider + */ + public function testValidateParameters( array $params, array $definitions, Options $options, array $expected = [] ) { + $validator = Processor::newFromOptions( $options ); + + $validator->setParameters( $params, $definitions ); + + $processingResult = $validator->processParameters(); + + $actualValues = []; + + foreach ( $processingResult->getParameters() as $param ) { + $actualValues[$param->getName()] = $param->getValue(); + } + + $this->assertEquals( $expected, $actualValues ); + + + } + + public function testProcessParametersOnEmptyOptions() { + $processor = Processor::newDefault(); + + $this->assertInstanceOf( + ProcessingResult::class, + $processor->processParameters() + ); + } + + public function testErrorsCanBeRetrievedAfterProcessing() { + $processor = Processor::newDefault(); + + $this->processWithOneError( $processor ); + + $this->assertCount( 1, $processor->getErrors() ); + } + + private function processWithOneError( Processor $processor ) { + $processor->setParameters( + [], + [ + 'awesome' => [ + 'type' => 'boolean', + 'message' => 'test-awesome' + ], + ] + ); + + // There should be a single "missing required parameter" error. + $processor->processParameters(); + } + + public function testErrorsAreClearedBetweenProcessingRuns() { + $processor = Processor::newDefault(); + + $this->processWithOneError( $processor ); + $processor->setParameters( [], [] ); + $processor->processParameters(); + + $this->assertEmpty( $processor->getErrors() ); + } + + public function testInvalidListElementsAreOmitted() { + $processor = Processor::newDefault(); + + $processor->setFunctionParams( + [ + 'some-list=1,2,3, ,4,' + ], + [ + 'some-list' => [ + 'type' => 'integer', + 'message' => 'test', + 'islist' => true + ], + ] + ); + + $this->assertSame( + [ 1, 2, 3, 4 ], + $processor->processParameters()->getParameters()['some-list']->getValue() + ); + } + + public function testListParametersAreNotDefaultedWhenSomeElementsAreInvalid() { + $processor = Processor::newDefault(); + + $processor->setFunctionParams( + [ + 'some-list=1,nan' + ], + [ + 'some-list' => [ + 'type' => 'integer', + 'message' => 'test', + 'islist' => true, + 'default' => [] + ], + ] + ); + + $this->assertSame( + [ 1 ], + $processor->processParameters()->getParameters()['some-list']->getValue() + ); + } + + public function testListParametersAreDefaultedWhenAllElementsAreInvalid() { + $processor = Processor::newDefault(); + + $processor->setFunctionParams( + [ + 'some-list=such,nan' + ], + [ + 'some-list' => [ + 'type' => 'integer', + 'message' => 'test', + 'islist' => true, + 'default' => [ 42 ] + ], + ] + ); + + $this->assertSame( + [ 42 ], + $processor->processParameters()->getParameters()['some-list']->getValue() + ); + } + + public function testSetParameterDefinitions() { + $processor = Processor::newDefault(); + + $processor->setFunctionParams( [ 'some-list=42,23,9001' ] ); + + $processor->setParameterDefinitions( + [ + ( ParamDefinitionFactory::newDefault() )->newDefinitionFromArray( + [ + 'name' => 'some-list', + 'type' => 'integer', + 'message' => 'test', + 'islist' => true + ] + ) + ] + ); + + $this->assertSame( + [ 42, 23, 9001 ], + $processor->processParameters()->getParameters()['some-list']->getValue() + ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/OptionsTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/OptionsTest.php new file mode 100644 index 00000000..76b826ca --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/OptionsTest.php @@ -0,0 +1,48 @@ +<?php + +declare( strict_types = 1 ); + +namespace ParamProcessor\Tests\Unit; + +use ParamProcessor\Options; +use PHPUnit\Framework\TestCase; + +/** + * @covers \ParamProcessor\Options + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class OptionsTest extends TestCase { + + public function testBooleanSettersAndGetters() { + $methods = [ + 'setUnknownInvalid' => 'unknownIsInvalid', + 'setLowercaseNames' => 'lowercaseNames', + 'setRawStringInputs' => 'isStringlyTyped', + 'setTrimNames' => 'trimNames', + 'setTrimValues' => 'trimValues', + 'setLowercaseValues' => 'lowercaseValues', + ]; + + foreach ( $methods as $setter => $getter ) { + $options = new Options(); + + foreach ( [ false, true, false ] as $boolean ) { + call_user_func_array( [ $options, $setter ], [ $boolean ] ); + + $this->assertEquals( $boolean, call_user_func( [ $options, $getter ] ) ); + } + } + } + + public function testSetAndGetName() { + $options = new Options(); + + foreach ( [ 'foo', 'bar baz' ] as $name ) { + $options->setName( $name ); + $this->assertEquals( $name, $options->getName() ); + } + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/PackagePrivate/DimensionParserTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/PackagePrivate/DimensionParserTest.php new file mode 100644 index 00000000..e82bb8b7 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/PackagePrivate/DimensionParserTest.php @@ -0,0 +1,51 @@ +<?php + +declare( strict_types = 1 ); + +namespace ParamProcessor\Tests\Unit\PackagePrivate; + +use ParamProcessor\PackagePrivate\DimensionParser; +use PHPUnit\Framework\TestCase; +use ValueParsers\ParseException; +use ValueParsers\ParserOptions; + +class DimensionParserTest extends TestCase { + + public function testParserExceptionOnNonString() { + $this->expectException( ParseException::class ); + $this->parse( 32202 ); + } + + private function parse( $input ) { + return ( new DimensionParser() )->parse( $input ); + } + + /** + * @dataProvider validDimensionProvider + */ + public function testParsingValidInputs( string $input, string $expected ) { + $this->assertSame( $expected, $this->parse( $input ) ); + } + + public function validDimensionProvider() { + yield [ '10px', '10px' ]; + yield [ '10ex', '10ex' ]; + yield [ '10em', '10em' ]; + yield [ '2.5px', '2.5px' ]; + + yield [ '10 px', '10px' ]; + yield [ '10 px', '10px' ]; + yield [ ' 10 px ', '10px' ]; + + yield [ '10', '10px' ]; + yield [ '2.5', '2.5px' ]; + } + + public function testAlternateDefaultUnit() { + $this->assertSame( + '1%', + ( new DimensionParser( new ParserOptions( [ DimensionParser::DEFAULT_UNIT => '%' ] ) ) )->parse( '1' ) + ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamAliasTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamAliasTest.php new file mode 100644 index 00000000..bd57dbd3 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamAliasTest.php @@ -0,0 +1,21 @@ +<?php + +namespace ParamProcessor\Tests\Unit; + +use ParamProcessor\Param; +use ParamProcessor\ParamDefinition; +use PHPUnit\Framework\TestCase; + +/** + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ParamAliasTest extends TestCase { + + public function testListParamProcessingWithEmptyListAsDefault() { + $definition = new ParamDefinition( 'string', 'something' ); + $param = new Param( $definition ); + $this->assertTrue( $param->isRequired() ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamDefinitionFactoryTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamDefinitionFactoryTest.php new file mode 100644 index 00000000..1e727713 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamDefinitionFactoryTest.php @@ -0,0 +1,140 @@ +<?php + +namespace ParamProcessor\Tests\Unit; + +use ParamProcessor\ParamDefinition; +use ParamProcessor\ParamDefinitionFactory; +use ParamProcessor\ParameterTypes; +use PHPUnit\Framework\TestCase; + +/** + * @covers \ParamProcessor\ParamDefinitionFactory + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ParamDefinitionFactoryTest extends TestCase { + + public function testNewDefinitionFromArray() { + $definition = ParamDefinitionFactory::newDefault()->newDefinitionFromArray( + [ + 'name' => 'some-list', + 'type' => 'integer', + 'message' => 'test-message', + 'islist' => true + ] + ); + + $this->assertSame( 'some-list', $definition->getName() ); + $this->assertSame( 'integer', $definition->getType() ); + $this->assertSame( 'test-message', $definition->getMessage() ); + $this->assertTrue( $definition->isList() ); + $this->assertTrue( $definition->isRequired() ); + } + + public function testNewDefinition() { + $definition = ParamDefinitionFactory::newDefault()->newDefinition( + 'integer', + 'some-list', + null, + 'test-message', + true + ); + + $this->assertSame( 'some-list', $definition->getName() ); + $this->assertSame( 'integer', $definition->getType() ); + $this->assertSame( 'test-message', $definition->getMessage() ); + $this->assertTrue( $definition->isList() ); + $this->assertTrue( $definition->isRequired() ); + } + + public function testNewDefinitionFromArray_typeDefaultsToString() { + $this->assertSame( 'string', $this->newBasicParamFromArray()->getType() ); + } + + private function newBasicParamFromArray(): ParamDefinition { + return ParamDefinitionFactory::newDefault()->newDefinitionFromArray( + [ + 'name' => 'irrelevant', + 'message' => 'irrelevant' + ] + ); + } + + public function testNewDefinitionFromArray_isListDefaultsToFalse() { + $this->assertFalse( $this->newBasicParamFromArray()->isList() ); + } + + public function testNewDefinitionFromArray_isRequiredDefaultsToTrue() { + $this->assertTrue( $this->newBasicParamFromArray()->isRequired() ); + } + + public function testNewDefinitionFromArray_optionsAreSet() { + $arrayDefinition = [ + 'name' => 'some-list', + 'type' => 'integer', + 'message' => 'test-message', + 'islist' => true + ]; + + $definition = ParamDefinitionFactory::newDefault()->newDefinitionFromArray( $arrayDefinition ); + + $this->assertSame( $arrayDefinition, $definition->getOptions() ); + } + + public function testNewDefinitionsFromArrays_preservesDefinitionInstances() { + $this->assertEquals( + [ + 'kittens' => new ParamDefinition( ParameterTypes::STRING, 'kittens' ), + 'cats' => new ParamDefinition( ParameterTypes::INTEGER, 'cats' ), + ], + ParamDefinitionFactory::newDefault()->newDefinitionsFromArrays( + [ + new ParamDefinition( ParameterTypes::STRING, 'kittens' ), + new ParamDefinition( ParameterTypes::INTEGER, 'cats' ), + ] + ) + ); + } + + public function testNewDefinitionsFromArrays_handlesNamesAsKeys() { + $definitions = ParamDefinitionFactory::newDefault()->newDefinitionsFromArrays( + [ + 'kittens' => [ + 'type' => ParameterTypes::STRING, + 'message' => 'test-message', + ] + ] + ); + + $this->assertSame( 'kittens', $definitions['kittens']->getName() ); + } + + public function testNewDefinitionsFromArrays_nameFieldTakesPriorityOverKey() { + $definitions = ParamDefinitionFactory::newDefault()->newDefinitionsFromArrays( + [ + 'cats' => [ + 'name' => 'kittens', + 'type' => ParameterTypes::STRING, + 'message' => 'test-message', + ] + ] + ); + + $this->assertSame( 'kittens', $definitions['kittens']->getName() ); + } + + public function testNewDefinitionsFromArrays_missingNameLeadsToException() { + $this->expectException( \Exception::class ); + + ParamDefinitionFactory::newDefault()->newDefinitionsFromArrays( + [ + [ + 'type' => ParameterTypes::STRING, + 'message' => 'test-message', + ] + ] + ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamTest.php new file mode 100644 index 00000000..4510409d --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParamTest.php @@ -0,0 +1,28 @@ +<?php + +namespace ParamProcessor\Tests\Unit; + +use ParamProcessor\Options; +use ParamProcessor\PackagePrivate\Param; +use ParamProcessor\ParamDefinition; +use PHPUnit\Framework\TestCase; + +/** + * @covers \ParamProcessor\PackagePrivate\Param + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ParamTest extends TestCase { + + public function testListParamProcessingWithEmptyListAsDefault() { + $definition = new ParamDefinition( 'string', 'something', [] ); + $definitions = [ $definition ]; + + $param = new Param( $definition ); + $param->process( $definitions, [], new Options() ); + + $this->assertSame( [], $param->getValue() ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParameterTypesTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParameterTypesTest.php new file mode 100644 index 00000000..7f4970a6 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ParameterTypesTest.php @@ -0,0 +1,75 @@ +<?php + +namespace ParamProcessor\Tests\Unit; + +use ParamProcessor\ParameterTypes; +use PHPUnit\Framework\TestCase; +use ValueParsers\NullParser; +use ValueValidators\NullValidator; + +/** + * @covers \ParamProcessor\ParameterTypes + */ +class ParameterTypesTest extends TestCase { + + public function testAddType_defaultsAreSet() { + $types = new ParameterTypes(); + + $types->addType( + 'kitten', + [] + ); + + $type = $types->getType( 'kitten' ); + + $this->assertSame( + NullParser::class, + $type->getStringParserClass() + ); + + $this->assertSame( + NullParser::class, + $type->getTypedParserClass() + ); + + $this->assertSame( + NullValidator::class, + $type->getValidatorClass() + ); + + $this->assertNull( + $type->getValidationCallback() + ); + } + + public function testRegisterType_parametersAreUsed() { + $types = new ParameterTypes(); + + $types->addType( + 'kitten', + [ + 'string-parser' => 'KittenParser', + 'validation-callback' => 'is_int', + 'validator' => 'KittenValidator', + ] + ); + + $type = $types->getType( 'kitten' ); + + $this->assertSame( + 'KittenParser', + $type->getStringParserClass() + ); + + $this->assertSame( + 'KittenValidator', + $type->getValidatorClass() + ); + + $this->assertSame( + 'is_int', + $type->getValidationCallback() + ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/ProcessingResultTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ProcessingResultTest.php new file mode 100644 index 00000000..e90209a4 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/ProcessingResultTest.php @@ -0,0 +1,89 @@ +<?php + +namespace ParamProcessor\Tests\Unit; + +use ParamProcessor\ProcessedParam; +use ParamProcessor\ProcessingError; +use ParamProcessor\ProcessingResult; +use PHPUnit\Framework\TestCase; + +/** + * @covers \ParamProcessor\ProcessingResult + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class ProcessingResultTest extends TestCase { + + public function testGetParameters() { + $processedParams = [ + $this->createMock( ProcessedParam::class ) + ]; + + $result = new ProcessingResult( $processedParams ); + + $this->assertEquals( $processedParams, $result->getParameters() ); + } + + public function testGetErrors() { + $errors = [ + $this->createMock( ProcessingError::class ) + ]; + + $result = new ProcessingResult( [], $errors ); + + $this->assertEquals( $errors, $result->getErrors() ); + } + + public function testGivenNoErrors_HasNoFatal() { + $this->assertNoFatalForErrors( [] ); + } + + private function assertNoFatalForErrors( array $errors ) { + $result = new ProcessingResult( [], $errors ); + + $this->assertFalse( $result->hasFatal() ); + } + + public function testGivenNonfatalErrors_HasNoFatal() { + $this->assertNoFatalForErrors( [ + new ProcessingError( '', ProcessingError::SEVERITY_HIGH ), + new ProcessingError( '', ProcessingError::SEVERITY_LOW ), + new ProcessingError( '', ProcessingError::SEVERITY_MINOR ), + new ProcessingError( '', ProcessingError::SEVERITY_NORMAL ), + ] ); + } + + public function testGivenFatalError_HasFatal() { + $result = new ProcessingResult( [], [ + new ProcessingError( '', ProcessingError::SEVERITY_HIGH ), + new ProcessingError( '', ProcessingError::SEVERITY_LOW ), + new ProcessingError( '', ProcessingError::SEVERITY_FATAL ), + new ProcessingError( '', ProcessingError::SEVERITY_MINOR ), + new ProcessingError( '', ProcessingError::SEVERITY_NORMAL ), + ] ); + + $this->assertTrue( $result->hasFatal() ); + } + + public function testGetParameterArrayWithNoParameters() { + $this->assertSame( + [], + ( new ProcessingResult( [] ) )->getParameterArray() + ); + } + + public function testGetParameterArray() { + $this->assertSame( + [ + 'first' => 42, + 'second' => 23, + ], + ( new ProcessingResult( [ + new ProcessedParam( 'first', 42, false ), + new ProcessedParam( 'second', 23, true ) + ] ) )->getParameterArray() + ); + } + +}
\ No newline at end of file diff --git a/www/wiki/vendor/param-processor/param-processor/tests/Unit/SettingsTest.php b/www/wiki/vendor/param-processor/param-processor/tests/Unit/SettingsTest.php new file mode 100644 index 00000000..eec970d9 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/Unit/SettingsTest.php @@ -0,0 +1,42 @@ +<?php + +namespace ParamProcessor\Tests\Unit; + +use ParamProcessor\Settings; +use PHPUnit\Framework\TestCase; + +/** + * @covers \ParamProcessor\Settings + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class SettingsTest extends TestCase { + + public function constructorProvider() { + $settingArrays = [ + [ [] ], + [ [ 'foo' => 'bar' ] ], + [ [ 'foo' => 'bar', 'baz' => 'BAH' ] ], + [ [ '~[,,_,,]:3' => [ 9001, 4.2 ] ] ], + ]; + + return $settingArrays; + } + + /** + * @dataProvider constructorProvider + * + * @param array $settings + */ + public function testConstructor( array $settings ) { + $settingsObject = new Settings( $settings ); + + foreach ( $settings as $name => $value ) { + $this->assertEquals( $value, $settingsObject->get( $name ) ); + } + + $this->assertTrue( true ); + } + +} diff --git a/www/wiki/vendor/param-processor/param-processor/tests/bootstrap.php b/www/wiki/vendor/param-processor/param-processor/tests/bootstrap.php new file mode 100644 index 00000000..0e2d07c9 --- /dev/null +++ b/www/wiki/vendor/param-processor/param-processor/tests/bootstrap.php @@ -0,0 +1,14 @@ +<?php + +if ( PHP_SAPI !== 'cli' ) { + die( 'Not an entry point' ); +} + +error_reporting( E_ALL | E_STRICT ); +ini_set( 'display_errors', 1 ); + +if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) { + die( 'You need to install this package with Composer before you can run the tests' ); +} + +require_once( __DIR__ . '/../vendor/autoload.php' ); |