[Pkg-owncloud-commits] [php-sabredav] 103/163: Missing files.
David Prévot
taffit at moszumanska.debian.org
Tue May 20 18:54:58 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.
commit f4cded1ab66ac6c0a5ff5153e8be74d947f8a4ca
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Sat May 3 00:07:26 2014 -0400
Missing files.
---
lib/Sabre/DAV/PropFind.php | 295 +++++++++++++++++++++++++++++++++++++++
tests/Sabre/DAV/PropFindTest.php | 16 +++
2 files changed, 311 insertions(+)
diff --git a/lib/Sabre/DAV/PropFind.php b/lib/Sabre/DAV/PropFind.php
new file mode 100644
index 0000000..66d9de1
--- /dev/null
+++ b/lib/Sabre/DAV/PropFind.php
@@ -0,0 +1,295 @@
+<?php
+
+namespace Sabre\DAV;
+
+/**
+ * This class holds all the information about a PROPFIND request.
+ *
+ * It contains the type of PROPFIND request, which properties were requested
+ * and also the returned items.
+ */
+class PropFind {
+
+ /**
+ * A normal propfind
+ */
+ const NORMAL = 0;
+
+ /**
+ * An allprops request.
+ *
+ * While this was originally intended for instructing the server to really
+ * fetch every property, because it was used so often and it's so heavy
+ * this turned into a small list of default properties after a while.
+ *
+ * So 'all properties' now means a hardcoded list.
+ */
+ const ALLPROPS = 1;
+
+ /**
+ * A propname request. This just returns a list of properties that are
+ * defined on a node, without their values.
+ */
+ const PROPNAME = 2;
+
+
+ /**
+ * Creates the PROPFIND object
+ *
+ * @param string $path
+ * @param array $properties
+ * @param int $depth
+ * @param int $requestType
+ */
+ public function __construct($path, array $properties, $depth = 0, $requestType = self::NORMAL) {
+
+ $this->path = $path;
+ $this->properties = $properties;
+ $this->depth = $depth;
+ $this->requestType = $requestType;
+
+ if($requestType === self::ALLPROPS) {
+ $this->properties = [
+ '{DAV:}getlastmodified',
+ '{DAV:}getcontentlength',
+ '{DAV:}resourcetype',
+ '{DAV:}quota-used-bytes',
+ '{DAV:}quota-available-bytes',
+ '{DAV:}getetag',
+ '{DAV:}getcontenttype',
+ ];
+ }
+
+ foreach($properties as $propertyName) {
+
+ // Seeding properties with 404's.
+ $this->result[$propertyName] = [404, null];
+
+ }
+ $this->itemsLeft = count($this->result);
+
+ }
+
+ /**
+ * Handles a specific property.
+ *
+ * This method checks wether the specified property was requested in this
+ * PROPFIND request, and if so, it will call the callback and use the
+ * return value for it's value.
+ *
+ * Example:
+ *
+ * $propFind->handle('{DAV:}displayname', function() {
+ * return 'hello';
+ * });
+ *
+ * Note that handle will only work the first time. If null is returned, the
+ * value is ignored.
+ *
+ * It's also possible to not pass a callback, but immediately pass a value
+ *
+ * @param string $propertyName
+ * @param mixed $valueOrCallBack
+ * @return void
+ */
+ public function handle($propertyName, $valueOrCallBack) {
+
+ if ($this->itemsLeft && isset($this->result[$propertyName]) && $this->result[$propertyName][0] === 404) {
+ if (is_callable($valueOrCallBack)) {
+ $value = $valueOrCallBack();
+ } else {
+ $value = $valueOrCallBack;
+ }
+ if (!is_null($value)) {
+ $this->itemsLeft--;
+ $this->result[$propertyName] = [200, $value];
+ }
+ }
+
+ }
+
+ /**
+ * Sets the status code and optionally the value of a property.
+ *
+ * If the property was never requested, it will be ignored.
+ *
+ * @param string $propertyName
+ * @param int $status
+ * @param mixed $value
+ * @return void
+ */
+ public function set($propertyName, $status, $value = null) {
+
+ if (isset($this->result[$propertyName])) {
+ if ($status!==404 && $this->result[$propertyName][0]===404) {
+ $this->itemsLeft--;
+ } elseif ($status === 404 && $this->result[$propertyName][0] !== 404) {
+ $this->itemsLeft++;
+ }
+ $this->result[$propertyName] = [$status, $value];
+ }
+
+ }
+
+ /**
+ * Updates the path for this PROPFIND.
+ *
+ * @param string $path
+ * @return void
+ */
+ public function setPath($path) {
+
+ $this->path = $path;
+
+ }
+
+ /**
+ * Returns the path this PROPFIND request is for.
+ *
+ * @return string
+ */
+ public function getPath() {
+
+ return $this->path;
+
+ }
+
+ /**
+ * Returns the depth of this propfind request.
+ *
+ * @return int
+ */
+ public function getDepth() {
+
+ return $this->depth;
+
+ }
+
+ /**
+ * Updates the depth of this propfind request.
+ *
+ * @param int $depth
+ * @return void
+ */
+ public function setDepth($depth) {
+
+ $this->depth = $depth;
+
+ }
+
+ /**
+ * Returns all propertynames that have a 404 status, and thus don't have a
+ * value yet.
+ *
+ * @return array
+ */
+ public function get404Properties() {
+
+ if ($this->itemsLeft === 0) {
+ return [];
+ }
+ $result = [];
+ foreach($this->result as $propertyName=>$stuff) {
+ if ($stuff[0]===404) {
+ $this->itemsLeft[] = $propertyName;
+ }
+ }
+ return $result;
+
+ }
+
+ /**
+ * Returns the full list of requested properties.
+ *
+ * This returns just their names, not a status or value.
+ *
+ * @return array
+ */
+ public function getRequestedProperties() {
+
+ return $this->properties;
+
+ }
+
+ /**
+ * Returns a result array that's often used in multistatus responses.
+ *
+ * The array uses status codes as keys, and property names and value pairs
+ * as the value of the top array.. such as :
+ *
+ * [
+ * 200 => [ '{DAV:}displayname' => 'foo' ],
+ * ]
+ *
+ * @return array
+ */
+ public function getResultForMultiStatus() {
+
+ $r = [];
+ foreach($this->result as $propertyName=>$info) {
+ if (!isset($r[$info[0]])) {
+ $r[$info[0]] = [$propertyName => $info[1]];
+ } else {
+ $r[$info[0]][$propertyName] = $info[1];
+ }
+ }
+ return $r;
+
+ }
+
+ /**
+ * The path that we're fetching properties for.
+ *
+ * @var string
+ */
+ protected $path;
+
+ /**
+ * The Depth of the request.
+ *
+ * 0 means only the current item. 1 means the current item + its children.
+ * It can also be DEPTH_INFINITY if this is enabled in the server.
+ *
+ * @var int
+ */
+ protected $depth = 0;
+
+ /**
+ * The type of request. See the TYPE constants
+ */
+ protected $requestType;
+
+ /**
+ * A list of requested properties
+ *
+ * @var array
+ */
+ protected $properties = [];
+
+ /**
+ * The result of the operation.
+ *
+ * The keys in this array are property names.
+ * The values are an array with two elements: the http status code and then
+ * optionally a value.
+ *
+ * Example:
+ *
+ * [
+ * "{DAV:}owner" : [404],
+ * "{DAV:}displayname" : [200, "Admin"]
+ * ]
+ *
+ * @var array
+ */
+ protected $result = [];
+
+ /**
+ * This is used as an internal counter for the number of properties that do
+ * not yet have a value.
+ *
+ * @var int
+ */
+ protected $itemsLeft;
+
+}
diff --git a/tests/Sabre/DAV/PropFindTest.php b/tests/Sabre/DAV/PropFindTest.php
new file mode 100644
index 0000000..3e2ba58
--- /dev/null
+++ b/tests/Sabre/DAV/PropFindTest.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Sabre\DAV;
+
+class PropFindTest extends \PHPUnit_Framework_TestCase {
+
+ function testHandle() {
+
+ $propFind = new PropFind('foo', ['{DAV:}displayname']);
+ $propFind->handle('{DAV:}displayname', 'foobar');
+
+ $this->assertEquals([200 => ['{DAV:}displayname' => 'foobar']], $propFind->getResultForMultiStatus());
+
+ }
+
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list