Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/einenlum/iron
Transform \DateTimeInterface PHP objects the easy way
https://github.com/einenlum/iron
Last synced: about 11 hours ago
JSON representation
Transform \DateTimeInterface PHP objects the easy way
- Host: GitHub
- URL: https://github.com/einenlum/iron
- Owner: Einenlum
- License: mit
- Created: 2018-11-02T14:14:26.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-02T17:39:52.000Z (about 6 years ago)
- Last Synced: 2024-04-16T16:53:03.526Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Iron
[![CircleCI](https://circleci.com/gh/Einenlum/iron.svg?style=svg)](https://circleci.com/gh/Einenlum/iron)
[![Latest Stable Version](https://poser.pugx.org/einenlum/iron/v/stable)](https://packagist.org/packages/einenlum/iron)
[![Latest Unstable Version](https://poser.pugx.org/einenlum/iron/v/unstable)](https://packagist.org/packages/einenlum/iron)A Carbon-like tool done the right way.
## Install
`composer require einenlum/iron:dev-master`
## Usage
```php
addDays(2)->toDateTimeImmutable();
```## Available methods
- [toDateTime](doc/methods.md#todatetime)
- [toDateTimeImmutable](doc/methods.md#todatetimeimmutable)
- [toDateTimeMutable](doc/methods.md#todatetimemutable)And every method (and getter) available in [Carbon](https://github.com/briannesbitt/Carbon) on the `CarbonImmutable` objects.
## Why?
[Carbon](https://github.com/briannesbitt/Carbon) is a really useful tool. I'm just not really happy with the implementation they chose. Extending the native `\DateTime` class seems dangerous ([here is some documentation](https://github.com/getify/You-Dont-Know-JS/blob/master/types%20%26%20grammar/apA.md#native-prototypes) about this problem in JS, but it works for PHP too). We should not extend the behavior of code we don't own. Also, being able to pass a `Carbon` object to a method waiting for a native `\DateTime` object, seems wrong to me.
Here we use `Iron` to manipulate data in a fluent API using an `\ImmutableDateTime` object under the hood and we finally return a native PHP `\DateTimeImmutable` (or `\DateTime`) object.
**For now it just wraps carbon calls and getters. Next step will be for sure to implement here all the methods we need to get rid of Carbon in the end.**
## Tests
This project is tested thanks to PHPSpec and PHPUnit. To run the tests:
`composer test`
## CS Fixing
Coding Standards are checked and fixed thanks to PHP-CS-Fixer. To fix your code, just run `composer cs-fix`.
## Contributing
Please, feel free to contribute and improve this project.
## License
MIT.