Skip to content

Commit

Permalink
Cast ProcessResult objects (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot authored Feb 15, 2023
1 parent fd80739 commit 04a2d3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Console/TinkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ protected function getCasters()
$casters['Illuminate\Database\Eloquent\Model'] = 'Laravel\Tinker\TinkerCaster::castModel';
}

if (class_exists('Illuminate\Process\ProcessResult')) {
$casters['Illuminate\Process\ProcessResult'] = 'Laravel\Tinker\TinkerCaster::castProcessResult';
}

if (class_exists('Illuminate\Foundation\Application')) {
$casters['Illuminate\Foundation\Application'] = 'Laravel\Tinker\TinkerCaster::castApplication';
}
Expand Down
16 changes: 16 additions & 0 deletions src/TinkerCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ public static function castStringable($stringable)
];
}

/**
* Get an array representing the properties of a process result.
*
* @param \Illuminate\Process\ProcessResult $result
* @return array
*/
public static function castProcessResult($result)
{
return [
Caster::PREFIX_VIRTUAL.'output' => $result->output(),
Caster::PREFIX_VIRTUAL.'errorOutput' => $result->errorOutput(),
Caster::PREFIX_VIRTUAL.'exitCode' => $result->exitCode(),
Caster::PREFIX_VIRTUAL.'successful' => $result->successful(),
];
}

/**
* Get an array representing the properties of a model.
*
Expand Down

0 comments on commit 04a2d3b

Please sign in to comment.