| @@ 1839-1856 (lines=18) @@ | ||
| 1836 | * @return Assert |
|
| 1837 | * @throws AssertionFailedException |
|
| 1838 | */ |
|
| 1839 | public function directory($message = null, $propertyPath = null) |
|
| 1840 | { |
|
| 1841 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1842 | { |
|
| 1843 | return $this; |
|
| 1844 | } |
|
| 1845 | $this->string($message, $propertyPath); |
|
| 1846 | if ( !is_dir($this->value) ) |
|
| 1847 | { |
|
| 1848 | $message = $message ?: $this->overrideError; |
|
| 1849 | $message = sprintf( |
|
| 1850 | $message ?: 'Path "%s" was expected to be a directory.', |
|
| 1851 | $this->stringify($this->value) |
|
| 1852 | ); |
|
| 1853 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $propertyPath); |
|
| 1854 | } |
|
| 1855 | return $this; |
|
| 1856 | } |
|
| 1857 | ||
| 1858 | /** |
|
| 1859 | * Assert that the value is something readable |
|
| @@ 1866-1883 (lines=18) @@ | ||
| 1863 | * @return Assert |
|
| 1864 | * @throws AssertionFailedException |
|
| 1865 | */ |
|
| 1866 | public function readable($message = null, $propertyPath = null) |
|
| 1867 | { |
|
| 1868 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1869 | { |
|
| 1870 | return $this; |
|
| 1871 | } |
|
| 1872 | $this->string($message, $propertyPath); |
|
| 1873 | if ( !is_readable($this->value) ) |
|
| 1874 | { |
|
| 1875 | $message = $message ?: $this->overrideError; |
|
| 1876 | $message = sprintf( |
|
| 1877 | $message ?: 'Path "%s" was expected to be readable.', |
|
| 1878 | $this->stringify($this->value) |
|
| 1879 | ); |
|
| 1880 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $propertyPath); |
|
| 1881 | } |
|
| 1882 | return $this; |
|
| 1883 | } |
|
| 1884 | ||
| 1885 | /** |
|
| 1886 | * Assert that the value is something writeable |
|
| @@ 1893-1910 (lines=18) @@ | ||
| 1890 | * @return Assert |
|
| 1891 | * @throws AssertionFailedException |
|
| 1892 | */ |
|
| 1893 | public function writeable($message = null, $propertyPath = null) |
|
| 1894 | { |
|
| 1895 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1896 | { |
|
| 1897 | return $this; |
|
| 1898 | } |
|
| 1899 | $this->string($message, $propertyPath); |
|
| 1900 | if ( !is_writeable($this->value) ) |
|
| 1901 | { |
|
| 1902 | $message = $message ?: $this->overrideError; |
|
| 1903 | $message = sprintf( |
|
| 1904 | $message ?: 'Path "%s" was expected to be writeable.', |
|
| 1905 | $this->stringify($this->value) |
|
| 1906 | ); |
|
| 1907 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $propertyPath); |
|
| 1908 | } |
|
| 1909 | return $this; |
|
| 1910 | } |
|
| 1911 | ||
| 1912 | /** |
|
| 1913 | * Assert that value is an email adress (using |
|
| @@ 2054-2075 (lines=22) @@ | ||
| 2051 | * @return Assert |
|
| 2052 | * @throws AssertionFailedException |
|
| 2053 | */ |
|
| 2054 | public function alnum($message = null, $propertyPath = null) |
|
| 2055 | { |
|
| 2056 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2057 | { |
|
| 2058 | return $this; |
|
| 2059 | } |
|
| 2060 | try |
|
| 2061 | { |
|
| 2062 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath); |
|
| 2063 | } |
|
| 2064 | catch (AssertionFailedException $e) |
|
| 2065 | { |
|
| 2066 | $message = $message ?: $this->overrideError; |
|
| 2067 | $message = sprintf( |
|
| 2068 | $message |
|
| 2069 | ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.', |
|
| 2070 | $this->stringify($this->value) |
|
| 2071 | ); |
|
| 2072 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $propertyPath); |
|
| 2073 | } |
|
| 2074 | return $this; |
|
| 2075 | } |
|
| 2076 | ||
| 2077 | /** |
|
| 2078 | * Assert that the value is boolean True. |
|