Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webbasics
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webbasics
Commits
522e75f0
Commit
522e75f0
authored
Oct 06, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Singleton interface
parent
6e91a09d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
1 deletion
+22
-1
base.php
base.php
+17
-0
session.php
session.php
+1
-1
tests/SingletonTestCase.php
tests/SingletonTestCase.php
+4
-0
No files found.
base.php
View file @
522e75f0
...
@@ -103,6 +103,23 @@ class FileNotFoundError extends \Exception {
...
@@ -103,6 +103,23 @@ class FileNotFoundError extends \Exception {
}
}
}
}
/**
* The Singleton interface mshould be implemented by classes that allow only
* one instance.
*
* The instance must be saved statically after the constructor has been
* called. When getInstance() is called another time, this instance is
* returned.
*/
interface
Singleton
{
/**
* Create a new singleton instance, and save it in the static $instance variable.
*
* @return object An existing instance from the $instance variable, or a new instance.
*/
public
static
function
getInstance
();
}
/**
/**
* Format a string using parameters in an associative array.
* Format a string using parameters in an associative array.
*
*
...
...
session.php
View file @
522e75f0
...
@@ -10,7 +10,7 @@ namespace webbasics;
...
@@ -10,7 +10,7 @@ namespace webbasics;
require_once
'base.php'
;
require_once
'base.php'
;
class
Session
{
class
Session
implements
Singleton
{
private
static
$instance
;
private
static
$instance
;
static
function
getInstance
()
{
static
function
getInstance
()
{
...
...
tests/SingletonTestCase.php
View file @
522e75f0
...
@@ -9,6 +9,10 @@ abstract class SingletonTestCase extends PHPUnit_Framework_TestCase {
...
@@ -9,6 +9,10 @@ abstract class SingletonTestCase extends PHPUnit_Framework_TestCase {
$this
->
rclass
=
new
ReflectionClass
(
$this
->
getClassName
());
$this
->
rclass
=
new
ReflectionClass
(
$this
->
getClassName
());
}
}
function
testSingletonInterface
()
{
$this
->
assertTrue
(
$this
->
rclass
->
implementsInterface
(
'webbasics\Singleton'
));
}
function
testConstructorPrivateness
()
{
function
testConstructorPrivateness
()
{
$rmethod
=
new
ReflectionMethod
(
$this
->
getClassName
(),
'__construct'
);
$rmethod
=
new
ReflectionMethod
(
$this
->
getClassName
(),
'__construct'
);
$this
->
assertTrue
(
$rmethod
->
isPrivate
());
$this
->
assertTrue
(
$rmethod
->
isPrivate
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment