| 1 |
<?php |
| 2 |
/** |
| 3 |
* Creates a Duration object from the duration in seconds. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Timer; |
| 11 |
|
| 12 |
use SolidWP\Performance\Container; |
| 13 |
|
| 14 |
/** |
| 15 |
* Creates a Duration object from the duration in seconds. |
| 16 |
* |
| 17 |
* @package SolidWP\Performance |
| 18 |
*/ |
| 19 |
final class Duration_Factory { |
| 20 |
|
| 21 |
/** |
| 22 |
* @var Container |
| 23 |
*/ |
| 24 |
private Container $container; |
| 25 |
|
| 26 |
/** |
| 27 |
* @param Container $container The container. |
| 28 |
*/ |
| 29 |
public function __construct( Container $container ) { |
| 30 |
$this->container = $container; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Make a duration object. |
| 35 |
* |
| 36 |
* @param float $seconds The duration in seconds. |
| 37 |
* |
| 38 |
* @return Duration |
| 39 |
*/ |
| 40 |
public function make( float $seconds ): Duration { |
| 41 |
$this->container->when( Duration::class ) |
| 42 |
->needs( '$seconds' ) |
| 43 |
->give( $seconds ); |
| 44 |
|
| 45 |
return $this->container->get( Duration::class ); |
| 46 |
} |
| 47 |
} |
| 48 |
|