Skip to content

Commit 5f820d8

Browse files
committed
Feat: Adding file and directory checker functions
1 parent 64030fe commit 5f820d8

4 files changed

Lines changed: 75 additions & 1 deletion

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/*
3+
* This file is part of the Nigatedev PHP framework package
4+
*
5+
* (c) Abass Ben Cheik <abass@todaysdev.com>
6+
*/
7+
8+
namespace Nigatedev\Filesystem\Exceptions;
9+
10+
class DirNotFoundException extends \Exception implements FileExceptionInterface
11+
{
12+
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/*
3+
* This file is part of the Nigatedev PHP framework package
4+
*
5+
* (c) Abass Ben Cheik <abass@todaysdev.com>
6+
*/
7+
8+
namespace Nigatedev\Filesystem\Exceptions;
9+
10+
/**
11+
* Filesystem exception interface
12+
*
13+
* @author Abass Ben Cheik <abass@todaysdev.com>
14+
*/
15+
interface FileExceptionInterface extends \Throwable
16+
{
17+
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/*
3+
* This file is part of the Nigatedev PHP framework package
4+
*
5+
* (c) Abass Ben Cheik <abass@todaysdev.com>
6+
*/
7+
8+
namespace Nigatedev\Filesystem\Exceptions;
9+
10+
class FileNotFoundException extends \Exception implements FileExceptionInterface
11+
{
12+
13+
}

src/Filesystem.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
11
<?php
22
/*
3-
* This file is part of the Nigatedev PHP framework
3+
* This file is part of the Nigatedev PHP framework package
44
*
55
* (c) Abass Ben Cheik <abass@todaysdev.com>
66
*/
77

88
namespace Nigatedev\Filesystem;
99

10+
use Nigatedev\Filesystem\Exceptions\FileNotFoundException;
11+
use Nigatedev\Filesystem\Exceptions\DirNotFoundException;
12+
1013
/**
1114
* The Nigatedev PHP framework filesystem manipulator
1215
*
1316
* @author Abass Ben Cheik <abass@todaysdev.com>
1417
*/
1518
class Filesystem {
1619

20+
/**
21+
* @var string $fieName
22+
*/
23+
private string $fieName;
24+
25+
public function isFile($fieName): bool
26+
{
27+
if (!file_exists($fieName)) {
28+
throw new FileNotFoundException("Fatal error: {$fieName} file not found");
29+
}
30+
return true;
31+
}
32+
33+
public function isFilePut($fieName)
34+
{
35+
if ($this->isFile($fieName)) {
36+
return file_put_contents($fieName);
37+
}
38+
}
39+
40+
public function isDir($dirName)
41+
{
42+
if (!is_dir($dirName)) {
43+
throw new DirNotFoundException("Fatal error: {$dirName} directory not found");
44+
}
45+
return true;
46+
}
1747
}

0 commit comments

Comments
 (0)