diff --git a/README.md b/README.md index 340f34d..9bfdd1c 100755 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ ----- # Singleton | [API](https://github.com/Jagepard/PhpDesignPatterns-Singleton/blob/master/docs.md "Documentation API") -```php run``` Запустить исполнение шаблона в терминале - -Одиночка +```php run``` execute in terminal ![Singleton](https://github.com/Jagepard/PhpDesignPatterns-Singleton/blob/master/UML.png) diff --git a/docs.md b/docs.md index 9f7d841..5531fa9 100644 --- a/docs.md +++ b/docs.md @@ -6,13 +6,11 @@ ### Class: \AntiPatterns\Singleton\Singleton -> Class Singleton - | Visibility | Function | |:-----------|:---------| | public | __clone() : void | -| public | __construct() : void | +| public | __construct() : void
SingletonTrait constructor. | | public | __sleep() : void | | public | __wakeup() : void | -| public static | getInstance() : mixed | +| public static | getInstance() : \AntiPatterns\Singleton\self | diff --git a/src/Singleton.php b/src/Singleton.php index fd44da1..2c79a4e 100644 --- a/src/Singleton.php +++ b/src/Singleton.php @@ -1,15 +1,56 @@ - * @license https://mit-license.org/ MIT + * @author : Jagepard + * @license https://mit-license.org/ MIT */ namespace AntiPatterns\Singleton; final class Singleton { - use SingletonTrait; + /** + * @var self + */ + private static $instance; + + /** + * @return self + */ + public static function getInstance(): self + { + if (!self::$instance instanceof self) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * SingletonTrait constructor. + */ + public function __construct() + { + } + + /** + * @codeCoverageIgnore + */ + public function __sleep() + { + } + + /** + * @codeCoverageIgnore + */ + public function __wakeup() + { + } + + /** + * @codeCoverageIgnore + */ + public function __clone() + { + } } diff --git a/src/SingletonTrait.php b/src/SingletonTrait.php deleted file mode 100644 index 5c53172..0000000 --- a/src/SingletonTrait.php +++ /dev/null @@ -1,58 +0,0 @@ - - * @license https://mit-license.org/ MIT - */ - -namespace AntiPatterns\Singleton; - -trait SingletonTrait -{ - /** - * @var self - */ - private static $instance; - - /** - * @return self - */ - public static function getInstance(): self - { - if (!self::$instance instanceof self) { - self::$instance = new self(); - } - - return self::$instance; - } - - /** - * SingletonTrait constructor. - */ - public function __construct() - { - } - - /** - * @codeCoverageIgnore - */ - public function __sleep() - { - } - - /** - * @codeCoverageIgnore - */ - public function __wakeup() - { - } - - /** - * @codeCoverageIgnore - */ - public function __clone() - { - } -} diff --git a/tests/SingletonTest.php b/tests/SingletonTest.php index 0cc3931..957a69c 100755 --- a/tests/SingletonTest.php +++ b/tests/SingletonTest.php @@ -1,10 +1,8 @@ - * @license https://mit-license.org/ MIT + * @author : Jagepard + * @license https://mit-license.org/ MIT */ namespace AntiPatterns\Singleton\Tests;