Download the PHP package huynt57/laravel-singletonize without Composer

On this page you can find all versions of the php package huynt57/laravel-singletonize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-singletonize

Laravel Singletonize

Laravel Singletonize is a lightweight package that switches the default behaviour of the Laravel service container to resolve dependencies as singletons. Once installed, every concrete that is resolved without an explicit binding will automatically be cached and reused by the container.

Compatibility

Laravel Singletonize is tested against Laravel 10.x, 11.x, and 12.x applications.

Why this package?

Laravel's automatic resolution relies heavily on reflection to discover constructor dependencies on every request. For large codebases with many services, repeatedly reflecting on types becomes expensive and increases bootstrapping time. By promoting implicitly resolved services to singletons, the package ensures the reflection work is only performed once per service lifecycle, which can noticeably improve application performance.

This package was inspired by a Laravel core PR that aimed to improve container performance, although it was never merged into the framework itself: https://github.com/laravel/framework/pull/51209

Installation

The service provider is auto-discovered through Laravel's package discovery. If you prefer to register it manually, add the provider to your config/app.php file:

Configuration

Publish the configuration file to toggle the behaviour at runtime:

The published file config/laravel-singletonize.php contains a single option:

Set enabled to false to restore Laravel's default behaviour of creating a fresh instance on every resolution unless it has been explicitly registered as a singleton.

How it works

Singletonize boots a small helper (Huynt57\LaravelSingletonize\Singletonizer) that hooks into Laravel's container before any concrete is resolved. The helper inspects the abstract being requested and, the first time it encounters a class name, rewrites the container's internal binding definition to:

  1. Wrap the original concrete (class name, closure, or alias) in a memoized closure that stores the first resolved instance in $container->instances.
  2. Mark the binding as shared, so future resolutions skip the normal reflection/build process.

Because the memoized closure still receives the container and the original parameter array, contextual bindings and parameterised make() calls continue to work. When parameters are provided, the memoized closure bypasses the cached instance and rebuilds the object, ensuring runtime factories keep their expected behaviour.

The helper only runs once per abstract per request, so the bookkeeping overhead is minimal while every implicitly resolved service becomes a singleton automatically.

Testing

A lightweight test harness is provided in tests/run.php. Execute the suite with:

The tests cover:


All versions of laravel-singletonize with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/container Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package huynt57/laravel-singletonize contains the following files

Loading the files please wait ...