Skip to content

Commit

Permalink
Merge pull request #8 from iumio/1.0
Browse files Browse the repository at this point in the history
Create the 1.0.2 SUN STS
  • Loading branch information
danyRafina committed Jul 23, 2018
2 parents 8cef6e9 + 1489d0b commit 5c11426
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 83 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: php
php:
- '7.2'
before_script:
- mkdir elements && mkdir elements/cache && mkdir elements/cache/dev && mkdir elements/cache/prod
- composer install
script: phpunit --configuration phpunit.xml
File renamed without changes.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@ All notable changes to this project will be documented in this file.
<img src="https://framework.iumio.com/images/iumio-framework-horizontal.png" width="350">
</a></p>

iumio Framework, an iumio component[https://www.iumio.com]
[iumio Framework, an iumio component]
========================================================

@ Let's create more simply

## [STABLE RELEASE]

## [1.0.2] STS - 2018-07-23
- Fixed :
- HttpSession : Causes by Phpunit PrinterClass
- Added :
- Constant IUMIO_ROOT for root project directory path
- Session file on cache directory


## [1.0.1] STS - 2018-07-01
- Fixed :
- HttpSession


## [1.0.0] STS - 2018-06-01
- Fixes :
- HttpSession

[STABLE RELEASE]: https://github.com/iumio-team/iumio-framework/
[1.0.0]: https://github.com/iumio-team/iumio-framework/releases/tag/v1.0.0
[1.0.1]: https://github.com/iumio-team/iumio-framework/releases/tag/v1.0.1
[1.0.2]: https://github.com/iumio-team/iumio-framework/releases/tag/v1.0.2
[iumio Framework, an iumio component]: https://www.iumio.com
164 changes: 120 additions & 44 deletions Core/Base/Http/HttpSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use iumioFramework\Core\Exception\Server\Server500;
use iumioFramework\Core\Requirement\Patterns\Singleton\SingletonClassicPattern;
use iumioFramework\Core\Server\Server;

/**
* HttpSession class.
Expand All @@ -26,8 +27,20 @@
*/
class HttpSession extends SingletonClassicPattern implements SessionInterfaceRequest
{
/**
* @var null|array The session oject : Initialized to null firstly
*/
protected $session = null;

/**
* @var null|string The session identifier : Initialized to null firstly
*/
private $id = null;

/**
* @var null|string The session name : Initialized to null firstly
*/
private $name = null;

/**
* HttpSession constructor.
Expand All @@ -38,28 +51,35 @@ public function __construct()
$this->start();
}

/** Start the session
* @return void
* @throws Server500
* @throws \Exception
*/
public function start()
{
if (!$this->isStarted() && null === $this->session) {
$_SESSION = [];
$this->initSessionConfig();
session_start();
$this->session = $_SESSION;
}
}

/**
* @return mixed
/** Get the session id
* @return mixed The session id
*/
public function getId()
{
return (session_id());
return ($this->id);
}

/**
* @param string $id
* @return mixed
/** Set a new session id
* @param string $id The session id
* @return mixed Return the session id
*/
public function setId($id)
{
$this->id = $id;
return (session_id($id));
}

Expand All @@ -68,7 +88,7 @@ public function setId($id)
*/
public function getName()
{
return (session_name());
return ($this->name);
}

/**
Expand All @@ -77,6 +97,7 @@ public function getName()
*/
public function setName($name)
{
$this->name = $name;
return (session_name($name));
}

Expand All @@ -100,37 +121,41 @@ public function migrate($destroy = false, $lifetime = null)
}

/**
* @return mixed
* Save the modification about sessions items
* @return bool true if iumio session is the same as PHP SESSION, false for an error
* ($_SESSION & $this->session not the same)
*/
public function save()
public function save():bool
{
$_SESSION = array_merge($this->session, $_SESSION);
$_SESSION = $this->session;
return (0 === count(array_diff($this->session, $_SESSION)))? true : false;
}

/**
* @param string $name
* @return mixed
* Check if a session key exist
* @param string $name The session key
* @return bool If exist or not
*/
public function has($name)
public function has($name):bool
{
return ((isset($this->session[$name]) && null != $this->session[$name])? true : false);
}

/**
* @param string $name
/** Get a session key value
* @param string $name The session key
* @param mixed|null $default
* @return mixed
* @return mixed The result (if null : not result)
*/
public function get($name, $default = null)
{
return ((isset($this->session[$name]) && null != $this->session[$name])? $this->session[$name] : null);
}

/**
* @param string $name
* @param mixed $value
* @return bool
* Edit a session key
* @param string $name Key name
* @param mixed $value session item value
* @return bool If session exist or not
* @throws Server500
*/
public function set($name, $value)
Expand All @@ -146,59 +171,110 @@ public function set($name, $value)
}

/**
* @return mixed
* Return all session items
* @return null|array Null if session are not initialized or an array with all session item
*/
public function all()
public function all():?array
{
return ($this->session);
}

/**
* @param array $attributes
* @return mixed
/** Replace session items
* @param array $attributes Session item with key/value
* @return bool false if not session item has not edited or true if it has been edited
* @throws Server500
*/
public function replace(array $attributes)
public function replace(array $attributes):bool
{
// TODO: Implement replace() method.
$status = false;
foreach ($this->session as $one => $value) {
if (null !== $this->get($one)) {
$this->set($one, $value);
$status = true;
}
}
if (true === $status) {
$this->save();
}

return ($status);
}

/**
* @param string $name
/** Remove a session item
* @param string $name Item name
* @return bool
* @throws Server500
* @throws \Exception
*/
public function remove($name)
public function remove($name):bool
{
if (isset($_SESSION[$name])) {
unset($_SESSION[$name]);
$this->start();
if (isset($this->session[$name])) {
unset($this->session[$name]);
$this->save();
return (true);
} else {
throw new Server500(new \ArrayObject(array("explain" =>
"iumio Session Error : Your session name is not defined", "solution" =>
"Please check the session object with HttpSession::all instruction")));
"Session Error : The session name [$name] is not defined", "solution" =>
"Please check the session object with HttpSession::all instruction to remove".
" the correct session item")));
}
}

/**
* @return mixed
* Clear the session
* @return bool If session is clear properly or not
* @throws Server500
*/
public function clear()
public function clear():bool
{
if ($this->isStarted()) {
return (session_destroy());
if (true === $this->isStarted()) {
session_unset();
$this->setToDefault();
session_regenerate_id(true);
return (empty($_SESSION)? true : false);
}
return (false);
throw new Server500(new \ArrayObject(array("explain" => "Cannot clear the session when is not started",
"solution" => "Please start a session instance before clear it")));
}

/**
* Set all value to default
*/
private function setToDefault():void
{
$this->session = null;
$this->id = null;
$this->name = null;
}

/** Init the session configuration
* @throws Server500
* @throws \Exception
* @return void
*/
private function initSessionConfig():void
{
if (!defined("IUMIO_ENV")) {
throw new Server500(new \ArrayObject(array("explain" => "Framework Environment is not defined",
"solution" => "Please initialize the framework environment")));
}
if (false === Server::exist(IUMIO_ROOT."/elements/cache/".strtolower(IUMIO_ENV)."/sessions")) {
Server::create(IUMIO_ROOT."/elements/cache/".
strtolower(IUMIO_ENV)."/sessions", "directory");
}

$this->id = session_id();
$this->name = session_name();
session_save_path(IUMIO_ROOT.'/elements/cache/'.strtolower(IUMIO_ENV).'/sessions');
ini_set('session.gc_probability', 1);
}


/** Check if session is started
* @return bool
*/
public function isStarted()
{
if ('cli' !== php_sapi_name()) {
return ((PHP_SESSION_ACTIVE === session_status()) ? true : false);
}
return (false);
return ((PHP_SESSION_ACTIVE === session_status()) ? true : false);
}
}
1 change: 0 additions & 1 deletion Core/Base/Http/MetaBagRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* Adds metadata to the session.
*
* @author Fabien Potencier <[email protected]>
* @author Dany RAFINA <[email protected]>
* @category Framework
* @licence MIT License
* @link https://framework.iumio.com
Expand Down
30 changes: 0 additions & 30 deletions Core/Base/Http/SessionInterfaceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,6 @@ public function getName();
*/
public function setName($name);

/**
* Invalidates the current session.
*
* Clears all session attributes and flashes and regenerates the
* session and deletes the old session from persistence.
*
* @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
* will leave the system settings unchanged, 0 sets the cookie
* to expire with browser session. Time is in seconds, and is
* not a Unix timestamp.
*
* @return bool True if session invalidated, false if error
*/
public function invalidate($lifetime = null);

/**
* Migrates the current session to a new session id while maintaining all
* session attributes.
*
* @param bool $destroy Whether to delete the old session or leave it to garbage collection
* @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
* will leave the system settings unchanged, 0 sets the cookie
* to expire with browser session. Time is in seconds, and is
* not a Unix timestamp.
*
* @return bool True if session migrated, false if error
*/
public function migrate($destroy = false, $lifetime = null);

/**
* Force the session to be saved and closed.
*
Expand Down Expand Up @@ -158,5 +129,4 @@ public function clear();
* @return bool
*/
public function isStarted();

}
4 changes: 2 additions & 2 deletions Core/Masters/MasterCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use iumioFramework\Core\Requirement\FrameworkServices\GlobalCoreService;
use iumioFramework\Core\Base\Database\DatabaseAccess as IDA;
use iumioFramework\Core\Exception\Server\Server500;
use iumioFramework\Core\Base\Http\Session\HttpSession;
use iumioFramework\Core\Base\Http\HttpSession;
use iumioFramework\Core\Base\Json\JsonListener as JL;

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ final protected function get(string $component)
return (FrameworkCore::getRuntimeParameters())->query;
break;
case 'session':
return (new HttpSession());
return (HttpSession::getInstance());
break;
case 'service':
return (Services::getInstance());
Expand Down
1 change: 1 addition & 0 deletions Core/Requirement/Environment/FrameworkEnvironment.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function definer(string $env):int
$base = realpath(__DIR__ . "/../../../../../../")."/";

define('IUMIO_ENV', $env);
define('IUMIO_ROOT', $base);

$current = self::getProtocol()."://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$current_temp = substr($current, 0, strpos($current, self::getFileEnv($env)));
Expand Down
Loading

0 comments on commit 5c11426

Please sign in to comment.