1. Go to this page and download the library: Download dozer111/type_checker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dozer111 / type_checker example snippets
TypeChecker::hardCheck($value,[__INTEGER__,__STRING__]);
TypeChecker::hardCheckInt($value,[__INTEGER__,__STRING__]);
TypeChecker::hardCheckString($value,[__INTEGER__,__STRING__]);
// or same, but with synonyms
TypeChecker::guard($value,[__INTEGER__,__STRING__]);
TypeChecker::guardInt($value,[__INTEGER__,__STRING__]);
TypeChecker::guardString($value,[__INTEGER__,__STRING__]);
//before
$value = '<someYourValue>';
if(is_int($value) || is_string($value))
{
doSmth();
}
// now
$valueHasCorrectType = TypeChecker::check($value,[__INTEGER__,__STRING__]);
//========================================================================================================================
//========================================================================================================================
// before
if(is_int($value) || is_string($value))
{
throw new SomeYourException();
}
// now hardCheck or guard
TypeChecker::hardCheck($value,[__INTEGER__,__STRING__]);
TypeChecker::guard($value,[__INTEGER__,__STRING__]);
// add manually
TypeChecker::check($value,[__INTEGER__,__STRING__,__NULL__]);
// or use nullable mechanism
TypeChecker::check($value,[__INTEGER__,__STRING__],true);
TypeChecker::hardCheckInt($x,true); // null or int
TypeChecker::hardCheckInt($x); // int ONLY!
// we can check objects in couple of ways:
// 1 => using TypeChecker::check
TypeChecker::check($value,[__OBJECT__]);
TypeChecker::check($value,[YorClassName::class]);
// 2 => TypeChecker::checkObject()/TypeChecker::hardCheckObject()
TypeChecker::checkObject($value); // will check for `object` type
TypeChecker::checkObject($value,YorClassName::class); // will check for `object` && YorClassName types
TypeChecker::checkObject($value,YorClassName::class,true); // will check for (`object` && YorClassName) or null types
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.