[TikiWiki-commits] [Git][tikiwiki/tiki][master] [REF] PSR12 Migration Changes For ShippingLib

"SoftStart Code \(@softstartcode\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68a5ab454d75c_2c2b54a94227de@gitlab-sidekiq-low-urgency-cpu-bound-v2-78d9d68c78-f7htq.mail>

SoftStart Code pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
cb0e1d51 by Sandeep D at 2025-08-20T10:54:25+00:00
[REF] PSR12 Migration Changes For ShippingLib
---
* [REF] PSR12 Migration Changes For ShippingLib

See merge request tikiwiki/tiki!8336

- - - - -


18 changed files:

- .gitattributes
- doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json
- + lib/Shipping/Provider/AbstractCustomShippingProvider.php
- lib/shipping/custom/example.php → lib/Shipping/Provider/Custom/Example.php
- lib/shipping/provider_fedex.php → lib/Shipping/Provider/Fedex.php
- + lib/Shipping/Provider/ShippingProviderInterface.php
- lib/shipping/provider_ups.php → lib/Shipping/Provider/Ups.php
- lib/shipping/FedEx_v8.wsdl → lib/Shipping/Provider/wsdl/fedex/FedEx_v8.wsdl
- lib/shipping/ups-wsdl/Error1.1.xsd → lib/Shipping/Provider/wsdl/ups/Error1.1.xsd
- lib/shipping/ups-wsdl/RateWS.wsdl → lib/Shipping/Provider/wsdl/ups/RateWS.wsdl
- lib/shipping/ups-wsdl/RateWebServiceSchema.xsd → lib/Shipping/Provider/wsdl/ups/RateWebServiceSchema.xsd
- lib/shipping/ups-wsdl/UPSSecurity.xsd → lib/Shipping/Provider/wsdl/ups/UPSSecurity.xsd
- lib/shipping/ups-wsdl/common.xsd → lib/Shipping/Provider/wsdl/ups/common.xsd
- lib/shipping/shippinglib.php → lib/Shipping/ShippingLib.php
- lib/core/Tiki/PSR12Migration/Autoload.php
- lib/prefs/shipping.php
- lib/test/shipping/ShippingTest.php
- tiki-ajax_services.php


Changes:

=====================================
.gitattributes
=====================================
@@ -4053,19 +4053,21 @@ lib/Sheet/ole/pps/file.php -text
 lib/Sheet/ole/pps/index.php -text
 lib/Sheet/ole/pps/root.php -text
 lib/Sheet/sheetlib.php -text
-lib/shipping/FedEx_v8.wsdl -text
-lib/shipping/custom/example.php -text
-lib/shipping/custom/index.php -text
-lib/shipping/index.php -text
-lib/shipping/provider_fedex.php -text
-lib/shipping/provider_ups.php -text
-lib/shipping/shippinglib.php -text
-lib/shipping/ups-wsdl/Error1.1.xsd -text
-lib/shipping/ups-wsdl/RateWS.wsdl -text
-lib/shipping/ups-wsdl/RateWebServiceSchema.xsd -text
-lib/shipping/ups-wsdl/UPSSecurity.xsd -text
-lib/shipping/ups-wsdl/common.xsd -text
-lib/shipping/ups-wsdl/index.php -text
+lib/Shipping/Provider/wsdl/fedex/FedEx_v8.wsdl -text
+lib/Shipping/Provider/Custom/Example.php -text
+lib/Shipping/Provider/Custom/index.php -text
+lib/Shipping/index.php -text
+lib/Shipping/Provider/AbstractCustomShippingProvider.php -text
+lib/Shipping/Provider/ShippingProviderInterface.php -text
+lib/Shipping/Provider/Fedex.php -text
+lib/Shipping/Provider/Ups.php -text
+lib/Shipping/ShippingLib.php -text
+lib/Shipping/Provider/wsdl/ups/Error1.1.xsd -text
+lib/Shipping/Provider/wsdl/ups/RateWS.wsdl -text
+lib/Shipping/Provider/wsdl/ups/RateWebServiceSchema.xsd -text
+lib/Shipping/Provider/wsdl/ups/UPSSecurity.xsd -text
+lib/Shipping/Provider/wsdl/ups/common.xsd -text
+lib/Shipping/Provider/wsdl/ups/index.php -text
 lib/shoutbox/index.php -text
 lib/shoutbox/shoutboxlib.php -text
 lib/simile_tiki/index.php -text


=====================================
doc/devtools/codesniffer/standards/TikiIgnore/ignore_list.json
=====================================
@@ -3211,20 +3211,6 @@
         "lib\/trackers\/trackerlib.php": {
             "class:TrackerLib": true
         },
