| @@ 2150-2169 (lines=20) @@ | ||
| 2147 | * @return Assert |
|
| 2148 | * @throws AssertionFailedException |
|
| 2149 | */ |
|
| 2150 | public function directory(string $message='', string $fieldName='') : Assert |
|
| 2151 | { |
|
| 2152 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2153 | { |
|
| 2154 | return $this; |
|
| 2155 | } |
|
| 2156 | $this->string($message, $fieldName); |
|
| 2157 | if ( !is_dir($this->value) ) |
|
| 2158 | { |
|
| 2159 | $message = $message ?: $this->overrideError; |
|
| 2160 | $message = sprintf( |
|
| 2161 | $message ?: 'Path "%s" was expected to be a directory.', |
|
| 2162 | $this->stringify($this->value) |
|
| 2163 | ); |
|
| 2164 | ||
| 2165 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $fieldName); |
|
| 2166 | } |
|
| 2167 | ||
| 2168 | return $this; |
|
| 2169 | } |
|
| 2170 | ||
| 2171 | /** |
|
| 2172 | * Assert that value is something readable. |
|
| @@ 2179-2198 (lines=20) @@ | ||
| 2176 | * @return Assert |
|
| 2177 | * @throws AssertionFailedException |
|
| 2178 | */ |
|
| 2179 | public function readable(string $message='', string $fieldName='') : Assert |
|
| 2180 | { |
|
| 2181 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2182 | { |
|
| 2183 | return $this; |
|
| 2184 | } |
|
| 2185 | $this->string($message, $fieldName); |
|
| 2186 | if ( !is_readable($this->value) ) |
|
| 2187 | { |
|
| 2188 | $message = $message ?: $this->overrideError; |
|
| 2189 | $message = sprintf( |
|
| 2190 | $message ?: 'Path "%s" was expected to be readable.', |
|
| 2191 | $this->stringify($this->value) |
|
| 2192 | ); |
|
| 2193 | ||
| 2194 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $fieldName); |
|
| 2195 | } |
|
| 2196 | ||
| 2197 | return $this; |
|
| 2198 | } |
|
| 2199 | ||
| 2200 | /** |
|
| 2201 | * Assert that value is something writeable. |
|
| @@ 2208-2227 (lines=20) @@ | ||
| 2205 | * @return Assert |
|
| 2206 | * @throws AssertionFailedException |
|
| 2207 | */ |
|
| 2208 | public function writeable(string $message='', string $fieldName='') : Assert |
|
| 2209 | { |
|
| 2210 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2211 | { |
|
| 2212 | return $this; |
|
| 2213 | } |
|
| 2214 | $this->string($message, $fieldName); |
|
| 2215 | if ( !is_writeable($this->value) ) |
|
| 2216 | { |
|
| 2217 | $message = $message ?: $this->overrideError; |
|
| 2218 | $message = sprintf( |
|
| 2219 | $message ?: 'Path "%s" was expected to be writeable.', |
|
| 2220 | $this->stringify($this->value) |
|
| 2221 | ); |
|
| 2222 | ||
| 2223 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $fieldName); |
|
| 2224 | } |
|
| 2225 | ||
| 2226 | return $this; |
|
| 2227 | } |
|
| 2228 | ||
| 2229 | /** |
|
| 2230 | * Assert that value is a valid email address (using input_filter/FILTER_VALIDATE_EMAIL). |
|
| @@ 2379-2399 (lines=21) @@ | ||
| 2376 | * @return $this |
|
| 2377 | * @throws AssertionFailedException |
|
| 2378 | */ |
|
| 2379 | public function ausMobile(string $message='', string $fieldName='') : Assert |
|
| 2380 | { |
|
| 2381 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2382 | { |
|
| 2383 | return $this; |
|
| 2384 | } |
|
| 2385 | $this->string($message, $fieldName); |
|
| 2386 | if ( ! static::isAusMobile($this->value) ) |
|
| 2387 | { |
|
| 2388 | $message = $message ?: $this->overrideError; |
|
| 2389 | $message = sprintf( |
|
| 2390 | $message |
|
| 2391 | ?: 'Value "%s" is not an australian mobile number.', |
|
| 2392 | $this->stringify($this->value) |
|
| 2393 | ); |
|
| 2394 | ||
| 2395 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_AUS_MOBILE, $fieldName); |
|
| 2396 | } |
|
| 2397 | ||
| 2398 | return $this; |
|
| 2399 | } |
|
| 2400 | ||
| 2401 | /** |
|
| 2402 | * @param string $value |
|
| @@ 2418-2441 (lines=24) @@ | ||
| 2415 | * @return Assert |
|
| 2416 | * @throws AssertionFailedException |
|
| 2417 | */ |
|
| 2418 | public function alnum(string $message='', string $fieldName='') : Assert |
|
| 2419 | { |
|
| 2420 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2421 | { |
|
| 2422 | return $this; |
|
| 2423 | } |
|
| 2424 | try |
|
| 2425 | { |
|
| 2426 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $fieldName); |
|
| 2427 | } |
|
| 2428 | catch (AssertionFailedException $e) |
|
| 2429 | { |
|
| 2430 | $message = $message ?: $this->overrideError; |
|
| 2431 | $message = sprintf( |
|
| 2432 | $message |
|
| 2433 | ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.', |
|
| 2434 | $this->stringify($this->value) |
|
| 2435 | ); |
|
| 2436 | ||
| 2437 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $fieldName); |
|
| 2438 | } |
|
| 2439 | ||
| 2440 | return $this; |
|
| 2441 | } |
|
| 2442 | ||
| 2443 | /** |
|
| 2444 | * Assert that value is boolean True. |
|
| @@ 2725-2748 (lines=24) @@ | ||
| 2722 | * @return Assert |
|
| 2723 | * @throws AssertionFailedException |
|
| 2724 | */ |
|
| 2725 | public function userPrincipalName(string $message='', string $fieldName='') : Assert |
|
| 2726 | { |
|
| 2727 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2728 | { |
|
| 2729 | return $this; |
|
| 2730 | } |
|
| 2731 | try |
|
| 2732 | { |
|
| 2733 | $this->email($message, $fieldName); |
|
| 2734 | } |
|
| 2735 | catch (AssertionFailedException $e) |
|
| 2736 | { |
|
| 2737 | $message = $message ?: $this->overrideError; |
|
| 2738 | $message = sprintf( |
|
| 2739 | $message |
|
| 2740 | ?: 'Value "%s" is not a valid userPrincipalName.', |
|
| 2741 | $this->stringify($this->value) |
|
| 2742 | ); |
|
| 2743 | ||
| 2744 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_USERPRINCIPALNAME, $fieldName); |
|
| 2745 | } |
|
| 2746 | ||
| 2747 | return $this; |
|
| 2748 | } |
|
| 2749 | ||
| 2750 | /** |
|
| 2751 | * Assert that the given string is a valid UUID |
|