{"id":33974918,"url":"https://github.com/phpnomad/singleton","last_synced_at":"2026-06-01T04:31:14.834Z","repository":{"id":244274157,"uuid":"704508630","full_name":"phpnomad/singleton","owner":"phpnomad","description":"Trait-based singleton pattern implementation for PHPNomad","archived":false,"fork":false,"pushed_at":"2026-04-15T04:19:30.000Z","size":107,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-05-09T04:45:47.669Z","etag":null,"topics":["design-pattern","framework","php","phpnomad","platform-agnostic","singleton"],"latest_commit_sha":null,"homepage":"https://phpnomad.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpnomad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-10-13T12:10:16.000Z","updated_at":"2026-04-10T02:09:32.000Z","dependencies_parsed_at":"2024-06-13T19:56:12.756Z","dependency_job_id":"781bea2a-e1a7-4d09-8501-4d7086c02efd","html_url":"https://github.com/phpnomad/singleton","commit_stats":null,"previous_names":["phpnomad/singleton"],"tags_count":1,"template":false,"template_full_name":"phpnomad/repository-template","purl":"pkg:github/phpnomad/singleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpnomad%2Fsingleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpnomad%2Fsingleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpnomad%2Fsingleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpnomad%2Fsingleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpnomad","download_url":"https://codeload.github.com/phpnomad/singleton/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpnomad%2Fsingleton/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33760645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["design-pattern","framework","php","phpnomad","platform-agnostic","singleton"],"created_at":"2025-12-13T01:56:32.248Z","updated_at":"2026-06-01T04:31:14.829Z","avatar_url":"https://github.com/phpnomad.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phpnomad/singleton\n\n[![Latest Version](https://img.shields.io/packagist/v/phpnomad/singleton.svg)](https://packagist.org/packages/phpnomad/singleton) [![Total Downloads](https://img.shields.io/packagist/dt/phpnomad/singleton.svg)](https://packagist.org/packages/phpnomad/singleton) [![PHP Version](https://img.shields.io/packagist/php-v/phpnomad/singleton.svg)](https://packagist.org/packages/phpnomad/singleton) [![License](https://img.shields.io/packagist/l/phpnomad/singleton.svg)](https://packagist.org/packages/phpnomad/singleton)\n\n`phpnomad/singleton` is a single-trait package for [PHPNomad](https://phpnomad.com). It provides `WithInstance`, a trait that gives any class a static `instance()` method returning a lazily-created, per-class singleton. It has zero runtime dependencies and is what `phpnomad/facade` and the rest of the framework use whenever a class needs a single shared instance without reaching for a container.\n\n## Installation\n\n```bash\ncomposer require phpnomad/singleton\n```\n\n## Quick Start\n\nAdd the trait to a class, then call `instance()` to get the shared object.\n\n```php\n\u003c?php\n\nuse PHPNomad\\Singleton\\Traits\\WithInstance;\n\nclass Registry\n{\n    use WithInstance;\n\n    private array $items = [];\n\n    public function register(string $key, $value): void\n    {\n        $this-\u003eitems[$key] = $value;\n    }\n\n    public function get(string $key)\n    {\n        return $this-\u003eitems[$key] ?? null;\n    }\n}\n\nRegistry::instance()-\u003eregister('theme', 'dark');\n$theme = Registry::instance()-\u003eget('theme'); // 'dark'\n```\n\nEvery call to `Registry::instance()` returns the same object for the lifetime of the request.\n\n## Overview\n\nThe package is intentionally tiny. The trait adds a protected static `$instance` property and a public static `instance()` method, and nothing else.\n\n- Lazy initialization, so the instance is only built the first time `instance()` is called\n- Late static binding (`new static`), so subclasses each get their own singleton rather than sharing the parent's\n- Zero runtime dependencies, which means adding it to a project pulls in nothing else\n- Lives under the `PHPNomad\\Singleton\\Traits` namespace, importable via `use PHPNomad\\Singleton\\Traits\\WithInstance;`\n- Used by `phpnomad/facade` to back its static service facades across the framework\n\n## Documentation\n\nThe full package guide, including inheritance behavior, testing strategies, and when to reach for a DI container instead, lives at [phpnomad.com](https://phpnomad.com).\n\n## License\n\nMIT, see [LICENSE.txt](LICENSE.txt) for the full text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpnomad%2Fsingleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpnomad%2Fsingleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpnomad%2Fsingleton/lists"}