Installation:
composer require demontpx/util-bundle
Ensure Demontpx\UtilBundle\DemontpxUtilBundle() is registered in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3).
First Use Case:
Check the Utils class for common helpers. Example:
use Demontpx\UtilBundle\Utils;
// Format a date (if included)
$formattedDate = Utils::formatDate(new \DateTime(), 'Y-m-d');
// Validate an email (if included)
$isValid = Utils::isValidEmail('test@example.com');
Where to Look First:
src/Utils.php for available static methods.Resources/config/services.yaml for services (if any).README.md for undocumented features (e.g., Twig extensions, event listeners).Data Validation:
// Validate input (if methods exist)
if (Utils::isValidPhone('+1234567890')) {
// Proceed
}
String Manipulation:
// Slugify a string (if included)
$slug = Utils::slugify('Hello World!');
// Truncate text
$shortened = Utils::truncate('Long text...', 20);
Array Utilities:
// Merge arrays recursively (if included)
$merged = Utils::deepMerge($array1, $array2);
// Filter empty values
$cleaned = Utils::removeEmpty($array);
Integration with Symfony:
{{ 'text'|slugify }}), register them in twig.config:
# config/packages/twig.yaml
twig:
globals:
util: '@demontpx_util.utils'
Resources/config/services.yaml and extend them.Dependency Injection: If the bundle provides services, autowire them:
use Demontpx\UtilBundle\Service\SomeService;
public function __construct(private SomeService $someService) {}
Undocumented Methods:
Utils before relying on them (e.g., Utils::formatDate() may not exist).get_class_methods(\Demontpx\UtilBundle\Utils::class) to list available methods dynamically.Symfony Version Compatibility:
autoconfigure: true in services.yaml). Verify compatibility by checking composer.json constraints.No Configuration:
config/packages/demontpx_util.yaml (if the file exists).Twig Integration:
php bin/console cache:clear
Extend the Bundle:
Utils class in your project to add custom methods:
namespace App\Utils;
use Demontpx\UtilBundle\Utils as BaseUtils;
class Utils extends BaseUtils {
public static function customMethod() { ... }
}
Testing:
Utils class in tests to isolate logic:
$this->getMockBuilder(\Demontpx\UtilBundle\Utils::class)
->disableOriginalConstructor()
->onlyMethods(['methodToMock'])
->getMock();
Performance:
Utils::isValidEmail() inside a foreach). Cache results if possible.Contributing:
Fallback Logic:
try {
$result = Utils::someMethod();
} catch (\BadMethodCallException $e) {
// Fallback to custom logic
$result = self::fallbackMethod();
}
How can I help you explore Laravel packages today?