1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Input\Parser\FacetBuilder; |
4
|
|
|
|
5
|
|
|
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher; |
6
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\ContentQuery as QueryParser; |
7
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\ContentTypeParser; |
8
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\CriterionParser; |
9
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\DateRangeParser; |
10
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\FieldParser; |
11
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\FieldRangeParser; |
12
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\LocationParser; |
13
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\SectionParser; |
14
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\TermParser; |
15
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder\UserParser; |
16
|
|
|
use eZ\Publish\Core\REST\Server\Tests\Input\Parser\BaseTest; |
17
|
|
|
|
18
|
|
|
abstract class FacetBuilderBaseTest extends BaseTest |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @return \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher |
22
|
|
|
*/ |
23
|
|
|
protected function getParsingDispatcher() |
24
|
|
|
{ |
25
|
|
|
$parsingDispatcher = new ParsingDispatcher(); |
26
|
|
|
|
27
|
|
|
$parsingDispatcher->addParser( |
28
|
|
|
'application/vnd.ez.api.internal.facetbuilder.ContentType', |
29
|
|
|
new ContentTypeParser() |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$parsingDispatcher->addParser( |
33
|
|
|
'application/vnd.ez.api.internal.facetbuilder.Criterion', |
34
|
|
|
new CriterionParser() |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$parsingDispatcher->addParser( |
38
|
|
|
'application/vnd.ez.api.internal.facetbuilder.DateRange', |
39
|
|
|
new DateRangeParser() |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$parsingDispatcher->addParser( |
43
|
|
|
'application/vnd.ez.api.internal.facetbuilder.Field', |
44
|
|
|
new FieldParser() |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$parsingDispatcher->addParser( |
48
|
|
|
'application/vnd.ez.api.internal.facetbuilder.FieldRange', |
49
|
|
|
new FieldRangeParser() |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$parsingDispatcher->addParser( |
53
|
|
|
'application/vnd.ez.api.internal.facetbuilder.Location', |
54
|
|
|
new LocationParser() |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$parsingDispatcher->addParser( |
58
|
|
|
'application/vnd.ez.api.internal.facetbuilder.Section', |
59
|
|
|
new SectionParser() |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$parsingDispatcher->addParser( |
63
|
|
|
'application/vnd.ez.api.internal.facetbuilder.Term', |
64
|
|
|
new TermParser() |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$parsingDispatcher->addParser( |
68
|
|
|
'application/vnd.ez.api.internal.facetbuilder.User', |
69
|
|
|
new UserParser() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
return $parsingDispatcher; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns the query parser. |
77
|
|
|
* |
78
|
|
|
* @return \eZ\Publish\Core\REST\Server\Input\Parser\ContentQuery |
79
|
|
|
*/ |
80
|
|
|
protected function internalGetParser() |
81
|
|
|
{ |
82
|
|
|
return new QueryParser(); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.