/** * Retrieves reference on usable variable space. * * @note Using global session space shared by several applications requires * external setup to provide access on same PHP session. * * @param int $scope one of the SCOPE_* constants * @param string|bool $parameter additional selector used according to $scope * @return array-ref */ public final function &access($scope, $parameter = null) { if (!class_exists('\\de\\toxa\\txf\\txf', false)) { throw new \RuntimeException('missing TXF context for accessing managed data'); } // ensure session has been restored from serialization $this->makeUsable(); /* * process selected scope */ // validate provided parameter if ($scope & self::SCOPE_CLASS) { if (!($parameter = data::isNonEmptyString($parameter))) { throw new \InvalidArgumentException('invalid/missing class selector'); } } // prepare subset of session data according to scope and parameter and // return reference on it for read/write access switch ($scope) { case self::SCOPE_SCRIPT: self::makeArray($this->usable['applications']); self::makeArray($this->usable['applications'][TXF_APPLICATION]); self::makeArray($this->usable['applications'][TXF_APPLICATION]['scripts']); self::makeArray($this->usable['applications'][TXF_APPLICATION]['scripts'][TXF_SCRIPT_PATH]); return $this->usable['applications'][TXF_APPLICATION]['scripts'][TXF_SCRIPT_PATH]; case self::SCOPE_CLASS + self::SCOPE_SCRIPT: self::makeArray($this->usable['applications']); self::makeArray($this->usable['applications'][TXF_APPLICATION]); self::makeArray($this->usable['applications'][TXF_APPLICATION]['scripts']); self::makeArray($this->usable['applications'][TXF_APPLICATION]['scripts'][TXF_SCRIPT_PATH]); self::makeArray($this->usable['applications'][TXF_APPLICATION]['scripts'][TXF_SCRIPT_PATH]['classes']); self::makeArray($this->usable['applications'][TXF_APPLICATION]['scripts'][TXF_SCRIPT_PATH]['classes'][$parameter]); return $this->usable['applications'][TXF_APPLICATION]['scripts'][TXF_SCRIPT_PATH]['classes'][$parameter]; case self::SCOPE_CLASS + self::SCOPE_APPLICATION: self::makeArray($this->usable['applications']); self::makeArray($this->usable['applications'][TXF_APPLICATION]); self::makeArray($this->usable['applications'][TXF_APPLICATION]['classes']); self::makeArray($this->usable['applications'][TXF_APPLICATION]['classes'][$parameter]); return $this->usable['applications'][TXF_APPLICATION]['classes'][$parameter]; case self::SCOPE_CLASS + self::SCOPE_GLOBAL: self::makeArray($this->usable['classes']); self::makeArray($this->usable['classes'][$parameter]); return $this->usable['classes'][$parameter]; case self::SCOPE_APPLICATION: self::makeArray($this->usable['applications']); self::makeArray($this->usable['applications'][TXF_APPLICATION]); self::makeArray($this->usable['applications'][TXF_APPLICATION]['shared']); return $this->usable['applications'][TXF_APPLICATION]['shared']; case self::SCOPE_GLOBAL: self::makeArray($this->usable['shared']); return $this->usable['shared']; default: throw new \InvalidArgumentException('invalid session scope'); } }
/** * Adjusts value of selected variable. * * If selected variable isn't found in variable space, it's created * implicitly. * * @param string $name name for variable to change * @param mixed $value value to assign * @throws \InvalidArgumentException * @return mixed adjusted value for chaining assignments */ public function update($name, $value = null) { if (($name = data::isNonEmptyString($name)) === false) { throw new \InvalidArgumentException('invalid variable name'); } if (\func_num_args() == 1) { unset($this->__heap[$name]); } else { $this->__heap[$name] = $value; } return $value; }