Ignore php.ini
[xhtml-compiler.git] / XHTMLCompiler / File.php
blob011fbeb976d999993f6a2a82fd3bf15ea1b88c0c
1 <?php
3 /**
4 * Represents a file in the filesystem
5 */
6 class XHTMLCompiler_File
9 /** Filename of file this object represents */
10 protected $name;
12 /**
13 * Filename of file you wish to instantiate.
14 * @note This file need not exist
16 public function __construct($name) {
17 $this->name = $name;
20 /**
21 * Returns the filename of the file.
23 public function getName() {return $this->name;}
25 /**
26 * Returns directory of the file without trailing slash
28 public function getDirectory() {return dirname($this->name);}
30 /**
31 * Retrieves the contents of a file
32 * @todo Throw an exception if file doesn't exist
34 public function get() {
35 return file_get_contents($this->name);
38 /**
39 * Writes contents to a file, creates new file if necessary
40 * @param $contents String contents to write to file
42 public function write($contents) {
43 file_put_contents($this->name, $contents);
46 /**
47 * Deletes the file
49 public function delete() {
50 unlink($this->name);
53 /**
54 * Returns true if file exists and is a file.
56 public function exists() {
57 $php = XHTMLCompiler::getPHPWrapper();
58 return $php->isFile($this->name);
61 /**
62 * Returns last file modification time
64 public function getMTime() {
65 return filemtime($this->name);
68 /** Returns the last inode modifiation time */
69 public function getCTime() {
70 return filectime($this->name);
73 /**
74 * Chmod a file
75 * @note We ignore errors because of some weird owner trickery due
76 * to SVN duality
78 public function chmod($octal_code) {
79 @chmod($this->name, $octal_code);
82 /**
83 * Touches a file.
85 public function touch() {
86 touch($this->name);