/** * @param string $template A Blade template read into a string * @param array $data The data to render * @param array $mergeData Data to merge with the existing view data * * @return mixed|string */ public function makeFromString($template, $data = [], $mergeData = []) { $_json = false; $_workTemplate = $template; !is_string($_workTemplate) && ($_workTemplate = JsonFile::encode($_workTemplate)) && ($_json = true); /** @type \Wpb\StringBladeCompiler\StringView $_view */ /** @noinspection PhpUndefinedMethodInspection */ $_view = StringView::make(['template' => $_workTemplate, 'cache_key' => md5(array_get($data, 'cache_key', microtime(true)) . sha1($_workTemplate)), 'updated_at' => time()], $data, $mergeData); $_workTemplate = $_view->render(); return $_json ? JsonFile::decode($_workTemplate, true) : $_workTemplate; }
/** * Retrieves an input argument and checks for valid JSON. * * @param string|null $optionKey The option name to retrieve * @param string|null $arrayKey If specified, decoded array will be placed into $array[$arrayKey] * @param array|null $array The $array in which to place the result * @param bool $required If this is required * * @return bool|array */ protected function optionArray($optionKey = null, $arrayKey = null, array &$array = null, $required = false) { /** @noinspection PhpUndefinedMethodInspection */ $_data = $this->option($optionKey); if (null === $arrayKey) { return $_data; } if (empty($_data)) { if ($required) { /** @noinspection PhpUndefinedMethodInspection */ $this->writeln('"' . $optionKey . '" is a required option for this operation.'); return false; } $array[$arrayKey] = $_data = []; return true; } try { $_data = JsonFile::decode($_data); } catch (\Exception $_ex) { /** @noinspection PhpUndefinedMethodInspection */ $this->writeln('the "' . $optionKey . '" provided does not contain valid JSON.'); return false; } $array[$arrayKey] = $_data; return true; }