-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the
DateTimeFactory
and the DateTimeImmutableFactory
- Loading branch information
1 parent
b2a3c19
commit bb2bf73
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
src/JaroslavLibal/DateTime/Factory/DateTimeImmutableFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |