Browse Source

Rewrite for PHP7.4

Joachim M. Giæver 2 years ago
parent
commit
b5ff5b1ebc
9 changed files with 115 additions and 54 deletions
  1. 6 1
      composer.json
  2. 13 10
      composer.lock
  3. 1 1
      src/AbstractPostSerializable.php
  4. 14 3
      src/Assigment.php
  5. 12 17
      src/Client.php
  6. 25 8
      src/ClientConfig.php
  7. 18 6
      src/Customer.php
  8. 13 4
      src/Prospectus.php
  9. 13 4
      src/Questionaire.php

+ 6 - 1
composer.json

@@ -8,12 +8,17 @@
         "name": "Joachim M. Giaever",
         "email": "joachim@giaever.online"
     }],
+    "config": {
+        "platform": {
+            "php": "7.4"
+        }
+    },
     "autoload": {
         "psr-4": {
             "DNB\\": "src/"
         }
     },
     "require": {
-        "symfony/http-client": "^5.3"
+        "symfony/http-client": "^5.1"
     }
 }

+ 13 - 10
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "ea60d84ee2ac4e529040e18b98cc7513",
+    "content-hash": "bcf9e00a58e257b19da296bdad96f18b",
     "packages": [
         {
             "name": "psr/container",
@@ -56,30 +56,30 @@
         },
         {
             "name": "psr/log",
-            "version": "3.0.0",
+            "version": "1.1.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/php-fig/log.git",
-                "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001"
+                "reference": "d49695b909c3b7628b6289db5479a1c204601f11"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001",
-                "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001",
+                "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11",
+                "reference": "d49695b909c3b7628b6289db5479a1c204601f11",
                 "shasum": ""
             },
             "require": {
-                "php": ">=8.0.0"
+                "php": ">=5.3.0"
             },
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "3.x-dev"
+                    "dev-master": "1.1.x-dev"
                 }
             },
             "autoload": {
                 "psr-4": {
-                    "Psr\\Log\\": "src"
+                    "Psr\\Log\\": "Psr/Log/"
                 }
             },
             "notification-url": "https://packagist.org/downloads/",
@@ -100,9 +100,9 @@
                 "psr-3"
             ],
             "support": {
-                "source": "https://github.com/php-fig/log/tree/3.0.0"
+                "source": "https://github.com/php-fig/log/tree/1.1.4"
             },
-            "time": "2021-07-14T16:46:02+00:00"
+            "time": "2021-05-03T11:20:27+00:00"
         },
         {
             "name": "symfony/deprecation-contracts",
@@ -586,5 +586,8 @@
     "prefer-lowest": false,
     "platform": [],
     "platform-dev": [],
+    "platform-overrides": {
+        "php": "7.4"
+    },
     "plugin-api-version": "2.0.0"
 }

+ 1 - 1
src/AbstractPostSerializable.php

@@ -9,7 +9,7 @@ abstract class AbstractPostSerializable implements PostSerializableInterface {
         foreach (static::getClassVars() as $key)
             $vars[$key] = isset($post[$key]) && ((bool)$post[$key]) && strtolower((string)$post[$key]) != "off" ? htmlspecialchars($post[$key], ENT_QUOTES | ENT_SUBSTITUTE) : null;
 
-        return new static(...$vars);
+        return new static(...array_values($vars));
     }
 
     abstract protected static function getClassVars(): array;

+ 14 - 3
src/Assigment.php

