composer require sabre/xml-atom
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for sabre/xml-atom ^0.1.0 -> satisfiable by sabre/xml-atom[0.1.0].
- sabre/xml-atom 0.1.0 requires sabre/xml ^1.4.0 -> satisfiable by sabre/xml[1.4.0, 1.4.1, 1.4.2, 1.4.x-dev, 1.5.0, 1.5.x-dev] but these conflict with your requirements or minimum-stability.
Installation failed, reverting ./composer.json to its original content.
<title ">dive into mark</title>
<title type="text">dive into mark</title>
[
"name" => "title",
"value" => "dive into mark",
"attributes" => ["type" => "text"]
]
It's only when you use one of the default 'deserializers' that you get different structures. In the sabre/xml-atom example there's two major ones used:
1. The valueObject mapper, which is a standard sabre/xml built-in one that maps PHP classes and properties to XML elements and child elements.
2. An attributeReader/attributeWriter which in the case of sabre/xml-atom is a custom one.
So if you have an xml tag that you want to extract both an attribute and a value from, and you hypothetically would want to map that to a PHP class like this:
class Title {
public $title;
public $value;
}
The correct sabre/xml solution is to write a custom parser like this:
$server->elementMap['{myNamespace}title'] = function($reader) {
$result = new Title();
$result->type = $reader->getAttribute('type');
$result->value = $reader->readText();
$reader->next();
return $result;
};
class Feed {
public $subtitle;
}
class Subtitle {
public $type;
public $value;
}
$this->mapValueObject($atom . 'subtitle', Element\Subtitle::class);
$this->elementMap[$atom . 'Subtitle'] = function($reader) {
$result = new Subtitle();
$result->type = $reader->getAttribute('type');
$result->value = $reader->readText();
$reader->next();
return $result;
};
[subtitle] => Sabre\Xml\Atom\Element\Subtitle Object
(
[type] =>
[value] =>
)
what am I doing wrong?
<subtitle type="html">
A <em>lot</em> of effort
went into making this effortless
</subtitle>
class Feed {
//....
public $subtitle;
}
class Subtitle {
public $type;
public $value;
}
Service.php
// atom:subtitle
$this->elementMap[$atom . 'subtitle'] = function($reader) {
$result = new Subtitle();
$result->type = $reader->getAttribute('type');
$result->value = $reader->readText();
$reader->next();
return $result;
};
Fatal error: Uncaught Error: Class 'Sabre\Xml\Atom\Subtitle' not found in /home/he052rz5/www/home/sabre-xml-atom/lib/Service.php:94 Stack trace: #0 [internal function]: Sabre\Xml\Atom\Service->Sabre\Xml\Atom\{closure}(Object(Sabre\Xml\Reader)) #1 /home/he052rz5/www/home/vendor/sabre/xml/lib/Reader.php(229): call_user_func(Object(Closure), Object(Sabre\Xml\Reader)) #2 /home/he052rz5/www/home/vendor/sabre/xml/lib/Deserializer/functions.php(190): Sabre\Xml\Reader->parseCurrentElement() #3 /home/he052rz5/www/home/vendor/sabre/xml/lib/Service.php(220): Sabre\Xml\Deserializer\valueObject(Object(Sabre\Xml\Reader), 'Sabre\\Xml\\Atom\\...', 'http://www.w3.o...') #4 [internal function]: Sabre\Xml\Service->Sabre\Xml\{closure}(Object(Sabre\Xml\Reader)) #5 /home/he052rz5/www/home/vendor/sabre/xml/lib/Reader.php(229): call_user_func(Object(Closure), Object(Sabre\Xml\Reader)) #6 /home/he052rz5/www/home/vendor/sabre/xml/lib/Reader.php(71): Sabre\Xml\Reader->parseCurrentElement() #7 /home/he052rz5/www/home/vendor/sabre/xml/lib/Service.php in /home/he052rz5/www/home/sabre-xml-atom/lib/Service.php on line 94
--
You received this message because you are subscribed to the Google Groups "SabreDAV Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sabredav-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sabredav-discuss/eef43f63-1828-42bf-8f5f-75ea05ab0b54%40googlegroups.com.
// atom:subtitle
$this->elementMap[$atom . 'subtitle'] = function($reader) {
$result = new Element\Subtitle();
$result->type = $reader->getAttribute('type');
$result->value = $reader->readText();
$reader->next();
return $result;
};
[subtitle] => Sabre\Xml\Atom\Element\Subtitle Object ( [type] => html [value] => A lot of effort went into making this effortless )
Works like a charm now. Thanks!