Skip to content

Instantly share code, notes, and snippets.

@DavertMik
Created February 28, 2012 20:04
Show Gist options
  • Save DavertMik/1934769 to your computer and use it in GitHub Desktop.
Save DavertMik/1934769 to your computer and use it in GitHub Desktop.
Global Object Access
<?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