1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-07 17:10:05 +01:00

Clean up helpers

This commit is contained in:
Matt Stauffer
2022-12-20 20:04:28 -05:00
parent b2b0e1d592
commit 6bd3cf660a

View File

@@ -33,7 +33,7 @@
* Set or get a global console writer. * Set or get a global console writer.
* *
* @param null|Symfony\Component\Console\Output\ConsoleOutputInterface $writer * @param null|Symfony\Component\Console\Output\ConsoleOutputInterface $writer
* @return void|Symfony\Component\Console\Output\ConsoleOutputInterface * @return Symfony\Component\Console\Output\ConsoleOutputInterface
*/ */
function writer($writer = null) function writer($writer = null)
{ {
@@ -47,7 +47,7 @@ function writer($writer = null)
return $container->make('writer'); return $container->make('writer');
} }
Container::getInstance()->instance('writer', $writer); return Container::getInstance()->instance('writer', $writer);
} }
/** /**
@@ -109,17 +109,15 @@ function output($output)
writer()->writeln($output); writer()->writeln($output);
} }
if (! function_exists('resolve')) { /**
/**
* Resolve the given class from the container. * Resolve the given class from the container.
* *
* @param string $class * @param string $class
* @return mixed * @return mixed
*/ */
function resolve($class) function resolve($class)
{ {
return Container::getInstance()->make($class); return Container::getInstance()->make($class);
}
} }
/** /**
@@ -134,8 +132,7 @@ function swap($class, $instance)
Container::getInstance()->instance($class, $instance); Container::getInstance()->instance($class, $instance);
} }
if (! function_exists('retry')) { /**
/**
* Retry the given function N times. * Retry the given function N times.
* *
* @param int $retries * @param int $retries
@@ -143,8 +140,8 @@ function swap($class, $instance)
* @param int $sleep * @param int $sleep
* @return mixed * @return mixed
*/ */
function retry($retries, $fn, $sleep = 0) function retry($retries, $fn, $sleep = 0)
{ {
beginning: beginning:
try { try {
return $fn(); return $fn();
@@ -161,7 +158,6 @@ function retry($retries, $fn, $sleep = 0)
goto beginning; goto beginning;
} }
}
} }
/** /**
@@ -176,32 +172,29 @@ function should_be_sudo()
} }
} }
if (! function_exists('tap')) { /**
/**
* Tap the given value. * Tap the given value.
* *
* @param mixed $value * @param mixed $value
* @param callable $callback * @param callable $callback
* @return mixed * @return mixed
*/ */
function tap($value, callable $callback) function tap($value, callable $callback)
{ {
$callback($value); $callback($value);
return $value; return $value;
}
} }
if (! function_exists('ends_with')) { /**
/**
* Determine if a given string ends with a given substring. * Determine if a given string ends with a given substring.
* *
* @param string $haystack * @param string $haystack
* @param string|array $needles * @param string|array $needles
* @return bool * @return bool
*/ */
function ends_with($haystack, $needles) function ends_with($haystack, $needles)
{ {
foreach ((array) $needles as $needle) { foreach ((array) $needles as $needle) {
if (substr($haystack, -strlen($needle)) === (string) $needle) { if (substr($haystack, -strlen($needle)) === (string) $needle) {
return true; return true;
@@ -209,19 +202,17 @@ function ends_with($haystack, $needles)
} }
return false; return false;
}
} }
if (! function_exists('starts_with')) { /**
/**
* Determine if a given string starts with a given substring. * Determine if a given string starts with a given substring.
* *
* @param string $haystack * @param string $haystack
* @param string|string[] $needles * @param string|string[] $needles
* @return bool * @return bool
*/ */
function starts_with($haystack, $needles) function starts_with($haystack, $needles)
{ {
foreach ((array) $needles as $needle) { foreach ((array) $needles as $needle) {
if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) { if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) {
return true; return true;
@@ -229,7 +220,6 @@ function starts_with($haystack, $needles)
} }
return false; return false;
}
} }
/** /**