IOException.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * CFPropertyList
  4. * {@link http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/plist.5.html Property Lists}
  5. *
  6. * @author Rodney Rehm <rodney.rehm@medialize.de>
  7. * @author Christian Kruse <cjk@wwwtech.de>
  8. * @package plist
  9. * @version $Id$
  10. */
  11. /**
  12. * Basic Input / Output Exception
  13. *
  14. * @author Rodney Rehm <rodney.rehm@medialize.de>
  15. * @author Christian Kruse <cjk@wwwtech.de>
  16. * @package plist
  17. */
  18. class IOException extends Exception {
  19. /**
  20. * Flag telling the File could not be found
  21. */
  22. const NOT_FOUND = 1;
  23. /**
  24. * Flag telling the File is not readable
  25. */
  26. const NOT_READABLE = 2;
  27. /**
  28. * Flag telling the File is not writable
  29. */
  30. const NOT_WRITABLE = 3;
  31. /**
  32. * Flag telling there was a read error
  33. */
  34. const READ_ERROR = 4;
  35. /**
  36. * Flag telling there was a read error
  37. */
  38. const WRITE_ERROR = 5;
  39. /**
  40. * Create new IOException
  41. *
  42. * @param string $path Source of the problem
  43. * @param integer $type Type of the problem
  44. */
  45. public function __construct($path, $type = null) {
  46. if (is_resource($path)) {
  47. //$path = (string)$path;
  48. $path = '<stream>';
  49. } elseif ($path == '') {
  50. $path = 'null';
  51. }
  52. parent::__construct($path, $type);
  53. }
  54. /**
  55. * Create new FileNotFound-Exception
  56. *
  57. * @param string $path Source of the problem
  58. *
  59. * @return IOException new FileNotFound-Exception
  60. */
  61. public static function notFound($path) {
  62. return new IOException($path, self::NOT_FOUND);
  63. }
  64. /**
  65. * Create new FileNotReadable-Exception
  66. *
  67. * @param string $path Source of the problem
  68. *
  69. * @return IOException new FileNotReadable-Exception
  70. */
  71. public static function notReadable($path) {
  72. return new IOException($path, self::NOT_READABLE);
  73. }
  74. /**
  75. * Create new FileNotWritable-Exception
  76. *
  77. * @param string $path Source of the problem
  78. *
  79. * @return IOException new FileNotWritable-Exception
  80. */
  81. public static function notWritable($path) {
  82. return new IOException($path, self::NOT_WRITABLE);
  83. }
  84. /**
  85. * Create new ReadError-Exception
  86. *
  87. * @param string $path Source of the problem
  88. *
  89. * @return IOException new ReadError-Exception
  90. */
  91. public static function readError($path) {
  92. return new IOException($path, self::READ_ERROR);
  93. }
  94. /**
  95. * Create new WriteError-Exception
  96. *
  97. * @param string $path Source of the problem
  98. *
  99. * @return IOException new WriteError-Exception
  100. */
  101. public static function writeError($path) {
  102. return new IOException($path, self::WRITE_ERROR);
  103. }
  104. }