File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 1111 * source code.
1212 */
1313
14- use Doctrine \Common \Annotations \Annotation as DoctrineAnnotation ;
14+ use Doctrine \Common \Annotations \Annotation \ NamedArgumentConstructor ;
1515
1616/**
1717 * @Annotation
18- * @DoctrineAnnotation\Target("METHOD")
18+ * @NamedArgumentConstructor
19+ * @Target("METHOD")
1920 */
21+ #[\Attribute(\Attribute::TARGET_METHOD )]
2022final class Defer
2123{
2224 /**
@@ -32,15 +34,16 @@ final class Defer
3234 public $ options ;
3335
3436 /**
35- * @param array $values
36- * @throws \InvalidArgumentException
37+ * @param string|null $queueName
38+ * @param array|null $options
39+ * @param string|null $value
3740 */
38- public function __construct (array $ values )
41+ public function __construct (? string $ queueName = null , ? array $ options = null , ? string $ value = null )
3942 {
40- if (! isset ( $ values [ ' value ' ]) && ! isset ( $ values [ ' queueName ' ]) ) {
41- throw new \InvalidArgumentException ('A Defer annotation must specify a queueName. ' , 1334128835 );
43+ if ($ value === null && $ queueName === null ) {
44+ throw new \InvalidArgumentException ('A Defer attribute must specify a queueName. ' , 1334128835 );
4245 }
43- $ this ->queueName = isset ( $ values [ ' queueName ' ]) ? $ values [ ' queueName ' ] : $ values [ ' value ' ] ;
44- $ this ->options = isset ( $ values [ ' options ' ]) ? $ values [ ' options ' ] : [];
46+ $ this ->queueName = $ queueName ?? $ value ;
47+ $ this ->options = $ options ?? [];
4548 }
4649}
Original file line number Diff line number Diff line change @@ -63,6 +63,21 @@ Neos Flow package that allows for asynchronous and distributed execution of task
6363 }
6464 ```
6565
66+ or use attributes instead of annotations (PHP 8.0 and later):
67+
68+ ``` php
69+ use Flowpack\JobQueue\Common\Annotations as Job;
70+
71+ class SomeClass {
72+
73+ #[Job\Defer(queueName: "some-queue")]
74+ public function sendEmail($emailAddress)
75+ {
76+ // send some email to $emailAddress
77+ }
78+ }
79+ ```
80+
6681 * Note:* The method needs to be * public* and it must not return anything
6782
68835 . ** Start the worker (if required)**
You can’t perform that action at this time.
0 commit comments