Skip to content

Commit

Permalink
Add the DateTimeFactory and the DateTimeImmutableFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslavlibal committed Jul 8, 2017
1 parent b2a3c19 commit bb2bf73
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# datetime-factory
# DateTime

## Installation

Install package [`jaroslavlibal/datetime`](https://packagist.org/packages/jaroslavlibal/datetime) with [Composer](https://getcomposer.org/) and register the parts you need as the services.

```
composer require jaroslavlibal/datetime
```

## Factory

Retrieve the DateTime and DateTimeImmutable objects from the mockable and testable factory instead of direct `new \DateTime()` creation.

### Usage
```php
class Foo
{

use JaroslavLibal\DateTime\Factory\DateTimeFactory;
use JaroslavLibal\DateTime\Factory\DateTimeFactory;

private DateTimeFactory;
private DateTimeImmutableFactory;

public function __construct(DateTimeFactory $dateTimeFactory, DateTimeImmutableFactory $dateTimeImmutableFactory)

private function bar() {
$dateTimeFactory->create();
$dateTimeImmutableFactory->create();
}
}
```
13 changes: 13 additions & 0 deletions src/JaroslavLibal/DateTime/Factory/DateTimeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace JaroslavLibal\DateTime\Factory;

use DateTime;

class DateTimeFactory {

public function create(): DateTime {
return new DateTime();
}

}
13 changes: 13 additions & 0 deletions src/JaroslavLibal/DateTime/Factory/DateTimeImmutableFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace JaroslavLibal\DateTime\Factory;

use DateTimeImmutable;

class DateTimeImmutableFactory {

public function create(): DateTimeImmutable {
return new DateTimeImmutable();
}

}

0 comments on commit bb2bf73

Please sign in to comment.