{"id":20741622,"url":"https://github.com/attitude/prop-types-php","last_synced_at":"2025-12-25T05:02:03.311Z","repository":{"id":138279877,"uuid":"302164872","full_name":"attitude/prop-types-php","owner":"attitude","description":"A very lean implementation of React Prop Types library in PHP","archived":false,"fork":false,"pushed_at":"2024-03-29T18:44:04.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T02:14:46.107Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/attitude.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-07T21:30:11.000Z","updated_at":"2024-03-11T17:47:52.000Z","dependencies_parsed_at":"2024-03-29T19:40:36.234Z","dependency_job_id":"6b859f2c-ca04-44b4-9faa-a5ee4c7a88e3","html_url":"https://github.com/attitude/prop-types-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attitude%2Fprop-types-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attitude%2Fprop-types-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attitude%2Fprop-types-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attitude%2Fprop-types-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/attitude","download_url":"https://codeload.github.com/attitude/prop-types-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243030817,"owners_count":20224666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T06:42:28.204Z","updated_at":"2025-12-25T05:01:58.262Z","avatar_url":"https://github.com/attitude.png","language":"PHP","readme":"# React PropTypes implemented in PHP\n\nA lean implementation inspired by the [React Prop Types](https://reactjs.org/docs/typechecking-with-proptypes.html) library and [Flow](https://flow.org) done for PHP. All the types are overridable (displays warnings you can turn off) and you can even define/register your own types for better reuse (inspired by the Flow types).\n\nAll registered types are accessible as static methods of the `PropTypes` class.\n\n## Install using composer:\n\n```json\n{\n    \"name\": \"you/example-project\",\n    \"repositories\": [\n        {\n            \"type\": \"vcs\",\n            \"url\": \"https://github.com/attitude/prop-types-php\"\n        }\n    ],\n    \"require\": {\n        \"attitude/prop-types-php\": \"dev-main\"\n    }\n}\n```\n\n## Use in your code\n\n```php\n\u003c?php\n\n// Require autoloader\nrequire_once('vendor/autoload.php');\n\n// Use the PropTypes container\nuse \\PropTypes\\PropTypes;\n\n// Register your own type\nPropTypes::register('SomeComponentType', PropTypes::exact([\n  'names' =\u003e PropTypes::array()-\u003eisRequired,\n  'bool' =\u003e PropTypes::bool(),\n  'structure' =\u003e PropTypes::shape([\n    'deep' =\u003e PropTypes::array()-\u003eisRequired,\n    'enum' =\u003e PropTypes::oneOf(['1', 2, 'three']),\n    'oneOf' =\u003e PropTypes::oneOfType([\n      PropTypes::array(),\n      PropTypes::string(),\n      PropTypes::bool(),\n    ])-\u003eisRequired,\n    'arrayOf' =\u003e PropTypes::arrayOf(PropTypes::string())-\u003eisRequired,\n    'objectOf' =\u003e PropTypes::objectOf(PropTypes::string())-\u003eisRequired,\n    'requiredAny' =\u003e PropTypes::any()-\u003eisRequired,\n    'instanceOf' =\u003e PropTypes::instanceOf('StdClass')-\u003eisRequired,\n  ]),\n]));\n\nfunction SomeComponent($props) {\n  // Check the props\n  PropTypes::SomeComponentType()-\u003eassert($props);\n\n  // rest of the component code...\n}\n\n// Run your code:\nSomeComponent([\n  'names' =\u003e ['Martin'],\n  'bool' =\u003e true,\n  'structure' =\u003e [\n    'deep' =\u003e ['Adamko'],\n    'enum' =\u003e 2,\n    'oneOf' =\u003e '',\n    'arrayOf' =\u003e ['2'],\n    'objectOf' =\u003e (object)['2'],\n    'requiredAny' =\u003e '',\n    'instanceOf' =\u003e (object) [],\n  ],\n  'extraKey' =\u003e '123', // \u003c\u003c\u003c This should throw an error\n]);\n\n```\n\n## Options\n\nConstant                          | type    | default | Description\n----------------------------------|---------|---------|------------\n`PROP_TYPES_STRICT_OBJECTS_SHAPE` | boolean | false   | Whether Shape accepts both `StdClass` and `array` or strictly just `StdClass` instance\n`PROP_TYPES_WARNINGS_ENABLED`     | boolean | true    | Show or hide warnings\n\n## API\n\n- #### static method `PropTypes::register()`\n  Used for registering a new type. See `/src/bootstrap.php` for more examples.\n  ##### Arguments:\n  - *string* `$typeName` - name for the type, e.g. `'Props'`\n  - *callable | TypeInterface* `$typeFactoryOrType` - a `TypeInterface` of a factory function that returns a `TypeInterface`\n- #### static method `PropTypes::__callStatic()`\n  Overloading method used to get any registered type Some of the types require arguments. Consult the [React Prop Types](https://reactjs.org/docs/typechecking-with-proptypes.html) documentation.\n\n  ```php\n  // Get registered type instance:\n  $type = `PropTypes::PreviouslyRegisteredTypeName()`;\n  // Validates props variable against the registered type:\n  $type-\u003eassert ($props);\n  ```\n\n\u003e This project is predecessor of \u003ca href=\"https://github.com/attitude/duck-types-php\" style=\"color: inherit;text-decoration:underline;font-weight:bold\"\u003eDuck Types for PHP\u003c/a\u003e — your asserts turn into readable and short one-liners with Flow-flavoured syntax annotations.\n\n---\n\nNot implemented types:\n\n- symbol\n- node\n- element\n- elementType\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattitude%2Fprop-types-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fattitude%2Fprop-types-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattitude%2Fprop-types-php/lists"}