ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\Parser\Json Class Reference

Json Parser. More...

+ Inheritance diagram for Sabre\VObject\Parser\Json:
+ Collaboration diagram for Sabre\VObject\Parser\Json:

Public Member Functions

 parse ($input=null, $options=0)
 This method starts the parsing process. More...
 
 parseComponent (array $jComp)
 Parses a component. More...
 
 parseProperty (array $jProp)
 Parses properties. More...
 
 setInput ($input)
 Sets the input data. More...
 
- Public Member Functions inherited from Sabre\VObject\Parser\Parser
 __construct ($input=null, $options=0)
 Creates the parser. More...
 
 parse ($input=null, $options=0)
 This method starts the parsing process. More...
 
 setInput ($input)
 Sets the input data. More...
 

Protected Attributes

 $input
 
 $root
 
- Protected Attributes inherited from Sabre\VObject\Parser\Parser
 $options
 

Additional Inherited Members

- Data Fields inherited from Sabre\VObject\Parser\Parser
const OPTION_FORGIVING = 1
 Turning on this option makes the parser more forgiving. More...
 
const OPTION_IGNORE_INVALID_LINES = 2
 If this option is turned on, any lines we cannot parse will be ignored by the reader. More...
 

Detailed Description

Json Parser.

This parser parses both the jCal and jCard formats.

Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 19 of file Json.php.

Member Function Documentation

◆ parse()

Sabre\VObject\Parser\Json::parse (   $input = null,
  $options = 0 
)

This method starts the parsing process.

If the input was not supplied during construction, it's possible to pass it here instead.

If either input or options are not supplied, the defaults will be used.

Parameters
resource | string | array | null$input
int$options
Returns
Sabre

Definition at line 48 of file Json.php.

References Sabre\VObject\Parser\Json\$input, Sabre\VObject\Parser\Parser\$options, Sabre\VObject\Parser\Json\$root, input, Sabre\VObject\Parser\Json\parseComponent(), Sabre\VObject\Parser\Json\parseProperty(), and Sabre\VObject\Parser\Json\setInput().

48  {
49 
50  if (!is_null($input)) {
51  $this->setInput($input);
52  }
53  if (is_null($this->input)) {
54  throw new EofException('End of input stream, or no input supplied');
55  }
56 
57  if (0 !== $options) {
58  $this->options = $options;
59  }
60 
61  switch ($this->input[0]) {
62  case 'vcalendar' :
63  $this->root = new VCalendar([], false);
64  break;
65  case 'vcard' :
66  $this->root = new VCard([], false);
67  break;
68  default :
69  throw new ParseException('The root component must either be a vcalendar, or a vcard');
70 
71  }
72  foreach ($this->input[1] as $prop) {
73  $this->root->add($this->parseProperty($prop));
74  }
75  if (isset($this->input[2])) foreach ($this->input[2] as $comp) {
76  $this->root->add($this->parseComponent($comp));
77  }
78 
79  // Resetting the input so we can throw an feof exception the next time.
80  $this->input = null;
81 
82  return $this->root;
83 
84  }
setInput($input)
Sets the input data.
Definition: Json.php:185
parseComponent(array $jComp)
Parses a component.
Definition: Json.php:93
parseProperty(array $jProp)
Parses properties.
Definition: Json.php:131
input
Definition: langcheck.php:166
+ Here is the call graph for this function:

◆ parseComponent()

Sabre\VObject\Parser\Json::parseComponent ( array  $jComp)

Parses a component.

Parameters
array$jComp
Returns

Definition at line 93 of file Json.php.

Referenced by Sabre\VObject\Parser\Json\parse().

93  {
94 
95  // We can remove $self from PHP 5.4 onward.
96  $self = $this;
97 
98  $properties = array_map(
99  function($jProp) use ($self) {
100  return $self->parseProperty($jProp);
101  },
102  $jComp[1]
103  );
104 
105  if (isset($jComp[2])) {
106 
107  $components = array_map(
108  function($jComp) use ($self) {
109  return $self->parseComponent($jComp);
110  },
111  $jComp[2]
112  );
113 
114  } else $components = [];
115 
116  return $this->root->createComponent(
117  $jComp[0],
118  array_merge($properties, $components),
119  $defaults = false
120  );
121 
122  }
+ Here is the caller graph for this function:

◆ parseProperty()

Sabre\VObject\Parser\Json::parseProperty ( array  $jProp)

Parses properties.

Parameters
array$jProp
Returns

Definition at line 131 of file Json.php.

Referenced by Sabre\VObject\Parser\Json\parse().

131  {
132 
133  list(
134  $propertyName,
135  $parameters,
136  $valueType
137  ) = $jProp;
138 
139  $propertyName = strtoupper($propertyName);
140 
141  // This is the default class we would be using if we didn't know the
142  // value type. We're using this value later in this function.
143  $defaultPropertyClass = $this->root->getClassNameForPropertyName($propertyName);
144 
145  $parameters = (array)$parameters;
146 
147  $value = array_slice($jProp, 3);
148 
149  $valueType = strtoupper($valueType);
150 
151  if (isset($parameters['group'])) {
152  $propertyName = $parameters['group'] . '.' . $propertyName;
153  unset($parameters['group']);
154  }
155 
156  $prop = $this->root->createProperty($propertyName, null, $parameters, $valueType);
157  $prop->setJsonValue($value);
158 
159  // We have to do something awkward here. FlatText as well as Text
160  // represents TEXT values. We have to normalize these here. In the
161  // future we can get rid of FlatText once we're allowed to break BC
162  // again.
163  if ($defaultPropertyClass === 'Sabre\VObject\Property\FlatText') {
164  $defaultPropertyClass = 'Sabre\VObject\Property\Text';
165  }
166 
167  // If the value type we received (e.g.: TEXT) was not the default value
168  // type for the given property (e.g.: BDAY), we need to add a VALUE=
169  // parameter.
170  if ($defaultPropertyClass !== get_class($prop)) {
171  $prop["VALUE"] = $valueType;
172  }
173 
174  return $prop;
175 
176  }
+ Here is the caller graph for this function:

◆ setInput()

Sabre\VObject\Parser\Json::setInput (   $input)

Sets the input data.

Parameters
resource | string | array$input
Returns
void

Definition at line 185 of file Json.php.

References Sabre\VObject\Parser\Json\$input, and input.

Referenced by Sabre\VObject\Parser\Json\parse().

185  {
186 
187  if (is_resource($input)) {
188  $input = stream_get_contents($input);
189  }
190  if (is_string($input)) {
191  $input = json_decode($input);
192  }
193  $this->input = $input;
194 
195  }
input
Definition: langcheck.php:166
+ Here is the caller graph for this function:

Field Documentation

◆ $input

Sabre\VObject\Parser\Json::$input
protected

Definition at line 26 of file Json.php.

Referenced by Sabre\VObject\Parser\Json\parse(), and Sabre\VObject\Parser\Json\setInput().

◆ $root

Sabre\VObject\Parser\Json::$root
protected

Definition at line 33 of file Json.php.

Referenced by Sabre\VObject\Parser\Json\parse().


The documentation for this class was generated from the following file: