Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Given the parameter `serializer`, still got exception information `A valid serializer is required` #14324

Closed
ZhangRuiMingZRM opened this issue Aug 23, 2019 · 2 comments
Labels
Projects

Comments

@ZhangRuiMingZRM
Copy link
Contributor

@ZhangRuiMingZRM ZhangRuiMingZRM commented Aug 23, 2019

  • Phalcon version: 4.0.0
  • PHP Version: 7.3.7
  • Operating System: ubuntu
  • Installation type: Compiling from source
  • Server: php web server

In the document of Cache Component

use Phalcon\Cache\Adapter\Stream;
use Phalcon\Storage\Serializer\Json;

$jsonSerializer = new Json();

$options = [
    'defaultSerializer' => 'Json',
    'lifetime'          => 7200,
    'serializer'        => $jsonSerializer,    
    'cacheDir'          => '/data/storage/cache',
];

$adapter = new Stream(null, $options);

I got an exception when running this code.

A valid serializer is required

This is caused by

protected function getUnserializedData(var content, var defaultValue = null) -> var
{
if !content {
return defaultValue;
}
if this->defaultSerializer !== "" {
this->serializer->unserialize(content);
let content = this->serializer->getData();
}
return content;
}

I think only if both conditions ( null === this->serializerFactory && null === this->serializer ) are met can throw exception

This may be a solution

protected function initSerializer() -> void
 {
        string className;

        if unlikely (null === this->serializerFactory && null === this->serializer) {
            throw new Exception("A valid serializer is required");
        }

       if !(typeof this->serializer == "object" && this->serializer instanceof SerializerInterface) {
            let className        = strtolower(this->defaultSerializer),
                this->serializer = this->serializerFactory->newInstance(className);
        }
}
@CameronHall

This comment has been minimized.

Copy link
Member

@CameronHall CameronHall commented Aug 23, 2019

If you're up to it @ZhangRuiMingZRM, feel free to create a PR to address the issue. If not we'll get to it soon :)

@ZhangRuiMingZRM ZhangRuiMingZRM referenced this issue Aug 23, 2019
4 of 5 tasks complete
ZhangRuiMingZRM added a commit to ZhangRuiMingZRM/cphalcon that referenced this issue Aug 26, 2019
@ruudboon ruudboon added this to To do in 4.0 Release via automation Aug 26, 2019
@ruudboon

This comment has been minimized.

Copy link
Member

@ruudboon ruudboon commented Aug 26, 2019

Fixed in 4.0.x branch. thnx @ZhangRuiMingZRM ZhangRuiMingZRM,

@ruudboon ruudboon closed this Aug 26, 2019
4.0 Release automation moved this from To do to Done Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4.0 Release
  
Done
3 participants
You can’t perform that action at this time.