PHPackages                             cse/base-singleton - 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. [Framework](/categories/framework)
4. /
5. cse/base-singleton

ActiveLibrary[Framework](/categories/framework)

cse/base-singleton
==================

A Singleton Design Pattern which allow easy used singleton class.

1.0.0(7y ago)572MITPHPPHP &gt;=7.1

Since May 12Pushed 7y ago3 watchersCompare

[ Source](https://github.com/cs-eliseev/base-singleton)[ Packagist](https://packagist.org/packages/cse/base-singleton)[ Docs](https://github.com/cs-eliseev/base-singleton)[ RSS](/packages/cse-base-singleton/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

English | [Русский](https://github.com/cs-eliseev/base-singleton/blob/master/README.ru_RU.md)

SINGLETON CSE BASE
==================

[](#singleton-cse-base)

[![Travis (.org)](https://camo.githubusercontent.com/819ca3720cb3d09178b5ca31770380a58655616621e9ce9bc7935a687dfa8079/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63732d656c69736565762f626173652d73696e676c65746f6e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/cs-eliseev/base-singleton)[![Codecov](https://camo.githubusercontent.com/65b382c3daf107072d55e821aa22c56fc31905d439d5a863803ede8f9cd101fd/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f63732d656c69736565762f626173652d73696e676c65746f6e2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/cs-eliseev/base-singleton)[![Scrutinizer code quality](https://camo.githubusercontent.com/103e25c17183f06df7839701daa532c919247fe288df5cac1d6c6d5692897f5a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f63732d656c69736565762f626173652d73696e676c65746f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cs-eliseev/base-singleton/?branch=master)

[![Packagist](https://camo.githubusercontent.com/338f0f5d91e4e056e9e2f3e4e3c6aa76779782ba548b23f446f1ba0bbe751fb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6373652f626173652d73696e676c65746f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cse/base-singleton)[![Minimum PHP Version](https://camo.githubusercontent.com/dcd4b4aec2c1709157fa6a2c050f709d75cde9552a79cfff0b70a97fad7281ae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cse/base-singleton)[![Packagist](https://camo.githubusercontent.com/d295c6527e59f3d26fbb5c6099c48894e64a43ce4cab4b3075536f7ab5df3c62/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6373652f626173652d73696e676c65746f6e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/cs-eliseev/base-singleton/blob/master/LICENSE.md)[![GitHub repo size](https://camo.githubusercontent.com/cce05f617e0e9d6ece82a5818e9455fba69d3bc79c88b10e2348c4bf5ab7f5f9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f63732d656c69736565762f626173652d73696e676c65746f6e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/cs-eliseev/base-singleton/archive/master.zip)

A Singleton Design Pattern which allow easy used singleton class.

Project repository:

**DEMO**

```
class ExampleSingleton
{
    use SingletonTrait;
    ...
}
$instance = ExampleSingleton::getInstance();
$instanceName = ExampleSingleton::getInstance('instance_name');
```

---

Introduction
------------

[](#introduction)

CSE BASE is a set of libraries written in PHP specifically to extend your classes.

A set of basic methods for creating your classes is what you need to quickly create web applications. SINGLETON CSE BASE, позволяет легко и просто создавать singleton класс.

CSE BASE was created for the rapid development of web applications.

**CSE Base project:**

- [Exceptions CSE base](https://github.com/cs-eliseev/base-exceptions)
- [Singleton CSE base](https://github.com/cs-eliseev/base-singleton)

Below you will find some information on how to init library and perform common commands.

Install
-------

[](#install)

You can find the most recent version of this project [here](https://github.com/cs-eliseev/base-singleton).

### Composer

[](#composer)

Execute the following command to get the latest version of the package:

```
composer require cse/base-singleton
```

Or file composer.json should include the following contents:

```
{
    "require": {
        "cse/base-singleton": "*"
    }
}
```

### Git

[](#git)

Clone this repository locally:

```
git clone https://github.com/cs-eliseev/base-singleton.git
```

### Download

[](#download)

[Download the latest release here](https://github.com/cs-eliseev/base-singleton/archive/master.zip).

Usage
-----

[](#usage)

View test model: [ModelSingleton.php](https://github.com/cs-eliseev/base-singleton/blob/master/tests-data/ModelSingleton.php)

See examples: [examples-singleton.php](https://github.com/cs-eliseev/base-singleton/blob/master/examples/examples-singleton.php)

**Create Model Singleton**

Examples:

```
class ModelSingleton
{
    use SingletonTrait;

    protected $param = 0;

    /**
     * @param int $param
     */
    public function setParam(int $param): void
    {
        $this->param = $param;
    }

    /**
     * @return int
     */
    public function getParam(): int
    {
        return $this->param;
    }
}
```

**Create INSTANCE singleton**

Examples:

```
$instance = ModelSingleton::getInstance();
$instance->setParam(10);
$instance->getParam();
// 10
```

Create singleton instance by name:

```
$instance2 = ModelSingleton::getInstance('new');
$instance2->setParam(20);
$instance->getParam();
// 10
$instance2->getParam();
// 20
```

Restore singleton instance:

```
$instance3 = ModelSingleton::getInstance();
$instance3->setParam(30);
$instance->getParam();
// 30
$instance2->getParam();
// 20
$instance3->getParam();
// 30
```

**EXCEPTIONS singleton**

\_\_CLONE:

```
try {
    $clone = clone ModelSingleton::getInstance();
} catch (CSESingletonException $e) {
    // Singleton can not using clone
}
```

\_\_SLEEP:

```
try {
    $serialize = serialize(ModelSingleton::getInstance());
} catch (CSESingletonException $e) {
    // Singleton can not serialize
}
```

\_\_WAKEUP:

```
try {
    ...
} catch (CSESingletonException $e) {
    // Singleton can not deserialize
}
```

Testing &amp; Code Coverage
---------------------------

[](#testing--code-coverage)

PHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.

General PHPUnit documentation can be found at .

To run the PHPUnit unit tests, execute:

```
phpunit PATH/TO/PROJECT/tests/
```

If you want code coverage reports, use the following:

```
phpunit --coverage-html ./report PATH/TO/PROJECT/tests/
```

Used PHPUnit default config:

```
phpunit --configuration PATH/TO/PROJECT/phpunit.xml
```

Donating
--------

[](#donating)

You can support this project [here](https://www.paypal.me/cseliseev/10usd). You can also help out by contributing to the project, or reporting bugs. Even voicing your suggestions for features is great. Anything to help is much appreciated.

License
-------

[](#license)

The 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.

---

> GitHub [@cs-eliseev](https://github.com/cs-eliseev)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2559d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3b9e49d0ce3fd71c8eb31b7c14e48373dbb415a9d16950ce52d23bf89b2ae26?d=identicon)[ak\_eliseev](/maintainers/ak_eliseev)

---

Top Contributors

[![cs-eliseev](https://avatars.githubusercontent.com/u/24221291?v=4)](https://github.com/cs-eliseev "cs-eliseev (28 commits)")

---

Tags

collectioncollectionscseframeworkhelperhelperslibrarypatternphpsingletontooltoolsutilitiesutilityutilsframeworkhelperutilityhelperslibrarytoolcollectioncollectionstoolsutilspatternutilitiessingletoncse

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cse-base-singleton/health.svg)

```
[![Health](https://phpackages.com/badges/cse-base-singleton/health.svg)](https://phpackages.com/packages/cse-base-singleton)
```

###  Alternatives

[cse/helpers-session

The helpers allows you to easily manage session data. START, SET, GET DELETE, HAS method session - all this is available in this library.

102.6k3](/packages/cse-helpers-session)[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8321.5M36](/packages/jbzoo-utils)[dragon-code/support

Support package is a collection of helpers and tools for any project.

238.7M101](/packages/dragon-code-support)

PHPackages © 2026

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