Skip to content

Configured Serializer is not being used #210

@travisaustin

Description

@travisaustin

I am attempting to use the new Base64 serializer/encoder to serialize and encode my workflow objects. To do this, I added this line to the config/workflows.php file in my Laravel project:

	'serializer' => Workflow\Serializers\Base64::class,

When I test this, it seems that the workflows are encoded using Y::class instead of Base64::class as I intended. I traced the process and found what I think is an issue in Serializer.php. Specifically, the call to config('serializer') needs to be changed to config('workflows.serializer'):

    public static function __callStatic(string $name, array $arguments)
    {
        if ($name === 'unserialize') {
            if (str_starts_with($arguments[0], 'base64:')) {
                $instance = Base64::getInstance();
            } else {
                $instance = Y::getInstance();
            }
        } else {
            $instance = config('serializer', Y::class)::getInstance();
        }

        if (method_exists($instance, $name)) {
            return $instance->{$name}(...$arguments);
        }
    }

When I make this change, my workflows are successfully serialized using Base64:

# Current code in this package
$instance = config('serializer', Y::class)::getInstance();

# This is what I changed it to (from 'serializer' to 'workflows.serializer')
$instance = config('workflows.serializer', Y::class)::getInstance();

I don't have experience developing a Laravel package, so I am unfamiliar with accessing configurations for packages. Is this a typo in the package, and should the package include the prefix of workflows, or does Laravel automatically add that to any code that is executed from within the package?

I'm not sure if this is a bug or not. What do you think, @rmcdaniel ? It seems like a bug unless Laravel is supposed to do some magic here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy