Collection.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Collection class
  4. *
  5. * This is a helper class, that should aid in getting collections classes setup.
  6. * Most of its methods are implemented, and throw permission denied exceptions
  7. *
  8. * @package Sabre
  9. * @subpackage DAV
  10. * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
  11. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  12. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  13. */
  14. abstract class Sabre_DAV_Collection extends Sabre_DAV_Node implements Sabre_DAV_ICollection {
  15. /**
  16. * Returns a child object, by its name.
  17. *
  18. * This method makes use of the getChildren method to grab all the child nodes, and compares the name.
  19. * Generally its wise to override this, as this can usually be optimized
  20. *
  21. * @param string $name
  22. * @throws Sabre_DAV_Exception_NotFound
  23. * @return Sabre_DAV_INode
  24. */
  25. public function getChild($name) {
  26. foreach($this->getChildren() as $child) {
  27. if ($child->getName()==$name) return $child;
  28. }
  29. throw new Sabre_DAV_Exception_NotFound('File not found: ' . $name);
  30. }
  31. /**
  32. * Checks is a child-node exists.
  33. *
  34. * It is generally a good idea to try and override this. Usually it can be optimized.
  35. *
  36. * @param string $name
  37. * @return bool
  38. */
  39. public function childExists($name) {
  40. try {
  41. $this->getChild($name);
  42. return true;
  43. } catch(Sabre_DAV_Exception_NotFound $e) {
  44. return false;
  45. }
  46. }
  47. /**
  48. * Creates a new file in the directory
  49. *
  50. * Data will either be supplied as a stream resource, or in certain cases
  51. * as a string. Keep in mind that you may have to support either.
  52. *
  53. * After succesful creation of the file, you may choose to return the ETag
  54. * of the new file here.
  55. *
  56. * The returned ETag must be surrounded by double-quotes (The quotes should
  57. * be part of the actual string).
  58. *
  59. * If you cannot accurately determine the ETag, you should not return it.
  60. * If you don't store the file exactly as-is (you're transforming it
  61. * somehow) you should also not return an ETag.
  62. *
  63. * This means that if a subsequent GET to this new file does not exactly
  64. * return the same contents of what was submitted here, you are strongly
  65. * recommended to omit the ETag.
  66. *
  67. * @param string $name Name of the file
  68. * @param resource|string $data Initial payload
  69. * @return null|string
  70. */
  71. public function createFile($name, $data = null) {
  72. throw new Sabre_DAV_Exception_Forbidden('Permission denied to create file (filename ' . $name . ')');
  73. }
  74. /**
  75. * Creates a new subdirectory
  76. *
  77. * @param string $name
  78. * @throws Sabre_DAV_Exception_Forbidden
  79. * @return void
  80. */
  81. public function createDirectory($name) {
  82. throw new Sabre_DAV_Exception_Forbidden('Permission denied to create directory');
  83. }
  84. }