Skip to content

Commit b86fbad

Browse files
committed
Validators: added 'file', 'directory', 'class' & 'interface'
1 parent 020f61e commit b86fbad

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Utils/Validators.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ class Validators
4242
'uri' => [__CLASS__, 'isUri'],
4343
'none' => [__CLASS__, 'isNone'],
4444
'type' => [__CLASS__, 'isType'],
45+
'class' => 'class_exists',
46+
'interface' => 'interface_exists',
4547
'identifier' => [__CLASS__, 'isPhpIdentifier'],
48+
'file' => 'is_file',
49+
'directory' => 'is_dir',
4650
'pattern' => null,
4751
'alnum' => 'ctype_alnum',
4852
'alpha' => 'ctype_alpha',

tests/Utils/Validators.is().phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,32 @@ test(function () {
321321
});
322322

323323

324+
test(function () {
325+
Assert::true(Validators::is('rimmer', 'class'));
326+
Assert::false(Validators::is('kryton', 'class'));
327+
Assert::false(Validators::is('1', 'class'));
328+
});
329+
330+
331+
test(function () {
332+
Assert::false(Validators::is('rimmer', 'interface'));
333+
Assert::true(Validators::is('kryton', 'interface'));
334+
Assert::false(Validators::is('1', 'interface'));
335+
});
336+
337+
338+
test(function () {
339+
Assert::true(Validators::is(__FILE__, 'file'));
340+
Assert::false(Validators::is(__FILE__ . 'xx', 'class'));
341+
});
342+
343+
344+
test(function () {
345+
Assert::true(Validators::is(__DIR__, 'directory'));
346+
Assert::false(Validators::is(__DIR__ . 'xx', 'directory'));
347+
});
348+
349+
324350
test(function () {
325351
Assert::true(Validators::is('Item', 'identifier'));
326352
Assert::false(Validators::is('0Item', 'identifier'));

0 commit comments

Comments
 (0)