Skip to content

Allow non-array values to be properly written when parsing schemas - #162

Merged
opengeek merged 1 commit into
3.xfrom
Mark-H/parse-schema-constants
Sep 24, 2020
Merged

opengeek merged 1 commit into
3.xfrom
Mark-H/parse-schema-constants

Conversation

@Mark-H

@Mark-H Mark-H commented Sep 25, 2019

Copy link
Copy Markdown
Contributor

Imagine a model class like this:

class Account extends WhateverBaseObject
{
    public const SUSPEND_PAYMENTOVERDUE = 'payment_overdue';
    public const SUSPEND_REQUESTED = 'requested';
    public const SUSPEND_TRIALEND = 'trial_end';
    public const SUSPEND_NOPAYMENTMETHOD = 'no_payment_method';

    // ...
}

When parsing the schema with a command like this:

vendor/bin/xpdo parse-schema mysql package.mysql.schema.xml src/ -v --update=1 --psr4=Package

... the xPDOGenerator parses constants and writes them into the platform specific class.

However due to a bug in varExport, the value is lost, leading to the mysql class looking like this:

class Account extends \Package\Account
{
    const SUSPEND_PAYMENTOVERDUE = ;
    const SUSPEND_REQUESTED = ;
    const SUSPEND_TRIALEND = ;
    const SUSPEND_NOPAYMENTMETHOD = ;

which is invalid PHP and causes a hard fatal error.

With this patch, non-array values are preserved in constants, leading to functional code:

class Account extends \Package\Account
{
    const SUSPEND_PAYMENTOVERDUE = 'payment_overdue';
    const SUSPEND_REQUESTED = 'requested';
    const SUSPEND_TRIALEND = 'trial_end';
    const SUSPEND_NOPAYMENTMETHOD = 'no_payment_method';

Personally I think it would be better if the constants weren't copied into platform classes at all. They're inherited, so why write them again?

I'm also using some constants that refer to other constants (e.g. public const ENCRYPTION = EncryptionHelper::ENCRYPTION_SOME_TYPE), which due to this platform code is ending up with the value of that second constant, rather than the constant itself. Those values wont change, so that's fine for now, but it seems like a great source for potential bugs.

I've looked at defining a custom platform template that skips it, but that doesn't seem possible to pass in at the moment.

@Mark-H Mark-H changed the title Allow non-array constants to be properly written when parsing schemas Allow non-array values to be properly written when parsing schemas Sep 25, 2019
@opengeek
opengeek force-pushed the Mark-H/parse-schema-constants branch from c5a1c75 to b8337bd Compare September 24, 2020 18:42
@cla-bot cla-bot Bot added the cla-signed CLA confirmed for all contributors to this PR label Sep 24, 2020
@opengeek
opengeek merged commit f5716ae into 3.x Sep 24, 2020
@opengeek
opengeek deleted the Mark-H/parse-schema-constants branch September 24, 2020 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed CLA confirmed for all contributors to this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants