| @@ 2118-2137 (lines=20) @@ | ||
| 2115 | * @return Assert |
|
| 2116 | * @throws AssertionFailedException |
|
| 2117 | */ |
|
| 2118 | public function directory(string $message = '', string $fieldName = '') : Assert |
|
| 2119 | { |
|
| 2120 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2121 | { |
|
| 2122 | return $this; |
|
| 2123 | } |
|
| 2124 | $this->string($message, $fieldName); |
|
| 2125 | if ( !is_dir($this->value) ) |
|
| 2126 | { |
|
| 2127 | $message = $message ?: $this->overrideError; |
|
| 2128 | $message = sprintf( |
|
| 2129 | $message ?: 'Path "%s" was expected to be a directory.', |
|
| 2130 | $this->stringify($this->value) |
|
| 2131 | ); |
|
| 2132 | ||
| 2133 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $fieldName); |
|
| 2134 | } |
|
| 2135 | ||
| 2136 | return $this; |
|
| 2137 | } |
|
| 2138 | ||
| 2139 | /** |
|
| 2140 | * Assert that value is something readable. |
|
| @@ 2147-2166 (lines=20) @@ | ||
| 2144 | * @return Assert |
|
| 2145 | * @throws AssertionFailedException |
|
| 2146 | */ |
|
| 2147 | public function readable(string $message = '', string $fieldName = '') : Assert |
|
| 2148 | { |
|
| 2149 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2150 | { |
|
| 2151 | return $this; |
|
| 2152 | } |
|
| 2153 | $this->string($message, $fieldName); |
|
| 2154 | if ( !is_readable($this->value) ) |
|
| 2155 | { |
|
| 2156 | $message = $message ?: $this->overrideError; |
|
| 2157 | $message = sprintf( |
|
| 2158 | $message ?: 'Path "%s" was expected to be readable.', |
|
| 2159 | $this->stringify($this->value) |
|
| 2160 | ); |
|
| 2161 | ||
| 2162 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $fieldName); |
|
| 2163 | } |
|
| 2164 | ||
| 2165 | return $this; |
|
| 2166 | } |
|
| 2167 | ||
| 2168 | /** |
|
| 2169 | * Assert that value is something writeable. |
|
| @@ 2176-2195 (lines=20) @@ | ||
| 2173 | * @return Assert |
|
| 2174 | * @throws AssertionFailedException |
|
| 2175 | */ |
|
| 2176 | public function writeable(string $message = '', string $fieldName = '') : Assert |
|
| 2177 | { |
|
| 2178 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2179 | { |
|
| 2180 | return $this; |
|
| 2181 | } |
|
| 2182 | $this->string($message, $fieldName); |
|
| 2183 | if ( !is_writeable($this->value) ) |
|
| 2184 | { |
|
| 2185 | $message = $message ?: $this->overrideError; |
|
| 2186 | $message = sprintf( |
|
| 2187 | $message ?: 'Path "%s" was expected to be writeable.', |
|
| 2188 | $this->stringify($this->value) |
|
| 2189 | ); |
|
| 2190 | ||
| 2191 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $fieldName); |
|
| 2192 | } |
|
| 2193 | ||
| 2194 | return $this; |
|
| 2195 | } |
|
| 2196 | ||
| 2197 | /** |
|
| 2198 | * Assert that value is a valid email address (using input_filter/FILTER_VALIDATE_EMAIL). |
|
| @@ 2347-2370 (lines=24) @@ | ||
| 2344 | * @return Assert |
|
| 2345 | * @throws AssertionFailedException |
|
| 2346 | */ |
|
| 2347 | public function ausMobile(string $message = '', string $fieldName = '') : Assert |
|
| 2348 | { |
|
| 2349 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2350 | { |
|
| 2351 | return $this; |
|
| 2352 | } |
|
| 2353 | try |
|
| 2354 | { |
|
| 2355 | $this->regex('/^04[0-9]{8})$/', $message, $fieldName); |
|
| 2356 | } |
|
| 2357 | catch ( AssertionFailedException $e ) |
|
| 2358 | { |
|
| 2359 | $message = $message ?: $this->overrideError; |
|
| 2360 | $message = sprintf( |
|
| 2361 | $message |
|
| 2362 | ?: 'Value "%s" is not an australian mobile number.', |
|
| 2363 | $this->stringify($this->value) |
|
| 2364 | ); |
|
| 2365 | ||
| 2366 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_AUS_MOBILE, $fieldName); |
|
| 2367 | } |
|
| 2368 | ||
| 2369 | return $this; |
|
| 2370 | } |
|
| 2371 | ||
| 2372 | /** |
|
| 2373 | * Assert that value is alphanumeric. |
|
| @@ 2380-2403 (lines=24) @@ | ||
| 2377 | * @return Assert |
|
| 2378 | * @throws AssertionFailedException |
|
| 2379 | */ |
|
| 2380 | public function alnum(string $message = '', string $fieldName = '') : Assert |
|
| 2381 | { |
|
| 2382 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2383 | { |
|
| 2384 | return $this; |
|
| 2385 | } |
|
| 2386 | try |
|
| 2387 | { |
|
| 2388 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $fieldName); |
|
| 2389 | } |
|
| 2390 | catch (AssertionFailedException $e) |
|
| 2391 | { |
|
| 2392 | $message = $message ?: $this->overrideError; |
|
| 2393 | $message = sprintf( |
|
| 2394 | $message |
|
| 2395 | ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.', |
|
| 2396 | $this->stringify($this->value) |
|
| 2397 | ); |
|
| 2398 | ||
| 2399 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $fieldName); |
|
| 2400 | } |
|
| 2401 | ||
| 2402 | return $this; |
|
| 2403 | } |
|
| 2404 | ||
| 2405 | /** |
|
| 2406 | * Assert that value is boolean True. |
|
| @@ 2687-2710 (lines=24) @@ | ||
| 2684 | * @return Assert |
|
| 2685 | * @throws AssertionFailedException |
|
| 2686 | */ |
|
| 2687 | public function userPrincipalName(string $message = '', string $fieldName = '') : Assert |
|
| 2688 | { |
|
| 2689 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2690 | { |
|
| 2691 | return $this; |
|
| 2692 | } |
|
| 2693 | try |
|
| 2694 | { |
|
| 2695 | $this->email($message, $fieldName); |
|
| 2696 | } |
|
| 2697 | catch (AssertionFailedException $e) |
|
| 2698 | { |
|
| 2699 | $message = $message ?: $this->overrideError; |
|
| 2700 | $message = sprintf( |
|
| 2701 | $message |
|
| 2702 | ?: 'Value "%s" is not a valid userPrincipalName.', |
|
| 2703 | $this->stringify($this->value) |
|
| 2704 | ); |
|
| 2705 | ||
| 2706 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_USERPRINCIPALNAME, $fieldName); |
|
| 2707 | } |
|
| 2708 | ||
| 2709 | return $this; |
|
| 2710 | } |
|
| 2711 | ||
| 2712 | /** |
|
| 2713 | * Assert that the count of countable is equal to count. |
|