Skip to content

Commit

Permalink
Add "Contract" directory, deprecate "SessionInterface"
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Mar 21, 2024
1 parent b94f62f commit 70cf221
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 42 deletions.
46 changes: 46 additions & 0 deletions src/Contract/Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Rougin\Weasley\Contract;

/**
* Session Interface
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
*/
interface Session
{
/**
* Returns the value from the specified key.
*
* @param string $key
* @return boolean
*/
public function delete($key);

/**
* Returns the value from the specified key.
*
* @param string $key
* @param mixed|null $default
* @return mixed
*/
public function get($key, $default = null);

/**
* Updates the current session ID with a newly generated one.
*
* @param boolean $delete
* @return boolean
*/
public function regenerate($delete = false);

/**
* Sets the value to the specified key.
*
* @param string $key
* @param mixed $value
* @return self
*/
public function set($key, $value);
}
4 changes: 2 additions & 2 deletions src/Packages/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
class Session implements IntegrationInterface
{
const HANDLER = 'Rougin\Weasley\Session\SessionHandlerInterface';
const HANDLER = 'SessionHandlerInterface';

const SESSION = 'Rougin\Weasley\Session\SessionInterface';
const SESSION = 'Rougin\Weasley\Contract\Session';

/**
* Defines the specified integration.
Expand Down
4 changes: 3 additions & 1 deletion src/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace Rougin\Weasley\Session;

use Rougin\Weasley\Contract\Session as Contract;

/**
* Session
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
*/
class Session implements SessionInterface
class Session implements Contract
{
/**
* @var array<string, mixed>
Expand Down
39 changes: 5 additions & 34 deletions src/Session/SessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,16 @@

namespace Rougin\Weasley\Session;

use Rougin\Weasley\Contract\Session;

/**
* @deprecated since ~0.7, use "Contract/Session instead".
*
* Session Interface
*
* @package Weasley
* @author Rougin Gutib <rougingutib@gmail.com>
*/
interface SessionInterface
interface SessionInterface extends Session
{
/**
* Returns the value from the specified key.
*
* @param string $key
* @return boolean
*/
public function delete($key);

/**
* Returns the value from the specified key.
*
* @param string $key
* @param mixed|null $default
* @return mixed
*/
public function get($key, $default = null);

/**
* Updates the current session ID with a newly generated one.
*
* @param boolean $delete
* @return boolean
*/
public function regenerate($delete = false);

/**
* Sets the value to the specified key.
*
* @param string $key
* @param mixed $value
* @return self
*/
public function set($key, $value);
}
9 changes: 5 additions & 4 deletions tests/Session/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
abstract class AbstractTestCase extends \Rougin\Weasley\Testcase
{
const SESSION = 'Rougin\Weasley\Session\SessionInterface';
const SESSION = 'Rougin\Weasley\Contract\Session';

/**
* @var \Rougin\Slytherin\Integration\Configuration
Expand All @@ -31,11 +31,12 @@ abstract class AbstractTestCase extends \Rougin\Weasley\Testcase
*/
protected function doSetUp()
{
$message = 'SessionHandlerInterface is not yet installed.';

$interface = 'SessionHandlerInterface';

interface_exists($interface) || $this->markTestSkipped($message);
if (! interface_exists($interface))
{
$this->markTestSkipped('SessionHandlerInterface is not yet installed.');
}

$path = __DIR__ . '/../Fixture/Storage/Sessions';

Expand Down
2 changes: 1 addition & 1 deletion tests/Session/SessionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testDefineMethod()
{
$container = $this->integration->define(new Container, $this->config);

/** @var \Rougin\Weasley\Session\SessionInterface */
/** @var \Rougin\Weasley\Contract\Session */
$session = $container->get(self::SESSION);

$expected = 'Ron Weasley';
Expand Down

0 comments on commit 70cf221

Please sign in to comment.