Created
February 28, 2012 20:04
-
-
Save DavertMik/1934769 to your computer and use it in GitHub Desktop.
Global Object Access
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
<?php | |
class Controller implements RequestAccess, ResponseAccess, SessionAccess { | |
function getRequest() | |
{ | |
Registry::get('request', $this); | |
} | |
function getResponse() | |
{ | |
Registry::get('response', $this); | |
} | |
function getSession() | |
{ | |
Registry::get('response', $this); | |
} | |
} | |
class Registry { | |
public static $objects = array(); | |
public static function get($obj, $context = null) | |
{ | |
// here we get an array of required interfaces | |
if (self::$config[$obj]['restrict_access']) { | |
$obj = self::$objects[$obj]; | |
foreach (self::$config[$obj]['restrict_access'] as $interface) { | |
if ($context instanceof $interface) return $obj; | |
} | |
throw new Exception('Access denied'); | |
} | |
return self::$objects[$obj]; | |
} | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment