PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/system/php/spl/file_handling/SplFileInfo.php

https://github.com/tstarling/hiphop-php
PHP | 432 lines | 118 code | 32 blank | 282 comment | 4 complexity | e54280a4b7da304d235c1c1f8b056596 MD5 | raw file
  1. <?php
  2. // This doc comment block generated by idl/sysdoc.php
  3. /**
  4. * ( excerpt from http://php.net/manual/en/class.splfileinfo.php )
  5. *
  6. * The SplFileInfo class offers a high-level object oriented interface to
  7. * information for an individual file.
  8. *
  9. */
  10. class SplFileInfo {
  11. private $fileName;
  12. private $fileClass = "SplFileObject";
  13. private $infoClass;
  14. // This doc comment block generated by idl/sysdoc.php
  15. /**
  16. * ( excerpt from http://php.net/manual/en/splfileinfo.construct.php )
  17. *
  18. * Creates a new SplFileInfo object for the file_name specified. The file
  19. * does not need to exist, or be readable.
  20. *
  21. * @file_name mixed Path to the file.
  22. */
  23. public function __construct($file_name) {
  24. $this->setPathname($file_name);
  25. }
  26. // This doc comment block generated by idl/sysdoc.php
  27. /**
  28. * ( excerpt from http://php.net/manual/en/splfileinfo.getpath.php )
  29. *
  30. * Returns the path to the file, omitting the filename and any trailing
  31. * slash.
  32. *
  33. * @return mixed Returns the path to the file.
  34. */
  35. public function getPath() {
  36. return dirname($this->getPathname());
  37. }
  38. // This doc comment block generated by idl/sysdoc.php
  39. /**
  40. * ( excerpt from http://php.net/manual/en/splfileinfo.getfilename.php )
  41. *
  42. * Gets the filename without any path information.
  43. *
  44. * @return mixed The filename.
  45. */
  46. public function getFilename() {
  47. return $this->getBasename();
  48. }
  49. // This doc comment block generated by idl/sysdoc.php
  50. /**
  51. * ( excerpt from http://php.net/manual/en/splfileinfo.getfileinfo.php )
  52. *
  53. * This method gets an SplFileInfo object for the referenced file.
  54. *
  55. * @class_name mixed Name of an SplFileInfo derived class to use.
  56. *
  57. * @return mixed An SplFileInfo object created for the file.
  58. */
  59. public function getFileInfo($class_name = null) {
  60. if (!$class_name) {
  61. $class_name = $this->fileClass;
  62. }
  63. return new $class_name($this->getPathname());
  64. }
  65. // This doc comment block generated by idl/sysdoc.php
  66. /**
  67. * ( excerpt from http://php.net/manual/en/splfileinfo.getbasename.php )
  68. *
  69. * This method returns the base name of the file, directory, or link
  70. * without path info.
  71. *
  72. * @suffix mixed Optional suffix to omit from the base name returned.
  73. *
  74. * @return mixed Returns the base name without path information.
  75. */
  76. public function getBasename($suffix = "") {
  77. return basename($this->getPathname(), $suffix);
  78. }
  79. // This doc comment block generated by idl/sysdoc.php
  80. /**
  81. * ( excerpt from http://php.net/manual/en/splfileinfo.getpathname.php )
  82. *
  83. * Returns the path to the file.
  84. *
  85. * @return mixed The path to the file.
  86. */
  87. public function getPathname() {
  88. return $this->fileName;
  89. }
  90. // This doc comment block generated by idl/sysdoc.php
  91. /**
  92. * ( excerpt from http://php.net/manual/en/splfileinfo.getpathinfo.php )
  93. *
  94. * Gets an SplFileInfo object for the parent of the current file.
  95. *
  96. * @class_name mixed Name of an SplFileInfo derived class to use.
  97. *
  98. * @return mixed Returns an SplFileInfo object for the parent path of
  99. * the file.
  100. */
  101. public function getPathInfo($class_name = null) {
  102. if (!$class_name) {
  103. $class_name = $this->fileClass;
  104. }
  105. return new $class_name($this->getPath());
  106. }
  107. // This doc comment block generated by idl/sysdoc.php
  108. /**
  109. * ( excerpt from http://php.net/manual/en/splfileinfo.getperms.php )
  110. *
  111. * Gets the file permissions for the file.
  112. *
  113. * @return mixed Returns the file permissions.
  114. */
  115. public function getPerms() {
  116. return fileperms($this->getPathname());
  117. }
  118. // This doc comment block generated by idl/sysdoc.php
  119. /**
  120. * ( excerpt from http://php.net/manual/en/splfileinfo.getinode.php )
  121. *
  122. * Gets the inode number for the filesystem object.
  123. *
  124. * @return mixed Returns the inode number for the filesystem object.
  125. */
  126. public function getInode() {
  127. return fileinode($this->getPathname());
  128. }
  129. // This doc comment block generated by idl/sysdoc.php
  130. /**
  131. * ( excerpt from http://php.net/manual/en/splfileinfo.getsize.php )
  132. *
  133. * Returns the filesize in bytes for the file referenced.
  134. *
  135. * @return mixed The filesize in bytes.
  136. */
  137. public function getSize() {
  138. return filesize($this->getPathname());
  139. }
  140. // This doc comment block generated by idl/sysdoc.php
  141. /**
  142. * ( excerpt from http://php.net/manual/en/splfileinfo.getowner.php )
  143. *
  144. * Gets the file owner. The owner ID is returned in numerical format.
  145. *
  146. * @return mixed The owner id in numerical format.
  147. */
  148. public function getOwner() {
  149. return fileowner($this->getPathname());
  150. }
  151. // This doc comment block generated by idl/sysdoc.php
  152. /**
  153. * ( excerpt from http://php.net/manual/en/splfileinfo.getgroup.php )
  154. *
  155. * Gets the file group. The group ID is returned in numerical format.
  156. *
  157. * @return mixed The group id in numerical format.
  158. */
  159. public function getGroup() {
  160. return filegroup($this->getPathname());
  161. }
  162. // This doc comment block generated by idl/sysdoc.php
  163. /**
  164. * ( excerpt from http://php.net/manual/en/splfileinfo.getatime.php )
  165. *
  166. * Gets the last access time for the file.
  167. *
  168. * @return mixed Returns the time the file was last accessed.
  169. */
  170. public function getATime() {
  171. return fileatime($this->getPathname());
  172. }
  173. // This doc comment block generated by idl/sysdoc.php
  174. /**
  175. * ( excerpt from http://php.net/manual/en/splfileinfo.getmtime.php )
  176. *
  177. * Returns the time when the contents of the file were changed. The time
  178. * returned is a Unix timestamp.
  179. *
  180. * @return mixed Returns the last modified time for the file, in a
  181. * Unix timestamp.
  182. */
  183. public function getMTime() {
  184. return filemtime($this->getPathname());
  185. }
  186. // This doc comment block generated by idl/sysdoc.php
  187. /**
  188. * ( excerpt from http://php.net/manual/en/splfileinfo.getctime.php )
  189. *
  190. * Returns the inode change time for the file. The time returned is a Unix
  191. * timestamp.
  192. *
  193. * @return mixed The last change time, in a Unix timestamp.
  194. */
  195. public function getCTime() {
  196. return filectime($this->getPathname());
  197. }
  198. // This doc comment block generated by idl/sysdoc.php
  199. /**
  200. * ( excerpt from http://php.net/manual/en/splfileinfo.gettype.php )
  201. *
  202. * Returns the type of the file referenced.
  203. *
  204. * @return mixed A string representing the type of the entry. May be
  205. * one of file, link, or dir
  206. */
  207. public function getType() {
  208. return filetype($this->getPathname());
  209. }
  210. // This doc comment block generated by idl/sysdoc.php
  211. /**
  212. * ( excerpt from http://php.net/manual/en/splfileinfo.getextension.php )
  213. *
  214. * Retrieves the file extension.
  215. *
  216. * @return mixed Returns a string containing the file extension, or
  217. * an empty string if the file has no extension.
  218. */
  219. public function getExtension() {
  220. return pathinfo($this->getPathname(), PATHINFO_EXTENSION);
  221. }
  222. // This doc comment block generated by idl/sysdoc.php
  223. /**
  224. * ( excerpt from http://php.net/manual/en/splfileinfo.iswritable.php )
  225. *
  226. * Checks if the current entry is writable.
  227. *
  228. * @return mixed Returns TRUE if writable, FALSE otherwise;
  229. */
  230. public function isWritable() {
  231. return is_writable($this->getPathname());
  232. }
  233. // This doc comment block generated by idl/sysdoc.php
  234. /**
  235. * ( excerpt from http://php.net/manual/en/splfileinfo.isreadable.php )
  236. *
  237. * Check if the file is readable.
  238. *
  239. * @return mixed Returns TRUE if readable, FALSE otherwise.
  240. */
  241. public function isReadable() {
  242. return is_readable($this->getPathname());
  243. }
  244. // This doc comment block generated by idl/sysdoc.php
  245. /**
  246. * ( excerpt from http://php.net/manual/en/splfileinfo.isexecutable.php )
  247. *
  248. * Checks if the file is executable.
  249. *
  250. * @return mixed Returns TRUE if executable, FALSE otherwise.
  251. */
  252. public function isExecutable() {
  253. return is_executable($this->getPathname());
  254. }
  255. // This doc comment block generated by idl/sysdoc.php
  256. /**
  257. * ( excerpt from http://php.net/manual/en/splfileinfo.isfile.php )
  258. *
  259. * Checks if the file referenced by this SplFileInfo object exists and is
  260. * a regular file.
  261. *
  262. * @return mixed Returns TRUE if the file exists and is a regular
  263. * file (not a link), FALSE otherwise.
  264. */
  265. public function isFile() {
  266. return is_file($this->getPathname());
  267. }
  268. // This doc comment block generated by idl/sysdoc.php
  269. /**
  270. * ( excerpt from http://php.net/manual/en/splfileinfo.isdir.php )
  271. *
  272. * This method can be used to determine if the file is a directory.
  273. *
  274. * @return mixed Returns TRUE if a directory, FALSE otherwise.
  275. */
  276. public function isDir() {
  277. return is_dir($this->getPathname());
  278. }
  279. // This doc comment block generated by idl/sysdoc.php
  280. /**
  281. * ( excerpt from http://php.net/manual/en/splfileinfo.islink.php )
  282. *
  283. * Use this method to check if the file referenced by the SplFileInfo
  284. * object is a link.
  285. *
  286. * @return mixed Returns TRUE if the file is a link, FALSE otherwise.
  287. */
  288. public function isLink() {
  289. return is_link($this->getPathname());
  290. }
  291. // This doc comment block generated by idl/sysdoc.php
  292. /**
  293. * ( excerpt from http://php.net/manual/en/splfileinfo.getlinktarget.php )
  294. *
  295. * Gets the target of a filesystem link.
  296. *
  297. * The target may not be the real path on the filesystem. Use
  298. * SplFileInfo::getRealPath() to determine the true path on the filesystem.
  299. *
  300. * @return mixed Returns the target of the filesystem link.
  301. */
  302. public function getLinkTarget() {
  303. $link = @readlink($this->getPathname());
  304. if ($link === false) {
  305. throw new Exception(
  306. 'Unable to read link '.$this->getPathname()
  307. );
  308. }
  309. return $link;
  310. }
  311. // This doc comment block generated by idl/sysdoc.php
  312. /**
  313. * ( excerpt from http://php.net/manual/en/splfileinfo.getrealpath.php )
  314. *
  315. * This method expands all symbolic links, resolves relative references
  316. * and returns the real path to the file.
  317. *
  318. * @return mixed Returns the path to the file.
  319. */
  320. public function getRealPath() {
  321. return realpath($this->getPathname());
  322. }
  323. // This doc comment block generated by idl/sysdoc.php
  324. /**
  325. * ( excerpt from http://php.net/manual/en/splfileinfo.tostring.php )
  326. *
  327. * This method will return the file name of the referenced file.
  328. *
  329. * @return mixed Returns the path to the file.
  330. */
  331. public function __toString() {
  332. return $this->getPathname();
  333. }
  334. // This doc comment block generated by idl/sysdoc.php
  335. /**
  336. * ( excerpt from http://php.net/manual/en/splfileinfo.openfile.php )
  337. *
  338. * Creates an SplFileObject object of the file. This is useful because
  339. * SplFileObject contains additional methods for manipulating the file
  340. * whereas SplFileInfo is only useful for gaining information, like whether
  341. * the file is writable.
  342. *
  343. * @mode mixed The mode for opening the file. See the fopen()
  344. * documentation for descriptions of possible modes.
  345. * The default is read only.
  346. * @use_include_path
  347. * mixed When set to TRUE, the filename is also searched for
  348. * within the include_path
  349. * @context mixed Refer to the context section of the manual for a
  350. * description of contexts.
  351. *
  352. * @return mixed The opened file as an SplFileObject object.
  353. */
  354. public function openFile($mode = 'r', $use_include_path = false,
  355. $context = null) {
  356. $class_name = $this->fileClass;
  357. return new $class_name(
  358. $this->getPathname(),
  359. $mode,
  360. $use_include_path,
  361. $context
  362. );
  363. }
  364. // This doc comment block generated by idl/sysdoc.php
  365. /**
  366. * ( excerpt from http://php.net/manual/en/splfileinfo.setfileclass.php )
  367. *
  368. * Set the class name which SplFileInfo will use to open files with when
  369. * openFile() is called. The class name passed to this method must be
  370. * derived from SplFileObject.
  371. *
  372. * @class_name mixed The class name to use when openFile() is called.
  373. *
  374. * @return mixed No value is returned.
  375. */
  376. public function setFileClass($class_name = "SplFileObject") {
  377. $this->fileClass = $class_name;
  378. }
  379. // This doc comment block generated by idl/sysdoc.php
  380. /**
  381. * ( excerpt from http://php.net/manual/en/splfileinfo.setinfoclass.php )
  382. *
  383. * Use this method to set a custom class which will be used when
  384. * getFileInfo and getPathInfo are called. The class name passed to this
  385. * method must be derived from SplFileInfo.
  386. *
  387. * @class_name mixed The class name to use.
  388. *
  389. * @return mixed No value is returned.
  390. */
  391. public function setInfoClass($class_name = "SplFileInfo") {
  392. $this->infoClass = $class_name;
  393. }
  394. protected function setPathname($file_name) {
  395. if ($file_name !== false) {
  396. $file_name = rtrim($file_name, '/');
  397. }
  398. $this->fileName = $file_name;
  399. }
  400. }