Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Validation Strict Rules #5445

Merged
merged 22 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion system/Validation/FormatRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ public function valid_url_strict(?string $str = null, ?string $validSchemes = nu
return false;
}

$scheme = strtolower(parse_url($str, PHP_URL_SCHEME) ?? ''); // absent scheme gives null
// parse_url() may return null and false
$scheme = strtolower((string) parse_url($str, PHP_URL_SCHEME));
$validSchemes = explode(
',',
strtolower($validSchemes ?? 'http,https')
Expand Down
54 changes: 54 additions & 0 deletions system/Validation/StrictRules/CreditCardRules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Validation\StrictRules;

use CodeIgniter\Validation\CreditCardRules as NonStrictCreditCardRules;

/**
* Class CreditCardRules
*
* Provides validation methods for common credit-card inputs.
*
* @see http://en.wikipedia.org/wiki/Credit_card_number
*/
class CreditCardRules
{
private NonStrictCreditCardRules $nonStrictCreditCardRules;

public function __construct()
{
$this->nonStrictCreditCardRules = new NonStrictCreditCardRules();
}

/**
* Verifies that a credit card number is valid and matches the known
* formats for a wide number of credit card types. This does not verify
* that the card is a valid card, only that the number is formatted correctly.
*
* Example:
* $rules = [
* 'cc_num' => 'valid_cc_number[visa]'
* ];
*
* @param mixed $ccNumber
*/
public function valid_cc_number($ccNumber, string $type): bool
{
if (! is_string($ccNumber)) {
return false;
}

return $this->nonStrictCreditCardRules->valid_cc_number($ccNumber, $type);
}
}
23 changes: 23 additions & 0 deletions system/Validation/StrictRules/FileRules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Validation\StrictRules;

use CodeIgniter\Validation\FileRules as NonStrictFileRules;

/**
* File validation rules
*/
class FileRules extends NonStrictFileRules
{
}
Loading