You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by fo...@apache.org on 2020/05/11 06:59:32 UTC

[avro] branch master updated: AVRO-2751: Upgrade Compatibility to PHP 7.4 (#876)

This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 46d87d9  AVRO-2751: Upgrade Compatibility to PHP 7.4 (#876)
46d87d9 is described below

commit 46d87d9aa8964684e602f114292825b9fd5c2554
Author: Siad Ardroumli <si...@googlemail.com>
AuthorDate: Mon May 11 08:59:21 2020 +0200

    AVRO-2751: Upgrade Compatibility to PHP 7.4 (#876)
    
    * Fix deprecated issues under PHP 7.4
    
    * Removed unused
    
    * Removed outdated php versions
---
 lang/php/lib/avro/data_file.php        | 10 +++++-----
 lang/php/lib/avro/datum.php            |  2 +-
 lang/php/lib/avro/protocol.php         |  9 +++++----
 lang/php/test/DataFileTest.php         |  8 ++++----
 lang/php/test/FloatIntEncodingTest.php |  2 +-
 lang/php/test/InterOpTest.php          |  2 +-
 lang/php/test/LongEncodingTest.php     |  2 +-
 lang/php/test/ProtocolFileTest.php     |  2 +-
 share/docker/Dockerfile                | 13 +++----------
 9 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/lang/php/lib/avro/data_file.php b/lang/php/lib/avro/data_file.php
index 4271897..420f079 100644
--- a/lang/php/lib/avro/data_file.php
+++ b/lang/php/lib/avro/data_file.php
@@ -165,7 +165,7 @@ class AvroDataIO
    * @param string $codec
    * @returns AvroDataIOWriter
    */
-  protected function open_writer($io, $schema, $codec=self::NULL_CODEC)
+  protected static function open_writer($io, $schema, $codec=self::NULL_CODEC)
   {
     $writer = new AvroIODatumWriter($schema);
     return new AvroDataIOWriter($io, $writer, $schema, $codec);
@@ -176,7 +176,7 @@ class AvroDataIO
    * @param AvroSchema $schema
    * @returns AvroDataIOReader
    */
-  protected function open_reader($io, $schema)
+  protected static function open_reader($io, $schema)
   {
     $reader = new AvroIODatumReader(null, $schema);
     return new AvroDataIOReader($io, $reader);
@@ -209,12 +209,12 @@ class AvroDataIOReader
   /**
    * @var string
    */
-  private $sync_marker;
+  public $sync_marker;
 
   /**
    * @var array object container metadata
    */
-  private $metadata;
+  public $metadata;
 
   /**
    * @var int count of items in block
@@ -451,7 +451,7 @@ class AvroDataIOWriter
 
       $this->sync_marker = self::generate_sync_marker();
       $this->metadata[AvroDataIO::METADATA_CODEC_ATTR] = $this->codec = $codec;
-      $this->metadata[AvroDataIO::METADATA_SCHEMA_ATTR] = strval($writers_schema);
+      $this->metadata[AvroDataIO::METADATA_SCHEMA_ATTR] = (string) $writers_schema;
       $this->write_header();
     }
     else
diff --git a/lang/php/lib/avro/datum.php b/lang/php/lib/avro/datum.php
index 8e99e4d..68cb4ea 100644
--- a/lang/php/lib/avro/datum.php
+++ b/lang/php/lib/avro/datum.php
@@ -943,7 +943,7 @@ class AvroIOBinaryDecoder
 
   public function skip_int() { return $this->skip_long(); }
 
-  protected function skip_long()
+  public function skip_long()
   {
     $b = $this->next_byte();
     while (0 != (ord($b) & 0x80))
diff --git a/lang/php/lib/avro/protocol.php b/lang/php/lib/avro/protocol.php
index 59ed720..543dd5e 100644
--- a/lang/php/lib/avro/protocol.php
+++ b/lang/php/lib/avro/protocol.php
@@ -30,6 +30,7 @@ class AvroProtocol
   public $name;
   public $namespace;
   public $schemata;
+  public $messages;
 
   public static function parse($json)
   {
@@ -54,7 +55,7 @@ class AvroProtocol
     if (!is_null($avro["messages"])) {
       foreach ($avro["messages"] as $messageName => $messageAvro) {
         $message = new AvroProtocolMessage($messageName, $messageAvro, $this);
-        $this->messages{$messageName} = $message;
+        $this->messages[$messageName] = $message;
       }
     }
   }
@@ -73,12 +74,12 @@ class AvroProtocolMessage
   public function __construct($name, $avro, $protocol)
   {
     $this->name = $name;
-    $this->request = new AvroRecordSchema(new AvroName($name, null, $protocol->namespace), null, $avro{'request'}, $protocol->schemata, AvroSchema::REQUEST_SCHEMA);
+    $this->request = new AvroRecordSchema(new AvroName($name, null, $protocol->namespace), null, $avro['request'], $protocol->schemata, AvroSchema::REQUEST_SCHEMA);
 
     if (array_key_exists('response', $avro)) {
-      $this->response = $protocol->schemata->schema_by_name(new AvroName($avro{'response'}, $protocol->namespace, $protocol->namespace));
+      $this->response = $protocol->schemata->schema_by_name(new AvroName($avro['response'], $protocol->namespace, $protocol->namespace));
       if ($this->response == null)
-        $this->response = new AvroPrimitiveSchema($avro{'response'});
+        $this->response = new AvroPrimitiveSchema($avro['response']);
     }
   }
 }
diff --git a/lang/php/test/DataFileTest.php b/lang/php/test/DataFileTest.php
index 5f7214f..f7befd4 100644
--- a/lang/php/test/DataFileTest.php
+++ b/lang/php/test/DataFileTest.php
@@ -47,17 +47,17 @@ class DataFileTest extends PHPUnit\Framework\TestCase
     if (self::REMOVE_DATA_FILES
         && !empty($this->data_files))
       foreach ($this->data_files as $data_file)
-        $this->remove_data_file($data_file);
+        self::remove_data_file($data_file);
   }
 
-  protected function setUp()
+  protected function setUp(): void
   {
     if (!file_exists(TEST_TEMP_DIR))
       mkdir(TEST_TEMP_DIR);
     $this->remove_data_files();
   }
 
-  protected function tearDown()
+  protected function tearDown(): void
   {
     $this->remove_data_files();
   }
@@ -192,7 +192,7 @@ class DataFileTest extends PHPUnit\Framework\TestCase
   public function test_differing_schemas_with_primitives()
   {
     foreach (AvroDataIO::valid_codecs() as $codec) {
-      $data_file = $this->add_data_file('data-prim-%s.avr', $codec);
+      $data_file = $this->add_data_file('data-prim-%s.avr');
 
       $writer_schema = <<<JSON
 { "type": "record",
diff --git a/lang/php/test/FloatIntEncodingTest.php b/lang/php/test/FloatIntEncodingTest.php
index 27b4dea..957fab9 100644
--- a/lang/php/test/FloatIntEncodingTest.php
+++ b/lang/php/test/FloatIntEncodingTest.php
@@ -54,7 +54,7 @@ class FloatIntEncodingTest extends PHPUnit\Framework\TestCase
     self::$INT_BITS_NEG_INF  = strrev(pack('H*', 'ff800000'));
   }
 
-  function setUp()
+  function setUp(): void
   {
     self::make_special_vals();
   }
diff --git a/lang/php/test/InterOpTest.php b/lang/php/test/InterOpTest.php
index c92b87d..95ad732 100644
--- a/lang/php/test/InterOpTest.php
+++ b/lang/php/test/InterOpTest.php
@@ -24,7 +24,7 @@ class InterOpTest extends PHPUnit\Framework\TestCase
   var $projection_json;
   var $projection;
 
-  public function setUp()
+  public function setUp(): void
   {
     $interop_schema_file_name = AVRO_INTEROP_SCHEMA;
     $this->projection_json = file_get_contents($interop_schema_file_name);
diff --git a/lang/php/test/LongEncodingTest.php b/lang/php/test/LongEncodingTest.php
index 102a539..4cd8e8e 100644
--- a/lang/php/test/LongEncodingTest.php
+++ b/lang/php/test/LongEncodingTest.php
@@ -21,7 +21,7 @@ require_once('test_helper.php');
 class LongEncodingTest extends PHPUnit\Framework\TestCase
 {
 
-  function setUp()
+  function setUp(): void
   {
     Avro::check_platform();
   }
diff --git a/lang/php/test/ProtocolFileTest.php b/lang/php/test/ProtocolFileTest.php
index 91755ef..81eb5fe 100644
--- a/lang/php/test/ProtocolFileTest.php
+++ b/lang/php/test/ProtocolFileTest.php
@@ -22,7 +22,7 @@ require_once('test_helper.php');
 // near-verbatim port of test_protocol.py
 class ProtocolFileTest extends PHPUnit\Framework\TestCase
 {
-	protected function setUp() {
+	protected function setUp(): void {
 	}
 	
 	public function testParsing() {
diff --git a/share/docker/Dockerfile b/share/docker/Dockerfile
index 5dbe528..66267b7 100644
--- a/share/docker/Dockerfile
+++ b/share/docker/Dockerfile
@@ -81,23 +81,16 @@ RUN curl -sSL https://deb.nodesource.com/setup_10.x \
  && npm cache clean --force
 
 # Install PHP
-# TODO: Remove php5-related packages when we drop PHP 5.6 support in the future
-# TODO: Consolidate the php versions into a single one (7.x) when we drop PHP 5.6 support in the future
-ENV PHP5_VERSION=5.6 \
-    PHP7_VERSION=7.1
+ENV PHP7_VERSION=7.3
 RUN curl -sSL https://packages.sury.org/php/apt.gpg \
   | apt-key add --no-tty - \
  && echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \
  && apt-get -qqy update \
- && apt-get -qqy install --no-install-recommends php${PHP5_VERSION} \
-                                                 php${PHP5_VERSION}-gmp \
-                                                 php${PHP7_VERSION} \
+ && apt-get -qqy install --no-install-recommends php${PHP7_VERSION} \
                                                  php${PHP7_VERSION}-gmp \
  && apt-get -qqy clean \
  && rm -rf /var/lib/apt/lists
-# Install PHPUnit 5.7, which is the only version that supports both PHP 5.6 and 7.x
-# TODO: use PHPUnit 7.x instead of 5.7 when we drop PHP 5.6 support in the future
-RUN curl -sSL https://phar.phpunit.de/phpunit-5.7.phar > /usr/local/bin/phpunit \
+RUN curl -sSL https://phar.phpunit.de/phpunit-9.0.phar > /usr/local/bin/phpunit \
  && chmod +x /usr/local/bin/phpunit
 
 # Install Perl modules