for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Phossa Project
*
* PHP version 5.4
* @category Library
* @package Phossa2\Shared
* @copyright Copyright (c) 2016 phossa.com
* @license http://mit-license.org/ MIT License
* @link http://www.phossa.com/
*/
/*# declare(strict_types=1); */
namespace Phossa2\Shared\Singleton;
use Phossa2\Shared\Exception\LogicException;
* SingletonTrait
* @author Hong Zhang <[email protected]>
* @see SingletonInterface
* @version 2.0.28
* @since 2.0.28 added
trait SingletonTrait
{
* Singletons' pool
* Use array here to make Singleton class INHERITABLE!
* @var SingletonInstance[]
* @access private
* @static
private static $singletons = [];
* {@inheritDoc}
public static function getInstance()/*# : SingletonInterface */
$class = get_called_class();
if (!isset(self::$singletons[$class])) {
self::$singletons[$class] = new static();
}
return self::$singletons[$class];
* no instantiation from outside
* @return void
@return
Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.
Please refer to the PHP core documentation on constructors.
* @access protected
* @final
protected function __construct()
* prevent from being cloned.
* @access public
final public function __clone()
throw new LogicException('SINGLETON CAN NOT BE CLONED');
* prevent from being unserialized.
final public function __wakeup()
throw new LogicException('SINGLETON CAN NOT BE WAKEUP');
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.