-        "lib\/shipping\/shippinglib.php": {
-            "interface:ShippingProvider": true,
-            "class:CustomShippingProvider": true,
-            "class:ShippingLib": true
-        },
-        "lib\/shipping\/provider_ups.php": {
-            "class:ShippingProvider_Ups": true
-        },
-        "lib\/shipping\/custom\/example.php": {
-            "class:CustomShippingProvider_Example": true
-        },
-        "lib\/shipping\/provider_fedex.php": {
-            "class:ShippingProvider_Fedex": true
-        },
         "lib\/soap\/wsdllib.php": {
             "class:Tiki_Wsdl": true
         },
@@ -6177,15 +6163,6 @@
         "lib\/user\/blacklistlib.php": {
             "blacklistLib": true
         },
-        "lib\/shipping\/provider_ups.php": {
-            "ShippingProvider_Ups": true
-        },
-        "lib\/shipping\/custom\/example.php": {
-            "CustomShippingProvider_Example": true
-        },
-        "lib\/shipping\/provider_fedex.php": {
-            "ShippingProvider_Fedex": true
-        },
         "lib\/soap\/wsdllib.php": {
             "Tiki_Wsdl": true
         },
@@ -6235,12 +6212,7 @@
             "DbgCmd_Watch": true
         }
     },
