gpupo/common
PHP 8+ utility library with common tools for building PHP components. Includes developer tooling such as generating PHPUnit TestCases from existing classes (dev/debug focus). Designed as a reusable library (not a standalone app or plugin).
Install the package via Composer in your Laravel project:
composer require gpupo/common:^5.9
First Steps:
tests/ directory to understand usage patterns.vendor/bin/developer-toolbox developer-toolbox:tests:generate --class 'App\Models\YourClass'
Gpupo\Common\Tools\Datetime\TimeShift for date/time manipulations.Gpupo\Common\Support\Str for string operations (snake_case/camelCase conversions).Gpupo\Common\Validation\Rules for custom validation logic.Quick Example:
use Gpupo\Common\Tools\Datetime\TimeShift;
// Shift a date by 5 days
$shiftedDate = TimeShift::shift('2024-01-01', 5, 'days');
Pattern: Use traits and base classes to reduce boilerplate.
use Gpupo\Common\Traits\SingletonTrait;
use Gpupo\Common\Traits\GettersTypeTrait;
class YourService
{
use SingletonTrait, GettersTypeTrait;
// Singleton ensures one instance; GettersTypeTrait adds typed getters.
}
When to Use:
Pattern: Automate test generation and debugging.
# Generate test stubs for a class
vendor/bin/developer-toolbox developer-toolbox:tests:generate --class 'App\Services\PaymentService'
# Debug configuration (dev-only)
vendor/bin/developer-toolbox developer-toolbox:config:dump
Use Cases:
Pattern: Extend Laravel’s built-in features with gpupo/common utilities.
// In AppServiceProvider
use Gpupo\Common\Http\ResponseFactory;
public function boot()
{
Response::macro('api', function ($data, $status = 200) {
return ResponseFactory::json($data, $status);
});
}
// Usage in controllers
return response()->api(['message' => 'Success'], 201);
Why:
ResponseFactory for consistent JSON/API formats.Pattern: Reuse or extend validation rules.
use Gpupo\Common\Validation\Rules\CustomRule;
$validator = Validator::make($request->all(), [
'email' => ['required', new CustomRule],
]);
Tip:
CustomRule to add project-specific logic (e.g., domain validation).Pattern: Override defaults via Laravel’s config.
// config/gpupo.php
return [
'datetime_format' => 'Y-m-d H:i:s', // Override package defaults
];
Use Case:
Symfony 6 Dependency Conflicts
HttpFoundation) from v5.x, conflicts may arise.^6.x or pin versions:
"symfony/http-foundation": "^6.0"
PHP 8.3 Strict Typing
composer.json:
"require": {
"php": "^8.3"
}
CLI Tools Are Dev-Only
developer-toolbox are for debugging and won’t work in production.if (app()->environment('local')).Unit Tests Are the Documentation
tests/ directory for patterns (e.g., TimeShiftTest.php).Enable Debug Mode
// In AppServiceProvider
\Gpupo\Common\Support\Debug::enable();
storage/logs/gpupo-debug.log.Dump Configurations
vendor/bin/developer-toolbox developer-toolbox:config:dump
Check for Deprecated Methods
vendor/bin/phpstan analyse --level 8
Custom Traits
SingletonTrait or GettersTypeTrait for project-specific logic:
trait YourCustomTrait extends GettersTypeTrait {
public function customMethod(): string { ... }
}
Override Validation Rules
Gpupo\Common\Validation\Rules\AbstractRule:
class UniqueDomainRule extends AbstractRule {
public function passes($attribute, $value) { ... }
}
Modify Response Factory
ResponseFactory in AppServiceProvider:
$this->app->singleton(\Gpupo\Common\Http\ResponseFactory::class, function () {
return new CustomResponseFactory();
});
SingletonTrait can lead to memory bloat. Prefer dependency injection where possible.$validator = Validator::make($data, $rules, [], [], ['rules' => Cache::remember('validator_rules', ...));
Service Provider Binding
$this->app->rebinding(\Gpupo\Common\Contracts\Example::class, function ($app, $abstract, $concrete) {
return new CustomExample();
});
Blade Directives
AppServiceProvider:
Blade::directive('gpupo', function () {
return "<?php echo Gpupo\Common\Support\Blade::render(); ?>";
});
Queue Jobs
gpupo/common in queue jobs, ensure the SingletonTrait is not overused (jobs are stateless by design).How can I help you explore Laravel packages today?