-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A user can be given a particular label and access to resources can be restricted to only users with that label.
- Loading branch information
1 parent
d821d1f
commit 2d770e6
Showing
9 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Utopia\Database\Validator; | ||
|
||
use Utopia\Validator\Text; | ||
|
||
class Alphanumeric extends Text | ||
{ | ||
/** | ||
* Alphanumeric constructor. | ||
* | ||
* Validate text with maximum length $length. Use $length = 0 for unlimited length. | ||
* | ||
* @param int $length | ||
* @param int $min | ||
*/ | ||
public function __construct(int $length, int $min = 1) | ||
{ | ||
parent::__construct($length, $min, \array_merge(Text::ALPHABET_UPPER, Text::ALPHABET_LOWER, Text::NUMBERS)); | ||
} | ||
|
||
/** | ||
* Get Description | ||
* | ||
* Returns validator description | ||
* | ||
* @return string | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
$message = 'Value must be a valid string'; | ||
|
||
if ($this->min === $this->length) { | ||
$message .= ' and exactly '.$this->length.' chars'; | ||
} else { | ||
if ($this->min) { | ||
$message .= ' and at least '.$this->min.' chars'; | ||
} | ||
|
||
if ($this->length) { | ||
$message .= ' and no longer than '.$this->length.' chars'; | ||
} | ||
} | ||
|
||
$message .= ' and only consist of alphanumeric chars'; | ||
|
||
return $message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Utopia\Database\Validator; | ||
|
||
class Label extends Alphanumeric | ||
{ | ||
/** | ||
* Label constructor. | ||
* | ||
* Validate text is a valid label | ||
* | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(36, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters