一致性 - PHP功能的一致方法和添加
PHP offers a lot of handy functionality, but due to its organic growth this is not always easily usable. The aim of this library is to provide consistent approach to PHP's functionality. This means:
Install package consistence/consistence with Composer:
composer require consistence/consistenceThere are no further steps needed, you can start using Consistence whenever suitable in your codebase, see features below.
If you are using one of the following libraries/frameworks, check out these integrations:
In following sections, there are excerpts of Consistence functionality helping in key areas along with links to dedicated documentation pages.
Enums represent predefined set of values. The available values are defined statically by each enum class. Each value is represented by an instance of this class in a flyweight manner. This ensures that the same values are always the same instance.
Learn more about Enums in Consistence](docs/Enum/enums.md)
With [MultiEnums](docs/Enum/multi-enums.md) you can even represent multiple values and operations on them in a single object.
### [Strict Types](docs/Type/strict-types.md)
PHP contains by default a lot of magic behavior and checks almost nothing. When particular type is expected, PHP tries to convert given type to the expected one, which can yield unexpected results. Consistence promotes using strict types to achieve more predictable, maintainable and readable code.
```php
bar = 'bar'; Learn more about Strict Types in Consistence](docs/Type/strict-types.md)
### [Time Format](docs/Time/time-format.md)
Using [value objects](http://martinfowler.com/bliki/ValueObject.html) is great, because you get clear type hint and you can be sure, that the value you get is in consistent state and that it is valid (if the representation follows the principles).
[DateTime](http://php.net/manual/en/class.datetime.php) is one of the few value objects which are natively in PHP. Unfortunately, PHP again prefers using magic behavior over clear errors by default and there is also quite a lot of commonly required functionality missing, so Consistence tries to help with these shortcomings.
…
php
Learn more about Arrays in Consistence](docs/Type/arrays.md)暂无开放 Issues,或尚未同步最近议题。