]> git.mxchange.org Git - friendica.git/commitdiff
Remove dependency to the second parameter of XML::fromArray
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 31 Dec 2022 16:59:19 +0000 (11:59 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 2 Jan 2023 00:20:42 +0000 (19:20 -0500)
mod/oexchange.php
src/Core/System.php
src/Module/Api/ApiResponse.php
src/Module/OpenSearch.php
src/Module/ReallySimpleDiscovery.php
src/Module/WellKnown/HostMeta.php
src/Module/Xrd.php
src/Protocol/Diaspora.php
src/Protocol/Salmon.php
src/Util/XML.php

index c531eefdf6f0254070302c6422171e1a7751b407..4fbf7ffeb8e0aa0854b3fee73b2ce9124a62e5a1 100644 (file)
@@ -36,9 +36,7 @@ function oexchange_init(App $a)
 
        $baseURL = DI::baseUrl()->get();
 
-       $xml = null;
-
-       XML::fromArray([
+       $xmlString = XML::fromArray([
                'XRD' => [
                        '@attributes' => [
                                'xmlns'    => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
@@ -90,9 +88,9 @@ function oexchange_init(App $a)
                                ]
                        ],
                ],
-       ], $xml);
+       ]);
 
-       System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
+       System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml');
 }
 
 function oexchange_content(App $a)
index 4f06bcf52055ab2441f15aff9285aa5a12e9dcd0..f94004a880ab10a047935c653432cb887cc25aab 100644 (file)
@@ -294,7 +294,7 @@ class System
                }
 
                DI::apiResponse()->setType(Response::TYPE_XML);
-               DI::apiResponse()->addContent(XML::fromArray(["result" => $result], $xml));
+               DI::apiResponse()->addContent(XML::fromArray(['result' => $result]));
                DI::page()->exit(DI::apiResponse()->generate());
 
                self::exit();
index a113dab84f3b110f400b5cf4d8e2d5def81fa4c6..2d54bc176533fead897ea18ffb68c6ee801e9f8f 100644 (file)
@@ -99,7 +99,7 @@ class ApiResponse extends Response
 
                $data3 = [$root_element => $data2];
 
-               return XML::fromArray($data3, $xml, false, $namespaces);
+               return XML::fromArray($data3, $dummy, false, $namespaces);
        }
 
        /**
index d5426cf3843ba33d163a18e872c489fc98539b80..36e8713d99b2be0c339ac75e3499b3f2d719c582 100644 (file)
@@ -43,8 +43,6 @@ class OpenSearch extends BaseModule
                $baseUrl  = DI::baseUrl()->get();
 
                /** @var DOMDocument $xml */
