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