-
Notifications
You must be signed in to change notification settings - Fork 208
/
ContentObjectStates.php
60 lines (54 loc) · 2.04 KB
/
ContentObjectStates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* File containing the ContentObjectStates parser class
*
* @copyright Copyright (C) 1999-2014 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version //autogentag//
*/
namespace eZ\Publish\Core\REST\Common\Input\Parser;
use eZ\Publish\Core\REST\Common\Input\BaseParser;
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
use eZ\Publish\Core\REST\Common\Exceptions;
use eZ\Publish\Core\REST\Common\Values\RestObjectState;
use eZ\Publish\Core\Repository\Values\ObjectState\ObjectState;
/**
* Parser for ContentObjectStates
*/
class ContentObjectStates extends BaseParser
{
/**
* Parse input structure
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @return \eZ\Publish\Core\REST\Common\Values\RestObjectState[]
*/
public function parse( array $data, ParsingDispatcher $parsingDispatcher )
{
// @todo XSD says that no ObjectState elements is valid,
// but we should at least have one if setting new states to content?
if ( !array_key_exists( 'ObjectState', $data ) || !is_array( $data['ObjectState'] ) || empty( $data['ObjectState'] ) )
{
throw new Exceptions\Parser( "Missing or invalid 'ObjectState' elements for ContentObjectStates." );
}
$states = array();
foreach ( $data['ObjectState'] as $rawStateData )
{
if ( !array_key_exists( '_href', $rawStateData ) )
{
throw new Exceptions\Parser( "Missing '_href' attribute for ObjectState." );
}
$states[] = new RestObjectState(
new ObjectState(
array(
'id' => $this->requestParser->parseHref( $rawStateData['_href'], 'objectStateId' )
)
),
$this->requestParser->parseHref( $rawStateData['_href'], 'objectStateGroupId' )
);
}
return $states;
}
}