Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Utility Bundle Laravel Package

namshi/utility-bundle

Namshi Utility Bundle is a small Symfony bundle that packages reusable utility services and helpers for common PHP/Symfony tasks, aiming to reduce boilerplate. Adoption is limited, so it best suits legacy projects; check Symfony version compatibility and maintenance status before use.

View on GitHub
Deep Wiki
Context7

Getting Started

Start with the reality check, not the README. namshi/utility-bundle is a Symfony 2 bundle. There is no service provider, no facade, no config/*.php, and no package auto-discovery. composer require namshi/utility-bundle in a modern Laravel app will almost certainly die on constraints (symfony/symfony ~2.x, symfony/framework-bundle, likely a PHP 5.x floor) before you get to vendor/. Confirm that in the first two minutes by reading the repo's composer.json — it tells you the PHP floor, the Symfony constraints, and whether coexistence is even theoretically possible. Usually it isn't.

Then enumerate the real API surface. A Symfony 2 bundle is four conventional files, and this one is no different:

  • NamshiUtilityBundle.php — the bundle class, almost always empty boilerplate.
  • DependencyInjection/NamshiUtilityExtension.php — loads service definitions.
  • DependencyInjection/Configuration.php — the tunable config tree (this is the closest thing to a Laravel config/*.php).
  • Resources/config/services.yml — the actual inventory of classes. This is your table of contents. Read it before anything else.

Everything else in the repo is helper classes. That's the whole package.

Decide install vs. mine before writing code. With 6 stars, 0 dependents, and a Symfony 2 target, the answer is mine essentially every time. Copy the one or two stateless helpers you actually want into app/Support/, strip the Symfony wiring (container references, Extension, Twig extensions, event subscribers), and bind them in a provider.

First concrete use case: you spotted a string/array/date helper that Illuminate\Support\Str/Arr/Carbon doesn't cover. Copy the class body into app/Support/YourHelper.php, drop the use Symfony\... imports, add namespace App\Support;, and register it as a singleton in AppServiceProvider::register(). That's the entire "integration" — and it takes twenty minutes, not a dependency decision.

Implementation Patterns

Port-then-bind (the default pattern). Extract a stateless class into app/Support, make it plain PHP, and bind it in a service provider so you can inject it the Laravel way:

// AppServiceProvider::register()
$this->app->singleton(\App\Support\Slugger::class);

Then inject Slugger into a controller, job, or command exactly as you would any first-party service. This is the day-to-day shape: you are not adopting the bundle, you are adopting one class from it and wiring it Laravel-style.

Static utility class for pure functions. If the helper has no dependencies, don't bother with the container at all. App\Support\Format::bytes($n) used directly at call sites is simpler, testable, and greppable. Reserve the provider for anything with state or config.

Facade only if the call sites are noisy. A Format facade is worth it if the helper gets called from Blade templates and controllers alike; otherwise skip it and inject. Don't add a facade just to feel "Laravel-y."

Wrap it in a config-driven service when the original was configurable. The bundle's Configuration.php exposes tunables through Symfony's tree builder. Map each option to a Laravel config entry under config/support.php and read it in the constructor:

public function __construct(private array $options) {}
// config/support.php -> 'formatter' => ['locale' => 'en_GB', ...]

Test the port before trusting it. Write a PHPUnit test against the copied class covering the behavior you actually rely on, not the whole surface. You're establishing a baseline so that when you refactor the internals (and you will), you can prove nothing changed. This is the single highest-value step in the whole exercise.

Private composer package when it grows past one or two classes. If you end up wanting five or more helpers, promote app/Support into an internal package (company/laravel-support) so multiple apps can share it. It's the same code; you've just changed where it lives and gained versioning.

Migration sequencing. Inventory → license check → gap analysis against Str/Arr/Collection/Carbon/ramsey/uuid → extract survivors → test → wire → feature-flag the call sites that switch over → delete the old path once parity holds. Most items terminate at gap analysis; that's the point.

Gotchas and Tips

PHP 5-era syntax is a landmine, not a deprecation. Expect each(), create_function(), curly-brace string offsets, and un-typed properties. Under PHP 8.1+ these are fatal errors, not warnings. Run Rector on the extracted class and PHPStan at a decent level before you commit it. Don't assume "it looked fine when I copied it" means it runs.

The bundle's DI wiring is not portable — do not try to bridge it. There's no equivalent to Symfony's container compilation in Laravel. Attempting to shim Symfony service definitions into Laravel's container invites subtle bugs: eager instantiation, shared state, and service IDs that shadow your own bindings. Strip the wiring and re-register in a provider. Every time.

Twig and HTTP-kernel helpers don't survive the port. Anything extending AbstractExtension, subscribing to kernel.* events, or type-hinting Symfony\Component\HttpKernel\* is framework-coupled and gets discarded, not refactored. If what you actually wanted is a Twig extension, the Laravel equivalent is a Blade directive, and you'll write that from scratch.

Check the license before you copy a single line. A code lift into a proprietary codebase is a license decision as much as a technical one. Confirm the license text allows your use, and confirm Namshi holds clean copyright for the files you take. Get this signed off before the code lands in app/Support, not after.

Watch for PSR-0 vs. PSR-4. Older Namshi bundles used PSR-0 conventions. When you drop a class into app/Support, rename and re-namespace it to PSR-4, and make sure the filename matches the class exactly — Laravel's autoloader will silently fail to find it otherwise, and you'll chase a "Class not found" that's actually a naming mismatch.

Debugging tip: when a ported helper misbehaves, diff its behavior in isolation first. Write a tiny PHPUnit test that exercises just the copied class against the input you're seeing in production. Nine times out of ten the bug is a PHP version behavior difference (numeric strings, null coercion, strlen(null)) rather than a logic error, and the isolated test surfaces it in seconds. The alternative — debugging through a controller with the container in the middle — wastes an afternoon.

Silent behavioral drift is the real risk. Locale handling, date math, and string encoding are the classic places where a PHP 5 helper and a PHP 8 caller disagree, and disagreements here produce wrong output, not exceptions. If you port a locale-sensitive or date-sensitive helper, pin the behavior with tests before shipping, and consider just using Carbon / IntlDateFormatter / mb_* directly instead of porting.

Container collisions are a production-only failure mode. If you name a binding formatter and something else in the app already binds formatter, tests pass and production does the wrong thing. Namespace your bindings (support.formatter) or bind by class name, and avoid short generic keys.

Abandoned-dependency scanners will flag the original. If your supply-chain tooling runs against composer.json and sees namshi/utility-bundle, it will flag the build and gate your pipeline for a package that provides almost nothing. Another reason to mine rather than require: the scanner never sees the fork you own, which is the correct posture.

Own it explicitly when you fork. Once the code lives in app/Support or an internal package, name a team and a deprecation path. Unmaintained internal utility code drifts into "nobody knows what this does" faster than anything else, and no upstream exists to tell you when it breaks. A short docblock pointing back to the source repo and noting "ported from namshi/utility-bundle, owned by X" costs nothing and saves a future engineer an hour.

When in doubt, rebuild instead of port. Most utility-bundle helpers are 20–50 lines. A one-hour spike that reads the class and reimplements the idea in Laravel-native style — with tests, current PHP idioms, and no legacy baggage — will usually beat a careful port. Treat the repo as reference prior art, not as source material.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin