Skip to content

Commit

Permalink
Added integer validation
Browse files Browse the repository at this point in the history
Closes vlucas#118
  • Loading branch information
BruceDev authored and GrahamCampbell committed Dec 29, 2015
1 parent be2a943 commit fce9a5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ If the environment variable is empty, you'd get an Exception:
One or more environment variables failed assertions: DATABASE_DSN is empty
```

### Integer Variables

You might also need to ensure the the variable is of an integer value. You may do the following:

```php
$dotenv->required('FOO')->isInteger();
```

If the environment variable is not an integer, you'd get an Exception:

```
One or more environment variables failed assertions: FOO is not an integer
```

### Allowed Values

It is also possible to define a set of values that your environment variable
Expand Down
15 changes: 15 additions & 0 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ function ($value) {
);
}

/**
* Assert that each specified variable is a number.
*
* @return \Dotenv\Validator
*/
public function isInteger()
{
return $this->assertCallback(
function ($value) {
return ctype_digit($value);
},
'is not an integer'
);
}

/**
* Assert that each variable is amongst the given choices.
*
Expand Down

0 comments on commit fce9a5f

Please sign in to comment.