File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types = 1 );
4+
5+ /*
6+ * This file is part of the brainbits blocking package.
7+ *
8+ * (c) brainbits GmbH (http://www.brainbits.net)
9+ *
10+ * For the full copyright and license information, please view the LICENSE
11+ * file that was distributed with this source code.
12+ */
13+
14+ namespace Brainbits \Blocking \Exception ;
15+
16+ /**
17+ * Unserialize failed exception.
18+ */
19+ final class UnserializeFailedException extends RuntimeException
20+ {
21+ /**
22+ * @param mixed $input
23+ */
24+ public static function createFromInput ($ input ): self
25+ {
26+ return new self ("Unserialize failed: " .$ input );
27+ }
28+ }
Original file line number Diff line number Diff line change 1717use Brainbits \Blocking \Exception \DirectoryNotWritableException ;
1818use Brainbits \Blocking \Exception \FileNotWritableException ;
1919use Brainbits \Blocking \Exception \IOException ;
20+ use Brainbits \Blocking \Exception \UnserializeFailedException ;
2021use Brainbits \Blocking \Identity \IdentityInterface ;
2122use DateTimeImmutable ;
2223
@@ -92,6 +93,10 @@ public function get(IdentityInterface $identifier): ?BlockInterface
9293 $ content = file_get_contents ($ filename );
9394 $ updatedAt = DateTimeImmutable::createFromFormat ('U ' , (string ) filemtime ($ filename ));
9495 $ block = unserialize ($ content );
96+ if (!$ block ) {
97+ throw UnserializeFailedException::createFromInput ($ content );
98+ }
99+
95100 $ block ->touch ($ updatedAt );
96101
97102 return $ block ;
You can’t perform that action at this time.
0 commit comments