{"id":20583675,"url":"https://github.com/chrisnharvey/php-singleton-trait","last_synced_at":"2026-07-03T00:34:14.768Z","repository":{"id":4741290,"uuid":"5890648","full_name":"chrisnharvey/PHP-Singleton-Trait","owner":"chrisnharvey","description":"A quick way to turn any class into a singleton using this trait.","archived":false,"fork":false,"pushed_at":"2012-09-22T10:49:31.000Z","size":97,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-16T23:06:17.248Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrisnharvey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-20T17:59:06.000Z","updated_at":"2019-05-22T05:43:01.000Z","dependencies_parsed_at":"2022-08-30T17:12:18.470Z","dependency_job_id":null,"html_url":"https://github.com/chrisnharvey/PHP-Singleton-Trait","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisnharvey%2FPHP-Singleton-Trait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisnharvey%2FPHP-Singleton-Trait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisnharvey%2FPHP-Singleton-Trait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisnharvey%2FPHP-Singleton-Trait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisnharvey","download_url":"https://codeload.github.com/chrisnharvey/PHP-Singleton-Trait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242213281,"owners_count":20090676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-16T06:41:08.110Z","updated_at":"2026-07-03T00:34:14.734Z","avatar_url":"https://github.com/chrisnharvey.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PHP Singleton Trait\n===================\n\nA quick way to turn any class into a singleton using this trait.\n\n## Usage\nYou can easily turn your classes into singletons. See the following example.\n\n\t\u003c?php\n\tclass MySingletonClass\n\t{\n\t\tuse Singleton;\n\t\t\n\t\tpublic function init()\n\t\t{\n\t\t\t// Your __construct code goes here\n\t\t}\n\n\t\tpublic static function helloWorld()\n\t\t{\n\t\t\t// You create your class normally from now on\n\t\t\t// but using self::instance() instead of $this.\n\t\t\t// You can also return self::instance() and \n\t\t\t// chain your methods.\n\n\t\t\techo 'Hello World';\n\t\t\t\n\t\t\treturn self::instance();\n\t\t}\n\n\t\tpublic static function helloAgain()\n\t\t{\n\t\t\techo '\u003cbr\u003eHello again';\n\t\t}\n\t}\n\nYou can then call any of these functions statically and method chain them as if they were instantiated.\n\n\tMySingletonClass::helloWorld()-\u003ehelloAgain();\n\nThis would output:\n\n\tHello World\n\tHello again\n\nIf you would like to submit changes or pull requests then please feel free.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisnharvey%2Fphp-singleton-trait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisnharvey%2Fphp-singleton-trait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisnharvey%2Fphp-singleton-trait/lists"}