/**
  * @inheritdoc
  */
 public function save(SessionInterface $session)
 {
     $data = $session->getData();
     $filename = $this->getFilename($session);
     if (empty($data)) {
         if (file_exists($filename)) {
             unlink($filename);
         }
         return true;
     }
     $this->mkDir(dirname($filename));
     $result = file_put_contents($filename, json_encode($data));
     if ($result === false) {
         throw new \Exception("Failed to save session to file: {$filename}");
     }
     chmod($filename, self::FILE_MODE);
     return true;
 }