File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33class CacheException extends \RuntimeException implements ExceptionInterface
44{
5+ /**
6+ * @return \CodeIgniter\Cache\Exceptions\CacheException
7+ */
8+ public static function forUnableToWrite (string $ path )
9+ {
10+ return new static (lang ('Cache.unableToWrite ' , [$ path ]));
11+ }
12+
513 /**
614 * @return \CodeIgniter\Cache\Exceptions\CacheException
715 */
Original file line number Diff line number Diff line change 3737 */
3838
3939use CodeIgniter \Cache \CacheInterface ;
40+ use CodeIgniter \Cache \Exceptions \CacheException ;
4041
4142class FileHandler implements CacheInterface
4243{
@@ -59,10 +60,14 @@ class FileHandler implements CacheInterface
5960
6061 public function __construct ($ config )
6162 {
62- $ this ->prefix = $ config ->prefix ?: '' ;
63- $ this ->path = ! empty ($ config ->storePath ) ? $ config ->storePath : WRITEPATH . 'cache ' ;
63+ $ path = ! empty ($ config ->storePath ) ? $ config ->storePath : WRITEPATH . 'cache ' ;
64+ if (! is_really_writable ($ path ))
65+ {
66+ throw CacheException::forUnableToWrite ($ path );
67+ }
6468
65- $ this ->path = rtrim ($ this ->path , '/ ' ) . '/ ' ;
69+ $ this ->prefix = $ config ->prefix ?: '' ;
70+ $ this ->path = rtrim ($ path , '/ ' ) . '/ ' ;
6671 }
6772
6873 //--------------------------------------------------------------------
@@ -329,11 +334,7 @@ protected function getItem(string $key)
329334 */
330335 protected function writeFile ($ path , $ data , $ mode = 'wb ' )
331336 {
332- if (($ fp = @fopen ($ path , $ mode )) === false )
333- {
334- return false ;
335- }
336-
337+ fopen ($ path , $ mode );
337338 flock ($ fp , LOCK_EX );
338339
339340 for ($ result = $ written = 0 , $ length = strlen ($ data ); $ written < $ length ; $ written += $ result )
Original file line number Diff line number Diff line change 1515 */
1616
1717return [
18+ 'unableToWrite ' => 'Cache unable to write to {0} ' ,
1819 'invalidHandlers ' => 'Cache config must have an array of $validHandlers. ' ,
1920 'noBackup ' => 'Cache config must have a handler and backupHandler set. ' ,
2021 'handlerNotFound ' => 'Cache config has an invalid handler or backup handler specified. ' ,
You can’t perform that action at this time.
0 commit comments