Skip to content

Commit

Permalink
Merge pull request #4 from iumio/1.0
Browse files Browse the repository at this point in the history
1.0
  • Loading branch information
danyRafina committed Jun 22, 2018
2 parents 04ffcb7 + 84c181b commit f962d44
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 74 deletions.
80 changes: 30 additions & 50 deletions Core/Base/Http/HttpSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
* file that was distributed with this source code.
*/

namespace iumioFramework\Core\Base\Http\Session;
namespace iumioFramework\Core\Base\Http;

use iumioFramework\Core\Base\Http\SessionBagRequest;
use iumioFramework\Core\Base\Http\SessionInterfaceRequest;
use iumioFramework\Core\Exception\Server\Server500;
use iumioFramework\Core\Requirement\Patterns\Singleton\SingletonClassicPattern;

/**
* HttpSession class.
Expand All @@ -25,33 +24,34 @@
* @licence MIT License
* @link https://framework.iumio.com
*/
class HttpSession implements SessionInterfaceRequest
class HttpSession extends SingletonClassicPattern implements SessionInterfaceRequest
{
protected $session;
/**
* @return mixed
*/
protected $session = null;


/**
* HttpSession constructor.
* @throws
*/
public function __construct()
{
//session_start();
$this->start();
}

public function start()
{
$this->session = $_SESSION;
if (!$this->isStarted() && null === $this->session) {
$_SESSION = [];
$this->session = $_SESSION;
}
}

/**
* @return mixed
*/
public function getId()
{
// TODO: Implement getId() method.
return (session_id());
}

/**
Expand All @@ -60,15 +60,15 @@ public function getId()
*/
public function setId($id)
{
// TODO: Implement setId() method.
return (session_id($id));
}

/**
* @return mixed
*/
public function getName()
{
// TODO: Implement getName() method.
return (session_name());
}

/**
Expand All @@ -77,7 +77,7 @@ public function getName()
*/
public function setName($name)
{
// TODO: Implement setName() method.
return (session_name($name));
}

/**
Expand All @@ -104,7 +104,8 @@ public function migrate($destroy = false, $lifetime = null)
*/
public function save()
{
// TODO: Implement save() method.
$_SESSION = array_merge($this->session, $_SESSION);
return (0 === count(array_diff($this->session, $_SESSION)))? true : false;
}

/**
Expand All @@ -113,7 +114,7 @@ public function save()
*/
public function has($name)
{
// TODO: Implement has() method.
return ((isset($this->session[$name]) && null != $this->session[$name])? true : false);
}

/**
Expand All @@ -123,7 +124,7 @@ public function has($name)
*/
public function get($name, $default = null)
{
return (isset($this->session[$name])? $this->session[$name] : null);
return ((isset($this->session[$name]) && null != $this->session[$name])? $this->session[$name] : null);
}

/**
Expand All @@ -135,9 +136,8 @@ public function get($name, $default = null)
public function set($name, $value)
{
if (is_string($name)) {
$_SESSION[$name] = $value;
$this->start();
return (true);
$this->session[$name] = $value;
return ((isset($this->session[$name]) && null != $this->session[$name])? true : false);
} else {
throw new Server500(new \ArrayObject(array("explain" =>
"Session Error : Your session name is not a string value", "solution" =>
Expand Down Expand Up @@ -185,40 +185,20 @@ public function remove($name)
*/
public function clear()
{
return(session_destroy());
if ($this->isStarted()) {
return (session_destroy());
}
return (false);
}

/**
* @return mixed
/** Check if session is started
* @return bool
*/
public function isStarted()
{
// TODO: Implement isStarted() method.
}

/**
* @param SessionBagRequest $bag
* @return mixed
*/
public function registerBag(SessionBagRequest $bag)
{
// TODO: Implement registerBag() method.
}

/**
* @param string $name
* @return mixed
*/
public function getBag($name)
{
// TODO: Implement getBag() method.
}

/**
* @return mixed
*/
public function getMetaBagRequest()
{
// TODO: Implement getMetaBagRequest() method.
if ('cli' !== php_sapi_name()) {
return ((PHP_SESSION_ACTIVE === session_status()) ? true : false);
}
return (false);
}
}
22 changes: 0 additions & 22 deletions Core/Base/Http/SessionInterfaceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,4 @@ public function clear();
*/
public function isStarted();

/**
* Registers a SessionBagRequest with the session.
*
* @param SessionBagRequest $bag
*/
public function registerBag(SessionBagRequest $bag);

/**
* Gets a bag instance by name.
*
* @param string $name
*
* @return SessionBagRequest
*/
public function getBag($name);

/**
* Gets session meta.
*
* @return MetaBagRequest
*/
public function getMetaBagRequest();
}
4 changes: 2 additions & 2 deletions Core/Requirement/FrameworkCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ abstract class FrameworkCore extends GlobalCoreService
protected $environment;
private static $runtime_parameters = null;

public const CORE_VERSION = '1.0.0';
public const CORE_VERSION = '1.0.1';
public const CORE_NAME = 'SUN';
public const CORE_STAGE = 'STS';
public const CORE_BUILD = 201800;
public const CORE_BUILD = 201801;
protected static $edition = array();

/**
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"role": "iumio Framework Co-Architect / iumio Co-Founder"
}
],
"autoload-dev": {
"psr-4": {
"iumioFramework\\Tests\\": "tests/"
}
},
"autoload": {
"psr-4": {
"iumioFramework\\": "",
Expand Down
40 changes: 40 additions & 0 deletions tests/HttpSessionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
*
* * This is an iumio Framework component
* *
* * (c) RAFINA DANY <[email protected]>
* *
* * iumio Framework, an iumio component [https://iumio.com]
* *
* * To get more information about licence, please check the licence file
*
*/


namespace iumioFramework\Tests;

use iumioFramework\Core\Base\Http\HttpSession;
use PHPUnit\Framework\TestCase;

/**
* Class ServerTest
* @package iumioFramework\Tests
*/
class HttpSessionTest extends TestCase
{
/**
* Test create an instance of HttpSession
* @throws \Exception
*/
public function testCreateInstance()
{
$instance = HttpSession::getInstance();
$instance->set("test", "value1");
$instance->save();
$this->assertInstanceOf("iumioFramework\Core\Base\Http\HttpSession", $instance);
$this->assertTrue(isset($_SESSION["test"]));
$this->assertEquals($_SESSION["test"], "value1");
}
}

0 comments on commit f962d44

Please sign in to comment.