-               $xml = null;
-
                XML::fromArray([
                        'OpenSearchDescription' => [
                                '@attributes' => [
index 11ab3596d680d6fcfb04b9f49d1597390a20fae3..d76094003feaabb78a60cd36d017782543c7c1c1 100644 (file)
@@ -34,7 +34,6 @@ class ReallySimpleDiscovery extends BaseModule
 {
        protected function rawContent(array $request = [])
        {
-               $xml = null;
                $content = XML::fromArray([
                        'rsd' => [
                                '@attributes' => [
@@ -67,7 +66,7 @@ class ReallySimpleDiscovery extends BaseModule
                                        ],
                                ],
                        ],
-               ], $xml);
+               ]);
                System::httpExit($content, Response::TYPE_XML);
        }
 }
index fdebb05d71fa8b862b3d59482a20d042129355fa..fa6619920f8a7b375c4da1f3ad21a70d3b711b69 100644 (file)
@@ -48,7 +48,6 @@ class HostMeta extends BaseModule
 
                $domain = DI::baseUrl()->get();
 
-               $xml = null;
                XML::fromArray([
                        'XRD' => [
                                '@attributes' => [
index 7b008549d6e73d51a26dfe994a0985bc5178989e..ad2b25902567d238f1d5f663366f162140d9f251 100644 (file)
@@ -230,9 +230,7 @@ class Xrd extends BaseModule
        {
                $baseURL = $this->baseUrl->get();
 
-               $xml = null;
-
-               XML::fromArray([
+               $xmlString = XML::fromArray([
                        'XRD' => [
                                '@attributes' => [
                                        'xmlns'    => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
@@ -319,10 +317,10 @@ class Xrd extends BaseModule
                                        ]
                                ],
                        ],
-               ], $xml);
+               ]);
 
                header('Access-Control-Allow-Origin: *');
 
-               System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
+               System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml');
        }
 }
index bf6bfdd63dcefd078ff2fa36e4e86d40e198b15c..c0d0bc051073c48740223a9896b631dd01eb2f5d 100644 (file)
@@ -2855,7 +2855,7 @@ class Diaspora
 
                $namespaces = ['me' => ActivityNamespace::SALMON_ME];
 
-               return XML::fromArray($xmldata, $xml, false, $namespaces);
+               return XML::fromArray($xmldata, $dummy, false, $namespaces);
        }
 
        /**
@@ -2974,12 +2974,11 @@ class Diaspora
         * @param array  $message The message data
         *
         * @return string The post XML
+        * @throws \Exception
         */
        public static function buildPostXml(string $type, array $message): string
        {
-               $data = [$type => $message];
-
-               return XML::fromArray($data, $xml);
+               return XML::fromArray([$type => $message]);
        }
 
        /**
index 7685c1dd97584177e942d9f55e32a4804a42feb3..50d1b931c9d4c91f29cffea0698809a9b4c2c558 100644 (file)
@@ -160,7 +160,7 @@ class Salmon
 
                $namespaces = ['me' => ActivityNamespace::SALMON_ME];
 
-               $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
+               $salmon = XML::fromArray($xmldata, $dummy, false, $namespaces);
 
                // slap them
                $postResult = DI::httpClient()->post($url, $salmon, [
@@ -187,9 +187,7 @@ class Salmon
                                ]
                        ];
 
-                       $namespaces = ['me' => ActivityNamespace::SALMON_ME];
-
-                       $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
+                       $salmon = XML::fromArray($xmldata, $dummy, false, $namespaces);
 
                        // slap them
                        $postResult = DI::httpClient()->post($url, $salmon, [
@@ -214,9 +212,7 @@ class Salmon
                                ]
                        ];
 
-                       $namespaces = ['me' => ActivityNamespace::SALMON_ME];
-
-                       $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
+                       $salmon = XML::fromArray($xmldata, $dummy, false, $namespaces);
 
                        // slap them
                        $postResult = DI::httpClient()->post($url, $salmon, [
index 50ecc6d2cbe4bb1dffca672cfee9c3096d5669ca..0cdf1f34ed2f48db15e2b12bb6a214cf38487132 100644 (file)
@@ -37,14 +37,15 @@ class XML
        /**
         * Creates an XML structure out of a given array
         *
-        * @param array  $array         The array of the XML structure that will be generated
-        * @param object $xml           The created XML will be returned by reference
-        * @param bool   $remove_header Should the XML header be removed or not?
-        * @param array  $namespaces    List of namespaces
-        * @param bool   $root          interally used parameter. Mustn't be used from outside.
+        * @param array       $array         The array of the XML structure that will be generated
+        * @param object|null $xml           The created XML will be returned by reference
+        * @param bool        $remove_header Should the XML header be removed or not?
+        * @param array       $namespaces    List of namespaces
+        * @param bool        $root          interally used parameter. Mustn't be used from outside.
         * @return string
+        * @throws \Exception
         */
-       public static function fromArray(array $array, &$xml, bool $remove_header = false, array $namespaces = [], bool $root = true): string
+       public static function fromArray(array $array, object &$xml = null, bool $remove_header = false, array $namespaces = [], bool $root = true): string
        {
                if ($root) {
                        foreach ($array as $key => $value) {
@@ -125,7 +126,7 @@ class XML
 
                        if (!is_array($value)) {
                                $element = $xml->addChild($key, self::escape($value ?? ''), $namespace);
-                       } elseif (is_array($value)) {
+                       } else {
                                $element = $xml->addChild($key, null, $namespace);
                                self::fromArray($value, $element, $remove_header, $namespaces, false);
                        }