carloschininin/app-util
Laravel utility helpers for building apps: handy functions, common traits, and small components to speed up development and reduce boilerplate. Lightweight package you can drop into projects for everyday tasks and consistent utilities.
Installation
composer require carloschininin/app-util:^0.2.0
Add to config/app.php under providers:
CarlosChininin\AppUtil\AppUtilServiceProvider::class,
First Use Case: Helper Functions
The package now supports Symfony 8.0 compatibility. Test the updated Helper facade:
use CarlosChininin\AppUtil\Facades\Helper;
// Example: Generate a random string (works with Symfony 8.0)
$randomString = Helper::randomString(10);
dd($randomString); // Outputs a 10-character alphanumeric string
Key Facades (Unchanged)
Helper – General utilities (strings, arrays, etc.)ResponseHelper – HTTP response helpersFileHelper – File operationsPattern: Replace Laravel’s Str and Arr helpers with Helper for consistency.
// Works seamlessly with Symfony 8.0 components
$slug = Helper::slug('Hello World!');
// Symfony 8.0 compatible array operations
$values = Helper::pluck($array, 'key');
Pattern: Use ResponseHelper for API responses.
use CarlosChininin\AppUtil\Facades\ResponseHelper;
return ResponseHelper::success($data, 'Operation completed');
// Returns: { "success": true, "data": [...], "message": "Operation completed" }
Pattern: Centralize file handling with Symfony 8.0 filesystem components.
use CarlosChininin\AppUtil\Facades\FileHelper;
// Upload a file (now supports Symfony 8.0 filesystem)
$path = FileHelper::upload('file.jpg', 'uploads/');
// Generate a download URL (Symfony 8.0 compatible)
$url = FileHelper::generateDownloadUrl($path);
Pattern: Use Helper::ip() or Helper::userAgent() in middleware.
public function handle($request, Closure $next) {
$ip = Helper::ip($request); // Works with Symfony 8.0 RequestStack
$request->merge(['user_ip' => $ip]);
return $next($request);
}
Pattern: Extend ResponseHelper with Symfony 8.0 ResponseFactory.
php artisan vendor:publish --provider="CarlosChininin\AppUtil\AppUtilServiceProvider"
Modify config/app-util.php to integrate Symfony 8.0 response formats:
'response' => [
'factory' => \Symfony\Component\HttpFoundation\ResponseFactory::class,
],
Symfony 8.0 Dependency Conflicts
composer require symfony/http-foundation:^6.3
Facade Caching (Symfony 8.0 Service Container)
php artisan config:clear
php artisan cache:clear
File Path Assumptions (Symfony 8.0 Filesystem)
FileHelper now defaults to Symfony 8.0 Filesystem. Override in config:
'file' => [
'adapter' => 'local', // 'local', 's3', or custom
'symfony_version' => '8.0',
],
Random String Collisions (Symfony 8.0 Random Generator)
Helper::randomString() now uses Symfony 8.0's Random component. For cryptographic needs, use:
use Symfony\Component\Uid\Uuid;
$uuid = Uuid::v4();
Symfony 8.0 Debugging
Enable debug mode in config/app-util.php:
'debug' => env('APP_DEBUG', false),
Logs facade calls to storage/logs/app-util.log with Symfony 8.0 stack traces.
Check Published Config
Ensure config/app-util.php matches Symfony 8.0 expectations after publishing:
php artisan vendor:publish --provider="CarlosChininin\AppUtil\AppUtilServiceProvider"
Add Custom Helpers (Symfony 8.0 Service Integration)
Bind new helpers in AppServiceProvider with Symfony 8.0 services:
Helper::extend('custom', function ($input) {
return strtoupper($input);
});
Usage:
Helper::custom('hello'); // "HELLO"
Override Response Templates (Symfony 8.0 Response)
Extend ResponseHelper with Symfony 8.0 Response:
ResponseHelper::macro('customResponse', function ($data) {
return new \Symfony\Component\HttpFoundation\JsonResponse(['custom' => $data]);
});
File Helper Events (Symfony 8.0 EventDispatcher) Listen for file operations via Symfony 8.0 events (publish events first):
php artisan vendor:publish --tag="app-util-events"
Example listener with Symfony 8.0 EventDispatcher:
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use CarlosChininin\AppUtil\Events\FileUploaded;
class FileUploadSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
FileUploaded::class => 'onFileUploaded',
];
}
public function onFileUploaded(FileUploaded $event)
{
Log::info('File uploaded:', ['path' => $event->path]);
}
}
How can I help you explore Laravel packages today?