mirror of
https://github.com/torrentpier/torrentpier-lts.git
synced 2025-02-28 15:10:54 +03:00
Updated utf8 & reflection type hint classes (#320)
* Updated UTF8 & ReflectionTypeHint classes * Update reflection.php * Update reflection.php * Update CHANGELOG.md
This commit is contained in:
parent
8b63d5abae
commit
52ee42e107
@ -8,6 +8,7 @@
|
||||
**Merged pull requests:**
|
||||
|
||||
- Release v2.1.5-2023.10 🎉
|
||||
- Updated utf8 & reflection type hint classes [\#320](https://github.com/torrentpier/torrentpier-lts/pull/320) ([belomaxorka](https://github.com/belomaxorka))
|
||||
- Updated Text_LangCorrect class [\#309](https://github.com/torrentpier/torrentpier-lts/pull/309) ([belomaxorka](https://github.com/belomaxorka))
|
||||
- Minor improvements [\#297](https://github.com/torrentpier/torrentpier-lts/pull/297), [\#298](https://github.com/torrentpier/torrentpier-lts/pull/298), [\#300](https://github.com/torrentpier/torrentpier-lts/pull/300), [\#301](https://github.com/torrentpier/torrentpier-lts/pull/301), [\#302](https://github.com/torrentpier/torrentpier-lts/pull/302), [\#303](https://github.com/torrentpier/torrentpier-lts/pull/303), [\#305](https://github.com/torrentpier/torrentpier-lts/pull/305), [\#306](https://github.com/torrentpier/torrentpier-lts/pull/306), [\#307](https://github.com/torrentpier/torrentpier-lts/pull/307), [\#310](https://github.com/torrentpier/torrentpier-lts/pull/310), [\#312](https://github.com/torrentpier/torrentpier-lts/pull/312), [\#313](https://github.com/torrentpier/torrentpier-lts/pull/313), [\#315](https://github.com/torrentpier/torrentpier-lts/pull/315), [\#316](https://github.com/torrentpier/torrentpier-lts/pull/316), [\#317](https://github.com/torrentpier/torrentpier-lts/pull/317), [\#319](https://github.com/torrentpier/torrentpier-lts/pull/319) ([belomaxorka](https://github.com/belomaxorka))
|
||||
|
||||
|
@ -6,16 +6,33 @@ if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
* A class for validating method parameters to allowed types via reflection.
|
||||
*
|
||||
* Purpose
|
||||
* Used as a more convenient multiple assert(), standing after the declaration of the methods.
|
||||
* * Used as a more convenient mechanism than a big code for checking types,
|
||||
* standing after the declaration of the methods.
|
||||
* * Requires write correct phpDoc
|
||||
*
|
||||
* Features and advantage
|
||||
* Features
|
||||
* * Very easy to use
|
||||
* * Ability to turn off on the production server
|
||||
*
|
||||
* Understanding
|
||||
* All built-in PHP functions check the type of input variables and the "swearing", if not given.
|
||||
* ReflectionTypeHint does too.
|
||||
* Previously, I wrote this (the correct way, but a lot of code):
|
||||
* if (! is_bool($b)) {
|
||||
* trigger_error('A bool type expected in 1-st parameter, ' . gettype($b) . ' type given!', E_USER_WARNING);
|
||||
* return false;
|
||||
* }
|
||||
* if (! is_string($s)) {
|
||||
* trigger_error('A string type expected in 2-nd parameter, ' . gettype($s) . ' type given!', E_USER_WARNING);
|
||||
* return false;
|
||||
* }
|
||||
* Now I'm doing this one line of code:
|
||||
* if (! ReflectionTypeHint::isValid()) return false;
|
||||
*
|
||||
* WARNING
|
||||
* On a production server, it is important to disable assert, that would save server resources.
|
||||
* For this, use the assert_options(ASSERT_ACTIVE, false) or INI setting "assert.active 0".
|
||||
* In this case ReflectionTypeHint::isValid() always returns TRUE!
|
||||
* In this case ReflectionTypeHint::isValid() always immediately returns TRUE!
|
||||
*
|
||||
* Useful links
|
||||
* http://www.ilia.ws/archives/205-Type-hinting-for-PHP-5.3.html
|
||||
@ -27,7 +44,6 @@ if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
* @author Nasibullin Rinat
|
||||
* @version 1.1.0
|
||||
*/
|
||||
|
||||
class ReflectionTypeHint
|
||||
{
|
||||
protected static $hints = array(
|
||||
@ -184,4 +200,4 @@ class ReflectionTypeHint
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user