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

/server/classes/ezc/Webdav/requests/copy.php

https://github.com/drucko/AjaXplorer
PHP | 151 lines | 62 code | 13 blank | 76 comment | 11 complexity | d2657707312ba986304f412c1b8850a8 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause, BSD-2-Clause, Apache-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * File containing the ezcWebdavCopyRequest class.
  4. *
  5. * @package Webdav
  6. * @version 1.1.4
  7. * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
  8. * @license http://ez.no/licenses/new_bsd New BSD License
  9. */
  10. /**
  11. * Abstract representation of a COPY request.
  12. *
  13. * An instance of this class represents the WebDAV COPY request.
  14. *
  15. * Required headers for this request are:
  16. * <ul>
  17. * <li>Destination</li>
  18. * </ul>
  19. *
  20. * Optional headers for this request are:
  21. * <ul>
  22. * <li>Overwrite (default: 'T')</li>
  23. * <li>Depth (default: ezcWebdavRequest::DEPTH_ZERO)</li>
  24. * </ul>
  25. *
  26. * @package Webdav
  27. * @version 1.1.4
  28. *
  29. * @property ezcWebdavRequestPropertyBehaviourContent $propertyBehaviour
  30. * Contains the <propertybehavior /> element, if submitted with the
  31. * request. If not, this property is null.
  32. */
  33. class ezcWebdavCopyRequest extends ezcWebdavRequest
  34. {
  35. /**
  36. * Creates a new COPY request object.
  37. *
  38. * Expected are the $requestUri, which references the source to copy, and
  39. * the $destination, which is the URI referencing the destination resource
  40. * to copy to.
  41. *
  42. * @param string $requestUri
  43. * @param string $destination
  44. * @return void
  45. */
  46. public function __construct( $requestUri, $destination )
  47. {
  48. // Set from constructor values
  49. parent::__construct( $requestUri );
  50. $this->headers['Destination'] = $destination;
  51. // Set header defaults
  52. $this->headers['Overwrite'] = 'T';
  53. $this->headers['Depth'] = ezcWebdavRequest::DEPTH_ZERO;
  54. // Create properties
  55. $this->properties['propertyBehaviour'] = null;
  56. }
  57. /**
  58. * Sets a property.
  59. *
  60. * This method is called when an property is to be set.
  61. *
  62. * @param string $propertyName The name of the property to set.
  63. * @param mixed $propertyValue The property value.
  64. * @return void
  65. * @ignore
  66. *
  67. * @throws ezcBasePropertyNotFoundException
  68. * if the given property does not exist.
  69. * @throws ezcBaseValueException
  70. * if the value to be assigned to a property is invalid.
  71. * @throws ezcBasePropertyPermissionException
  72. * if the property to be set is a read-only property.
  73. */
  74. public function __set( $propertyName, $propertyValue )
  75. {
  76. switch ( $propertyName )
  77. {
  78. case 'propertyBehaviour':
  79. if ( !( $propertyValue instanceof ezcWebdavRequestPropertyBehaviourContent ) && $propertyValue !== null )
  80. {
  81. throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcWebdavRequestPropertyBehaviourContent' );
  82. }
  83. break;
  84. default:
  85. parent::__set( $propertyName, $propertyValue );
  86. }
  87. $this->properties[$propertyName] = $propertyValue;
  88. }
  89. /**
  90. * Validates the headers set in this request.
  91. *
  92. * This method validates that all required headers are available and that
  93. * all feasible headers for this request have valid values.
  94. *
  95. * @return void
  96. *
  97. * @throws ezcWebdavMissingHeaderException
  98. * if a required header is missing.
  99. * @throws ezcWebdavInvalidHeaderException
  100. * if a header is present, but its content does not validate.
  101. */
  102. public function validateHeaders()
  103. {
  104. if ( !isset( $this->headers['Destination'] ) )
  105. {
  106. throw new ezcWebdavMissingHeaderException( 'Destination' );
  107. }
  108. if ( !isset( $this->headers['Overwrite'] ) )
  109. {
  110. throw new ezcWebdavMissingHeaderException( 'Overwrite' );
  111. }
  112. if ( $this->headers['Overwrite'] !== 'T' && $this->headers['Overwrite'] !== 'F' )
  113. {
  114. throw new ezcWebdavInvalidHeaderException(
  115. 'Overwrite',
  116. $this->headers['Overwrite'],
  117. "'T' or 'F'"
  118. );
  119. }
  120. if ( !isset( $this->headers['Depth'] ) )
  121. {
  122. throw new ezcWebdavMissingHeaderException( 'Depth' );
  123. }
  124. if ( $this->headers['Depth'] !== ezcWebdavRequest::DEPTH_ZERO
  125. && $this->headers['Depth'] !== ezcWebdavRequest::DEPTH_ONE
  126. && $this->headers['Depth'] !== ezcWebdavRequest::DEPTH_INFINITY )
  127. {
  128. throw new ezcWebdavInvalidHeaderException(
  129. 'Depth',
  130. $this->headers['Depth'],
  131. 'ezcWebdavRequest::DEPTH_ZERO, ezcWebdavRequest::DEPTH_ONE or ezcWebdavRequest::DEPTH_INFINITY'
  132. );
  133. }
  134. // Validate common HTTP/WebDAV headers
  135. parent::validateHeaders();
  136. }
  137. }
  138. ?>