-    "PSR1.Classes.ClassDeclaration.MultipleClasses": {
-        "lib\/shipping\/shippinglib.php": {
-            "class:CustomShippingProvider": true,
-            "class:ShippingLib": true
-        }
-    },
+    "PSR1.Classes.ClassDeclaration.MultipleClasses": {},
     "PSR1.Methods.CamelCapsMethodName.NotCamelCaps": {
         "tiki-check.php": {
             "BenchmarkPhp::test_benchmark": true,


=====================================
lib/Shipping/Provider/AbstractCustomShippingProvider.php
=====================================
@@ -0,0 +1,12 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+namespace Tiki\Lib\Shipping\Provider;
+
+abstract class AbstractCustomShippingProvider implements ShippingProviderInterface
+{
+    abstract public function getName();
+}


=====================================
lib/shipping/custom/example.php → lib/Shipping/Provider/Custom/Example.php
=====================================
@@ -11,10 +11,11 @@
  * Declare the options you require in the constructor
  * and the logic to caluculate the price etc (in this case) in getRate
  */
+namespace Tiki\Lib\Shipping\Provider\Custom;
 
-require_once 'lib/shipping/shippinglib.php';
+use Tiki\Lib\Shipping\Provider\AbstractCustomShippingProvider as CustomShippingProvider;
 
-class CustomShippingProvider_Example extends CustomShippingProvider
+class Example extends CustomShippingProvider
 {
     private $services;
 


=====================================
lib/shipping/provider_fedex.php → lib/Shipping/Provider/Fedex.php
=====================================
@@ -4,7 +4,13 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
-class ShippingProvider_Fedex implements ShippingProvider
+namespace Tiki\Lib\Shipping\Provider;
+
+use SoapClient;
+use SoapFault;
+use Tiki\Lib\Shipping\Provider\ShippingProviderInterface as ShippingProvider;
+
+class Fedex implements ShippingProvider
 {
     public $account;
     private $key;
@@ -24,7 +30,7 @@ class ShippingProvider_Fedex implements ShippingProvider
             return [];
         }
 
-        $wsdl = __DIR__ . '/FedEx_v8.wsdl';
+        $wsdl = __DIR__ . '/wsdl/fedex/FedEx_v8.wsdl';
         $args = [];
 
         $request = $this->getRequest($from, $to, $packages);


=====================================
lib/Shipping/Provider/ShippingProviderInterface.php
=====================================
@@ -0,0 +1,12 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+namespace Tiki\Lib\Shipping\Provider;
+
+interface ShippingProviderInterface
+{
+    public function getRates(array $from, array $to, array $packages);
+}


=====================================
lib/shipping/provider_ups.php → lib/Shipping/Provider/Ups.php
=====================================
@@ -4,9 +4,16 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
-require_once 'lib/shipping/shippinglib.php';
+namespace Tiki\Lib\Shipping\Provider;
 
-class ShippingProvider_Ups implements ShippingProvider
+use DOMDocument;
+use DOMXPath;
+use Laminas\Http\Client\Exception\ExceptionInterface;
+use Laminas\Http\Request;
+use Tiki\Lib\Shipping\Provider\ShippingProviderInterface as ShippingProvider;
+use TikiLib;
+
+class Ups implements ShippingProvider
 {
     private $username;
     private $password;
@@ -44,7 +51,7 @@ class ShippingProvider_Ups implements ShippingProvider
             $client->setUri('https://www.ups.com/ups.app/xml/Rate');
             $client->setRawBody($auth . $request);
 
-            $client->setMethod(Laminas\Http\Request::METHOD_POST);
+            $client->setMethod(Request::METHOD_POST);
             $response = $client->send();
             $body = $response->getBody();
 
@@ -52,7 +59,7 @@ class ShippingProvider_Ups implements ShippingProvider
             $dom->loadXML($body);
 
             return $dom;
-        } catch (Laminas\Http\Exception\ExceptionInterface $e) {
+        } catch (ExceptionInterface $e) {
             return null;
         }
     }


=====================================
lib/shipping/FedEx_v8.wsdl → lib/Shipping/Provider/wsdl/fedex/FedEx_v8.wsdl
=====================================


=====================================
lib/shipping/ups-wsdl/Error1.1.xsd → lib/Shipping/Provider/wsdl/ups/Error1.1.xsd
=====================================


=====================================
lib/shipping/ups-wsdl/RateWS.wsdl → lib/Shipping/Provider/wsdl/ups/RateWS.wsdl
=====================================


=====================================
lib/shipping/ups-wsdl/RateWebServiceSchema.xsd → lib/Shipping/Provider/wsdl/ups/RateWebServiceSchema.xsd
=====================================


=====================================
lib/shipping/ups-wsdl/UPSSecurity.xsd → lib/Shipping/Provider/wsdl/ups/UPSSecurity.xsd
=====================================


=====================================
lib/shipping/ups-wsdl/common.xsd → lib/Shipping/Provider/wsdl/ups/common.xsd
=====================================


=====================================
lib/shipping/shippinglib.php → lib/Shipping/ShippingLib.php
=====================================
@@ -4,15 +4,12 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
-interface ShippingProvider
-{
-    public function getRates(array $from, array $to, array $packages);
-}
+namespace Tiki\Lib\Shipping;
 
-abstract class CustomShippingProvider implements ShippingProvider
-{
-    abstract public function getName();
-}
+use Feedback;
+use Tiki\Lib\Shipping\Provider\ShippingProviderInterface as ShippingProvider;
+use Tiki\Lib\Shipping\Provider\Fedex;
+use Tiki\Lib\Shipping\Provider\Ups;
 
 class ShippingLib
 {
@@ -22,6 +19,38 @@ class ShippingLib
         '/^[0-9]{5}$/' => 'US',
     ];
 
+    public function __construct()
+    {
+        global $prefs;
+
+        if (! empty($prefs['shipping_fedex_enable']) && $prefs['shipping_fedex_enable'] === 'y') {
+            $this->addProvider(
+                new Fedex([
+                    'key' => $prefs['shipping_fedex_key'],
+                    'password' => $prefs['shipping_fedex_password'],
+                    'meter' => $prefs['shipping_fedex_meter'],
+                ])
+            );
+        }
+
+        if (! empty($prefs['shipping_ups_enable']) && $prefs['shipping_ups_enable'] === 'y') {
+            $this->addProvider(
+                new Ups([
+                    'username' => $prefs['shipping_ups_username'],
+                    'password' => $prefs['shipping_ups_password'],
+                    'license' => $prefs['shipping_ups_license'],
+                ])
+            );
+        }
+
+        if (! empty($prefs['shipping_custom_provider'])) {
+            $customProvider = self::getCustomShippingProvider($prefs['shipping_custom_provider']);
+            if ($customProvider !== null) {
+                $this->addProvider($customProvider);
+            }
+        }
+    }
+
     public function addProvider(ShippingProvider $provider)
     {
         $this->providers[] = $provider;
@@ -83,49 +112,27 @@ class ShippingLib
 
     public static function getCustomShippingProvider($name)
     {
+        $file = __DIR__ . '/Provider/Custom/' . $name . '.php';
+        $customShippingProvider = ucfirst($name);
+        $class = "\\Tiki\\Lib\\Shipping\\Provider\\Custom\\$customShippingProvider";
 
-        $file = __DIR__ . '/custom/' . $name . '.php';
-        $className = 'CustomShippingProvider_' . ucfirst($name);
-        if (is_readable($file)) {
-            require_once $file;
-            if (class_exists($className) && method_exists($className, 'getName')) {
-                $provider = new $className();
-                return $provider;
-            }
+        if (! is_readable($file)) {
+            Feedback::error(tr('Custom Shipping Provider file "%0" does not exist.', $file));
+            return null;
         }
-        Feedback::error(tr('Problem reading custom shipping provider "%0"', $name));
-    }
-}
 
-global $shippinglib, $prefs;
-$shippinglib = new ShippingLib();
-
-if (! empty($prefs['shipping_fedex_enable']) && $prefs['shipping_fedex_enable'] === 'y') {
-    require_once 'lib/shipping/provider_fedex.php';
-    $shippinglib->addProvider(
-        new ShippingProvider_FedEx(
-            [
-                'key' => $prefs['shipping_fedex_key'],
-                'password' => $prefs['shipping_fedex_password'],
-                'meter' => $prefs['shipping_fedex_meter'],
-            ]
-        )
-    );
-}
+        if (! class_exists($class)) {
+            Feedback::error(tr('Custom Shipping Provider "%0" does not exist.', $name));
+            return null;
+        }
 
-if (! empty($prefs['shipping_ups_enable']) && $prefs['shipping_ups_enable'] === 'y') {
-    require_once 'lib/shipping/provider_ups.php';
-    $shippinglib->addProvider(
-        new ShippingProvider_Ups(
-            [
-                'username' => $prefs['shipping_ups_username'],
-                'password' => $prefs['shipping_ups_password'],
-                'license' => $prefs['shipping_ups_license'],
-            ]
-        )
-    );
-}
+        if (! method_exists($class, 'getName')) {
+            Feedback::error(tr('Custom Shipping Provider "%0" does not contains getName() method.', $name));
+            return null;
+        }
 
-if (! empty($prefs['shipping_custom_provider'])) {
-    $shippinglib->addProvider(ShippingLib::getCustomShippingProvider($prefs['shipping_custom_provider']));
+        $provider = new $class();
+
+        return $provider;
+    }
 }


=====================================
lib/core/Tiki/PSR12Migration/Autoload.php
=====================================
@@ -155,6 +155,12 @@ class Autoload
         'Tiki_Security_Policy' => 'Tiki\\Smarty\\SecurityPolicy',
         'Smarty_Tiki' => 'Tiki\\Smarty\\SmartyTiki',
         'SmartyTikiErrorHandler' => 'Tiki\\Smarty\\SmartyTikiErrorHandler',
+        'ShippingProvider' => 'Tiki\\Lib\\Shipping\\Provider\\ShippingProviderInterface',
+        'ShippingProvider_Fedex' => 'Tiki\\Lib\\Shipping\\Provider\\Fedex',
+        'ShippingProvider_Ups' => 'Tiki\\Lib\\Shipping\\Provider\\Ups',
+        'CustomShippingProvider' => 'Tiki\\Lib\\Shipping\\Provider\\AbstractCustomShippingProvider',
+        'CustomShippingProvider_Example' => 'Tiki\\Lib\\Shipping\\Provider\\Custom\\Example',
+        'ShippingLib' => 'Tiki\\Lib\\Shipping\\ShippingLib',
         'StyleType' => 'SmartyTiki\\Utils\\StyleType',
         'SmartyKint' => 'SmartyTiki\\Utils\\SmartyKint',
         'TikiAcceptanceTestDBRestorer' => 'Tiki\\Lib\\Test\\AcceptanceTests\\AbstractDBRestorer',


=====================================
lib/prefs/shipping.php
=====================================
@@ -4,15 +4,17 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+use Tiki\Lib\Shipping\ShippingLib;
+
 function prefs_shipping_list()
 {
-    require_once __DIR__ . '/../shipping/shippinglib.php';
-    $all = glob('lib/shipping/custom/*.php');
+    $all = glob('lib/Shipping/Provider/Custom/*.php');
 
     $custom_providers = [ '' => tra('None')];
 
     foreach ($all as $file) {
-        if ($file === "lib/shipping/custom/index.php") {
+        if ($file === "lib/Shipping/Provider/Custom/index.php") {
             continue;
         }
         $name = basename($file, '.php');


=====================================
lib/test/shipping/ShippingTest.php
=====================================
@@ -5,7 +5,8 @@
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
 
-require_once __DIR__ . '/../../shipping/shippinglib.php';
+use Tiki\Lib\Shipping\Provider\ShippingProviderInterface as ShippingProvider;
+use Tiki\Lib\Shipping\ShippingLib;
 
 class ShippingTest extends TikiTestCase implements ShippingProvider
 {


=====================================
tiki-ajax_services.php
=====================================
@@ -16,6 +16,9 @@
 // will be serialized and sent to the browser.
 //
 // Otherwise, the procedural script remains
+
+use Tiki\Lib\Shipping\ShippingLib;
+
 $inputConfiguration = [[
     'staticKeyFilters' => [
         'action' => 'word',         //get
@@ -168,8 +171,7 @@ if ($access->is_serializable_request() && $jitRequest->offsetExists('listonly'))
         read_icon_dir($dir, $icons, $max, $query);
         $access->output_serialized($icons);
     } elseif ($listonly == 'shipping' && $prefs['shipping_service'] == 'y') {
-        global $shippinglib;
-        require_once 'lib/shipping/shippinglib.php';
+        $shippinglib = new ShippingLib();
 
         $access->output_serialized($shippinglib->getRates($_REQUEST['from'], $_REQUEST['to'], $_REQUEST['packages']));
     } elseif ($listonly == 'trackername') {



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/cb0e1d51c76dc0fb341ed8a48c5c7bedbd011e2e

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/cb0e1d51c76dc0fb341ed8a48c5c7bedbd011e2e
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.