- private function normalizeUser($user_id)
- {
- if (substr($user_id, 0, 5) == 'http:' ||
- substr($user_id, 0, 6) == 'https:' ||
- substr($user_id, 0, 5) == 'acct:') {
- return $user_id;
+ protected $actor = null; // Profile of user who has signed the envelope
+
+ protected $data = null; // When stored here it is _always_ base64url encoded
+ protected $data_type = null;
+ protected $encoding = null;
+ protected $alg = null;
+ protected $sig = null;
+
+ /**
+ * Extract envelope data from an XML document containing an <me:env> or <me:provenance> element.
+ *
+ * @param string XML source
+ * @return mixed associative array of envelope data, or false on unrecognized input
+ *
+ * @fixme will spew errors to logs or output in case of XML parse errors
+ * @fixme may give fatal errors if some elements are missing or invalid XML
+ * @fixme calling DOMDocument::loadXML statically triggers warnings in strict mode
+ */
+ public function __construct($xml=null, Profile $actor=null) {
+ if (!empty($xml)) {
+ $dom = new DOMDocument();
+ if (!$dom->loadXML($xml)) {
+ throw new ServerException('Tried to load malformed XML as DOM');
+ } elseif (!$this->fromDom($dom)) {
+ throw new ServerException('Could not load MagicEnvelope from DOM');
+ }
+ } elseif ($actor instanceof Profile) {
+ // So far we only allow setting with _either_ $xml _or_ $actor as that's
+ // all our circumstances require. But it may be confusing for new developers.
+ // The idea is that feeding XML must be followed by interpretation and then
+ // running $magic_env->verify($profile), just as in SalmonAction->prepare(...)
+ // and supplying an $actor (which right now has to be a User) will require
+ // defining the $data, $data_type etc. attributes manually afterwards before
+ // signing the envelope..
+ $this->setActor($actor);