-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add methods DelayStamp::delayFor()
and DelayStamp::delayUntil()
.
#38480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Errors are not related to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR.
/** | ||
* Apply this stamp to delay delivery of your message on a transport. | ||
*/ | ||
final class DelayStamp implements StampInterface | ||
{ | ||
public const PERIOD_SECONDS = 'seconds'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to your comment about delayFor()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we dont need a way to redefine time.
* | ||
* @see https://www.php.net/manual/en/datetime.formats.relative.php#datetime.formats.relative | ||
*/ | ||
public static function delayFor(int $units, string $period) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not understanding: why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont need to reinvent a way to define time intervals. We got the DateInterval
, Either using that or a DateTime is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, should have I to add delayForDays()
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is simply a shortcut, like the ones already exist in the class.
I would be happy with this PR if the only thing you add is this factory method |
I added the method As is a common need to postpone the execution and that this need doesn't limit to seconds, minutes or hours, I thought it have would been a good idea to add a generic method as a shortcut. You are right: we already have Symfony has a lot of shortcuts and this is one of the greatest things of this framework: it covers also the smallest details... And this is one of them. I don't understand some of them nor I have never used them... but they are there and when it will come the time, I will be able to use them and be a bit more happy with my DX using Symfony. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote 👎 for this PR in the current state. I think it should be closed.
If you decided to follow my suggestion I would be happy to vote it up and make sure it gets merged.
I would be happy with this PR if the only thing you add is this factory method DelayStamp::delayUntil(DateTimeInterface $datetime) and a test for that method.
I have tried to explain myself that we dont need a new way to define time intervals. We also dont need existing methods to take an integer, convert to a datetime and then convert back to an integer.
@Nyholm , ok... I ask you to think about this for some time, please... May be you will arrive at a different conclusion, or may bb you will evaluate the tradoffs and decide that it is not a so big issue as you see it now to add a generic I did the same thing in the other issues where we met: I arrived at the conclusion you were right, but in this case, really, I don't see the issue... But maybe I'm wrong... rather: probably I'm... Let me think at this for some time, too... |
A "DateInterval" object is 100x better, less code and more flexibility. |
…:delayUntil() (Nyholm) This PR was squashed before being merged into the 5.x branch. Discussion ---------- [Messenger] Add DelayStamp::delayFor() and DelayStamp::delayUntil() | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #38141 | License | MIT | Doc PR | This PR will revert the work by @Toflar in #38141. He added some helper methods and I want to add a generic factory method that adds a DateInterval. This PR will also close #38480 and fix #38459. It is also related to a comment in #36512 (comment) that was liked by a few people. Maybe adding both `DelayStamp::delayFor(\DateInterval)` and `DelayStamp::delayUntil(\DateTimeInterface)` is overkill. But this covers all the bases and I hope that it will be the last change to this small class. Commits ------- c5de1eb [Messenger] Add DelayStamp::delayFor() and DelayStamp::delayUntil()
This PR adds two static factory methods:
DelayStamp::delayFor()
DelayStamp::delayUntil()
DelayStamp::delayFor()
Using the PHP relative
DateTime
formats, it is possible to create aDelayStamp
using a way more simple syntax:DelayStamp::delayUntil()
Passing a future
DateTime
, the method creates aDelayStamp
.Supersedes #36512
CHANGELOG.md