Skip to content

Commit

Permalink
Merge pull request #32 from Firesphere/master
Browse files Browse the repository at this point in the history
Many code-technical improvements.
  • Loading branch information
Firesphere committed Mar 28, 2016
2 parents 4d3ab2b + 6157637 commit 8b61f99
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 166 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ before_script:
- cd ~/builds/ss
language: php
php:
- 5.4
[5.3,5.4,5.5,5.6,7.0]

matrix:
include:
- php: 5.5
env: DB=MYSQL CORE_RELEASE=master
allow_failures:
- php: 7.0

script:
- vendor/bin/phpunit ideannotator/tests/
env:
Expand Down
58 changes: 50 additions & 8 deletions code/Annotatable.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,64 @@
<?php


/**
* Class Annotatable
*
* Annotate the provided DataObjects for autocompletion purposes.
* Start annotation, if skipannotation is not set and the annotator is enabled.
*
* @property DataObject|Annotatable owner
*/
class Annotatable extends DataExtension
{

/**
* @var DataObjectAnnotator
*/
protected $annotator;

/**
* @var AnnotatePermissionChecker
*/
protected $permissionChecker;

public function __construct() {
parent::__construct();
$this->annotator = Injector::inst()->get('DataObjectAnnotator');
$this->permissionChecker = Injector::inst()->get('AnnotatePermissionChecker');

}
/**
* This is the base function on which annotations are started.
*
* @todo rewrite this. It's not actually a requireDefaultRecords. But it's the only place to hook into the build-process to start the annotation process.
* @return bool
*/
public function requireDefaultRecords()
{
if (!Config::inst()->get('DataObjectAnnotator', 'enabled') || isset($_GET['skipannotation'])) {

/** @var SS_HTTPRequest|NullHTTPRequest $request */
$request = Controller::curr()->getRequest();
$skipAnnotation = $request->getVar('skipannotation');
if ($skipAnnotation !== null || !Config::inst()->get('DataObjectAnnotator', 'enabled')) {
return false;
}

/* @var $annotator DataObjectAnnotator */
$annotator = DataObjectAnnotator::create();
$annotator->annotateDataObject($this->owner->ClassName);
/* Annotate the current Class, if annotatable */
if ($this->permissionChecker->classNameIsAllowed($this->owner->ClassName)) {
$this->annotator->annotateDataObject($this->owner->ClassName);
}

if ($extensions = Config::inst()->get($this->owner->ClassName, 'extensions', Config::UNINHERITED)) {
foreach($extensions as $extension) {
$annotator->annotateDataObject($extension);
/** @var array $extensions */
$extensions = Config::inst()->get($this->owner->ClassName, 'extensions', Config::UNINHERITED);
/* Annotate the extensions for this Class, if annotatable */
if ($extensions) {
foreach ($extensions as $extension) {
if ($this->permissionChecker->classNameIsAllowed($extension)) {
$this->annotator->annotateDataObject($extension);
}
}
}

return null;
}
}
Loading

0 comments on commit 8b61f99

Please sign in to comment.