-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
remove illuminate dependency, apply php 7 syntax, refactoring
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace SfCod\QueueBundle\Base; | ||
|
||
use DateInterval; | ||
use DateTime; | ||
use DateTimeInterface; | ||
|
||
/** | ||
* Trait TimeTrait | ||
* | ||
* @author Virchenko Maksim <muslim1992@gmail.com> | ||
* | ||
* @package SfCod\QueueBundle\Job | ||
*/ | ||
trait InteractWithTimeTrait | ||
{ | ||
/** | ||
* Get the number of seconds until the given DateTime. | ||
* | ||
* @param DateTimeInterface|DateInterval|int $delay | ||
* | ||
* @return int | ||
*/ | ||
protected function secondsUntil($delay): int | ||
{ | ||
$delay = $this->parseDateInterval($delay); | ||
|
||
return $delay instanceof DateTimeInterface | ||
? max(0, $delay->getTimestamp() - $this->currentTime()) | ||
: (int)$delay; | ||
} | ||
|
||
/** | ||
* Get the "available at" UNIX timestamp. | ||
* | ||
* @param DateTimeInterface|DateInterval|int $delay | ||
* | ||
* @return int | ||
*/ | ||
protected function availableAt($delay = 0): int | ||
{ | ||
$delay = $this->parseDateInterval($delay); | ||
|
||
return $delay instanceof DateTimeInterface | ||
? $delay->getTimestamp() | ||
: (new DateTime())->add(new DateInterval(sprintf('PT%dS', $delay)))->getTimestamp(); | ||
} | ||
|
||
/** | ||
* If the given value is an interval, convert it to a DateTime instance. | ||
* | ||
* @param \DateTimeInterface|\DateInterval|int $delay | ||
* | ||
* @return \DateTimeInterface|int | ||
*/ | ||
protected function parseDateInterval($delay) | ||
{ | ||
if ($delay instanceof DateInterval) { | ||
$delay = (new DateTime())->add($delay); | ||
} | ||
|
||
return $delay; | ||
} | ||
|
||
/** | ||
* Get the current system time as a UNIX timestamp. | ||
* | ||
* @return int | ||
*/ | ||
protected function currentTime(): int | ||
{ | ||
return time(); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace SfCod\QueueBundle\Base; | ||
|
||
/** | ||
* Interface JobResolverInterface | ||
* | ||
* @package SfCod\QueueBundle\Service | ||
*/ | ||
interface JobResolverInterface | ||
{ | ||
/** | ||
* Resolve job by class | ||
* | ||
* @param string $class | ||
* | ||
* @return JobInterface | ||
*/ | ||
public function resolve(string $class): JobInterface; | ||
} |