Source of file SessionProgressStore.php
Size: 1,866 Bytes - Last Modified: 2021-12-24T06:40:50+00:00
/var/www/docs.ssmods.com/process/src/src/Model/Store/SessionProgressStore.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | <?php namespace CodeCraft\Pathfinder\Model\Store; use Psr\Log\LoggerInterface; use SilverStripe\Control\Controller; use SilverStripe\Control\Session; use SilverStripe\Core\Injector\Injector; /** * Uses the session to store a Pathfinder user's progress */ class SessionProgressStore extends ProgressStore { /** * {@inheritDoc} */ public function add(ProgressEntry $entry) { parent::add($entries); Controller::curr()->getRequest()->getSession()->set( $this->getStorageName(), json_encode($this->toArray()) ); return $this; } /** * {@inheritDoc} */ public function get() { $existing = parent::get(); if (is_array($existing)) { return $existing; }; $stored = Controller::curr()->getRequest()->getSession()->get($this->getStorageName()); if (!$stored) { // We want to return a helpful value, but not "cache" it return []; } $stored = json_decode($stored, true); if (!is_array($stored)) { Injector::inst()->get(LoggerInterface::class) ->warning(sprintf('Unexpected value stored in session for "%s::get()"', self::class)); // We want to return a helpful value, but not "cache" it return []; } $entries = []; foreach ($stored as $entry) { $entries[] = ProgressEntry::create($entry); } parent::set($entries); return parent::get(); } /** * {@inheritDoc} */ public function set(array $entries) { parent::set($entries); Controller::curr()->getRequest()->getSession()->set( $this->getStorageName(), json_encode($this->get()->toArray()) ); return $this; } } |