| @@ 1864-1881 (lines=18) @@ | ||
| 1861 | * @return Assert |
|
| 1862 | * @throws AssertionFailedException |
|
| 1863 | */ |
|
| 1864 | public function directory($message = null, $propertyPath = null) |
|
| 1865 | { |
|
| 1866 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1867 | { |
|
| 1868 | return $this; |
|
| 1869 | } |
|
| 1870 | $this->string($message, $propertyPath); |
|
| 1871 | if ( !is_dir($this->value) ) |
|
| 1872 | { |
|
| 1873 | $message = $message ?: $this->overrideError; |
|
| 1874 | $message = sprintf( |
|
| 1875 | $message ?: 'Path "%s" was expected to be a directory.', |
|
| 1876 | $this->stringify($this->value) |
|
| 1877 | ); |
|
| 1878 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $propertyPath); |
|
| 1879 | } |
|
| 1880 | return $this; |
|
| 1881 | } |
|
| 1882 | ||
| 1883 | /** |
|
| 1884 | * Assert that the value is something readable |
|
| @@ 1891-1908 (lines=18) @@ | ||
| 1888 | * @return Assert |
|
| 1889 | * @throws AssertionFailedException |
|
| 1890 | */ |
|
| 1891 | public function readable($message = null, $propertyPath = null) |
|
| 1892 | { |
|
| 1893 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1894 | { |
|
| 1895 | return $this; |
|
| 1896 | } |
|
| 1897 | $this->string($message, $propertyPath); |
|
| 1898 | if ( !is_readable($this->value) ) |
|
| 1899 | { |
|
| 1900 | $message = $message ?: $this->overrideError; |
|
| 1901 | $message = sprintf( |
|
| 1902 | $message ?: 'Path "%s" was expected to be readable.', |
|
| 1903 | $this->stringify($this->value) |
|
| 1904 | ); |
|
| 1905 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $propertyPath); |
|
| 1906 | } |
|
| 1907 | return $this; |
|
| 1908 | } |
|
| 1909 | ||
| 1910 | /** |
|
| 1911 | * Assert that the value is something writeable |
|
| @@ 1918-1935 (lines=18) @@ | ||
| 1915 | * @return Assert |
|
| 1916 | * @throws AssertionFailedException |
|
| 1917 | */ |
|
| 1918 | public function writeable($message = null, $propertyPath = null) |
|
| 1919 | { |
|
| 1920 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1921 | { |
|
| 1922 | return $this; |
|
| 1923 | } |
|
| 1924 | $this->string($message, $propertyPath); |
|
| 1925 | if ( !is_writeable($this->value) ) |
|
| 1926 | { |
|
| 1927 | $message = $message ?: $this->overrideError; |
|
| 1928 | $message = sprintf( |
|
| 1929 | $message ?: 'Path "%s" was expected to be writeable.', |
|
| 1930 | $this->stringify($this->value) |
|
| 1931 | ); |
|
| 1932 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $propertyPath); |
|
| 1933 | } |
|
| 1934 | return $this; |
|
| 1935 | } |
|
| 1936 | ||
| 1937 | /** |
|
| 1938 | * Assert that value is an email adress (using |
|
| @@ 2079-2100 (lines=22) @@ | ||
| 2076 | * @return Assert |
|
| 2077 | * @throws AssertionFailedException |
|
| 2078 | */ |
|
| 2079 | public function alnum($message = null, $propertyPath = null) |
|
| 2080 | { |
|
| 2081 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2082 | { |
|
| 2083 | return $this; |
|
| 2084 | } |
|
| 2085 | try |
|
| 2086 | { |
|
| 2087 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath); |
|
| 2088 | } |
|
| 2089 | catch (AssertionFailedException $e) |
|
| 2090 | { |
|
| 2091 | $message = $message ?: $this->overrideError; |
|
| 2092 | $message = sprintf( |
|
| 2093 | $message |
|
| 2094 | ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.', |
|
| 2095 | $this->stringify($this->value) |
|
| 2096 | ); |
|
| 2097 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $propertyPath); |
|
| 2098 | } |
|
| 2099 | return $this; |
|
| 2100 | } |
|
| 2101 | ||
| 2102 | /** |
|
| 2103 | * Assert that the value is boolean True. |
|