henrotaym / laravel-helpers
一套 Laravel 辅助工具。
v1.6.1
2022-01-28 15:17 UTC
Requires
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.5
README
一套可以通过外观访问的有用辅助工具。
安装
composer require henrotaym/laravel-helpers
访问外观
use Henrotaym/LaravelHelpers/Facades/Helpers;
可用方法
尝试
/**
* Trying to execute given callback with given args.
*
* @param callable $callback function to try.
* @param mixed $args arguments to give to callback.
* @return array First element is error (if any), second is response(if no error).
*/
public function try(callable $callback, ...$args): array;
可选
/**
* Trying to access nested property.
*
* @param object $element
* @param string|array $nested_properties Nested properties. Methods should be like ['method_name' => [$arg1, $arg2]] OR method_name() if it doesn't need arguments.
* @return Illuminate\Support\Optional Nullable nested property.
*/
public function optional(object $element, ...$nested_properties): Illuminate\Support\Optional
doIfJobIsInstanceOf
/**
* Executing given callback if serialized job is instance of given element.
*
* @param Job $job
* @param mixed $instance_of Same parameter types as native php instanceof.
* @param callable $callback It receives job instance as first parameter.
* @return mixed Callback returned value or null if any error.
*/
public function doIfJobIsInstanceOf(Job $job, $instance_of, callable $callback);
uuid
/**
* Creating unique uuid.
*
* @param bool $allow_dash Telling if dashes are allowed in created uuid.
* @return string
*/
public function uuid(bool $allow_dash = false): string;
str_contains
/**
* Telling if given string contains given substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
* @return bool
*/
public function str_contains(string $haystack, string $needle);
getDirectory
/**
* Getting directory where the file is located.
*
* @param string $class
* @return string|null Null if any error.
*/
public function getDirectory(string $class): ?string;