本文整理汇总了PHP中Sabre\Xml\Writer::startElement方法的典型用法代码示例。如果您正苦于以下问题:PHP Writer::startElement方法的具体用法?PHP Writer::startElement怎么用?PHP Writer::startElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\Xml\Writer
的用法示例。
在下文中一共展示了Writer::startElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmlSerialize
/**
* The serialize method is called during xml writing.
*
* It should use the $writer argument to encode this object into XML.
*
* Important note: it is not needed to create the parent element. The
* parent element is already created, and we only have to worry about
* attributes, child elements and text (if any).
*
* Important note 2: If you are writing any new elements, you are also
* responsible for closing them.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
foreach ($this->locks as $lock) {
$writer->startElement('{DAV:}activelock');
$writer->startElement('{DAV:}lockscope');
if ($lock->scope === LockInfo::SHARED) {
$writer->writeElement('{DAV:}shared');
} else {
$writer->writeElement('{DAV:}exclusive');
}
$writer->endElement();
// {DAV:}lockscope
$writer->startElement('{DAV:}locktype');
$writer->writeElement('{DAV:}write');
$writer->endElement();
// {DAV:}locktype
if (!self::$hideLockRoot) {
$writer->startElement('{DAV:}lockroot');
$writer->writeElement('{DAV:}href', $writer->contextUri . $lock->uri);
$writer->endElement();
// {DAV:}lockroot
}
$writer->writeElement('{DAV:}depth', $lock->depth == DAV\Server::DEPTH_INFINITY ? 'infinity' : $lock->depth);
$writer->writeElement('{DAV:}timeout', 'Second-' . $lock->timeout);
$writer->startElement('{DAV:}locktoken');
$writer->writeElement('{DAV:}href', 'opaquelocktoken:' . $lock->token);
$writer->endElement();
// {DAV:}locktoken
$writer->writeElement('{DAV:}owner', new XmlFragment($lock->owner));
$writer->endElement();
// {DAV:}activelock
}
}
示例2: generateXML
/**
* @param $items
* @return string
*/
public function generateXML($items)
{
$this->writer->openMemory();
$this->writer->startElement('properties');
foreach ($items['data'] as $data) {
$property = new Property();
$property->propertyId = $data['property-id'];
$property->dateListed = $data['date-listed'];
$property->setPropertyType($data['property-type']);
$property->setListingType($data['listing-type']);
$property->link = $data['link'];
$property->postalCode = $data['postal-code'];
$property->city = $data['city'];
$property->rooms = $data['rooms'];
$property->bedrooms = $data['bedrooms'];
$property->bathrooms = $data['bathrooms'];
$property->propertySize = $data['property-size'];
$property->landSize = $data['land-size'];
$property->price = $data['price'];
$property->images = $data['images'];
$property->title = $data['title'];
$property->description = $data['description'];
$property->languages = $data['languages'];
$this->writer->write(['property' => $property]);
}
$this->writer->endElement();
return $this->writer->outputMemory();
}
示例3: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
$writer->startElement('{' . Plugin::NS_CALDAV . '}calendar-data');
$writer->writeAttributes(['content-type' => 'text/calendar', 'version' => '2.0']);
$writer->endElement();
// calendar-data
$writer->startElement('{' . Plugin::NS_CALDAV . '}calendar-data');
$writer->writeAttributes(['content-type' => 'application/calendar+json']);
$writer->endElement();
// calendar-data
}
示例4: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
foreach ($this->properties as $propertyName => $propertyValue) {
if (is_null($propertyValue)) {
$writer->startElement("{DAV:}remove");
$writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]);
$writer->endElement();
} else {
$writer->startElement("{DAV:}set");
$writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]);
$writer->endElement();
}
}
}
示例5: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
foreach ($this->privileges as $privName) {
$writer->startElement('{DAV:}privilege');
$writer->writeElement($privName);
$writer->endElement();
}
}
示例6: writeXml
/**
* Serializes a xCal or xCard object.
*
* @param Component $component
*
* @return string
*/
static function writeXml(Component $component)
{
$writer = new Xml\Writer();
$writer->openMemory();
$writer->setIndent(true);
$writer->startDocument('1.0', 'utf-8');
if ($component instanceof Component\VCalendar) {
$writer->startElement('icalendar');
$writer->writeAttribute('xmlns', Parser\Xml::XCAL_NAMESPACE);
} else {
$writer->startElement('vcards');
$writer->writeAttribute('xmlns', Parser\Xml::XCARD_NAMESPACE);
}
$component->xmlSerialize($writer);
$writer->endElement();
return $writer->outputMemory();
}
示例7: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
foreach ($this->getValue() as $val) {
$writer->startElement('{DAV:}supported-method');
$writer->writeAttribute('name', $val);
$writer->endElement();
}
}
示例8: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
foreach ($this->components as $component) {
$writer->startElement('{' . Plugin::NS_CALDAV . '}comp');
$writer->writeAttributes(['name' => $component]);
$writer->endElement();
}
}
示例9: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
$cs = '{' . Plugin::NS_CALENDARSERVER . '}';
foreach ($this->sharees as $sharee) {
if ($sharee->access === \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER) {
$writer->startElement($cs . 'organizer');
} else {
$writer->startElement($cs . 'user');
switch ($sharee->inviteStatus) {
case DAV\Sharing\Plugin::INVITE_ACCEPTED:
$writer->writeElement($cs . 'invite-accepted');
break;
case DAV\Sharing\Plugin::INVITE_DECLINED:
$writer->writeElement($cs . 'invite-declined');
break;
case DAV\Sharing\Plugin::INVITE_NORESPONSE:
$writer->writeElement($cs . 'invite-noresponse');
break;
case DAV\Sharing\Plugin::INVITE_INVALID:
$writer->writeElement($cs . 'invite-invalid');
break;
}
$writer->startElement($cs . 'access');
switch ($sharee->access) {
case DAV\Sharing\Plugin::ACCESS_READWRITE:
$writer->writeElement($cs . 'read-write');
break;
case DAV\Sharing\Plugin::ACCESS_READ:
$writer->writeElement($cs . 'read');
break;
}
$writer->endElement();
// access
}
$href = new \Sabre\DAV\Xml\Property\Href($sharee->href);
$href->xmlSerialize($writer);
if (isset($sharee->properties['{DAV:}displayname'])) {
$writer->writeElement($cs . 'common-name', $sharee->properties['{DAV:}displayname']);
}
if ($sharee->comment) {
$writer->writeElement($cs . 'summary', $sharee->comment);
}
$writer->endElement();
// organizer or user
}
}
示例10: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
foreach ($this->supportedData as $supported) {
$writer->startElement('{' . Plugin::NS_CARDDAV . '}address-data-type');
$writer->writeAttributes(['content-type' => $supported['contentType'], 'version' => $supported['version']]);
$writer->endElement();
// address-data-type
}
}
示例11: writeDataFields
private function writeDataFields(array $fields, Writer $writer)
{
array_map(function (DataField $field) use($writer) {
$writer->startElement(static::nameElement('datafield'));
$writer->writeAttributes(['tag' => $field->getTag(), 'ind1' => $field->getIndicator1(), 'ind2' => $field->getIndicator2()]);
$this->writeSubFields($field->getSubFields(), $writer);
$writer->endElement();
}, $fields);
}
示例12: __construct
/**
* @param string $url
* @param \VirCom\ePUAP2\Requests\Logout $request
* @param \Sabre\Xml\Writer $xmlWriter
*/
public function __construct(Requests\Logout $request, Xml\Writer $xmlWriter)
{
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$xmlWriter->startDocument();
$xmlWriter->startElement('samlp:LogoutRequest');
$xmlWriter->writeAttribute('xmlns:samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
$xmlWriter->writeAttribute('xmlns:saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
$xmlWriter->writeAttribute('ID', microtime(true));
$xmlWriter->writeAttribute('IssueInstant', (new \DateTime())->format('Y-m-d\\TH:i:s\\Z'));
$xmlWriter->writeAttribute('Version', '2.0');
$xmlWriter->startElement('saml:Issuer');
$xmlWriter->write($request->getApplicationId());
$xmlWriter->endElement();
$xmlWriter->startElement('samlp:NameID');
$xmlWriter->write($request->getUsername());
$xmlWriter->endElement();
$xmlWriter->endElement();
$this->parsedMessage = $xmlWriter->outputMemory();
}
示例13: __construct
/**
* @param \VirCom\ePUAP2\Requests\Login $request
* @param \Sabre\Xml\Writer $xmlWriter
*/
public function __construct(Requests\Login $request, Xml\Writer $xmlWriter)
{
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$xmlWriter->startDocument();
$xmlWriter->startElement('samlp:AuthnRequest');
$xmlWriter->writeAttribute('xmlns:samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
$xmlWriter->writeAttribute('ID', microtime(true));
$xmlWriter->writeAttribute('IssueInstant', (new \DateTime())->format('Y-m-d\\TH:i:s\\Z'));
$xmlWriter->writeAttribute('Version', '2.0');
$xmlWriter->writeAttribute('Destination', $request->getUrl());
$xmlWriter->writeAttribute('IsPassive', 'false');
$xmlWriter->writeAttribute('AssertionConsumerServiceURL', $request->getResponseUrl());
$xmlWriter->startElement('saml:Issuer');
$xmlWriter->writeAttribute('xmlns:saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
$xmlWriter->write($request->getApplicationId());
$xmlWriter->endElement();
$xmlWriter->endElement();
$this->parsedMessage = $xmlWriter->outputMemory();
}
示例14: xmlSerialize
/**
* The xmlSerialize metod is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializble should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
function xmlSerialize(Writer $writer)
{
$reader = new Reader();
// Wrapping the xml in a container, so root-less values can still be
// parsed.
$xml = <<<XML
<?xml version="1.0"?>
<xml-fragment xmlns="http://sabre.io/ns">{$this->getXml()}</xml-fragment>
XML;
$reader->xml($xml);
$elementNamespace = null;
while ($reader->read()) {
if ($reader->depth < 1) {
// Skipping the root node.
continue;
}
switch ($reader->nodeType) {
case Reader::ELEMENT:
$writer->startElement($reader->getClark());
$empty = $reader->isEmptyElement;
while ($reader->moveToNextAttribute()) {
switch ($reader->namespaceURI) {
case '':
$writer->writeAttribute($reader->localName, $reader->value);
break;
case 'http://www.w3.org/2000/xmlns/':
// Skip namespace declarations
break;
default:
$writer->writeAttribute($reader->getClark(), $reader->value);
break;
}
}
if ($empty) {
$writer->endElement();
}
break;
case Reader::CDATA:
case Reader::TEXT:
$writer->text($reader->value);
break;
case Reader::END_ELEMENT:
$writer->endElement();
break;
}
}
}
示例15: testSerializers
/**
* @dataProvider dataProvider
*/
function testSerializers($notification, $expected1, $expected2)
{
$this->assertEquals('foo', $notification->getId());
$this->assertEquals('"1"', $notification->getETag());
$writer = new Writer();
$writer->namespaceMap = ['http://calendarserver.org/ns/' => 'cs'];
$writer->openMemory();
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('{http://calendarserver.org/ns/}root');
$writer->write($notification);
$writer->endElement();
$this->assertXmlStringEqualsXmlString($expected1, $writer->outputMemory());
$writer = new Writer();
$writer->namespaceMap = ['http://calendarserver.org/ns/' => 'cs', 'DAV:' => 'd'];
$writer->openMemory();
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('{http://calendarserver.org/ns/}root');
$notification->xmlSerializeFull($writer);
$writer->endElement();
$this->assertXmlStringEqualsXmlString($expected2, $writer->outputMemory());
}