1. Go to this page and download the library: Download guym4c/prop-types 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/ */
guym4c / prop-types example snippets
use Guym4c\PropTypes\Exception\PropTypeException;
use Guym4c\PropTypes\PropTypes;
[
// You can declare that a prop has a specific type.
// By default, these are all optional.
'optionalArray' => PropTypes::array(),
'optionalBool' => PropTypes::bool(),
'optionalFunction' => PropTypes::callable(),
'optionalInteger' => PropTypes::int(),
'optionalFloat' => PropTypes::float(),
'optionalIterable' => PropTypes::iterable(),
'optionalObject' => PropTypes::object(),
'optionalString' => PropTypes::string(),
// You can also declare that a prop is an instance of a class.
// This uses `instanceof` operator.
'optionalDateTime' => PropTypes::instanceOf(DateTime::class),
// You can ensure that your prop is limited to specific values
// by treating it as an enum.
'optionalEnum' => PropTypes::oneOf(['News', 'Photos']),
// An object that could be one of many types
'optionalUnion' => PropTypes::oneOfType([
PropTypes::string(),
PropTypes::int(),
PropTypes::instanceOf(DateTime::class),
]),
// Float or int shorthand
'optionalNumber' => PropTypes::number(),
// An array of a certain type
'optionalArrayOf' => PropTypes::arrayOf(PropTypes::int()),
// You can chain any of the above with `isRequired`
// to make sure an error is thrown if the prop isn't provided.
// An object taking on a particular shape
'optionalArrayWithShape' => PropTypes::shape([
'optionalProperty' => PropTypes::string(),
'