php Sabre-Xml-Writer类(方法)实例源码

下面列出了php Sabre-Xml-Writer 类(方法)源码代码实例,从而了解它的用法。

作者:ddolbi    项目:sabre-vobjec   
/**
  * This method serializes only the value of a property. This is used to
  * create xCard or xCal documents.
  *
  * @param Xml\Writer $writer  XML writer.
  *
  * @return void
  */
 protected function xmlSerializeValue(Xml\Writer $writer)
 {
     // xCard is the only XML and JSON format that has the same date and time
     // format than vCard.
     $valueType = strtolower($this->getValueType());
     $writer->writeElement($valueType, $this->getValue());
 }

作者:sebbie4    项目:casebo   
/**
  * 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)
 {
     $collations = ['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'];
     foreach ($collations as $collation) {
         $writer->writeElement('{' . Plugin::NS_CALDAV . '}supported-collation', $collation);
     }
 }

作者:ricardorsierr    项目:php-houn   
/**
  * Prepare XML file based on AnalysisResult.
  * @param AnalysisResult $result analysis result object.
  * @return string XML contents.
  */
 protected function getXmlFor(AnalysisResult $result)
 {
     $writer = new Writer();
     $writer->openMemory();
     $writer->write($this->getSabreXmlArrayFor($result));
     return '<?xml version="1.0" encoding="UTF-8"?>' . $writer->outputMemory();
 }

作者:laravelist    项目:bar   
/**
  * @param Writer $writer
  * @return void
  */
 function xmlSerialize(Writer $writer)
 {
     // This is required
     $writer->write(['loc' => $this->location]);
     // This is optional
     $this->add($writer, ['lastmod']);
 }

作者:netoholi    项目:store-integrato   
/**
  * 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)
 {
     $productData = [$this->category => []];
     if ($this->productType) {
         $productData[$this->category] = ['ProductType' => [$this->productType => ['AdditionalDrives' => 'dvd', 'ComputerMemoryType' => 'sodimm', 'DisplayResolutionMaximum' => 'fullhd   ']]];
     }
     $writer->write(['MessageID' => 1, 'OperationType' => 'Update', 'Product' => ['SKU' => $this->sku, 'DescriptionData' => ['Title' => $this->title, 'Brand' => $this->brand, 'Description' => $this->description, 'MSRP' => ['attributes' => ['currency' => $this->currency], 'value' => $this->msrp]], 'ProductData' => $productData]]);
 }

作者:sebbie4    项目:casebo   
/**
  * 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();
     }
 }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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();
     }
 }

作者:laravelist    项目:bar   
/**
  * Adds property from properties to url if it is not null.
  *
  * @param Writer $writer
  * @param array $properties
  */
 private function add(Writer $writer, array $properties)
 {
     foreach ($properties as $property) {
         if (!is_null($this->{$property})) {
             $writer->write([$property => $this->{$property}]);
         }
     }
 }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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();
     }
 }

作者:BlaBlaNe    项目:hubzill   
/**
  * 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->getResponses() as $response) {
         $writer->writeElement('{DAV:}response', $response);
     }
     if ($syncToken = $this->getSyncToken()) {
         $writer->writeElement('{DAV:}sync-token', $syncToken);
     }
 }

作者:sebbie4    项目:casebo   
/**
  * 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
     }
 }

作者:sebbie4    项目:casebo   
/**
  * 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)
 {
     if ($this->canBeShared) {
         $writer->writeElement('{' . Plugin::NS_CALENDARSERVER . '}can-be-shared');
     }
     if ($this->canBePublished) {
         $writer->writeElement('{' . Plugin::NS_CALENDARSERVER . '}can-be-published');
     }
 }

作者:Radiergumm    项目:anacronis   
function write($input)
 {
     $writer = new Writer();
     $writer->contextUri = $this->contextUri;
     $writer->namespaceMap = $this->namespaceMap;
     $writer->openMemory();
     $writer->setIndent(true);
     $writer->write($input);
     return $writer->outputMemory();
 }

作者:pagee    项目:sabre-da   
/**
  * 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)
 {
     switch ($this->value) {
         case self::TRANSPARENT:
             $writer->writeElement('{' . Plugin::NS_CALDAV . '}transparent');
             break;
         case self::OPAQUE:
             $writer->writeElement('{' . Plugin::NS_CALDAV . '}opaque');
             break;
     }
 }

作者:nikos    项目:openeclas   
/**
     * 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->write(['{DAV:}remove' => [$propertyName => $propertyValue]]);
            } else {
                $writer->write(['{DAV:}set' => [$propertyName => $propertyValue]]);
            }

        }

    }

作者:sebbie4    项目:casebo   
/**
     * 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;
            }
        }
    }

作者:sebbie4    项目:casebo   
/**
     * @dataProvider xmlProvider
     */
    function testSerialize($expectedFallback, $input, $expected = null)
    {
        if (is_null($expected)) {
            $expected = $expectedFallback;
        }
        $writer = new Writer();
        $writer->namespaceMap = ['http://sabredav.org/ns' => null];
        $writer->openMemory();
        $writer->startDocument('1.0');
        //$writer->setIndent(true);
        $writer->write(['{http://sabredav.org/ns}root' => ['{http://sabredav.org/ns}fragment' => new XmlFragment($input)]]);
        $output = $writer->outputMemory();
        $expected = <<<XML
<?xml version="1.0"?>
<root xmlns="http://sabredav.org/ns"><fragment>{$expected}</fragment></root>
XML;
        $this->assertEquals($expected, $output);
    }

作者:BlaBlaNe    项目:hubzill   
/**
  * The xmlSerialize method 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)
 {
     switch ($this->value) {
         case SharingPlugin::ACCESS_NOTSHARED:
             $writer->writeElement('{DAV:}not-shared');
             break;
         case SharingPlugin::ACCESS_SHAREDOWNER:
             $writer->writeElement('{DAV:}shared-owner');
             break;
         case SharingPlugin::ACCESS_READ:
             $writer->writeElement('{DAV:}read');
             break;
         case SharingPlugin::ACCESS_READWRITE:
             $writer->writeElement('{DAV:}read-write');
             break;
         case SharingPlugin::ACCESS_NOACCESS:
             $writer->writeElement('{DAV:}no-access');
             break;
     }
 }

作者:ddolbi    项目:sabre-vobjec   
/**
  * 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();
 }

作者:jakobsac    项目:sabre-da   
/**
  * @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());
 }


问题


面经


文章

微信
公众号

扫码关注公众号