1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\IDEAnnotator\Tasks; |
4
|
|
|
|
5
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
6
|
|
|
use ReflectionException; |
7
|
|
|
use SilverLeague\IDEAnnotator\DataObjectAnnotator; |
8
|
|
|
use SilverLeague\IDEAnnotator\Helpers\AnnotatePermissionChecker; |
9
|
|
|
use SilverStripe\Control\HTTPRequest; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Dev\BuildTask; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class DataObjectAnnotatorTask |
15
|
|
|
* |
16
|
|
|
* Task to add or remove annotations from a module or dataobject. |
17
|
|
|
* |
18
|
|
|
* @package IDEAnnotator/Tasks |
19
|
|
|
*/ |
20
|
|
|
class DataObjectAnnotatorTask extends BuildTask |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* DataObjectAnnotatorTask constructor. |
25
|
|
|
* Setup default values. In this case title and description. |
26
|
|
|
*/ |
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
parent::__construct(); |
30
|
|
|
$this->title = 'DataObject annotations for specific DataObjects, Extensions or Controllers'; |
31
|
|
|
|
32
|
|
|
$this->description = 'DataObject Annotator annotates your DO\'s if possible,' . |
33
|
|
|
' helping you write better code.' . |
34
|
|
|
'<br />Usage: add the module or DataObject as parameter to the URL,' . |
35
|
|
|
' e.g. ?module=mysite'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param HTTPRequest $request |
40
|
|
|
* @return bool |
41
|
|
|
* @throws ReflectionException |
42
|
|
|
* @throws NotFoundExceptionInterface |
43
|
|
|
*/ |
44
|
|
|
public function run($request) |
45
|
|
|
{ |
46
|
|
|
/* @var $permissionChecker AnnotatePermissionChecker */ |
47
|
|
|
$permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class); |
48
|
|
|
|
49
|
|
|
if (!$permissionChecker->environmentIsAllowed()) { |
50
|
|
|
return false; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/* @var $annotator DataObjectAnnotator */ |
54
|
|
|
$annotator = DataObjectAnnotator::create(); |
55
|
|
|
|
56
|
|
|
$annotator->annotateObject($request->getVar('object')); |
57
|
|
|
|
58
|
|
|
$annotator->annotateModule($request->getVar('module')); |
59
|
|
|
|
60
|
|
|
return true; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: