*/ protected $mutators; /** * Creates a new component instance. * * @param \Illuminate\Console\OutputStyle $output * @return void */ public function __construct($output) { $this->output = $output; } /** * Renders the given view. * * @param string $view * @param \Illuminate\Contracts\Support\Arrayable|array $data * @param int $verbosity * @return void */ protected function renderView($view, $data, $verbosity) { renderUsing($this->output); render((string) $this->compile($view, $data), $verbosity); } /** * Compile the given view contents. * * @param string $view * @param array $data * @return void */ protected function compile($view, $data) { extract($data); ob_start(); include __DIR__."/../../resources/views/components/$view.php"; return tap(ob_get_contents(), function () { ob_end_clean(); }); } /** * Mutates the given data with the given set of mutators. * * @param array|string $data * @param array $mutators * @return array|string */ protected function mutate($data, $mutators) { foreach ($mutators as $mutator) { $mutator = new $mutator; if (is_iterable($data)) { foreach ($data as $key => $value) { $data[$key] = $mutator($value); } } else { $data = $mutator($data); } } return $data; } /** * Eventually performs a question using the component's question helper. * * @param callable $callable * @return mixed */ protected function usingQuestionHelper($callable) { $property = with(new ReflectionClass(OutputStyle::class)) ->getParentClass() ->getProperty('questionHelper'); $property->setAccessible(true); $currentHelper = $property->isInitialized($this->output) ? $property->getValue($this->output) : new SymfonyQuestionHelper(); $property->setValue($this->output, new QuestionHelper); try { return $callable(); } finally { $property->setValue($this->output, $currentHelper); } } }