Page MenuHomePhabricator

WikiLambda: ZObject:getDefinition() methods are no longer necessary
Open, LowPublic

Description

We used getDefinition methods to perform validations while recursively creating the ZObjects/* classes instances. Currently the validation is done with function-schemata and all getDefinitions methods are no longer needed.

This task requires:

  • Remove ZObject::getDefinitions and all other getDefinitions of the child classes
  • Remove getDefinition method from ZTestType.php
  • Remove all builtin types that were present in the definitions (e.g. HACK_REFERENCE_TYPE)

Event Timeline

gengh removed gengh as the assignee of this task.Mar 17 2022, 8:57 AM

Current status:

getDefinition methods are currently used in a limited way:

  • getDefinition().type is used for returning the type of the ZObject and to inspect what type of shape the Z1K1 value has (is it a reference or a function call)
  • getDefinition().keys are used to create the object vars that the builtin class constructors need. What is checked is whether the key exists, and if it doesn't, whether the key is required or not.
  • getDefinition().additionalKeys is used to pass additional keys into the constructor.

getDefinition().keys[n].type (the type of the value that a particular key should hold) is NOT USED. This was the main usage of getDefinitions before, and it was used for validation. Currently validation is done by function-schemata. The thing about the type field, is that this why we added all the "HACK_type" constants, which could be very well removed now, and the type could just have the expected type, for the sake of information completeness.

For example, here's the definition of multilingual string:

public static function getDefinition(): array {
  return [
    'type' => [
      'type' => ZTypeRegistry::Z_REFERENCE,
      'value' => ZTypeRegistry::Z_MULTILINGUALSTRING,
    ],
    'keys' => [
      ZTypeRegistry::Z_MULTILINGUALSTRING_VALUE => [
        'type' => ZTypeRegistry::HACK_ARRAY_Z_MONOLINGUALSTRING,
        'required' => true,
      ],
    ],
  ];  
}

The constant HACK_ARRAY_Z_MONOLINGUALSTRING is not used anywhere.