Creates a reference to the response from a previous job, establishing an automatic dependency.
Signature
function response(string $job, ?string $key = null): ResponseReferenceInterface
Parameters
The name of the job whose response to reference.
Optional key or property to access from the job’s response. Use for accessing specific array keys or object properties.
Returns
ResponseReferenceInterface
ResponseReferenceInterface
A reference to the job’s response that will be resolved during workflow execution.
Usage
Basic response reference
use function Chevere\Workflow\{workflow, sync, variable, response, run};
$workflow = workflow(
calculate: sync(
function (int $a, int $b): int {
return $a + $b;
},
a: 10,
b: variable('value')
),
format: sync(
fn(int $result): string => "Result: {$result}",
result: response('calculate')
)
);
$run = run($workflow, value: 5);
echo $run->response('format')->string();
// Output: Result: 15
Chained responses
use function Chevere\Workflow\{workflow, sync, variable, response};
$workflow = workflow(
greet: sync(
MyAction::class,
foo: variable('super')
),
capo: sync(
MyAction::class,
foo: response('greet')
),
wea: sync(
function (string $foo) {
return "Wea, {$foo}";
},
foo: response('greet')
)
);
Accessing response keys
$workflow = workflow(
user: sync(
FetchUser::class,
userId: variable('id')
),
// Access specific key from array response
notify: sync(
SendEmail::class,
email: response('user', 'email'),
subject: 'Welcome!'
)
);
Accessing nested properties
$workflow = workflow(
fetch: sync(
FetchData::class,
url: variable('endpoint')
),
// Access entire response
process: sync(
ProcessData::class,
data: response('fetch')
),
// Access specific key
extract: sync(
ExtractField::class,
items: response('fetch', 'items')
)
);
Multiple dependencies
$workflow = workflow(
thumb: async(
ImageResize::class,
file: variable('image'),
size: 'thumb'
),
medium: async(
ImageResize::class,
file: variable('image'),
size: 'medium'
),
large: async(
ImageResize::class,
file: variable('image'),
size: 'large'
),
// Depends on all three resize jobs
store: sync(
StoreFiles::class,
thumb: response('thumb'),
medium: response('medium'),
large: response('large')
)
);
Notes
- Using
response() automatically creates a dependency between jobs
- The referenced job must exist in the workflow
- Jobs are executed in dependency order based on
response() references
- For array responses, use the second parameter to access specific keys
- For object responses, the key parameter accesses properties
- Use
variable() for runtime inputs instead of job responses