stimulsoft / Stimulsoft.Reports.PHP

Reports.PHP is a report generator intended to create, view, print, and export reports online using client-server technology. Includes the JS report engine, report designer and viewer. Support PHP 5, PHP 7, and PHP 8 versions.
https://www.stimulsoft.com/en/products/reports-php
Other
4 stars 4 forks source link

Support for PHP 8.2 #2

Open qwasyx0 opened 1 year ago

qwasyx0 commented 1 year ago

Hello, I am trying to run the package on a Laravel application which uses php 8.2.

I am getting some errors (already messaged stimulsoft support via email).

I wasn't able to show the designer or view because of the error linked under. On local development I was running 8.1 and all was alright, when I switched to 8.2, I'm getting these errors.

Will your package support newest php 8.2?

The error shown is in StiDataAdapter.php:

   protected function parseUnknownParameter($parameter, $name, $value)
    {
        if ($this->driverType == 'PDO' && mb_strlen($parameter) > 0) {
            if (mb_strlen($this->info->dsn) > 0)        <-- here is the error
                $this->info->dsn .= ';';

            $this->info->dsn .= $parameter;
        }
    }

Also other error I was able to debug in StiLicense.php:

    /** Get the HTML representation of the component. */
    public function getHtml()
    {
        $result = '';

        if (strlen($this->licenseKey) > 0)      <-- here is the error
            $result .= "Stimulsoft.Base.StiLicense.Key = '$this->licenseKey';\n";
        else if (strlen($this->licenseFile) > 0)      <-- also here
            $result .= "Stimulsoft.Base.StiLicense.loadFromFile('$this->licenseFile');\n";

        $this->isHtmlRendered = true;
        return $result;
    }

The stacktrace:

{"handlerVersion":null,"adapterVersion":null,"checkVersion":true,"success":false,"notice":"[1] Uncaught Error: Invalid callback Stimulsoft\\StiHandler::stiErrorHandler, cannot access private method Stimulsoft\\StiHandler::stiErrorHandler() in /www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php:110\nStack](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php:110%5CnStack) trace:\n#0 /www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php(110)](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php(110)): mb_strlen()\n#1 /www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php(100)](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php(100)): Stimulsoft\\Adapters\\StiDataAdapter->parseUnknownParameter()\n#2 /www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php(70)](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php(70)): Stimulsoft\\Adapters\\StiDataAdapter->parseParameters()\n#3 /www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiFirebirdAdapter.php(57)](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiFirebirdAdapter.php(57)): Stimulsoft\\Adapters\\StiDataAdapter->parse()\n#4 /www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/classes/StiDataHandler.php(84)](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/classes/StiDataHandler.php(84)): Stimulsoft\\Adapters\\StiFirebirdAdapter->parse()\n#5 /www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/StiHandler.php(314)](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/StiHandler.php(314)): Stimulsoft\\StiDataHandler->getDataAdapterResult()\n#6 /www/hosting/[sas-report.cz/crm/public/handler.php(135)](http://sas-report.cz/crm/public/handler.php(135)): Stimulsoft\\StiHandler->process()\n#7 {main}\n  thrown (/www/hosting/[sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php](http://sas-report.cz/crm/vendor/stimulsoft/reports-php/src/adapters/StiDataAdapter.php), Line 110)"}
AlexKulikow commented 1 year ago

We have added support for 8.2 version. You can update from the following link: https://packagist.org/packages/stimulsoft/reports-php#dev-master

or wait new release build 2023.1.7 in this week.

VladimirHot commented 1 year ago

If the problem persists in the new version, please open the ticket again.

qwasyx0 commented 1 year ago

Thank you for quick response, unfortunately I am not able to use the designer component on php8.2 with firebird. Snímek obrazovky 2023-02-13 v 21 01 03

Proposed fix:

<?php

namespace Stimulsoft\Adapters;

use Stimulsoft\StiDataResult;
use Stimulsoft\StiResult;

class StiFirebirdAdapter extends StiDataAdapter
{

// ...

    protected function getValue($type, $value)
    {
        if (is_null($value) || strlen($value) == 0)
            return null;

        switch ($type) {
            case 'array':
                return base64_encode($value);

            case 'datetime':
                $timestamp = strtotime($value);
                $format = date("Y-m-d\TH:i:s.v", $timestamp);
                if (strpos($format, '.v') > 0) $format = date("Y-m-d\TH:i:s.000", $timestamp);
                return $format;

            case 'time':
                $timestamp = strtotime($value);
                $format = date("H:i:s.v", $timestamp);
                if (strpos($format, '.v') > 0) $format = date("H:i:s.000", $timestamp);
                return $format;

            case 'string':
                return mb_convert_encoding($value, 'UTF-8', mb_list_encodings());     //   <- fix deprecated function
                // return utf8_encode($value);      //    <- current vesion
        }

        return $value;
    }

// ...
}

Second problem:

<?php

namespace Stimulsoft\Adapters;

use Stimulsoft\StiConnectionInfo;
use Stimulsoft\StiDatabaseType;
use Stimulsoft\StiDataResult;
use Stimulsoft\StiResult;

class StiDataAdapter
{

// ...

    private function detectType($value)
    {
        // if (preg_match('~[^\x20-\x7E\t\r\n]~', $value) > 0)   // <- current version
        if (is_array($value))    //   <- fixed but still fails somewhere else
            return 'array';

        if (is_numeric($value)) {
            if (strpos($value, '.') !== false) return 'number';
            return 'int';
        }

        if (\DateTime::createFromFormat('Y-m-d H:i:s', $value) !== false ||
            \DateTime::createFromFormat('Y-m-d', $value) !== false ||
            \DateTime::createFromFormat('Y-M-d', $value) !== false ||
            \DateTime::createFromFormat('H:i:s', $value) !== false)
            return 'datetime';

        if (is_string($value))
            return 'string';

        return 'array';
    }

// ...
}

After that I am unable to debug as I work mainly with PHP and the designer shows "Connection error", sometimes the fields of given IA_PREDPROT view are imported, but it is not consistent.

Hopefully this helps to fix the issue.

qwasyx0 commented 1 year ago

Also I am unable to re-open the issue as I was not the one who closed it.

VladimirHot commented 1 year ago

Thanks for the clarification. We have accepted your fix, the task has been submitted for testing, the fix will soon be publicly available.