{"id":22747156,"url":"https://github.com/cs-eliseev/base-singleton","last_synced_at":"2025-10-26T07:33:20.415Z","repository":{"id":56959787,"uuid":"185531839","full_name":"cs-eliseev/base-singleton","owner":"cs-eliseev","description":"A Singleton Design Pattern which allow easy used singleton class.","archived":false,"fork":false,"pushed_at":"2019-05-12T15:38:33.000Z","size":17,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-21T01:52:38.246Z","etag":null,"topics":["collection","collections","cse","framework","helper","helpers","library","pattern","php","singleton","tool","tools","utilities","utility","utils"],"latest_commit_sha":null,"homepage":"","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/cs-eliseev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-08T05:06:39.000Z","updated_at":"2022-10-01T18:06:05.000Z","dependencies_parsed_at":"2022-08-21T10:20:12.906Z","dependency_job_id":null,"html_url":"https://github.com/cs-eliseev/base-singleton","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cs-eliseev/base-singleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fbase-singleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fbase-singleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fbase-singleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fbase-singleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cs-eliseev","download_url":"https://codeload.github.com/cs-eliseev/base-singleton/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fbase-singleton/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264987395,"owners_count":23693823,"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":["collection","collections","cse","framework","helper","helpers","library","pattern","php","singleton","tool","tools","utilities","utility","utils"],"created_at":"2024-12-11T03:13:25.420Z","updated_at":"2025-10-26T07:33:20.331Z","avatar_url":"https://github.com/cs-eliseev.png","language":"PHP","funding_links":["https://www.paypal.me/cseliseev/10usd"],"categories":[],"sub_categories":[],"readme":"English | [Русский](https://github.com/cs-eliseev/base-singleton/blob/master/README.ru_RU.md)\n\nSINGLETON CSE BASE\n=======\n\n[![Travis (.org)](https://img.shields.io/travis/cs-eliseev/base-singleton.svg?style=flat-square)](https://travis-ci.org/cs-eliseev/base-singleton)\n[![Codecov](https://img.shields.io/codecov/c/github/cs-eliseev/base-singleton.svg?style=flat-square)](https://codecov.io/gh/cs-eliseev/base-singleton)\n[![Scrutinizer code quality](https://img.shields.io/scrutinizer/g/cs-eliseev/base-singleton.svg?style=flat-square)](https://scrutinizer-ci.com/g/cs-eliseev/base-singleton/?branch=master)\n\n[![Packagist](https://img.shields.io/packagist/v/cse/base-singleton.svg?style=flat-square)](https://packagist.org/packages/cse/base-singleton)\n[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square)](https://packagist.org/packages/cse/base-singleton)\n[![Packagist](https://img.shields.io/packagist/l/cse/base-singleton.svg?style=flat-square)](https://github.com/cs-eliseev/base-singleton/blob/master/LICENSE.md)\n[![GitHub repo size](https://img.shields.io/github/repo-size/cs-eliseev/base-singleton.svg?style=flat-square)](https://github.com/cs-eliseev/base-singleton/archive/master.zip)\n\nA Singleton Design Pattern which allow easy used singleton class.\n\nProject repository: https://github.com/cs-eliseev/base-singleton\n\n**DEMO**\n```php\nclass ExampleSingleton\n{\n    use SingletonTrait;\n    ...\n}\n$instance = ExampleSingleton::getInstance();\n$instanceName = ExampleSingleton::getInstance('instance_name');\n```\n\n***\n\n\n## Introduction\n\nCSE BASE is a set of libraries written in PHP specifically to extend your classes.\n\nA set of basic methods for creating your classes is what you need to quickly create web applications. \nSINGLETON CSE BASE, позволяет легко и просто создавать singleton класс.\n\nCSE BASE was created for the rapid development of web applications.\n\n**CSE Base project:**\n* [Exceptions CSE base](https://github.com/cs-eliseev/base-exceptions)\n* [Singleton CSE base](https://github.com/cs-eliseev/base-singleton)\n\nBelow you will find some information on how to init library and perform common commands.\n\n\n## Install\n\nYou can find the most recent version of this project [here](https://github.com/cs-eliseev/base-singleton).\n\n### Composer\n\nExecute the following command to get the latest version of the package:\n```bash\ncomposer require cse/base-singleton\n```\n\nOr file composer.json should include the following contents:\n```json\n{\n    \"require\": {\n        \"cse/base-singleton\": \"*\"\n    }\n}\n```\n\n### Git\n\nClone this repository locally:\n```bash\ngit clone https://github.com/cs-eliseev/base-singleton.git\n```\n\n### Download\n\n[Download the latest release here](https://github.com/cs-eliseev/base-singleton/archive/master.zip).\n\n\n## Usage\n\nView test model: [ModelSingleton.php](https://github.com/cs-eliseev/base-singleton/blob/master/tests-data/ModelSingleton.php)\n\nSee examples: [examples-singleton.php](https://github.com/cs-eliseev/base-singleton/blob/master/examples/examples-singleton.php)\n\n**Create Model Singleton**\n\nExamples:\n```php\nclass ModelSingleton\n{\n    use SingletonTrait;\n\n    protected $param = 0;\n\n    /**\n     * @param int $param\n     */\n    public function setParam(int $param): void\n    {\n        $this-\u003eparam = $param;\n    }\n\n    /**\n     * @return int\n     */\n    public function getParam(): int\n    {\n        return $this-\u003eparam;\n    }\n}\n```\n\n**Create INSTANCE singleton**\n\nExamples:\n```php\n$instance = ModelSingleton::getInstance();\n$instance-\u003esetParam(10);\n$instance-\u003egetParam();\n// 10\n```\n\nCreate singleton instance by name:\n```php\n$instance2 = ModelSingleton::getInstance('new');\n$instance2-\u003esetParam(20);\n$instance-\u003egetParam();\n// 10\n$instance2-\u003egetParam();\n// 20\n```\n\nRestore singleton instance:\n```php\n$instance3 = ModelSingleton::getInstance();\n$instance3-\u003esetParam(30);\n$instance-\u003egetParam();\n// 30\n$instance2-\u003egetParam();\n// 20\n$instance3-\u003egetParam();\n// 30\n```\n\n**EXCEPTIONS singleton**\n\n__CLONE:\n```php\ntry {\n    $clone = clone ModelSingleton::getInstance();\n} catch (CSESingletonException $e) {\n    // Singleton can not using clone\n}\n```\n\n__SLEEP:\n```php\ntry {\n    $serialize = serialize(ModelSingleton::getInstance());\n} catch (CSESingletonException $e) {\n    // Singleton can not serialize\n}\n```\n\n__WAKEUP:\n```php\ntry {\n    ...\n} catch (CSESingletonException $e) {\n    // Singleton can not deserialize\n}\n```\n\n## Testing \u0026 Code Coverage\n\nPHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.\n\nGeneral PHPUnit documentation can be found at https://phpunit.de/documentation.html.\n\nTo run the PHPUnit unit tests, execute:\n```bash\nphpunit PATH/TO/PROJECT/tests/\n```\n\nIf you want code coverage reports, use the following:\n```bash\nphpunit --coverage-html ./report PATH/TO/PROJECT/tests/\n```\n\nUsed PHPUnit default config:\n```bash\nphpunit --configuration PATH/TO/PROJECT/phpunit.xml\n```\n\n\n## Donating\n\nYou can support this project [here](https://www.paypal.me/cseliseev/10usd). \nYou can also help out by contributing to the project, or reporting bugs. \nEven voicing your suggestions for features is great. Anything to help is much appreciated.\n\n\n## License\n\nThe SINGLETON CSE BASE is open-source PHP library licensed under the MIT license. Please see [License File](https://github.com/cs-eliseev/base-singleton/blob/master/LICENSE.md) for more information.\n\n***\n\n\u003e GitHub [@cs-eliseev](https://github.com/cs-eliseev)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs-eliseev%2Fbase-singleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcs-eliseev%2Fbase-singleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs-eliseev%2Fbase-singleton/lists"}