|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
/**
|
|
4
|
|
|
* Quantum PHP Framework
|
|
5
|
|
|
*
|
|
6
|
|
|
* An open source software development framework for PHP
|
|
7
|
|
|
*
|
|
8
|
|
|
* @package Quantum
|
|
9
|
|
|
* @author Arman Ag. <[email protected]>
|
|
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
|
|
11
|
|
|
* @link http://quantum.softberg.org/
|
|
12
|
|
|
* @since 3.0.0
|
|
13
|
|
|
*/
|
|
14
|
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Cron\Exceptions;
|
|
16
|
|
|
|
|
17
|
|
|
use Quantum\Libraries\Cron\Enums\ExceptionMessages;
|
|
18
|
|
|
|
|
19
|
|
|
/**
|
|
20
|
|
|
* Class CronException
|
|
21
|
|
|
* @package Quantum\Libraries\Cron
|
|
22
|
|
|
*/
|
|
23
|
|
|
class CronException extends \Exception
|
|
24
|
|
|
{
|
|
25
|
|
|
/**
|
|
26
|
|
|
* Task not found exception
|
|
27
|
|
|
* @param string $taskName
|
|
28
|
|
|
* @return CronException
|
|
29
|
|
|
*/
|
|
30
|
|
|
public static function taskNotFound(string $taskName): CronException
|
|
31
|
|
|
{
|
|
32
|
|
|
return new self(sprintf(ExceptionMessages::TASK_NOT_FOUND->value, $taskName));
|
|
33
|
|
|
}
|
|
34
|
|
|
|
|
35
|
|
|
/**
|
|
36
|
|
|
* Invalid cron expression exception
|
|
37
|
|
|
* @param string $expression
|
|
38
|
|
|
* @return CronException
|
|
39
|
|
|
*/
|
|
40
|
|
|
public static function invalidExpression(string $expression): CronException
|
|
41
|
|
|
{
|
|
42
|
|
|
return new self(sprintf(ExceptionMessages::INVALID_EXPRESSION->value, $expression));
|
|
43
|
|
|
}
|
|
44
|
|
|
|
|
45
|
|
|
/**
|
|
46
|
|
|
* Lock acquire failed exception
|
|
47
|
|
|
* @param string $taskName
|
|
48
|
|
|
* @return CronException
|
|
49
|
|
|
*/
|
|
50
|
|
|
public static function lockAcquireFailed(string $taskName): CronException
|
|
51
|
|
|
{
|
|
52
|
|
|
return new self(sprintf(ExceptionMessages::LOCK_ACQUIRE_FAILED->value, $taskName));
|
|
53
|
|
|
}
|
|
54
|
|
|
|
|
55
|
|
|
/**
|
|
56
|
|
|
* Task execution failed exception
|
|
57
|
|
|
* @param string $taskName
|
|
58
|
|
|
* @param string $error
|
|
59
|
|
|
* @return CronException
|
|
60
|
|
|
*/
|
|
61
|
|
|
public static function taskExecutionFailed(string $taskName, string $error): CronException
|
|
62
|
|
|
{
|
|
63
|
|
|
return new self(sprintf(ExceptionMessages::TASK_EXECUTION_FAILED->value, $taskName, $error));
|
|
64
|
|
|
}
|
|
65
|
|
|
|
|
66
|
|
|
/**
|
|
67
|
|
|
* Invalid task file exception
|
|
68
|
|
|
* @param string $file
|
|
69
|
|
|
* @return CronException
|
|
70
|
|
|
*/
|
|
71
|
|
|
public static function invalidTaskFile(string $file): CronException
|
|
72
|
|
|
{
|
|
73
|
|
|
return new self(sprintf(ExceptionMessages::INVALID_TASK_FILE->value, $file));
|
|
74
|
|
|
}
|
|
75
|
|
|
|
|
76
|
|
|
/**
|
|
77
|
|
|
* Cron directory not found exception
|
|
78
|
|
|
* @param string $directory
|
|
79
|
|
|
* @return CronException
|
|
80
|
|
|
*/
|
|
81
|
|
|
public static function cronDirectoryNotFound(string $directory): CronException
|
|
82
|
|
|
{
|
|
83
|
|
|
return new self(sprintf(ExceptionMessages::CRON_DIRECTORY_NOT_FOUND->value, $directory));
|
|
84
|
|
|
}
|
|
85
|
|
|
|
|
86
|
|
|
/**
|
|
87
|
|
|
* Lock directory not writable exception
|
|
88
|
|
|
* @param string $directory
|
|
89
|
|
|
* @return CronException
|
|
90
|
|
|
*/
|
|
91
|
|
|
public static function lockDirectoryNotWritable(string $directory): CronException
|
|
92
|
|
|
{
|
|
93
|
|
|
return new self(sprintf(ExceptionMessages::LOCK_DIRECTORY_NOT_WRITABLE->value, $directory));
|
|
94
|
|
|
}
|
|
95
|
|
|
}
|
|
96
|
|
|
|