-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
class registry added using Singleton Pattern
- Loading branch information
Daniel Golub
committed
Nov 28, 2014
1 parent
eb662fd
commit fc345ca
Showing
11 changed files
with
138 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
"enabled" => true, | ||
"default" => "en" | ||
), | ||
"api" => "disabled" | ||
"api" => false, | ||
); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/* | ||
* Codengine | ||
* FilePath: /app/registy.php | ||
*/ | ||
|
||
class Registry implements ArrayAccess | ||
{ | ||
// basic setup | ||
private static $instance = null; | ||
private $registry = array(); | ||
|
||
public static function getInstance() { | ||
if(self::$instance === null) { | ||
self::$instance = new Registry(); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
private function __construct() {} | ||
private function __clone() {} | ||
|
||
// registry functions, set and get | ||
public function set($key, $value) { | ||
if (isset($this->registry[$key])) { | ||
throw new Exception("There is already an entry for key " . $key); | ||
} | ||
|
||
$this->registry[$key] = $value; | ||
} | ||
|
||
public function get($key) { | ||
if (!isset($this->registry[$key])) { | ||
throw new Exception("There is no entry for key " . $key); | ||
} | ||
|
||
return $this->registry[$key]; | ||
} | ||
|
||
|
||
// array access | ||
|
||
public function offsetExists( $key ) { | ||
return isset($this->registry[$key]); | ||
} | ||
|
||
public function offsetGet ( $key ) { | ||
if(isset($this->registry[$key])) { | ||
return $this->registry[$key]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function offsetSet ( $key , $value ) { | ||
return $this->registry[$key] = $value; | ||
} | ||
|
||
public function offsetUnset ( $key ) { | ||
unset($this->registry[$key]); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters