-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotation reader to dynamically add the document annotation (#515)
- Loading branch information
1 parent
cd7d87f
commit 57916c9
Showing
10 changed files
with
145 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ArticleBundle\Elasticsearch; | ||
|
||
use Doctrine\Common\Annotations\Reader; | ||
use ONGR\ElasticsearchBundle\Annotation\Document; | ||
|
||
class AnnotationReader implements Reader | ||
{ | ||
/** | ||
* @var Reader | ||
*/ | ||
private $inner; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $articleViewDocumentClass; | ||
|
||
public function __construct(Reader $inner, $articleViewDocumentClass) | ||
{ | ||
$this->inner = $inner; | ||
$this->articleViewDocumentClass = $articleViewDocumentClass; | ||
} | ||
|
||
public function getClassAnnotations(\ReflectionClass $class) | ||
{ | ||
return $this->inner->getClassAnnotations($class); | ||
} | ||
|
||
public function getClassAnnotation(\ReflectionClass $class, $annotationName) | ||
{ | ||
$result = $this->inner->getClassAnnotation($class, $annotationName); | ||
if (!$result && Document::class === $annotationName && $class->getName() === $this->articleViewDocumentClass) { | ||
$annotation = new Document(); | ||
$annotation->type = 'article'; | ||
|
||
return $annotation; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function getMethodAnnotations(\ReflectionMethod $method) | ||
{ | ||
return $this->inner->getMethodAnnotations($method); | ||
} | ||
|
||
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName) | ||
{ | ||
return $this->inner->getMethodAnnotation($method, $annotationName); | ||
} | ||
|
||
public function getPropertyAnnotations(\ReflectionProperty $property) | ||
{ | ||
return $this->inner->getPropertyAnnotations($property); | ||
} | ||
|
||
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName) | ||
{ | ||
return $this->inner->getPropertyAnnotation($property, $annotationName); | ||
} | ||
} |
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ArticleBundle\Tests\TestExtendBundle\Document; | ||
|
||
use ONGR\ElasticsearchBundle\Annotation\Document; | ||
use ONGR\ElasticsearchBundle\Annotation\Property; | ||
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument as SuluArticleViewDocument; | ||
|
||
/** | ||
* @Document(type="article") | ||
*/ | ||
class ArticleViewDocument extends SuluArticleViewDocument | ||
{ | ||
/** | ||
* @var string | ||
* | ||
* @Property(type="text") | ||
*/ | ||
public $article; | ||
} |
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
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