-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c70eac3
commit f351ee1
Showing
1 changed file
with
30 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,28 @@ | |
declare(strict_types=1); | ||
|
||
/** | ||
* Exception library managing multiple exceptions with CLI support for creating, | ||
* removing, and updating exceptions. | ||
* | ||
* The (exception) Github repository | ||
* @see https://github.com/lazervel/exception | ||
* | ||
* @author Shahzada Modassir <[email protected]> | ||
* @author Shahzadi Afsara <[email protected]> | ||
* | ||
* @copyright (c) Shahzada Modassir | ||
* @copyright (c) Shahzadi Afsara | ||
* | ||
* @license MIT License | ||
* @see https://github.com/lazervel/exception/blob/main/LICENSE | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Modassir\Exception; | ||
|
||
class Exception | ||
{ | ||
private const CUSTOM_EXCEPTION_DIR = CUSTOM_EXCEPTION_DIR ?? __DIR__.DIRECTORY_SEPARATOR.'Custom'; | ||
private const CUSTOM_EXCEPTION_DIR = __DIR__.DIRECTORY_SEPARATOR.'Custom'; | ||
private const CUSTOM_EXCEPTION_NAMESPACE = 'namespace Modassir\\Exception\\Custom;'; | ||
private const CUSTOM_EXCEPTION_USE = 'use Modassir\\Exception\\Exception\\'; | ||
|
||
|
@@ -32,6 +47,14 @@ public function __construct($executor, $primaryClass, $secondryClass) | |
$this->secondryClass = $secondryClass; | ||
} | ||
|
||
/** | ||
* @return string custom directory location. | ||
*/ | ||
private function CED() : string | ||
{ | ||
return \defined('CUSTOM_EXCEPTION_DIR') ? CUSTOM_EXCEPTION_DIR : $this->CED(); | ||
} | ||
|
||
/** | ||
* @param array $argv [required] | ||
* @return \Modassir\Exception\Exception | ||
|
@@ -105,7 +128,7 @@ public function rename(string $exception, string $newClass) : void | |
); | ||
} | ||
|
||
$lines = @\file(($path = \sprintf('%s/%s.php', self::CUSTOM_EXCEPTION_DIR, $exception))); | ||
$lines = @\file(($path = \sprintf('%s/%s.php', $this->CED(), $exception))); | ||
|
||
$matches_signature = \sprintf('class %s extends', $exception); | ||
|
||
|
@@ -117,7 +140,7 @@ public function rename(string $exception, string $newClass) : void | |
} | ||
|
||
@\file_put_contents($path, \join("", $lines)); | ||
\rename($path, \sprintf('%s/%s.php', self::CUSTOM_EXCEPTION_DIR, $newClass)); | ||
\rename($path, \sprintf('%s/%s.php', $this->CED(), $newClass)); | ||
self::exit("\nSuccess: Exception [%s] has been renamed.\n\n", false, $newClass); | ||
} | ||
|
||
|
@@ -133,7 +156,7 @@ public function make(string $subClass, string $newClass) : void | |
self::exit("\nError: Could not create Exception Invalid subclass [%s].\n\n", true, $subClass); | ||
} | ||
|
||
if (($dir = self::CUSTOM_EXCEPTION_DIR) && !\is_dir($dir)) { | ||
if (($dir = $this->CED()) && !\is_dir($dir)) { | ||
\mkdir($dir); | ||
} | ||
|
||
|
@@ -154,7 +177,7 @@ public function make(string $subClass, string $newClass) : void | |
|
||
private function exists(string $exception) : bool | ||
{ | ||
return \file_exists(\sprintf('%s/%s.php', self::CUSTOM_EXCEPTION_DIR, $exception)); | ||
return \file_exists(\sprintf('%s/%s.php', $this->CED(), $exception)); | ||
} | ||
|
||
/** | ||
|
@@ -171,7 +194,7 @@ public function remove(string $exception) : void | |
} | ||
|
||
if (self::exists($exception)) { | ||
\unlink(\sprintf('%s/%s.php', self::CUSTOM_EXCEPTION_DIR, $exception)); | ||
\unlink(\sprintf('%s/%s.php', $this->CED(), $exception)); | ||
self::exit("\nSuccess: Exception [%s] has been removed.\n\n", false, $exception); | ||
} else { | ||
self::exit("\nError: Could not remove Exception [%s] is not found.\n\n", true, $exception); | ||
|
@@ -215,4 +238,4 @@ public function run() : void | |
\call_user_func([$this, $this->executor], $this->primaryClass, $this->secondryClass); | ||
} | ||
} | ||
?> | ||
?> |