forked from mradcliffe/SingletonPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.php
More file actions
31 lines (23 loc) · 708 Bytes
/
app.php
File metadata and controls
31 lines (23 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
* @file
* Singleton pattern example.
*/
require __DIR__ . '/vendor/autoload.php';
use ColumbusPHP\SingletonPattern\App;
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
// Get an instance of the application and set foo.
$app = App::getInstance();
$app->setThing('foo');
assert($app->getThing() === 'foo');
// bool(true)
// Assert that foo is set on the second instance.
$anotherApp = App::getInstance();
assert($anotherApp->getThing() === 'foo');
// bool(true)
// Assert that bar changes in the first instance when changed from the second instance.
$anotherApp->setThing('bar');
assert($app->getThing() === 'bar');
// bool(true)