예제 #1
0
 public function setUp()
 {
     $httpClient = $this->getMockBuilder('\\Guzzle\\Http\\Client')->getMock();
     $wdavClient = $this->getMockBuilder('\\Grale\\WebDav\\WebDavClient')->getMock();
     $wdavClient->expects($this->any())->method('getHttpClient')->will($this->returnValue($httpClient));
     $stream = EntityBody::fromString('Hello World!');
     $wdavClient->expects($this->any())->method('getStream')->will($this->returnValue($stream));
     $propfind = MultiStatus::parse($wdavClient, file_get_contents(__DIR__ . '/../../fixtures/streamwrapper.opendir.xml'));
     $wdavClient->expects($this->any())->method('setThrowExceptions')->will($this->returnValue($this->client));
     $wdavClient->expects($this->any())->method('propfind')->will($this->returnValue($propfind));
     $this->client = $wdavClient;
     StreamWrapper::register(null, $this->client);
 }
예제 #2
0
 /**
  * Retrieve properties defined on the specified resource.
  *
  * Performs a <tt>PROPFIND</tt> request as defined in the
  * {@link http://tools.ietf.org/html/rfc4918#section-9.1 Section 9.1 of RFC-4918}.
  *
  * The following options are available:
  * - <tt>properties</tt>
  * - <tt>depth</tt>
  *
  * @param string $uri
  *            Resource URI
  * @param array $options
  *            Options to apply to the request
  *            
  * @return MultiStatus
  */
 public function propfind($uri, array $options = null)
 {
     $depth = isset($options['depth']) ? (int) $options['depth'] : 0;
     $properties = isset($options['properties']) ? $options['properties'] : array();
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $xPropfind = $dom->createElementNS('DAV:', 'D:propfind');
     if (count($properties) == 0) {
         $xProp = $dom->createElement('D:allprop');
     } else {
         $xProp = $dom->createElement('D:prop');
         $namespaces = array_flip($this->xmlNamespaces);
         foreach ($properties as $property) {
             list($prefix, ) = explode(':', $property, 2);
             if ($prefix !== null && isset($namespaces[$prefix])) {
                 $xProp->setAttributeNS('http://www.w3.org/2000/xmlns/', "xmlns:{$prefix}", $namespaces[$prefix]);
                 $xPropNode = $dom->createElementNs($namespaces[$prefix], $property);
             } else {
                 $xPropNode = $dom->createElement($property);
             }
             $xProp->appendChild($xPropNode);
         }
     }
     $dom->appendChild($xPropfind)->appendChild($xProp);
     $body = $dom->saveXML();
     $request = $this->createRequest('PROPFIND', $uri, array('Content-Type' => 'Content-Type: text/xml; charset="utf-8"', 'Depth' => $depth), $body);
     $response = $this->doRequest($request);
     return $response->getStatusCode() == 207 ? MultiStatus::parse($this, $response->getBody()) : null;
 }