mirror of
https://github.com/archtechx/helpers.git
synced 2025-12-13 04:14:03 +00:00
add code
This commit is contained in:
parent
2945c59e92
commit
0d63a5b79c
12 changed files with 97 additions and 109 deletions
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\REPLACE;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class REPLACEServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
// $this->loadViewsFrom(__DIR__ . '/../assets/views', 'replace');
|
||||
|
||||
// $this->publishes([
|
||||
// __DIR__ . '/../assets/views' => resource_path('views/vendor/replace'),
|
||||
// ], 'replace-views');
|
||||
|
||||
// $this->mergeConfigFrom(
|
||||
// __DIR__ . '/../assets/replace.php',
|
||||
// 'replace'
|
||||
// );
|
||||
|
||||
// $this->publishes([
|
||||
// __DIR__ . '/../assets/replace.php' => config_path('replace.php'),
|
||||
// ], 'replace-config');
|
||||
}
|
||||
}
|
||||
32
src/helpers.php
Normal file
32
src/helpers.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
if (! function_exists('uses_trait')) {
|
||||
/** Check if a class or an object uses the specified trait. */
|
||||
function uses_trait(object|string $class, string $trait): bool
|
||||
{
|
||||
return in_array($trait, class_uses_recursive($class), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('is_simple_array')) {
|
||||
/** Checks if a variadic array only has one element that's an array.
|
||||
* @example [['foo', 'bar']] is a simple array
|
||||
* @example [['foo'], ['bar']] is not a simple array
|
||||
*/
|
||||
function is_simple_array(array $variadicArray): bool
|
||||
{
|
||||
return count($variadicArray) === 1 && isset($variadicArray[0]) && is_array($variadicArray[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('variadic_array')) {
|
||||
/** Converts [[a]] into [a] and [a, b] into [a, b] */
|
||||
function variadic_array(array $items): array
|
||||
{
|
||||
if (is_simple_array($items)) {
|
||||
$items = $items[0];
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue