Download the PHP package skyzyx/strong-types without Composer
On this page you can find all versions of the php package skyzyx/strong-types. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package strong-types
PHP Strong Types
Enables strong types for PHP. This allows for tighter validation, especially when accepting input from users.
Why would anyone do this? This can be useful when developing APIs, and you want to require strict types. By defining those types/shapes ahead of time as classes, you can enforce incoming/outgoing data types, but also access the native values after the vaidation step has occurred.
It intentionally rejects and avoid any kind of "type massaging". If you pass an integer
to StringType
, you will get an exception. All errors are thrown as Exceptions with useful error messages.
Features
- BooleanType
- Collection (ArrayAccess)
- Enum
- FloatType
- IntegerType
- StringType (incl. Utf8String)
DateTime
is already strongly typed, so use that class for strong date/time types.
Examples
We can do simple validation enforcement, which can be valuable in PHP 5.x. (Use strict types instead in PHP 7.)
You can also extend the base types to create more specific data types (aka, data shapes).
Installation
Using Composer:
And include it in your scripts:
Testing
Firstly, run composer install -o
to download and install the dependencies.
You can run the tests as follows:
Contributing
Here's the process for contributing:
- Fork PHP Strong Types to your GitHub account.
- Clone your GitHub copy of the repository into your local workspace.
- Write code, fix bugs, and add tests with 100% code coverage.
- Commit your changes to your local workspace and push them up to your GitHub copy.
- You submit a GitHub pull request with a description of what the change is.
- The contribution is reviewed. Maybe there will be some banter back-and-forth in the comments.
- If all goes well, your pull request will be accepted and your changes are merged in.
Authors, Copyright & Licensing
- Copyright (c) 2014–2016 Ryan Parman.
See also the list of contributors who participated in this project.
Licensed for use under the terms of the MIT license.
Coding Standards
PSR-0/1/2 are a solid foundation, but are not an entire coding style by themselves. I have taken the time to document all of the nitpicky patterns and nuances of my personal coding style. It goes well-beyond brace placement and tabs vs. spaces to cover topics such as docblock annotations, ternary operations and which variation of English to use. It aims for thoroughness and pedanticism over hoping that we can all get along.