/** * Parse arguments. * * @param string $token * * @return \Viserio\Console\Input\InputArgument */ protected function parseArgument(string $token) : InputArgument { if (Str::endsWith($token, ']*')) { $mode = InputArgument::IS_ARRAY; $name = trim($token, '[]*'); } elseif (Str::endsWith($token, '*')) { $mode = InputArgument::IS_ARRAY | InputArgument::REQUIRED; $name = trim($token, '*'); } elseif (Str::startsWith($token, '[')) { $mode = InputArgument::OPTIONAL; $name = trim($token, '[]'); } else { $mode = InputArgument::REQUIRED; $name = $token; } return new InputArgument($name, $mode); }
/** * {@inheritdoc} */ public function renderEach(string $view, array $data, string $iterator, string $empty = 'raw|') : string { $result = ''; // If is actually data in the array, we will loop through the data and append // an instance of the partial view to the final result HTML passing in the // iterated value of this data array, allowing the views to access them. if (count($data) > 0) { foreach ($data as $key => $value) { $data = ['key' => $key, $iterator => $value]; $result .= $this->create($view, $data)->render(); } // If there is no data in the array, we will render the contents of the empty // view. Alternatively, the "empty view" could be a raw string that begins // with "raw|" for convenience and to let this know that it is a string. } else { if (Str::startsWith($empty, 'raw|')) { $result = substr($empty, 4); } else { $result = $this->create($empty)->render(); } } return $result; }
/** * Dynamically bind parameters to the view. * * @param string $method * @param array $parameters * * @throws \BadMethodCallException * * @return \Viserio\View\View */ public function __call(string $method, array $parameters) : ViewContract { if (Str::startsWith($method, 'with')) { return $this->with(Str::snake(substr($method, 4)), $parameters[0]); } throw new BadMethodCallException(sprintf('Method [%s] does not exist on view.', $method)); }
/** * Get the environment argument from the console. * * @param array $args * * @return string|null */ protected function getEnvironmentArgument(array $args) { return Arr::first($args, function ($k, $v) { return Str::startsWith($v, '--env'); }); }