From 9598fb9bfc2b581ea797674e7ccdfe61e95baea8 Mon Sep 17 00:00:00 2001 From: therselman Date: Sat, 26 Aug 2017 12:10:24 +0200 Subject: [PATCH] --- src/Container.php | 1 + src/Request.php | 7 ++- src/User.php | 131 ---------------------------------------------- 3 files changed, 6 insertions(+), 133 deletions(-) delete mode 100644 src/User.php diff --git a/src/Container.php b/src/Container.php index 7738b90..7d13d43 100644 --- a/src/Container.php +++ b/src/Container.php @@ -43,6 +43,7 @@ class Container implements ArrayAccess { if (static::$instance) throw new \Exception('Cannot create another Container instance!'); + static::$instance = $this; $this->bindings = $c; diff --git a/src/Request.php b/src/Request.php index f0c274b..26cc15e 100644 --- a/src/Request.php +++ b/src/Request.php @@ -316,11 +316,14 @@ class Request // private function _get_args_from_params(array $params) { +/* $byType = [ 'twister\container' => &$this->container, 'twister\db' => &$this->db, - 'twister\user' => &$this->container->user, + // 'twister\user' => &$this->container->user, 'twister\request' => &$this ]; +*/ + $byType = $this->requestRouteParams; $args = []; foreach ($params as $param) { @@ -616,7 +619,7 @@ class Request if (is_array($location)) { - throw new \Exception('Request section not implemented/RE-written yet!'); + throw new \Exception('Request section not implemented or re-written yet!'); if (isset($location['scheme']) && ! isset($location['host'])) $location['host'] = _::request('host'); diff --git a/src/User.php b/src/User.php deleted file mode 100644 index d8576ca..0000000 --- a/src/User.php +++ /dev/null @@ -1,131 +0,0 @@ -properties =& $properties; - } - - - function __construct(Container &$c, $id = 0) - { - $this->container = $c; - $this->db = $c->db; - - $this->id = $id; - - if ($id) - { - $this->load_permissions(); - } - } - - /** - * Get member by id/index - * - * @param string|int $key - * @return mixed - */ - public function __get($key) - { - switch ($key) - { - case 'managers': return $this->_properties[$key] = new Managers::factory(); - - } - return $this->_properties[$key]; - } - - /** - * Set member by id/index - * - * @param string|int $key - * @param mixed $value - * @return void - */ - public function __set($key, $value) - { - $this->_properties[$key] = $value; - } - - public function worlds($key, $value) - { - if ( ! isset($this->_properties['worlds'])) - { - $sql = 'SELECT * FROM user_worlds WHERE user_id = ' . $this->id; - $this->db->get_array($sql); - } - $this->_properties[$key] = $value; - } - public function getWorlds($key, $value) - { - $this->_properties[$key] = $value; - } - - public function isManager($id) - { - return $this->getManagers() - } - public function getManagers() - { - if ( ! isset($this->_properties['managers'])) - { - $sql = 'SELECT * FROM user_managers WHERE user_id = ' . $this->id; - $this->_properties['managers'] = $this->db->get_array($sql); - } - return $this->_properties['managers']; - } - - function __isset($key) - { - return isset($this->_properties[$key]); - } - function __unset($key) - { - unset($this->_properties[$key]); - } - - private function load_permissions() - { - $this->_permissions = $this->db->get_array( 'SELECT SQL_CACHE ' . // cached because these tables are less frequenty updated! - 'g.alias as g_alias,' . - 'p.alias as p_alias,' . - 'acl.object_id' . - ' FROM acl' . - ' JOIN acl_permissions p ON p.id = acl.permission_id' . - ' JOIN acl_groups g ON g.id = p.group_id' . - ' WHERE acl.user_id = ' . $this->id . - ' AND acl.disabled = 0', - ['g_alias', 'p_alias', 'object_id'], ['object_id']); - } - function permission($group_alias, $permission_alias, $query_data = null, $object = 0) - { - if (!is_array($object)) - { - if (isset($this->_permissions[$group_alias][$permission_alias][$object])) return true; - } - else // used when we want to specify default zero OR a value ... eg. array(0, 13); - foreach ($object as $obj) if (isset($this->_permissions[$group_alias][$permission_alias][$obj])) return true; - if (isset($this->_permissions['administrators']['super'])) return true; // super-admin bypass! - if (isset($query_data)) - { - if (is_string($query_data)) $query_data = ['next' => $query_data]; - $query_data['warning'] = 'Protected Area! Login with relevant permissions required!'; // <== TODO: Translate this!!! Or send a constant! - $this->container->request->redirect('/login?' . http_build_query($query_data)); - } - return false; - } - function permissions($group_alias, $permission_alias) - { - return isset($this->_permissions[$group_alias][$permission_alias]) ? array_keys($this->_permissions[$group_alias][$permission_alias]) : array(); - } -}