PHPackages                             vladimmi/construct-static - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vladimmi/construct-static

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vladimmi/construct-static
=========================

Small Composer wrapper to implement static class constructors

172.2k11PHP

Since Jan 9Pushed 3y ago4 watchersCompare

[ Source](https://github.com/vladimmi/construct-static)[ Packagist](https://packagist.org/packages/vladimmi/construct-static)[ RSS](/packages/vladimmi-construct-static/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (1)

Introduction
============

[](#introduction)

This is a small wrapper to Composer class loader intended to add functionality similar to static initializers in Java. You can define static method named `__constructStatic()` and it'll be invoked first time class loaded into project.

Example:

```
class MyTestClass
{
    private static function __constructStatic()
    {
        //this will be called once after class loaded
    }
}
```

Reqirements
===========

[](#reqirements)

No external libraries required, just use Composer autoloader in your project.

Installation
============

[](#installation)

Add to `composer.json` `require` block: `"vladimmi/construct-static": "dev-master@dev"`

Usage
=====

[](#usage)

```
$composer = require_once(__DIR__ . '/vendor/autoload.php');     //get Composer loader
$loader = new ConstructStatic\Loader($composer);                //wrap it
```

Details
=======

[](#details)

Composer autoloader is unregistered and wrapped with this one. Then all class load calls go to Composer through this loader. You can use `$loader` from the sample above as original `$composer` object - all methods calls are proxied to wrapped loader.

Other possible autoloaders remain registered so check resulting loaders order to prevent unexpected results.

Options
=======

[](#options)

Process previously loaded classes
---------------------------------

[](#process-previously-loaded-classes)

If you want to call static constructors on classes that were loaded before wrapper created, you can use `processLoadedClasses` method to do this:

```
$composer = require_once(__DIR__ . '/vendor/autoload.php');
$loader = new ConstructStatic\Loader($composer);
$loader->processLoadedClasses();        //call constructors on every already loaded class
```

Pass custom data to called constructors
---------------------------------------

[](#pass-custom-data-to-called-constructors)

You can pass some data to called constructors - for example, inject services or pass DI container. To do this you need to modify constructor a bit:

```
class MyTestClass
{
    //Added $params parameter
    private static function __constructStatic($params = [])
    {
        //this will be called once after class loaded
    }
}
```

Then you can set needed data when creating wrapping loader:

```
$composer = require_once(__DIR__ . '/vendor/autoload.php');
$params = [
    //set any needed data here...
];
$loader = new ConstructStatic\Loader($composer, $params);   //...and pass it to loader
```

That `$params` will be passed to every called constructor. If you want to pass some set of parameters to only specified classes to prevent conflicts or any other reason, you can set them this way:

```
$composer = require_once(__DIR__ . '/vendor/autoload.php');
$params = [
    //set any default data here
];
$anyYourClassParams = [
    //set any data for specific class here
];
$loader = new ConstructStatic\Loader($composer, $params);               //pass default data to loader
$loader->setClassParameters(AnyYourClass::class, $anyYourClassParams);  //pass data for specific class to loader
```

Then when `AnyYourClass` will be loaded it will receive `$anyYourClassParams` instead of `$params` while any other class will receive `$params` which are set as default.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 84.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d172bde195c85bae55e16ebb85a5875ff1d7bf71eb6138f9d83bd804925fecea?d=identicon)[vladimmi](/maintainers/vladimmi)

---

Top Contributors

[![vladimmi](https://avatars.githubusercontent.com/u/891830?v=4)](https://github.com/vladimmi "vladimmi (11 commits)")[![f3nrir92](https://avatars.githubusercontent.com/u/5359356?v=4)](https://github.com/f3nrir92 "f3nrir92 (2 commits)")

### Embed Badge

![Health badge](/badges/vladimmi-construct-static/health.svg)

```
[![Health](https://phpackages.com/badges/vladimmi-construct-static/health.svg)](https://phpackages.com/packages/vladimmi-construct-static)
```

###  Alternatives

[vonage/nexmo-bridge

Provides a bridge for using the Vonage PHP SDK with the older Nexmo namespace

5310.3M3](/packages/vonage-nexmo-bridge)[mediawiki/chameleon-skin

A highly flexible MediaWiki skin using Bootstrap 4

12481.8k2](/packages/mediawiki-chameleon-skin)[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)[aeon-php/calendar-holidays

Holidays calendar abstraction layer for Aeon Time management framework

14212.4k3](/packages/aeon-php-calendar-holidays)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
