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

https://github.com/soitun/hiphop-php · PHP · 456 lines · 142 code · 32 blank · 282 comment · 8 complexity · 3bc30dcd542373851e41a08a5008d0c9 MD5 · raw file

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