1<?php
2
3namespace Sabre\DAV\FS;
4
5use Sabre\DAV;
6use Sabre\HTTP\URLUtil;
7
8/**
9 * Base node-class
10 *
11 * The node class implements the method used by both the File and the Directory classes
12 *
13 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
14 * @author Evert Pot (http://evertpot.com/)
15 * @license http://sabre.io/license/ Modified BSD License
16 */
17abstract class Node implements DAV\INode {
18
19    /**
20     * The path to the current node
21     *
22     * @var string
23     */
24    protected $path;
25
26    /**
27     * Sets up the node, expects a full path name
28     *
29     * @param string $path
30     */
31    function __construct($path) {
32
33        $this->path = $path;
34
35    }
36
37
38
39    /**
40     * Returns the name of the node
41     *
42     * @return string
43     */
44    function getName() {
45
46        list(, $name)  = URLUtil::splitPath($this->path);
47        return $name;
48
49    }
50
51    /**
52     * Renames the node
53     *
54     * @param string $name The new name
55     * @return void
56     */
57    function setName($name) {
58
59        list($parentPath, ) = URLUtil::splitPath($this->path);
60        list(, $newName) = URLUtil::splitPath($name);
61
62        $newPath = $parentPath . '/' . $newName;
63        rename($this->path, $newPath);
64
65        $this->path = $newPath;
66
67    }
68
69    /**
70     * Returns the last modification time, as a unix timestamp
71     *
72     * @return int
73     */
74    function getLastModified() {
75
76        return filemtime($this->path);
77
78    }
79
80}
81