承接 cse/base-singleton 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cse/base-singleton

Composer 安装命令:

composer require cse/base-singleton

包简介

A Singleton Design Pattern which allow easy used singleton class.

README 文档

README

English | Русский

SINGLETON CSE BASE

Travis (.org) Codecov Scrutinizer code quality

Packagist Minimum PHP Version Packagist GitHub repo size

A Singleton Design Pattern which allow easy used singleton class.

Project repository: https://github.com/cs-eliseev/base-singleton

DEMO

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

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:

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

Install

You can find the most recent version of this project here.

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

Clone this repository locally:

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

Download

Download the latest release here.

Usage

View test model: ModelSingleton.php

See 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 & 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 https://phpunit.de/documentation.html.

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

You can support this project here. 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

The SINGLETON CSE BASE is open-source PHP library licensed under the MIT license. Please see License File for more information.

GitHub @cs-eliseev

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固