Skip to content

Commit 04a2d3b

Browse files
authored
Cast ProcessResult objects (#159)
1 parent fd80739 commit 04a2d3b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Console/TinkerCommand.php

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ protected function getCasters()
131131
$casters['Illuminate\Database\Eloquent\Model'] = 'Laravel\Tinker\TinkerCaster::castModel';
132132
}
133133

134+
if (class_exists('Illuminate\Process\ProcessResult')) {
135+
$casters['Illuminate\Process\ProcessResult'] = 'Laravel\Tinker\TinkerCaster::castProcessResult';
136+
}
137+
134138
if (class_exists('Illuminate\Foundation\Application')) {
135139
$casters['Illuminate\Foundation\Application'] = 'Laravel\Tinker\TinkerCaster::castApplication';
136140
}

src/TinkerCaster.php

+16
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ public static function castStringable($stringable)
9494
];
9595
}
9696

97+
/**
98+
* Get an array representing the properties of a process result.
99+
*
100+
* @param \Illuminate\Process\ProcessResult $result
101+
* @return array
102+
*/
103+
public static function castProcessResult($result)
104+
{
105+
return [
106+
Caster::PREFIX_VIRTUAL.'output' => $result->output(),
107+
Caster::PREFIX_VIRTUAL.'errorOutput' => $result->errorOutput(),
108+
Caster::PREFIX_VIRTUAL.'exitCode' => $result->exitCode(),
109+
Caster::PREFIX_VIRTUAL.'successful' => $result->successful(),
110+
];
111+
}
112+
97113
/**
98114
* Get an array representing the properties of a model.
99115
*

0 commit comments

Comments
 (0)