aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/xml/lib/Writer.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/xml/lib/Writer.php')
-rw-r--r--vendor/sabre/xml/lib/Writer.php117
1 files changed, 55 insertions, 62 deletions
diff --git a/vendor/sabre/xml/lib/Writer.php b/vendor/sabre/xml/lib/Writer.php
index 09d4cb321..f5957bbce 100644
--- a/vendor/sabre/xml/lib/Writer.php
+++ b/vendor/sabre/xml/lib/Writer.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
namespace Sabre\Xml;
use XMLWriter;
@@ -28,8 +30,8 @@ use XMLWriter;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Writer extends XMLWriter {
-
+class Writer extends XMLWriter
+{
use ContextStackTrait;
/**
@@ -93,12 +95,10 @@ class Writer extends XMLWriter {
* ]
*
* @param mixed $value
- * @return void
*/
- function write($value) {
-
+ public function write($value)
+ {
Serializer\standardSerializer($this, $value);
-
}
/**
@@ -115,52 +115,48 @@ class Writer extends XMLWriter {
*
* <entry xmlns="http://w3.org/2005/Atom">
*
+ * Note: this function doesn't have the string typehint, because PHP's
+ * XMLWriter::startElement doesn't either.
+ *
* @param string $name
- * @return bool
*/
- function startElement($name) {
-
- if ($name[0] === '{') {
-
+ public function startElement($name): bool
+ {
+ if ('{' === $name[0]) {
list($namespace, $localName) =
Service::parseClarkNotation($name);
if (array_key_exists($namespace, $this->namespaceMap)) {
$result = $this->startElementNS(
- $this->namespaceMap[$namespace] === '' ? null : $this->namespaceMap[$namespace],
+ '' === $this->namespaceMap[$namespace] ? null : $this->namespaceMap[$namespace],
$localName,
null
);
} else {
-
// An empty namespace means it's the global namespace. This is
// allowed, but it mustn't get a prefix.
- if ($namespace === "" || $namespace === null) {
+ if ('' === $namespace || null === $namespace) {
$result = $this->startElement($localName);
$this->writeAttribute('xmlns', '');
} else {
if (!isset($this->adhocNamespaces[$namespace])) {
- $this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces) + 1);
+ $this->adhocNamespaces[$namespace] = 'x'.(count($this->adhocNamespaces) + 1);
}
$result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace);
}
}
-
} else {
$result = parent::startElement($name);
}
if (!$this->namespacesWritten) {
-
foreach ($this->namespaceMap as $namespace => $prefix) {
- $this->writeAttribute(($prefix ? 'xmlns:' . $prefix : 'xmlns'), $namespace);
+ $this->writeAttribute(($prefix ? 'xmlns:'.$prefix : 'xmlns'), $namespace);
}
$this->namespacesWritten = true;
-
}
return $result;
-
}
/**
@@ -182,18 +178,22 @@ class Writer extends XMLWriter {
* becomes:
* <author xmlns="http://www.w3.org/2005" /><name>Evert Pot</name></author>
*
- * @param string $name
- * @param string $content
+ * Note: this function doesn't have the string typehint, because PHP's
+ * XMLWriter::startElement doesn't either.
+ *
+ * @param array|string|object|null $content
+ *
* @return bool
*/
- function writeElement($name, $content = null) {
-
+ public function writeElement($name, $content = null): bool
+ {
$this->startElement($name);
if (!is_null($content)) {
$this->write($content);
}
$this->endElement();
+ return true;
}
/**
@@ -204,16 +204,12 @@ class Writer extends XMLWriter {
* The key is an attribute name. If the key is a 'localName', the current
* xml namespace is assumed. If it's a 'clark notation key', this namespace
* will be used instead.
- *
- * @param array $attributes
- * @return void
*/
- function writeAttributes(array $attributes) {
-
+ public function writeAttributes(array $attributes)
+ {
foreach ($attributes as $name => $value) {
$this->writeAttribute($name, $value);
}
-
}
/**
@@ -223,44 +219,41 @@ class Writer extends XMLWriter {
*
* Returns true when successful.
*
+ * Note: this function doesn't have typehints, because for some reason
+ * PHP's XMLWriter::writeAttribute doesn't either.
+ *
* @param string $name
* @param string $value
- * @return bool
*/
- function writeAttribute($name, $value) {
-
- if ($name[0] === '{') {
-
- list(
- $namespace,
- $localName
- ) = Service::parseClarkNotation($name);
-
- if (array_key_exists($namespace, $this->namespaceMap)) {
- // It's an attribute with a namespace we know
- $this->writeAttribute(
- $this->namespaceMap[$namespace] . ':' . $localName,
- $value
- );
- } else {
-
- // We don't know the namespace, we must add it in-line
- if (!isset($this->adhocNamespaces[$namespace])) {
- $this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces) + 1);
- }
- $this->writeAttributeNS(
- $this->adhocNamespaces[$namespace],
- $localName,
- $namespace,
- $value
- );
+ public function writeAttribute($name, $value): bool
+ {
+ if ('{' !== $name[0]) {
+ return parent::writeAttribute($name, $value);
+ }
- }
+ list(
+ $namespace,
+ $localName
+ ) = Service::parseClarkNotation($name);
+
+ if (array_key_exists($namespace, $this->namespaceMap)) {
+ // It's an attribute with a namespace we know
+ return $this->writeAttribute(
+ $this->namespaceMap[$namespace].':'.$localName,
+ $value
+ );
+ }
- } else {
- return parent::writeAttribute($name, $value);
+ // We don't know the namespace, we must add it in-line
+ if (!isset($this->adhocNamespaces[$namespace])) {
+ $this->adhocNamespaces[$namespace] = 'x'.(count($this->adhocNamespaces) + 1);
}
+ return $this->writeAttributeNS(
+ $this->adhocNamespaces[$namespace],
+ $localName,
+ $namespace,
+ $value
+ );
}
-
}