You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
936 B
PHP
38 lines
936 B
PHP
<?php
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
/** @noinspection PhpIllegalPsrClassPathInspection */
|
|
|
|
use jrosset\Singleton\IRegistry;
|
|
use jrosset\Singleton\TRegistry;
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
class RegistryTest implements IRegistry {
|
|
use TRegistry;
|
|
|
|
private int $cpt;
|
|
|
|
private function __construct (int $cpt) {
|
|
$this->cpt = $cpt;
|
|
}
|
|
|
|
public function getCpt (): int {
|
|
return $this->cpt;
|
|
}
|
|
public function increment (): void {
|
|
$this->cpt++;
|
|
}
|
|
}
|
|
|
|
RegistryTest::addEntry('cpt_1', 0);
|
|
RegistryTest::addEntry('cpt_2', 5);
|
|
|
|
var_dump(RegistryTest::getInstance('cpt_1')->getCpt());
|
|
var_dump(RegistryTest::getInstance('cpt_2')->getCpt());
|
|
|
|
RegistryTest::getInstance('cpt_1')->increment();
|
|
RegistryTest::getInstance('cpt_2')->increment();
|
|
|
|
var_dump(RegistryTest::getInstance('cpt_1')->getCpt());
|
|
var_dump(RegistryTest::getInstance('cpt_2')->getCpt()); |