@@ -5,10 +5,21 @@ namespace DNB;
 use ArrayIterator;
 
 class Assigment extends AbstractPostSerializable implements PostSerializableInterface {
+    
+    private string $assignmentNumber;
+    private ?string $name;
+
     public function __construct(
-        private string $assignmentNumber,
-        private ?string $name
-    ){}
+        string $assignmentNumber,
+        ?string $name
+    ){
+        $this->assignmentNumber = $assignmentNumber;
+        $this->name = $name;
+    }
+
+    public function getName(): string {
+        return $this->name;
+    }
 
     public function toPostParams(): array {
         return [

+ 12 - 17
src/Client.php

@@ -7,9 +7,11 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
 
 final class Client {
     private HttpClientInterface $client;
+    private ClientConfig $clientConfig;
     private object $auth;
 
-    public function __construct(private ClientConfig $clientConfig) {
+    public function __construct(ClientConfig $clientConfig) {
+        $this->clientConfig = $clientConfig;
         $this->client = HttpClient::create(
             [
                 'headers' => [
@@ -44,10 +46,15 @@ final class Client {
             $result['access_token'],
             $result['token_type']
         ) {
+            private string $token;
+            private string $type;
             public function __construct(
-                private string $token,
-                private string $type,
-            ) {}
+                string $token,
+                string $type
+            ) {
+                $this->token = $token;
+                $this->type = $type;
+            }
 
             public function getHeader(): string {
                 return sprintf("%s %s", $this->type, $this->token);
@@ -64,7 +71,7 @@ final class Client {
     }
 
     public function orderProspectus(
-        Prospectus $prospectus,
+        Prospectus $prospectus
     ): bool {
         $ret = $this->getAuthClient()->request(
             "POST",
@@ -73,18 +80,6 @@ final class Client {
             ]
         );
         var_dump($ret->getContent(false));
-
-        // var_dump($params, $this, $this->getAuthClient());
-        //
-        // $this->getAuthClient()->request(
-        //     'POST',
-        //     $this->getUrl(
-        //         $this->clientConfig->get()->endpoint,
-        //         "/api/v1/autoprospect/orderprospect"
-        //     ), [
-        //         'json' => $params
-        //     ]
-        // );
         return false;
     }
 }

+ 25 - 8
src/ClientConfig.php

@@ -4,11 +4,18 @@ namespace DNB;
 
 final class ClientConfig {
 
+    private string $id;
+    private string $secret;
+    private bool $is_test;
+
     public function __construct(
-        private string $id,
-        private string $secret,
-        private bool $is_test = true,
+        string $id,
+        string $secret,
+        bool $is_test = true
     ) {
+        $this->id = $id;
+        $this->secret = $secret;
+        $this->is_test = $is_test;
     }
 
     public function get(): object {
@@ -18,12 +25,22 @@ final class ClientConfig {
             $this->is_test ? 'uat-process-externalpart' : 'dnb-process-externalpart',
             $this->is_test ? 'uat-nextgen-identityserver' : 'dnb-nextgen-identityserver',
         ) {
+            public string $id;
+            public string $secret;
+            public string $endpoint;
+            public string $auth_endpoint;
+
             public function __construct(
-                public string $id,
-                public string $secret,
-                public string $endpoint,
-                public string $auth_endpoint,
-            ) { }
+                string $id,
+                string $secret,
+                string $endpoint,
+                string $auth_endpoint
+            ) { 
+                $this->id = $id;
+                $this->secret = $secret;
+                $this->endpoint = $endpoint;
+                $this->auth_endpoint = $auth_endpoint;
+            }
         };
     }
 }

+ 18 - 6
src/Customer.php

@@ -3,13 +3,25 @@
 namespace DNB;
 
 class Customer extends AbstractPostSerializable implements PostSerializableInterface {
+    private string $name;
+    private ?string $email;
+    private string $mobilePhone;
+    private ?string $zipCode;
+    private ?string $comment;
+
     public function __construct(
-        private string $name,
-        private ?string $email,
-        private string $mobilePhone,
-        private ?string $zipCode = null,
-        private ?string $comment = null,
-    ) {}
+        string $name,
+        ?string $email,
+        string $mobilePhone,
+        ?string $zipCode = null,
+        ?string $comment = null
+    ) {
+        $this->name = $name;
+        $this->email = $email;
+        $this->mobilePhone = $mobilePhone;
+        $this->zipCode = $zipCode;
+        $this->comment = $comment;
+    }
 
     public function toPostParams(): array {
         $arr = [];

+ 13 - 4
src/Prospectus.php

@@ -3,11 +3,20 @@
 namespace DNB;
 
 class Prospectus extends AbstractPostSerializable implements PostSerializableInterface {
+
+    private Assigment $assigment;
+    private Questionaire $questionaire;
+    private Customer $customer;
+
     public function __construct(
-        private Assigment $assigment,
-        private Questionaire $questionaire,
-        private Customer $customer,
-    ) {}
+        Assigment $assigment,
+        Questionaire $questionaire,
+        Customer $customer
+    ) {
+        $this->assigment = $assigment;
+        $this->questionaire = $questionaire;
+        $this->customer = $customer;
+    }
 
     public function toPostParams(): array {
         return array_merge(

+ 13 - 4
src/Questionaire.php

@@ -3,11 +3,20 @@
 namespace DNB;
 
 class Questionaire extends AbstractPostSerializable implements PostSerializableInterface {
+
+    private ?bool $keepMeInformedOnBids;
+    private ?bool $contactForPropertyValuation;
+    private ?bool $contactForEconomicalAdvice;
+
     public function __construct(
-        private ?bool $keepMeInformedOnBids = null,
-        private ?bool $contactForPropertyValuation = null,
-        private ?bool $contactForEconomicalAdvice = null,
-    ){}
+        ?bool $keepMeInformedOnBids = null,
+        ?bool $contactForPropertyValuation = null,
+        ?bool $contactForEconomicalAdvice = null
+    ){
+        $this->keepMeInformedOnBids = $keepMeInformedOnBids;
+        $this->contactForPropertyValuation = $contactForPropertyValuation;
+        $this->contactForEconomicalAdvice = $contactForEconomicalAdvice;
+    }
 
     public function toPostParams(): array {
         $arr = [];