Node.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Base node-class
  4. *
  5. * The node class implements the method used by both the File and the Directory classes
  6. *
  7. * @package Sabre
  8. * @subpackage DAV
  9. * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
  10. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  11. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  12. */
  13. abstract class Sabre_DAV_FS_Node implements Sabre_DAV_INode {
  14. /**
  15. * The path to the current node
  16. *
  17. * @var string
  18. */
  19. protected $path;
  20. /**
  21. * Sets up the node, expects a full path name
  22. *
  23. * @param string $path
  24. */
  25. public function __construct($path) {
  26. $this->path = $path;
  27. }
  28. /**
  29. * Returns the name of the node
  30. *
  31. * @return string
  32. */
  33. public function getName() {
  34. list(, $name) = Sabre_DAV_URLUtil::splitPath($this->path);
  35. return $name;
  36. }
  37. /**
  38. * Renames the node
  39. *
  40. * @param string $name The new name
  41. * @return void
  42. */
  43. public function setName($name) {
  44. list($parentPath, ) = Sabre_DAV_URLUtil::splitPath($this->path);
  45. list(, $newName) = Sabre_DAV_URLUtil::splitPath($name);
  46. $newPath = $parentPath . '/' . $newName;
  47. rename($this->path,$newPath);
  48. $this->path = $newPath;
  49. }
  50. /**
  51. * Returns the last modification time, as a unix timestamp
  52. *
  53. * @return int
  54. */
  55. public function getLastModified() {
  56. return filemtime($this->path);
  57. }
  58. }