Skip to content

Commit 9adf20c

Browse files
author
James Wigger
committed
Consistent helper API. Added HTTP host helper
1 parent ac1636a commit 9adf20c

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

helpers.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*
88
* @return string
99
*/
10-
if (!function_exists('public_path')) {
11-
function public_path($path = '')
10+
if (!function_exists('base_public_path')) {
11+
function base_public_path($path = '')
1212
{
1313
$basePath = realpath(__DIR__ . '/../../../');
1414
$userPath = realpath($basePath . ($path ? '/' . trim($path, '/') : $path));
@@ -26,8 +26,8 @@ function public_path($path = '')
2626
* @return string
2727
* @throws Exception
2828
*/
29-
if (!function_exists('mix')) {
30-
function mix($path, $manifestDirectory = '')
29+
if (!function_exists('base_asset')) {
30+
function base_asset($path, $manifestDirectory = '')
3131
{
3232
static $manifest;
3333

@@ -38,7 +38,7 @@ function mix($path, $manifestDirectory = '')
3838
}
3939

4040
if (!$manifest) {
41-
if (!file_exists($manifestPath = public_path($manifestDirectory . '/mix-manifest.json'))) {
41+
if (!file_exists($manifestPath = base_public_path($manifestDirectory . '/mix-manifest.json'))) {
4242
throw new Exception('The Mix manifest does not exist.');
4343
}
4444

@@ -52,7 +52,7 @@ function mix($path, $manifestDirectory = '')
5252
);
5353
}
5454

55-
if (file_exists(public_path($manifestDirectory . '/hot'))) {
55+
if (file_exists(base_public_path($manifestDirectory . '/hot'))) {
5656
return "http://localhost:8080{$manifest[$path]}";
5757
}
5858

@@ -77,7 +77,7 @@ function base_layout($file, array $data = [], $return = false)
7777
$Base = Base::fetch();
7878
$Base->setLayoutVars($data);
7979

80-
$path = public_path('layouts/' . ltrim($file, '/') . '.php');
80+
$path = base_public_path('layouts/' . ltrim($file, '/') . '.php');
8181

8282
if (!file_exists($path)) {
8383
throw new Exception("Unable to locate layout file: {$path}. Please check the layout exists");
@@ -148,12 +148,25 @@ function base_layout_has($key)
148148
*
149149
* @return Faker\Generator
150150
*/
151-
if(!function_exists('base_faker_factory')) {
152-
function base_faker_factory() {
153-
if(!class_exists('Faker\Factory')) {
151+
if (!function_exists('base_faker_factory')) {
152+
function base_faker_factory()
153+
{
154+
if (!class_exists('Faker\Factory')) {
154155
throw new Exception('Faker library is not available.');
155156
}
156157

157158
return Faker\Factory::create();
158159
}
159160
}
161+
162+
/**
163+
* Returns the full HTTP host of the current request
164+
*
165+
* @return string
166+
*/
167+
if (!function_exists('base_http_host')) {
168+
function base_http_host()
169+
{
170+
return 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 's' : '') . '://' . $_SERVER['HTTP_HOST'];
171+
}
172+
}

0 commit comments

Comments
 (0)