for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of dimtrovich/cart".
*
* (c) 2024 Dimitri Sitchet Tomkeu <[email protected]>
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Dimtrovich\Cart\Handlers;
use Dimtrovich\Cart\Contracts\StoreManager;
class Session extends BaseHandler implements StoreManager
{
* {@inheritDoc}
public function init(string $cartId, array $options = []): bool
if (session_status() === PHP_SESSION_DISABLED) {
return false;
}
if (session_status() === PHP_SESSION_NONE) {
session_start();
return parent::init($cartId, $options);
public function has(): bool
return isset($_SESSION[$this->key()]);
public function read(): array
return $_SESSION[$this->key()] ?? [];
public function remove(): void
unset($_SESSION[$this->key()]);
protected function write(array $value): void
$_SESSION[$this->key()] = $value;