Skip to content

Create a base class which all classes object classes inherit from to share common code #67

@justincy

Description

@justincy

For example, all classes which represent a piece of the data model have the same constructor:

/**
 * Constructs a User from a (parsed) JSON hash
 *
 * @param mixed $o Either an array (JSON) or an XMLReader.
 *
 * @throws \Exception
 */
public function __construct($o = null)
{
    if (is_array($o)) {
        $this->initFromArray($o);
    }
    else if ($o instanceof \XMLReader) {
        $success = true;
        while ($success && $o->nodeType != \XMLReader::ELEMENT) {
            $success = $o->read();
        }
        if ($o->nodeType != \XMLReader::ELEMENT) {
            throw new \Exception("Unable to read XML: no start element found.");
        }

        $this->initFromReader($o);
    }
}

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