PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Webdav/src/requests/copy.php

https://github.com/Yannix/zetacomponents
PHP | 167 lines | 62 code | 13 blank | 92 comment | 11 complexity | 21a5a39c0da6e3e87b8a4ccbcf9cba09 MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the ezcWebdavCopyRequest class.
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Webdav
  23. * @version //autogentag//
  24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. */
  26. /**
  27. * Abstract representation of a COPY request.
  28. *
  29. * An instance of this class represents the WebDAV COPY request.
  30. *
  31. * Required headers for this request are:
  32. * <ul>
  33. * <li>Destination</li>
  34. * </ul>
  35. *
  36. * Optional headers for this request are:
  37. * <ul>
  38. * <li>Overwrite (default: 'T')</li>
  39. * <li>Depth (default: ezcWebdavRequest::DEPTH_ZERO)</li>
  40. * </ul>
  41. *
  42. * @package Webdav
  43. * @version //autogen//
  44. *
  45. * @property ezcWebdavRequestPropertyBehaviourContent $propertyBehaviour
  46. * Contains the <propertybehavior /> element, if submitted with the
  47. * request. If not, this property is null.
  48. */
  49. class ezcWebdavCopyRequest extends ezcWebdavRequest
  50. {
  51. /**
  52. * Creates a new COPY request object.
  53. *
  54. * Expected are the $requestUri, which references the source to copy, and
  55. * the $destination, which is the URI referencing the destination resource
  56. * to copy to.
  57. *
  58. * @param string $requestUri
  59. * @param string $destination
  60. * @return void
  61. */
  62. public function __construct( $requestUri, $destination )
  63. {
  64. // Set from constructor values
  65. parent::__construct( $requestUri );
  66. $this->headers['Destination'] = $destination;
  67. // Set header defaults
  68. $this->headers['Overwrite'] = 'T';
  69. $this->headers['Depth'] = ezcWebdavRequest::DEPTH_ZERO;
  70. // Create properties
  71. $this->properties['propertyBehaviour'] = null;
  72. }
  73. /**
  74. * Sets a property.
  75. *
  76. * This method is called when an property is to be set.
  77. *
  78. * @param string $propertyName The name of the property to set.
  79. * @param mixed $propertyValue The property value.
  80. * @return void
  81. * @ignore
  82. *
  83. * @throws ezcBasePropertyNotFoundException
  84. * if the given property does not exist.
  85. * @throws ezcBaseValueException
  86. * if the value to be assigned to a property is invalid.
  87. * @throws ezcBasePropertyPermissionException
  88. * if the property to be set is a read-only property.
  89. */
  90. public function __set( $propertyName, $propertyValue )
  91. {
  92. switch ( $propertyName )
  93. {
  94. case 'propertyBehaviour':
  95. if ( !( $propertyValue instanceof ezcWebdavRequestPropertyBehaviourContent ) && $propertyValue !== null )
  96. {
  97. throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcWebdavRequestPropertyBehaviourContent' );
  98. }
  99. break;
  100. default:
  101. parent::__set( $propertyName, $propertyValue );
  102. }
  103. $this->properties[$propertyName] = $propertyValue;
  104. }
  105. /**
  106. * Validates the headers set in this request.
  107. *
  108. * This method validates that all required headers are available and that
  109. * all feasible headers for this request have valid values.
  110. *
  111. * @return void
  112. *
  113. * @throws ezcWebdavMissingHeaderException
  114. * if a required header is missing.
  115. * @throws ezcWebdavInvalidHeaderException
  116. * if a header is present, but its content does not validate.
  117. */
  118. public function validateHeaders()
  119. {
  120. if ( !isset( $this->headers['Destination'] ) )
  121. {
  122. throw new ezcWebdavMissingHeaderException( 'Destination' );
  123. }
  124. if ( !isset( $this->headers['Overwrite'] ) )
  125. {
  126. throw new ezcWebdavMissingHeaderException( 'Overwrite' );
  127. }
  128. if ( $this->headers['Overwrite'] !== 'T' && $this->headers['Overwrite'] !== 'F' )
  129. {
  130. throw new ezcWebdavInvalidHeaderException(
  131. 'Overwrite',
  132. $this->headers['Overwrite'],
  133. "'T' or 'F'"
  134. );
  135. }
  136. if ( !isset( $this->headers['Depth'] ) )
  137. {
  138. throw new ezcWebdavMissingHeaderException( 'Depth' );
  139. }
  140. if ( $this->headers['Depth'] !== ezcWebdavRequest::DEPTH_ZERO
  141. && $this->headers['Depth'] !== ezcWebdavRequest::DEPTH_ONE
  142. && $this->headers['Depth'] !== ezcWebdavRequest::DEPTH_INFINITY )
  143. {
  144. throw new ezcWebdavInvalidHeaderException(
  145. 'Depth',
  146. $this->headers['Depth'],
  147. 'ezcWebdavRequest::DEPTH_ZERO, ezcWebdavRequest::DEPTH_ONE or ezcWebdavRequest::DEPTH_INFINITY'
  148. );
  149. }
  150. // Validate common HTTP/WebDAV headers
  151. parent::validateHeaders();
  152. }
  153. }
  154. ?>