Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public session #4888

Merged
merged 4 commits into from
Sep 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions lib/appframework/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ public function env($key) {
}


/**
* Shortcut for getting session variables
* @param string $key the key that will be taken from the $_SESSION array
* @return array the value in the $_SESSION element
*/
public function session($key) {
return $this->request->getSession($key);
}


/**
* Shortcut for getting cookie variables
* @param string $key the key that will be taken from the $_COOKIE array
Expand Down
51 changes: 16 additions & 35 deletions lib/appframework/http/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ class Request implements \ArrayAccess, \Countable, IRequest {

protected $items = array();
protected $allowedKeys = array(
'get',
'post',
'files',
'server',
'env',
'session',
'cookies',
'urlParams',
'params',
'parameters',
'get',
'post',
'files',
'server',
'env',
'cookies',
'urlParams',
'params',
'parameters',
'method'
);

Expand Down Expand Up @@ -156,7 +155,6 @@ public function __get($name) {
case 'files':
case 'server':
case 'env':
case 'session':
case 'cookies':
case 'parameters':
case 'params':
Expand Down Expand Up @@ -229,8 +227,7 @@ public function getHeader($name) {
* @param mixed $default If the key is not found, this value will be returned
* @return mixed the content of the array
*/
public function getParam($key, $default = null)
{
public function getParam($key, $default = null) {
return isset($this->parameters[$key])
? $this->parameters[$key]
: $default;
Expand All @@ -241,17 +238,15 @@ public function getParam($key, $default = null)
* (as GET or POST) or throuh the URL by the route
* @return array the array with all parameters
*/
public function getParams()
{
public function getParams() {
return $this->parameters;
}

/**
* Returns the method of the request
* @return string the method of the request (POST, GET, etc)
*/
public function getMethod()
{
public function getMethod() {
return $this->method;
}

Expand All @@ -260,8 +255,7 @@ public function getMethod()
* @param string $key the key that will be taken from the $_FILES array
* @return array the file in the $_FILES element
*/
public function getUploadedFile($key)
{
public function getUploadedFile($key) {
return isset($this->files[$key]) ? $this->files[$key] : null;
}

Expand All @@ -270,28 +264,16 @@ public function getUploadedFile($key)
* @param string $key the key that will be taken from the $_ENV array
* @return array the value in the $_ENV element
*/
public function getEnv($key)
{
public function getEnv($key) {
return isset($this->env[$key]) ? $this->env[$key] : null;
}

/**
* Shortcut for getting session variables
* @param string $key the key that will be taken from the $_SESSION array
* @return array the value in the $_SESSION element
*/
function getSession($key)
{
return isset($this->session[$key]) ? $this->session[$key] : null;
}

/**
* Shortcut for getting cookie variables
* @param string $key the key that will be taken from the $_COOKIE array
* @return array the value in the $_COOKIE element
*/
function getCookie($key)
{
function getCookie($key) {
return isset($this->cookies[$key]) ? $this->cookies[$key] : null;
}

Expand All @@ -304,8 +286,7 @@ function getCookie($key)
*
* @throws \LogicException
*/
function getContent($asResource = false)
{
function getContent($asResource = false) {
return null;
// if (false === $this->content || (true === $asResource && null !== $this->content)) {
// throw new \LogicException('getContent() can only be called once when using the resource return type.');
Expand Down
9 changes: 0 additions & 9 deletions lib/public/irequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ public function getUploadedFile($key);
public function getEnv($key);


/**
* Shortcut for getting session variables
*
* @param string $key the key that will be taken from the $_SESSION array
* @return array the value in the $_SESSION element
*/
function getSession($key);


/**
* Shortcut for getting cookie variables
*
Expand Down
7 changes: 7 additions & 0 deletions lib/public/iservercontainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ function getPreviewManager();
*/
function getRootFolder();

/**
* Returns the current session
*
* @return \OCP\ISession
*/
function getSession();

}
56 changes: 56 additions & 0 deletions lib/public/isession.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright (c) 2013 Thomas Tanghus ([email protected])
* @author Thomas Tanghus
* @author Robin Appelman
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/

namespace OCP;

/**
* Interface ISession
*
* wrap PHP's internal session handling into the ISession interface
*/
interface ISession {

/**
* Set a value in the session
*
* @param string $key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are quite self explaining - But I still like to have a little sentence here describing what the methods do.
We will generate the API documentation from the public interfaces and classes apt.owncloud.org

THX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I still like to have a little sentence here describing what the methods do.

Added basic docs @DeepDiver1975

* @param mixed $value
*/
public function set($key, $value);

/**
* Get a value from the session
*
* @param string $key
* @return mixed should return null if $key does not exist
*/
public function get($key);

/**
* Check if a named key exists in the session
*
* @param string $key
* @return bool
*/
public function exists($key);

/**
* Remove a $key/$value pair from the session
*
* @param string $key
*/
public function remove($key);

/**
* Reset and recreate the session
*/
public function clear();

}
11 changes: 10 additions & 1 deletion lib/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function __construct() {
'files' => $_FILES,
'server' => $_SERVER,
'env' => $_ENV,
'session' => $_SESSION,
'cookies' => $_COOKIE,
'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
? $_SERVER['REQUEST_METHOD']
Expand Down Expand Up @@ -97,4 +96,14 @@ function getRootFolder()
{
return $this->query('RootFolder');
}

/**
* Returns the current session
*
* @return \OCP\ISession
*/
function getSession() {
return \OC::$session;
}

}
2 changes: 1 addition & 1 deletion lib/session/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OC\Session;

abstract class Session implements \ArrayAccess {
abstract class Session implements \ArrayAccess, \OCP\ISession {
/**
* $name serves as a namespace for the session keys
*
Expand Down
5 changes: 0 additions & 5 deletions tests/lib/appframework/controller/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,4 @@ public function testGetEnvVariable(){
$this->assertEquals('daheim', $this->controller->env('PATH'));
}

public function testGetSessionVariable(){
$this->assertEquals('kein', $this->controller->session('sezession'));
}


}