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

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

Open
justincy opened this issue Nov 17, 2016 · 1 comment

Comments

@justincy
Copy link
Contributor

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);
    }
}
@justincy
Copy link
Contributor Author

setKnownAttribute() and toXml() could be part of the base class too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant