diff options
Diffstat (limited to 'vendor/sabre/vobject/lib/Parser/Json.php')
-rw-r--r-- | vendor/sabre/vobject/lib/Parser/Json.php | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/vendor/sabre/vobject/lib/Parser/Json.php b/vendor/sabre/vobject/lib/Parser/Json.php index 3fd307e97..a77258a2e 100644 --- a/vendor/sabre/vobject/lib/Parser/Json.php +++ b/vendor/sabre/vobject/lib/Parser/Json.php @@ -4,7 +4,6 @@ namespace Sabre\VObject\Parser; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCard; -use Sabre\VObject\Document; use Sabre\VObject\EofException; use Sabre\VObject\ParseException; @@ -17,8 +16,8 @@ use Sabre\VObject\ParseException; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class Json extends Parser -{ +class Json extends Parser { + /** * The input data. * @@ -42,12 +41,12 @@ class Json extends Parser * If either input or options are not supplied, the defaults will be used. * * @param resource|string|array|null $input - * @param int $options + * @param int $options * - * @return \Sabre\VObject\Document + * @return Sabre\VObject\Document */ - public function parse($input = null, $options = 0) - { + function parse($input = null, $options = 0) { + if (!is_null($input)) { $this->setInput($input); } @@ -60,28 +59,28 @@ class Json extends Parser } switch ($this->input[0]) { - case 'vcalendar': + case 'vcalendar' : $this->root = new VCalendar([], false); break; - case 'vcard': + case 'vcard' : $this->root = new VCard([], false); break; - default: + default : throw new ParseException('The root component must either be a vcalendar, or a vcard'); + } foreach ($this->input[1] as $prop) { $this->root->add($this->parseProperty($prop)); } - if (isset($this->input[2])) { - foreach ($this->input[2] as $comp) { - $this->root->add($this->parseComponent($comp)); - } + if (isset($this->input[2])) foreach ($this->input[2] as $comp) { + $this->root->add($this->parseComponent($comp)); } // Resetting the input so we can throw an feof exception the next time. $this->input = null; return $this->root; + } /** @@ -91,34 +90,35 @@ class Json extends Parser * * @return \Sabre\VObject\Component */ - public function parseComponent(array $jComp) - { + function parseComponent(array $jComp) { + // We can remove $self from PHP 5.4 onward. $self = $this; $properties = array_map( - function ($jProp) use ($self) { + function($jProp) use ($self) { return $self->parseProperty($jProp); }, $jComp[1] ); if (isset($jComp[2])) { + $components = array_map( - function ($jComp) use ($self) { + function($jComp) use ($self) { return $self->parseComponent($jComp); }, $jComp[2] ); - } else { - $components = []; - } + + } else $components = []; return $this->root->createComponent( $jComp[0], array_merge($properties, $components), $defaults = false ); + } /** @@ -128,8 +128,8 @@ class Json extends Parser * * @return \Sabre\VObject\Property */ - public function parseProperty(array $jProp) - { + function parseProperty(array $jProp) { + list( $propertyName, $parameters, @@ -142,14 +142,14 @@ class Json extends Parser // value type. We're using this value later in this function. $defaultPropertyClass = $this->root->getClassNameForPropertyName($propertyName); - $parameters = (array) $parameters; + $parameters = (array)$parameters; $value = array_slice($jProp, 3); $valueType = strtoupper($valueType); if (isset($parameters['group'])) { - $propertyName = $parameters['group'].'.'.$propertyName; + $propertyName = $parameters['group'] . '.' . $propertyName; unset($parameters['group']); } @@ -160,7 +160,7 @@ class Json extends Parser // represents TEXT values. We have to normalize these here. In the // future we can get rid of FlatText once we're allowed to break BC // again. - if ('Sabre\VObject\Property\FlatText' === $defaultPropertyClass) { + if ($defaultPropertyClass === 'Sabre\VObject\Property\FlatText') { $defaultPropertyClass = 'Sabre\VObject\Property\Text'; } @@ -168,19 +168,22 @@ class Json extends Parser // type for the given property (e.g.: BDAY), we need to add a VALUE= // parameter. if ($defaultPropertyClass !== get_class($prop)) { - $prop['VALUE'] = $valueType; + $prop["VALUE"] = $valueType; } return $prop; + } /** * Sets the input data. * * @param resource|string|array $input + * + * @return void */ - public function setInput($input) - { + function setInput($input) { + if (is_resource($input)) { $input = stream_get_contents($input); } @@ -188,5 +191,7 @@ class Json extends Parser $input = json_decode($input); } $this->input = $input; + } + } |