/** * base function to return assets * * @param mixed asset path data received from the image method * @return string url to pass to img or css */ protected function getAsset($assetData) { try { $Comet = \CometPHP\Comet::getInstance(); } catch (\CometPHP\Exceptions\CometNotBooted $e) { return null; } if (!is_array($assetData)) { $assetData = [$assetData]; } $asset = $Comet['template']->getFunction('asset')->call($this->template, $assetData); return $asset; }
/** * base function to return the url for the link method * * @param mixed url data received from the link method * @return string url to pass to href */ public function getUrl($url) { if (is_array($url) && !empty($url['route'])) { try { $Comet = \CometPHP\Comet::getInstance(); } catch (\CometPHP\Exceptions\CometNotBooted $e) { return null; } $routeName = $url['route']; unset($url['route']); $generatedUrl = $Comet['routeGenerator']->generate($routeName, $url); return $generatedUrl; } return $url; }
/** * get the post data to prefill the inputs * * @param string dot notation format of the input name we're looking for * @return mixed|null Return value from post data or null if not found */ public function getValue($name) { if (!is_string($name)) { return null; } try { $Comet = \CometPHP\Comet::getInstance(); } catch (\CometPHP\Exceptions\CometNotBooted $e) { return null; } $bits = explode('.', $name); $postData = $Comet['request']->request->all(); foreach ($bits as $key) { if (is_array($postData) && isset($postData[$key])) { $postData = $postData[$key]; } else { return null; } } return $postData; }