repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/LatinNumericRule.php | src/Validator/Rule/LatinNumericRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for latin and numeric character(s)
*
* @package Bluz\Validator\Rule
*/
class LatinNumericRule extends AbstractFilterRule
{
/**
* Check for latin and numeric character(s)
*
* @param mixed $input
*
* @return bool
*/
public function validateClean($input): bool
{
return (bool)preg_match('/^[a-z0-9]+$/i', $input);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if (empty($this->additionalChars)) {
return __('must contain only Latin letters and digits');
}
return __('must contain only Latin letters, digits and "%s"', $this->additionalChars);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/InStrictRule.php | src/Validator/Rule/InStrictRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for value in set
*
* @package Bluz\Validator\Rule
*/
class InStrictRule extends InRule
{
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
if (is_array($this->haystack)) {
return in_array($input, $this->haystack, true);
}
if (!is_string($this->haystack)) {
return false;
}
if (empty($input)) {
return false;
}
$enc = mb_detect_encoding($input);
return mb_strpos($this->haystack, $input, 0, $enc) !== false;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/BetweenRule.php | src/Validator/Rule/BetweenRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
use Bluz\Validator\Exception\ComponentException;
/**
* Check for value in range between minimum and maximum values
*
* @package Bluz\Validator\Rule
*/
class BetweenRule extends AbstractCompareRule
{
/**
* @var mixed minimum value
*/
protected $minValue;
/**
* @var mixed maximum value
*/
protected $maxValue;
/**
* Setup validation rule
*
* @param mixed $min
* @param mixed $max
*
* @throws \Bluz\Validator\Exception\ComponentException
*/
public function __construct($min, $max)
{
$this->minValue = $min;
$this->maxValue = $max;
if (null === $min || null === $max) {
throw new ComponentException('Minimum and maximum is required');
}
if ($min > $max) {
throw new ComponentException(sprintf('%s cannot be less than %s for validation', $min, $max));
}
}
/**
* Check input data
*
* @param NumericRule $input
*
* @return bool
*/
public function validate($input): bool
{
return $this->less($this->minValue, $input)
&& $this->less($input, $this->maxValue);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
$min = $this->minValue;
$max = $this->maxValue;
if ($min instanceof \DateTime) {
$min = date_format($min, 'r');
}
if ($max instanceof \DateTime) {
$max = date_format($max, 'r');
}
return __('must be between "%1s" and "%2s"', $min, $max);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/RequiredRule.php | src/Validator/Rule/RequiredRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check required
*
* @package Bluz\Validator\Rule
*/
class RequiredRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'is required';
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
if (is_string($input)) {
$input = trim($input);
}
return (false !== $input) && (null !== $input) && ('' !== $input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/BetweenInclusiveRule.php | src/Validator/Rule/BetweenInclusiveRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for value in range between minimum and maximum values
*
* @package Bluz\Validator\Rule
*/
class BetweenInclusiveRule extends BetweenRule
{
/**
* @var bool
*/
protected $inclusive = true;
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
$min = $this->minValue;
$max = $this->maxValue;
if ($min instanceof \DateTime) {
$min = date_format($min, 'r');
}
if ($max instanceof \DateTime) {
$max = date_format($max, 'r');
}
return __('must be inclusive between "%1s" and "%2s"', $min, $max);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/MoreRule.php | src/Validator/Rule/MoreRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for minimum
*
* @package Bluz\Validator\Rule
*/
class MoreRule extends AbstractCompareRule
{
/**
* @var mixed minimum value
*/
protected $minValue;
/**
* Setup validation rule
*
* @param mixed $minValue
*/
public function __construct($minValue)
{
$this->minValue = $minValue;
}
/**
* Check input data
*
* @param NumericRule $input
*
* @return bool
*/
public function validate($input): bool
{
return $this->less($this->minValue, $input);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
return __('must be greater than "%s"', $this->minValue);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/AlphaRule.php | src/Validator/Rule/AlphaRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for alphabetic character(s)
*
* @package Bluz\Validator\Rule
*/
class AlphaRule extends AbstractCtypeRule
{
/**
* Check for alphabetic character(s)
*
* @param string $input
*
* @return bool
*/
protected function validateClean($input): bool
{
return ctype_alpha($input);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if (empty($this->additionalChars)) {
return __('must contain only Latin letters');
}
return __('must contain only Latin letters and "%s"', $this->additionalChars);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/EqualsStrictRule.php | src/Validator/Rule/EqualsStrictRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check input data by compare with some value
*
* @package Bluz\Validator\Rule
*/
class EqualsStrictRule extends AbstractRule
{
/**
* @var string string for compare
*/
protected $compareTo;
/**
* Setup validation rule
*
* @param mixed $compareTo
*/
public function __construct($compareTo)
{
$this->compareTo = $compareTo;
}
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
return $input === $this->compareTo;
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
return __('must be identical as "%s"', $this->compareTo);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/AbstractCtypeRule.php | src/Validator/Rule/AbstractCtypeRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Abstract ctype rules
*
* @package Bluz\Validator\Rule
* @link http://php.net/manual/ru/book.ctype.php
*/
abstract class AbstractCtypeRule extends AbstractFilterRule
{
/**
* Filter input data
*
* @param string $input
*
* @return string
*/
protected function filter(string $input): string
{
$input = parent::filter((string)$input);
return preg_replace('/\s/', '', $input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/LatinRule.php | src/Validator/Rule/LatinRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for latin character(s)
*
* @package Bluz\Validator\Rule
*/
class LatinRule extends AbstractFilterRule
{
/**
* Check for latin character(s)
*
* @param mixed $input
*
* @return bool
*/
public function validateClean($input): bool
{
return (bool)preg_match('/^[a-z]+$/i', $input);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if (empty($this->additionalChars)) {
return __('must contain only Latin letters');
}
return __('must contain only Latin letters and "%s"', $this->additionalChars);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/ConditionRule.php | src/Validator/Rule/ConditionRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check input by condition
*
* @package Bluz\Validator\Rule
*/
class ConditionRule extends AbstractRule
{
/**
* @var bool condition rule
*/
protected $condition;
/**
* Setup validation rule
*
* @param bool $condition
*/
public function __construct($condition)
{
$this->condition = $condition;
}
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
return (bool)$this->condition;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/AbstractFilterRule.php | src/Validator/Rule/AbstractFilterRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
use Bluz\Validator\Exception\ComponentException;
/**
* Abstract rule for filters
*
* @package Bluz\Validator\Rule
*/
abstract class AbstractFilterRule extends AbstractRule
{
/**
* @var string additional chars
*/
protected $additionalChars = '';
/**
* Check input string
*
* @param string $input
*
* @return bool
*/
abstract protected function validateClean($input);
/**
* Setup validation rule
*
* @param string $additionalChars
*/
public function __construct(string $additionalChars = '')
{
$this->additionalChars .= $additionalChars;
}
/**
* Filter input data
*
* @param string $input
*
* @return string
*/
protected function filter(string $input): string
{
return str_replace(str_split($this->additionalChars), '', $input);
}
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
if (!is_scalar($input)) {
return false;
}
$cleanInput = $this->filter((string)$input);
return $cleanInput === '' || $this->validateClean($cleanInput);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/EmailRule.php | src/Validator/Rule/EmailRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for email
*
* @package Bluz\Validator\Rule
*/
class EmailRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a valid email address';
/**
* @var bool check DNS record flag
*/
protected $checkDns;
/**
* Setup validation rule
*
* @param bool $checkDns
*/
public function __construct(bool $checkDns = false)
{
$this->checkDns = $checkDns;
}
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
if (is_string($input) && filter_var($input, FILTER_VALIDATE_EMAIL)) {
[, $domain] = explode('@', $input, 2);
if ($this->checkDns) {
return checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A');
}
return true;
}
return false;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/InRule.php | src/Validator/Rule/InRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for value in set
*
* @package Bluz\Validator\Rule
*/
class InRule extends AbstractRule
{
/**
* @var string|array haystack for search, can be array or string
*/
protected $haystack;
/**
* Setup validation rule
*
* @param string|array $haystack
*/
public function __construct($haystack)
{
$this->haystack = $haystack;
}
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
if (is_array($this->haystack)) {
return in_array($input, $this->haystack, false);
}
if (!is_string($this->haystack)) {
return false;
}
if (empty($input)) {
return false;
}
$enc = mb_detect_encoding($input);
return mb_stripos($this->haystack, $input, 0, $enc) !== false;
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if (is_array($this->haystack)) {
$haystack = implode(', ', $this->haystack);
} else {
$haystack = $this->haystack;
}
return __('must be in "%s"', $haystack);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/FloatRule.php | src/Validator/Rule/FloatRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check float
*
* @package Bluz\Validator\Rule
*/
class FloatRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a float number';
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
return is_float(filter_var($input, FILTER_VALIDATE_FLOAT));
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/LengthRule.php | src/Validator/Rule/LengthRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
use Bluz\Validator\Exception\ComponentException;
use Countable;
/**
* Check for length in range between minimum and maximum values
*
* @package Bluz\Validator\Rule
*/
class LengthRule extends AbstractCompareRule
{
/**
* @var integer minimum value
*/
protected $minValue;
/**
* @var integer maximum value
*/
protected $maxValue;
/**
* @var bool
*/
protected $inclusive = true;
/**
* Setup validation rule
*
* @param integer|null $min
* @param integer|null $max
*
* @throws \Bluz\Validator\Exception\ComponentException
*/
public function __construct($min = null, $max = null)
{
$this->minValue = $min;
$this->maxValue = $max;
if (!is_numeric($min) && null !== $min) {
throw new ComponentException(
__('"%s" is not a valid numeric length', $min)
);
}
if (!is_numeric($max) && null !== $max) {
throw new ComponentException(
__('"%s" is not a valid numeric length', $max)
);
}
if (null !== $min && null !== $max && $min > $max) {
throw new ComponentException(
__('"%s" cannot be less than "%s" for validation', $min, $max)
);
}
}
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
if (!$length = $this->extractLength($input)) {
return false;
}
return (null === $this->minValue || $this->less($this->minValue, $length))
&& (null === $this->maxValue || $this->less($length, $this->maxValue));
}
/**
* Extract length
*
* @param string|object $input
*
* @return integer|false
*/
protected function extractLength($input)
{
if (is_string($input)) {
return mb_strlen($input, mb_detect_encoding($input));
}
if (is_array($input) || $input instanceof Countable) {
return count($input);
}
if (is_object($input)) {
return count(get_object_vars($input));
}
return false;
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if (!$this->minValue) {
return __('must have a length lower than "%d"', $this->maxValue);
}
if (!$this->maxValue) {
return __('must have a length greater than "%d"', $this->minValue);
}
if ($this->minValue === $this->maxValue) {
return __('must have a length "%d"', $this->minValue);
}
return __('must have a length between "%d" and "%d"', $this->minValue, $this->maxValue);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/CreditCardRule.php | src/Validator/Rule/CreditCardRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check credit card number by Mod10 algorithm
*
* @package Bluz\Validator\Rule
* @link https://en.wikipedia.org/wiki/Luhn_algorithm
*/
class CreditCardRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a valid Credit Card number';
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
$input = preg_replace('([ \.-])', '', (string) $input);
if (!is_numeric($input)) {
return false;
}
return $this->verifyMod10($input);
}
/**
* Verify by Mod10
*
* @param string $input
*
* @return bool
*/
private function verifyMod10(string $input): bool
{
$sum = 0;
$input = strrev($input);
$inputLen = \strlen($input);
for ($i = 0; $i < $inputLen; $i++) {
$current = $input[$i];
if ($i % 2 === 1) {
$current *= 2;
if ($current > 9) {
$firstDigit = $current % 10;
$secondDigit = ($current - $firstDigit) / 10;
$current = $firstDigit + $secondDigit;
}
}
$sum += $current;
}
return ($sum % 10 === 0);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/AbstractCompareRule.php | src/Validator/Rule/AbstractCompareRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Abstract rule of compare
*
* @package Bluz\Validator\Rule
*/
abstract class AbstractCompareRule extends AbstractRule
{
/**
* @var bool compare inclusive or not
*/
protected $inclusive;
/**
* Check $what less $than or not
*
* @param mixed $what
* @param mixed $than
*
* @return bool
*/
protected function less($what, $than): bool
{
if ($this->inclusive) {
return $what <= $than;
}
return $what < $than;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/NotEmptyRule.php | src/Validator/Rule/NotEmptyRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for not empty
*
* @package Bluz\Validator\Rule
*/
class NotEmptyRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must not be empty';
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
if (is_string($input)) {
$input = trim($input);
}
return !empty($input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/CountryCodeRule.php | src/Validator/Rule/CountryCodeRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for country code
*
* @package Bluz\Validator\Rule
* @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
*/
class CountryCodeRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a valid country code';
/**
* @var array list of valid country codes
*/
protected $countryCodeList = [
'AD',
'AE',
'AF',
'AG',
'AI',
'AL',
'AM',
'AO',
'AQ',
'AR',
'AS',
'AT',
'AU',
'AW',
'AX',
'AZ',
'BA',
'BB',
'BD',
'BE',
'BF',
'BG',
'BH',
'BI',
'BJ',
'BL',
'BM',
'BN',
'BO',
'BQ',
'BR',
'BS',
'BT',
'BV',
'BW',
'BY',
'BZ',
'CA',
'CC',
'CD',
'CF',
'CG',
'CH',
'CI',
'CK',
'CL',
'CM',
'CN',
'CO',
'CR',
'CU',
'CV',
'CW',
'CX',
'CY',
'CZ',
'DE',
'DJ',
'DK',
'DM',
'DO',
'DZ',
'EC',
'EE',
'EG',
'EH',
'ER',
'ES',
'ET',
'FI',
'FJ',
'FK',
'FM',
'FO',
'FR',
'GA',
'GB',
'GD',
'GE',
'GF',
'GG',
'GH',
'GI',
'GL',
'GM',
'GN',
'GP',
'GQ',
'GR',
'GS',
'GT',
'GU',
'GW',
'GY',
'HK',
'HM',
'HN',
'HR',
'HT',
'HU',
'ID',
'IE',
'IL',
'IM',
'IN',
'IO',
'IQ',
'IR',
'IS',
'IT',
'JE',
'JM',
'JO',
'JP',
'KE',
'KG',
'KH',
'KI',
'KM',
'KN',
'KP',
'KR',
'KW',
'KY',
'KZ',
'LA',
'LB',
'LC',
'LI',
'LK',
'LR',
'LS',
'LT',
'LU',
'LV',
'LY',
'MA',
'MC',
'MD',
'ME',
'MF',
'MG',
'MH',
'MK',
'ML',
'MM',
'MN',
'MO',
'MP',
'MQ',
'MR',
'MS',
'MT',
'MU',
'MV',
'MW',
'MX',
'MY',
'MZ',
'NA',
'NC',
'NE',
'NF',
'NG',
'NI',
'NL',
'NO',
'NP',
'NR',
'NU',
'NZ',
'OM',
'PA',
'PE',
'PF',
'PG',
'PH',
'PK',
'PL',
'PM',
'PN',
'PR',
'PS',
'PT',
'PW',
'PY',
'QA',
'RE',
'RO',
'RS',
'RU',
'RW',
'SA',
'SB',
'SC',
'SD',
'SE',
'SG',
'SH',
'SI',
'SJ',
'SK',
'SL',
'SM',
'SN',
'SO',
'SR',
'SS',
'ST',
'SV',
'SX',
'SY',
'SZ',
'TC',
'TD',
'TF',
'TG',
'TH',
'TJ',
'TK',
'TL',
'TM',
'TN',
'TO',
'TR',
'TT',
'TV',
'TW',
'TZ',
'UA',
'UG',
'UM',
'US',
'UY',
'UZ',
'VA',
'VC',
'VE',
'VG',
'VI',
'VN',
'VU',
'WF',
'WS',
'YE',
'YT',
'ZA',
'ZM',
'ZW'
];
/**
* Check for country code
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
return in_array(strtoupper($input), $this->countryCodeList, true);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/ArrayRule.php | src/Validator/Rule/ArrayRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
use Bluz\Validator\Exception\ComponentException;
/**
* Check for array
*
* @package Bluz\Validator\Rule
*/
class ArrayRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be an array';
/**
* @var callable Callback for check input array
*/
protected $callback;
/**
* Setup validation rule
*
* @param callable $callback
*/
public function __construct(callable $callback)
{
$this->callback = $callback;
}
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
if (!is_array($input)) {
return false;
}
$filtered = array_filter($input, $this->callback);
return count($input) === count($filtered);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/CallbackRule.php | src/Validator/Rule/CallbackRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check input by callback
*
* @package Bluz\Validator\Rule
*/
class CallbackRule extends AbstractRule
{
/**
* @var callable callback for check input
*/
protected $callback;
/**
* Setup validation rule
*
* @param callable $callback
*/
public function __construct(callable $callback)
{
$this->callback = $callback;
}
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
return (bool)\call_user_func($this->callback, $input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/EqualsRule.php | src/Validator/Rule/EqualsRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check input data by compare with some value
*
* @package Bluz\Validator\Rule
*/
class EqualsRule extends AbstractRule
{
/**
* @var string string for compare
*/
protected $compareTo;
/**
* Setup validation rule
*
* @param mixed $compareTo
*/
public function __construct($compareTo)
{
$this->compareTo = $compareTo;
}
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
return $input == $this->compareTo;
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
return __('must be equals "%s"', $this->compareTo);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/AbstractRule.php | src/Validator/Rule/AbstractRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
use Bluz\Validator\Exception\ValidatorException;
/**
* Abstract validation rule
*
* @package Bluz\Validator\Rule
* @author Anton Shevchuk
*/
abstract class AbstractRule implements RuleInterface
{
/**
* Message for error output
* @var string
*/
protected $description = 'is invalid';
/**
* @inheritdoc
*/
public function assert($input): void
{
if (!$this->validate($input)) {
throw new ValidatorException($this->description);
}
}
/**
* @inheritdoc
*/
public function __invoke($input): bool
{
return $this->validate($input);
}
/**
* @inheritdoc
*/
public function __toString(): string
{
return $this->getDescription();
}
/**
* @inheritdoc
*/
public function getDescription(): string
{
return __($this->description);
}
/**
* @inheritdoc
*/
public function setDescription(string $description): RuleInterface
{
$this->description = $description;
return $this;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/IntegerRule.php | src/Validator/Rule/IntegerRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for iInteger
*
* @package Bluz\Validator\Rule
*/
class IntegerRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be an integer number';
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
return is_numeric($input) && (int)$input == $input;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/ContainsRule.php | src/Validator/Rule/ContainsRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for contains
*
* @package Bluz\Validator\Rule
*/
class ContainsRule extends AbstractRule
{
/**
* @var string needle for search inside input data (haystack)
*/
protected $containsValue;
/**
* Setup validation rule
*
* @param mixed $containsValue
*/
public function __construct($containsValue)
{
$this->containsValue = $containsValue;
}
/**
* Check input data
*
* @param string|array $input
*
* @return bool
*/
public function validate($input): bool
{
// for array
if (is_array($input)) {
return in_array($this->containsValue, $input, false);
}
// for string
if (is_string($input)) {
return false !== mb_stripos($input, $this->containsValue, 0, mb_detect_encoding($input));
}
// can't compare
return false;
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
return __('must contain the value "%s"', $this->containsValue);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/SlugRule.php | src/Validator/Rule/SlugRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for slug by regular expressions
*
* @package Bluz\Validator\Rule
*/
class SlugRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a valid slug';
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
if (false !== strpos($input, '--')) {
return false;
}
if (!preg_match('/^[0-9a-z\-]+$/', $input)) {
return false;
}
if (preg_match('/^-|-$/', $input)) {
return false;
}
return true;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/DateRule.php | src/Validator/Rule/DateRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
use DateTime;
/**
* Check for date
*
* @package Bluz\Validator\Rule
*/
class DateRule extends AbstractRule
{
/**
* @var string date format
*/
protected $format = null;
/**
* Setup validation rule
*
* @param string|null $format
*/
public function __construct(?string $format = null)
{
$this->format = $format;
}
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
if ($input instanceof DateTime) {
return true;
}
if (!is_string($input)) {
return false;
}
if (null === $this->format) {
return false !== strtotime($input);
}
$dateFromFormat = DateTime::createFromFormat($this->format, $input);
return $dateFromFormat
&& $input === date($this->format, $dateFromFormat->getTimestamp());
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if ($this->format) {
return __('must be a valid date. Sample format: "%s"', $this->format);
}
return __('must be a valid date');
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/IpRule.php | src/Validator/Rule/IpRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
namespace Bluz\Validator\Rule;
use Bluz\Validator\Exception\ComponentException;
/**
* Check for IP
*
* Strict mode disabled for this file, because function long2ip() was changed in PHP 7.1
*
* @package Bluz\Validator\Rule
*/
class IpRule extends AbstractRule
{
/**
* @var integer setup options
*/
protected $options;
/**
* @var array network range
*/
protected $networkRange;
/**
* Setup validation rule
*
* @param mixed $options
*
* @throws ComponentException
*/
public function __construct($options = null)
{
if (is_int($options)) {
$this->options = $options;
return;
}
$this->networkRange = $this->parseRange($options);
}
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
return $this->verifyAddress($input) && $this->verifyNetwork($input);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if (!empty($this->networkRange)) {
$message = $this->networkRange['min'];
if (isset($this->networkRange['max'])) {
$message .= '-' . $this->networkRange['max'];
} else {
$message .= '/' . long2ip((string)bindec($this->networkRange['mask']));
}
return __('must be an IP address in the "%s" range', $message);
}
return __('must be an IP address');
}
/**
* Parse IP range
*
* @param string $input
*
* @return array|null
* @throws ComponentException
*/
protected function parseRange($input): ?array
{
if (
$input === null || $input === '*' || $input === '*.*.*.*'
|| $input === '0.0.0.0-255.255.255.255'
) {
return null;
}
$range = ['min' => null, 'max' => null, 'mask' => null];
if (strpos($input, '-') !== false) {
[$range['min'], $range['max']] = explode('-', $input);
} elseif (strpos($input, '*') !== false) {
$this->parseRangeUsingWildcards($input, $range);
} elseif (strpos($input, '/') !== false) {
$this->parseRangeUsingCidr($input, $range);
} else {
throw new ComponentException('Invalid network range');
}
if (!$this->verifyAddress($range['min'])) {
throw new ComponentException('Invalid network range');
}
if (isset($range['max']) && !$this->verifyAddress($range['max'])) {
throw new ComponentException('Invalid network range');
}
return $range;
}
/**
* Fill address
*
* @param string $input
* @param string $char
*/
protected function fillAddress(&$input, $char = '*'): void
{
while (substr_count($input, '.') < 3) {
$input .= '.' . $char;
}
}
/**
* Parse range using wildcards
*
* @param string $input
* @param array $range
*/
protected function parseRangeUsingWildcards($input, &$range): void
{
$this->fillAddress($input);
$range['min'] = str_replace('*', '0', $input);
$range['max'] = str_replace('*', '255', $input);
}
/**
* Parse range using Classless Inter-Domain Routing (CIDR)
*
* @param string $input
* @param array $range
*
* @throws ComponentException
* @link http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
*/
protected function parseRangeUsingCidr($input, &$range): void
{
$input = explode('/', $input);
$this->fillAddress($input[0], '0');
$range['min'] = $input[0];
$isAddressMask = strpos($input[1], '.') !== false;
if ($isAddressMask && $this->verifyAddress($input[1])) {
$range['mask'] = sprintf('%032b', ip2long($input[1]));
return;
}
if ($isAddressMask || $input[1] < 8 || $input[1] > 30) {
throw new ComponentException('Invalid network mask');
}
$range['mask'] = sprintf('%032b', ip2long(long2ip(~(2 ** (32 - $input[1]) - 1))));
}
/**
* Verify IP address
*
* @param string $address
*
* @return bool
*/
protected function verifyAddress($address): bool
{
return (bool)filter_var(
$address,
FILTER_VALIDATE_IP,
[
'flags' => $this->options
]
);
}
/**
* Verify Network by mask
*
* @param string $input
*
* @return bool
*/
protected function verifyNetwork($input): bool
{
if ($this->networkRange === null) {
return true;
}
if (isset($this->networkRange['mask'])) {
return $this->belongsToSubnet($input);
}
$input = sprintf('%u', ip2long($input));
$min = sprintf('%u', ip2long($this->networkRange['min']));
$max = sprintf('%u', ip2long($this->networkRange['max']));
return ($input >= $min) && ($input <= $max);
}
/**
* Check subnet
*
* @param string $input
*
* @return bool
*/
protected function belongsToSubnet($input): bool
{
$range = $this->networkRange;
$min = sprintf('%032b', ip2long($range['min']));
$input = sprintf('%032b', ip2long($input));
return ($input & $range['mask']) === ($min & $range['mask']);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/StringRule.php | src/Validator/Rule/StringRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for string
*
* @package Bluz\Validator\Rule
*/
class StringRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a string';
/**
* Check input data
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
return is_string($input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/ContainsStrictRule.php | src/Validator/Rule/ContainsStrictRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for contains
*
* @package Bluz\Validator\Rule
*/
class ContainsStrictRule extends ContainsRule
{
/**
* Check input data
*
* @param string|array $input
*
* @return bool
*/
public function validate($input): bool
{
// for array
if (is_array($input)) {
return in_array($this->containsValue, $input, true);
}
// for string
if (is_string($input)) {
return false !== mb_strpos($input, $this->containsValue, 0, mb_detect_encoding($input));
}
return false;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/DomainRule.php | src/Validator/Rule/DomainRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for domain
*
* @package Bluz\Validator\Rule
*/
class DomainRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a valid domain';
/**
* @var bool check DNS record flag
*/
protected $checkDns;
/**
* Setup validation rule
*
* @param bool $checkDns
*/
public function __construct(bool $checkDns = false)
{
$this->checkDns = $checkDns;
}
/**
* Check input data
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
$input = (string)$input;
// check by regular expression
if (
preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $input)
&& preg_match("/^.{1,253}$/", $input)
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $input)
) {
// check by DNS record
if ($this->checkDns) {
return checkdnsrr($input, 'A');
}
return true;
}
return false;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/LessOrEqualRule.php | src/Validator/Rule/LessOrEqualRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for maximum
*
* @package Bluz\Validator\Rule
*/
class LessOrEqualRule extends LessRule
{
/**
* @var bool
*/
protected $inclusive = true;
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
return __('must be lower than or equals "%s"', $this->maxValue);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/JsonRule.php | src/Validator/Rule/JsonRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for JSON
*
* @package Bluz\Validator\Rule
*/
class JsonRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a valid JSON string';
/**
* Check for valid JSON string
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
return (bool)json_decode($input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/NumericRule.php | src/Validator/Rule/NumericRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for numeric
*
* @package Bluz\Validator\Rule
*/
class NumericRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be numeric';
/**
* Check for numeric
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
return is_numeric($input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/LessRule.php | src/Validator/Rule/LessRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for maximum
*
* @package Bluz\Validator\Rule
*/
class LessRule extends AbstractCompareRule
{
/**
* @var mixed maximum value
*/
protected $maxValue;
/**
* Setup validation rule
*
* @param mixed $maxValue
*/
public function __construct($maxValue)
{
$this->maxValue = $maxValue;
}
/**
* Check input data
*
* @param NumericRule $input
*
* @return bool
*/
public function validate($input): bool
{
return $this->less($input, $this->maxValue);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
return __('must be lower than "%s"', $this->maxValue);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/AlphaNumericRule.php | src/Validator/Rule/AlphaNumericRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for alphanumeric character(s)
*
* @package Bluz\Validator\Rule
*/
class AlphaNumericRule extends AbstractCtypeRule
{
/**
* Check for alphanumeric character(s)
*
* @param string $input
*
* @return bool
*/
protected function validateClean($input): bool
{
return ctype_alnum($input);
}
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
if (empty($this->additionalChars)) {
return __('must contain only Latin letters and digits');
}
return __('must contain only Latin letters, digits and "%s"', $this->additionalChars);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/NegativeRule.php | src/Validator/Rule/NegativeRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for negative number
*
* @package Bluz\Validator\Rule
*/
class NegativeRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be negative';
/**
* Check for negative number
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
return is_numeric($input) && $input < 0;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/MoreOrEqualRule.php | src/Validator/Rule/MoreOrEqualRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for minimum
*
* @package Bluz\Validator\Rule
*/
class MoreOrEqualRule extends MoreRule
{
/**
* @var bool
*/
protected $inclusive = true;
/**
* Get error template
*
* @return string
*/
public function getDescription(): string
{
return __('must be greater than or equals "%s"', $this->minValue);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/RegexpRule.php | src/Validator/Rule/RegexpRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check string by regular expression
*
* @package Bluz\Validator\Rule
*/
class RegexpRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must validate with regular expression rule';
/**
* @var string regular expression for check string
*/
protected $regexp;
/**
* Check string by regular expression
*
* @param string $regexp
*/
public function __construct(string $regexp)
{
$this->regexp = $regexp;
}
/**
* Check string by regular expression
*
* @param mixed $input
*
* @return bool
*/
public function validate($input): bool
{
return (bool)preg_match($this->regexp, $input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Validator/Rule/VersionRule.php | src/Validator/Rule/VersionRule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Validator\Rule;
/**
* Check for version format
*
* @package Bluz\Validator\Rule
* @link http://semver.org/
*/
class VersionRule extends AbstractRule
{
/**
* @var string error template
*/
protected $description = 'must be a valid version number';
/**
* Check for version format
*
* @param string $input
*
* @return bool
*/
public function validate($input): bool
{
$pattern = '/^\d+\.\d+\.\d+([+-][^+-][0-9A-Za-z-.]*)?$/';
return (bool)preg_match($pattern, $input);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Session/SessionException.php | src/Session/SessionException.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Session;
use Bluz\Common\Exception\CommonException;
/**
* Exception
*
* @package Bluz\Session
* @author Anton Shevchuk
*/
class SessionException extends CommonException
{
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Session/Session.php | src/Session/Session.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Session;
use Bluz\Common\Exception\ComponentException;
use Bluz\Common\Options;
use SessionHandlerInterface;
/**
* Session
*
* @package Bluz\Session
* @author Anton Shevchuk
* @link https://github.com/bluzphp/framework/wiki/Session
*/
class Session
{
use Options;
/**
* @var string value returned by session_name()
*/
protected $name;
/**
* @var string namespace
*/
protected $namespace = 'bluz';
/**
* @var string Session handler name
*/
protected $adapter = 'files';
/**
* @var SessionHandlerInterface Session save handler
*/
protected $sessionHandler;
/**
* Attempt to set the session name
*
* If the session has already been started, or if the name provided fails
* validation, an exception will be raised.
*
* @param string $name
*
* @return void
* @throws SessionException
*/
public function setName(string $name): void
{
if ($this->sessionExists()) {
throw new SessionException(
'Cannot set session name after a session has already started'
);
}
if (!preg_match('/^[a-zA-Z0-9]+$/', $name)) {
throw new SessionException(
'Name provided contains invalid characters; must be alphanumeric only'
);
}
$this->name = $name;
session_name($name);
}
/**
* Get session name
*
* Proxies to {@link session_name()}.
*
* @return string
*/
public function getName(): string
{
if (null === $this->name) {
// If we're grabbing via session_name(), we don't need our
// validation routine; additionally, calling setName() after
// session_start() can lead to issues, and often we just need the name
// in order to do things such as setting cookies.
$this->name = session_name();
}
return $this->name;
}
/**
* Set Namespace
*
* @param string $namespace
*
* @return void
*/
public function setNamespace(string $namespace): void
{
$this->namespace = $namespace;
}
/**
* Get Namespace
*
* @return string
*/
public function getNamespace(): string
{
return $this->namespace;
}
/**
* Set session ID
*
* Can safely be called in the middle of a session.
*
* @param string $id
*
* @return void
* @throws SessionException
*/
public function setId(string $id): void
{
if ($this->sessionExists()) {
throw new SessionException(
'Session has already been started, to change the session ID call regenerateId()'
);
}
session_id($id);
}
/**
* Get session ID
*
* Proxies to {@link session_id()}
*
* @return string
*/
public function getId(): string
{
return session_id();
}
/**
* Regenerate id
*
* Regenerate the session ID, using session save handler's
* native ID generation Can safely be called in the middle of a session.
*
* @param bool $deleteOldSession
*
* @return bool
*/
public function regenerateId(bool $deleteOldSession = true): bool
{
if ($this->sessionExists() && session_id() !== '') {
return session_regenerate_id($deleteOldSession);
}
return false;
}
/**
* Returns true if session ID is set
*
* @return bool
*/
public function cookieExists(): bool
{
return isset($_COOKIE[session_name()]);
}
/**
* Does a session started and is it currently active?
*
* @return bool
*/
public function sessionExists(): bool
{
return session_status() === PHP_SESSION_ACTIVE;
}
/**
* Start session
*
* if No session currently exists, attempt to start it. Calls
* {@link isValid()} once session_start() is called, and raises an
* exception if validation fails.
*
* @return bool
* @throws ComponentException
*/
public function start(): bool
{
if ($this->sessionExists()) {
return true;
}
if ($this->init()) {
return session_start();
}
throw new ComponentException('Invalid adapter settings');
}
/**
* Destroy/end a session
*
* @return void
*/
public function destroy(): void
{
if (!$this->cookieExists() || !$this->sessionExists()) {
return;
}
session_destroy();
// send expire cookies
$this->expireSessionCookie();
// clear session data
unset($_SESSION[$this->getNamespace()]);
}
/**
* Set session handler name
*
* @param string $adapter
*
* @return void
*/
public function setAdapter(string $adapter): void
{
$this->adapter = $adapter;
}
/**
* Get session handler name
*
* @return string
*/
public function getAdapter(): string
{
return $this->adapter;
}
/**
* Register Save Handler with ext/session
*
* Since ext/session is coupled to this particular session manager
* register the save handler with ext/session.
*
* @return bool
* @throws ComponentException
*/
protected function init(): bool
{
if ($this->sessionHandler) {
return true;
}
if ('files' === $this->adapter) {
$this->sessionHandler = new \SessionHandler();
// try to apply settings
if ($settings = $this->getOption('settings', 'files')) {
$this->setSavePath($settings['save_path']);
}
return session_set_save_handler($this->sessionHandler);
}
$adapterClass = '\\Bluz\\Session\\Adapter\\' . ucfirst($this->adapter);
if (!class_exists($adapterClass) || !is_subclass_of($adapterClass, SessionHandlerInterface::class)) {
throw new ComponentException("Class for session adapter `{$this->adapter}` not found");
}
$settings = $this->getOption('settings', $this->adapter) ?: [];
$this->sessionHandler = new $adapterClass($settings);
return session_set_save_handler($this->sessionHandler);
}
/**
* Set the session cookie lifetime
*
* If a session already exists, destroys it (without sending an expiration
* cookie), regenerates the session ID, and restarts the session.
*
* @param integer $ttl TTL in seconds
*
* @return void
*/
public function setSessionCookieLifetime(int $ttl): void
{
// Set new cookie TTL
session_set_cookie_params($ttl);
if ($this->sessionExists()) {
// There is a running session so we'll regenerate id to send a new cookie
$this->regenerateId();
}
}
/**
* Expire the session cookie
*
* Sends a session cookie with no value, and with an expiry in the past.
*
* @return void
*/
public function expireSessionCookie(): void
{
if (ini_get('session.use_cookies')) {
$params = session_get_cookie_params();
setcookie(
$this->getName(),
'',
$_SERVER['REQUEST_TIME'] - 42000,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
}
}
/**
* Set session save path
*
* @param string $savePath
*
* @return void
* @throws ComponentException
*/
protected function setSavePath(string $savePath): void
{
if (
!is_dir($savePath)
|| !is_writable($savePath)
) {
throw new ComponentException('Session path is not writable');
}
session_save_path($savePath);
}
/**
* Set key/value pair
*
* @param string $key
* @param mixed $value
*
* @return void
* @throws ComponentException
*/
public function set(string $key, $value): void
{
$this->start();
// check storage
if (!isset($_SESSION[$this->getNamespace()])) {
$_SESSION[$this->getNamespace()] = [];
}
$_SESSION[$this->namespace][$key] = $value;
}
/**
* Get value by key
*
* @param string $key
*
* @return mixed
* @throws ComponentException
*/
public function get(string $key)
{
if ($this->contains($key)) {
return $_SESSION[$this->namespace][$key];
}
return null;
}
/**
* Isset
*
* @param string $key
*
* @return bool
* @throws ComponentException
*/
public function contains(string $key): bool
{
if ($this->cookieExists()) {
$this->start();
} elseif (!$this->sessionExists()) {
return false;
}
return isset($_SESSION[$this->namespace][$key]);
}
/**
* Unset
*
* @param string $key
*
* @return void
* @throws ComponentException
*/
public function delete(string $key): void
{
if ($this->contains($key)) {
unset($_SESSION[$this->namespace][$key]);
}
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Session/Adapter/Redis.php | src/Session/Adapter/Redis.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Session\Adapter;
use Bluz\Common\Exception\ComponentException;
use Bluz\Common\Exception\ConfigurationException;
/**
* Redis session handler
*
* @package Bluz\Session\Adapter
*/
class Redis extends AbstractAdapter implements \SessionHandlerInterface
{
/**
* @var array default Redis settings
*/
protected $settings = [
'host' => '127.0.0.1',
'port' => 6379,
'timeout' => 0,
'persistence' => false,
];
/**
* Check and setup Redis server
*
* @param array $settings
*
* @throws ComponentException
* @throws ConfigurationException
*/
public function __construct(array $settings = [])
{
// check Redis extension
if (!extension_loaded('redis')) {
throw new ComponentException(
'Redis extension not installed/enabled.
Install and/or enable Redis extension [http://pecl.php.net/package/redis].
See phpinfo() for more information'
);
}
// check Redis settings
if (!is_array($settings) || empty($settings)) {
throw new ConfigurationException(
'Redis configuration is missed. Please check `session` configuration section'
);
}
// Update settings
$this->settings = array_replace_recursive($this->settings, $settings);
}
/**
* Initialize session
*
* @param string $savePath
* @param string $sessionName
*
* @return bool
*/
public function open($savePath, $sessionName): bool
{
parent::open($savePath, $sessionName);
$this->handler = new \Redis();
if ($this->settings['persistence']) {
$this->handler->pconnect($this->settings['host'], $this->settings['port'], $this->settings['timeout']);
} else {
$this->handler->connect($this->settings['host'], $this->settings['port'], $this->settings['timeout']);
}
if (isset($this->settings['options'])) {
foreach ($this->settings['options'] as $key => $value) {
$this->handler->setOption($key, $value);
}
}
return true;
}
/**
* Read session data
*
* @param string $id
*
* @return string
*/
public function read($id): string
{
return $this->handler->get($this->prepareId($id)) ?: '';
}
/**
* Write session data
*
* @param string $id
* @param string $data
*
* @return bool
*/
public function write($id, $data): bool
{
return $this->handler->set($this->prepareId($id), $data, (int)$this->ttl);
}
/**
* Destroy a session
*
* @param integer $id
*
* @return bool
*/
public function destroy($id): bool
{
$this->handler->del($this->prepareId($id));
return true;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Session/Adapter/AbstractAdapter.php | src/Session/Adapter/AbstractAdapter.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Session\Adapter;
/**
* Abstract session handler
*
* @package Bluz\Session\Adapter
*/
abstract class AbstractAdapter
{
/**
* @var mixed instance of Redis or Cache or some other
*/
protected $handler = null;
/**
* @var string prefix for session store
*/
protected $prefix = 'PHPSESSID:';
/**
* @var integer TTL of session
*/
protected $ttl = 1800;
/**
* Prepare Id - add prefix
*
* @param string $id
*
* @return string
*/
protected function prepareId($id): string
{
return $this->prefix . $id;
}
/**
* Initialize session
*
* @param string $savePath
* @param string $sessionName
*
* @return bool
*/
public function open($savePath, $sessionName): bool
{
$this->prefix = $sessionName . ':';
$this->ttl = (int)ini_get('session.gc_maxlifetime');
// No more action necessary because connection is injected
// in constructor and arguments are not applicable.
return true;
}
/**
* Close the session
*
* @return bool
*/
public function close(): bool
{
$this->handler = null;
unset($this->handler);
return true;
}
/**
* Cleanup old sessions
*
* @param integer $maxLifetime
*
* @return bool
*/
public function gc($maxLifetime): bool
{
// no action necessary because using EXPIRE
return true;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Session/Adapter/Cache.php | src/Session/Adapter/Cache.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Session\Adapter;
use Bluz\Common\Exception\ConfigurationException;
use Bluz\Proxy;
/**
* Cache session handler
*
* @package Bluz\Session\Adapter
*/
class Cache extends AbstractAdapter implements \SessionHandlerInterface
{
/**
* Check and setup Redis server
*
* @param array $settings
*
* @throws ConfigurationException
*/
public function __construct(array $settings = [])
{
if (!Proxy\Cache::getInstance()) {
throw new ConfigurationException(
'Cache configuration is missed or disabled. Please check `cache` configuration section'
);
}
}
/**
* Read session data
*
* @param string $id
*
* @return string
* @throws \Psr\Cache\InvalidArgumentException
*/
public function read($id): string
{
return Proxy\Cache::get($this->prepareId($id)) ?: '';
}
/**
* Write session data
*
* @param string $id
* @param string $data
*
* @return bool
* @throws \Psr\Cache\InvalidArgumentException
*/
public function write($id, $data): bool
{
return Proxy\Cache::set($this->prepareId($id), $data, $this->ttl);
}
/**
* Destroy a session
*
* @param integer $id
*
* @return bool
*/
public function destroy($id): bool
{
return Proxy\Cache::delete($this->prepareId($id));
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Db.php | src/Proxy/Db.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Db\Db as Instance;
use Bluz\Db\Query;
/**
* Proxy to Db
*
* Example of usage
* <code>
* use Bluz\Proxy\Db;
*
* Db::fetchAll('SELECT * FROM users');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static mixed getOption($key, $section = null)
* @see Instance::getOption()
*
* @method static \PDO handler()
* @see Instance::handler()
*
* @method static string quote($value)
* @see Instance::quote()
*
* @method static string quoteIdentifier($identifier)
* @see Instance::quoteIdentifier()
*
* @method static integer query($sql, $params = [], $types = [])
* @see Instance::query()
*
* @method static Query\Select select(...$select)
* @see Instance::select()
*
* @method static Query\Insert insert($table)
* @see Instance::insert()
*
* @method static Query\Update update($table)
* @see Instance::update()
*
* @method static Query\Delete delete($table)
* @see Instance::delete()
*
* @method static string fetchOne($sql, $params = [])
* @see Instance::fetchOne()
*
* @method static array fetchRow($sql, $params = [])
* @see Instance::fetchRow()
*
* @method static array fetchAll($sql, $params = [])
* @see Instance::fetchAll()
*
* @method static array fetchColumn($sql, $params = [])
* @see Instance::fetchColumn()
*
* @method static array fetchGroup($sql, $params = [], $object = null))
* @see Instance::fetchGroup()
*
* @method static array fetchColumnGroup($sql, $params = [])
* @see Instance::fetchColumnGroup()
*
* @method static array fetchUniqueGroup($sql, $params = [])
* @see Instance::fetchUniqueGroup()
*
* @method static array fetchPairs($sql, $params = [])
* @see Instance::fetchPairs()
*
* @method static array fetchObject($sql, $params = [], $object = "stdClass")
* @see Instance::fetchObject()
*
* @method static array fetchObjects($sql, $params = [], $object = null)
* @see Instance::fetchObjects()
*
* @method static array fetchRelations($sql, $params = [])
* @see Instance::fetchRelations()
*
* @method static bool transaction($process)
* @see Instance::transaction()
*
* @method static void disconnect()
* @see Instance::disconnect()
*/
final class Db
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
*/
private static function initInstance(): Instance
{
$instance = new Instance();
$instance->setOptions(Config::get('db'));
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Translator.php | src/Proxy/Translator.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Exception\ConfigurationException;
use Bluz\Translator\Translator as Instance;
/**
* Proxy to Translator
*
* Example of usage
* <code>
* use Bluz\Proxy\Translator;
*
* echo Translator::translate('message id');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static string translate($message, ...$text)
* @see Instance::translate()
*
* @method static string translatePlural($singular, $plural, $number, ...$text)
* @see Instance::translatePlural()
*/
final class Translator
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
* @throws ConfigurationException
*/
private static function initInstance(): Instance
{
$instance = new Instance();
$instance->setOptions(Config::get('translator'));
$instance->init();
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Registry.php | src/Proxy/Registry.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Registry\Registry as Instance;
/**
* Proxy to Registry
*
* Example of usage
* <code>
* use Bluz\Proxy\Registry;
*
* Registry::set('key', 'value');
* Registry::get('key');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static void set($key, $value)
* @see Instance::set()
*
* @method static mixed get($key)
* @see Instance::get()
*
* @method static bool contains($key)
* @see Instance::contains()
*
* @method static void delete($key)
* @see Instance::delete()
*/
final class Registry
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
*/
private static function initInstance(): Instance
{
$instance = new Instance();
if ($data = Config::get('registry')) {
$instance->setFromArray($data);
}
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Request.php | src/Proxy/Request.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Exception\ComponentException;
use Bluz\Http\RequestMethod;
use Psr\Http\Message\UriInterface;
use Laminas\Diactoros\ServerRequest as Instance;
use Laminas\Diactoros\UploadedFile;
/**
* Proxy to Request
*
* Example of usage
* <code>
* use Bluz\Proxy\Request;
*
* Request::getParam('foo');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @todo Proxy class should be clean
*
* @method static Instance getInstance()
*
* @method static UriInterface getUri()
* @see \Laminas\Diactoros\RequestTrait::getUri()
*/
final class Request
{
use ProxyTrait;
/**
* @const string HTTP content types
*/
public const TYPE_ANY = '*/*';
public const TYPE_HTML = 'text/html';
public const TYPE_JSON = 'application/json';
/**
* @var array|null Accepted type
*/
private static $accept;
/**
* @var array|null Accepted languages
*/
private static $language;
/**
* Init instance
*
* @throws ComponentException
*/
private static function initInstance()
{
throw new ComponentException('Class `Proxy\\Request` required external initialization');
}
/**
* Retrieve a member of the $_GET super global
*
* If no $key is passed, returns the entire $_GET array.
*
* @param string|null $key
* @param string|null $default Default value to use if key not found
*
* @return string|array|null Returns null if key does not exist
*/
public static function getQuery(?string $key = null, ?string $default = null)
{
return self::getInstance()->getQueryParams()[$key] ?? $default;
}
/**
* Retrieve a member of the $_POST super global
*
* If no $key is passed, returns the entire $_POST array.
*
* @param string|null $key
* @param string|null $default Default value to use if key not found
*
* @return string|array|null Returns null if key does not exist
*/
public static function getPost(?string $key = null, ?string $default = null)
{
return self::getInstance()->getParsedBody()[$key] ?? $default;
}
/**
* Retrieve a member of the $_SERVER super global
*
* If no $key is passed, returns the entire $_SERVER array.
*
* @param string|null $key
* @param string|null $default Default value to use if key not found
*
* @return string Returns null if key does not exist
*/
public static function getServer(?string $key = null, ?string $default = null)
{
return self::getInstance()->getServerParams()[$key] ?? $default;
}
/**
* Retrieve a member of the $_COOKIE super global
*
* If no $key is passed, returns the entire $_COOKIE array.
*
* @param string|null $key
* @param string|null $default Default value to use if key not found
*
* @return string Returns null if key does not exist
*/
public static function getCookie(?string $key = null, ?string $default = null)
{
return self::getInstance()->getCookieParams()[$key] ?? $default;
}
/**
* Retrieve a member of the $_ENV super global
*
* If no $key is passed, returns the entire $_ENV array.
*
* @param string|null $key
* @param string|null $default Default value to use if key not found
*
* @return string Returns null if key does not exist
*/
public static function getEnv(?string $key = null, ?string $default = null)
{
return $_ENV[$key] ?? $default;
}
/**
* Search for a header value
*
* @param string $header
* @param mixed $default
*
* @return string
*/
public static function getHeader(string $header, $default = null)
{
$header = strtolower($header);
$headers = self::getInstance()->getHeaders();
$headers = array_change_key_case($headers, CASE_LOWER);
if (array_key_exists($header, $headers)) {
$value = is_array($headers[$header]) ? implode(', ', $headers[$header]) : $headers[$header];
return $value;
}
return $default;
}
/**
* Access values contained in the superglobals as public members
* Order of precedence: 1. GET, 2. POST
*
* @param string $key
* @param null $default
*
* @return string|array|null
* @link http://msdn.microsoft.com/en-us/library/system.web.httprequest.item.aspx
*/
public static function getParam(string $key, $default = null)
{
return
self::getQuery($key) ??
self::getPost($key) ??
$default;
}
/**
* Get all params from GET and POST or PUT
*
* @return array
*/
public static function getParams(): array
{
$body = (array)self::getInstance()->getParsedBody();
$query = (array)self::getInstance()->getQueryParams();
return array_merge([], $body, $query);
}
/**
* Get uploaded file
*
* @param string $name
*
* @return UploadedFile
*/
public static function getFile(string $name)
{
return self::getInstance()->getUploadedFiles()[$name] ?? false;
}
/**
* Get the client's IP address
*
* @param bool $checkProxy
*
* @return string
*/
public static function getClientIp(bool $checkProxy = true)
{
$result = null;
if ($checkProxy) {
$result = self::getServer('HTTP_CLIENT_IP') ?? self::getServer('HTTP_X_FORWARDED_FOR') ?? null;
}
return $result ?? self::getServer('REMOTE_ADDR');
}
/**
* Get module
*
* @return string
*/
public static function getModule(): string
{
return self::getParam('_module', Router::getDefaultModule());
}
/**
* Get controller
*
* @return string
*/
public static function getController(): string
{
return self::getParam('_controller', Router::getDefaultController());
}
/**
* Get method
*
* @return string
*/
public static function getMethod(): string
{
return self::getParam('_method', self::getInstance()->getMethod());
}
/**
* Get Accept MIME Type
*
* @return array
*/
public static function getAccept(): array
{
if (!self::$accept) {
// get header from request
self::$accept = self::parseAcceptHeader(self::getHeader('Accept'));
}
return self::$accept;
}
/**
* Get Accept MIME Type
*
* @return array
*/
public static function getAcceptLanguage(): array
{
if (!self::$language) {
// get header from request
self::$language = self::parseAcceptHeader(self::getHeader('Accept-Language'));
}
return self::$language;
}
/**
* parseAcceptHeader
*
* @param string|null $header
*
* @return array
*/
private static function parseAcceptHeader(?string $header): array
{
// empty array
$accept = [];
// check empty
if (!$header || $header === '') {
return $accept;
}
// make array from header
$values = explode(',', $header);
$values = array_map('trim', $values);
foreach ($values as $a) {
// the default quality is 1.
$q = 1;
// check if there is a different quality
if (strpos($a, ';q=') || strpos($a, '; q=')) {
// divide "mime/type;q=X" into two parts: "mime/type" i "X"
[$a, $q] = preg_split('/;([ ]?)q=/', $a);
}
// remove other extension
if (strpos($a, ';')) {
$a = substr($a, 0, strpos($a, ';'));
}
// mime-type $a is accepted with the quality $q
// WARNING: $q == 0 means, that isn’t supported!
$accept[$a] = (float)$q;
}
arsort($accept);
return $accept;
}
/**
* Reset accept for tests
*
* @return void
*/
public static function resetAccept(): void
{
self::$accept = null;
}
/**
* Check Accept header
*
* @param array $allowTypes
*
* @return string|false
*/
public static function checkAccept(array $allowTypes = [])
{
$accept = self::getAccept();
// if no parameter was passed, just return first mime type from parsed data
if (empty($allowTypes)) {
return current(array_keys($accept));
}
$allowTypes = array_map('strtolower', $allowTypes);
// let’s check our supported types:
foreach ($accept as $mime => $quality) {
if ($quality && in_array($mime, $allowTypes, true)) {
return $mime;
}
}
// no mime-type found
return false;
}
/**
* Check CLI
*
* @return bool
*/
public static function isCli(): bool
{
return (PHP_SAPI === 'cli');
}
/**
* Check HTTP
*
* @return bool
*/
public static function isHttp(): bool
{
return (PHP_SAPI !== 'cli');
}
/**
* Is this a GET method request?
*
* @return bool
*/
public static function isGet(): bool
{
return (self::getInstance()->getMethod() === RequestMethod::GET);
}
/**
* Is this a POST method request?
*
* @return bool
*/
public static function isPost(): bool
{
return (self::getInstance()->getMethod() === RequestMethod::POST);
}
/**
* Is this a PUT method request?
*
* @return bool
*/
public static function isPut(): bool
{
return (self::getInstance()->getMethod() === RequestMethod::PUT);
}
/**
* Is this a DELETE method request?
*
* @return bool
*/
public static function isDelete(): bool
{
return (self::getInstance()->getMethod() === RequestMethod::DELETE);
}
/**
* Is the request a Javascript XMLHttpRequest?
*
* @return bool
*/
public static function isXmlHttpRequest(): bool
{
return (self::getHeader('X-Requested-With') === 'XMLHttpRequest');
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Auth.php | src/Proxy/Auth.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Auth\Auth as Instance;
use Bluz\Auth\IdentityInterface;
/**
* Proxy to Auth
*
* Example of usage
* use Bluz\Proxy\Auth;
*
* $user = Auth::getIdentity();
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static void setIdentity(IdentityInterface $identity)
* @see Instance::setIdentity()
*
* @method static IdentityInterface getIdentity()
* @see Instance::getIdentity()
*
* @method static void clearIdentity()
* @see Instance::clearIdentity()
*/
final class Auth
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
*/
private static function initInstance(): Instance
{
$instance = new Instance();
$instance->setOptions(Config::get('auth'));
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/HttpCacheControl.php | src/Proxy/HttpCacheControl.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Nil;
use Bluz\Http\CacheControl as Instance;
/**
* Proxy to Http\CacheControl
*
* Example of usage
* <code>
* use Bluz\Proxy\HttpCacheControl;
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static void setPrivate()
* @see Instance::setPrivate()
*
* @method static void setPublic()
* @see Instance::setPublic()
*
* @method static integer getMaxAge()
* @see Instance::getMaxAge()
*
* @method static void setMaxAge($value)
* @see Instance::getMaxAge()
*
* @method static void setSharedMaxAge($value)
* @see Instance::getMaxAge()
*
* @method static integer getTtl()
* @see Instance::getTtl()
*
* @method static void setTtl($seconds)
* @see Instance::setTtl()
*
* @method static void setClientTtl($seconds)
* @see Instance::setClientTtl()
*
* @method static string getEtag()
* @see Instance::getEtag()
*
* @method static void setEtag($etag, $weak = false)
* @see Instance::setEtag()
*
* @method static integer getAge()
* @see Instance::getAge()
*
* @method static void setAge($age)
* @see Instance::setAge()
*
* @method static \DateTime getExpires()
* @see Instance::getExpires()
*
* @method static void setExpires($date)
* @see Instance::setExpires()
*
* @method static \DateTime|null getLastModified()
* @see Instance::getLastModified()
*
* @method static void setLastModified($date)
* @see Instance::setLastModified()
*/
final class HttpCacheControl
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance|Nil
*/
private static function initInstance()
{
if (PHP_SAPI === 'cli') {
return new Nil();
}
return new Instance(Response::getInstance());
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Mailer.php | src/Proxy/Mailer.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Exception\ConfigurationException;
use Bluz\Mailer\Mailer as Instance;
/**
* Proxy to Mailer
*
* Example of usage
* <code>
* use Bluz\Proxy\Mailer;
*
* $mail = Mailer::create();
* $mail->From = 'from@example.com';
* $mail->Subject = 'Here is the subject';
* // ...
* Mailer::send($mail);
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static \PHPMailer\PHPMailer\PHPMailer create()
* @see Instance::create()
*
* @method static bool send(\PHPMailer\PHPMailer\PHPMailer $mail)
* @see Instance::send()
*/
final class Mailer
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
* @throws ConfigurationException
*/
private static function initInstance(): Instance
{
$instance = new Instance();
$instance->setOptions(Config::get('mailer'));
$instance->init();
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Response.php | src/Proxy/Response.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Exception\ComponentException;
use Bluz\Controller\Controller;
use Bluz\Http\Exception\RedirectException;
use Bluz\Response\Response as Instance;
/**
* Proxy to Response
*
* Example of usage
* <code>
* use Bluz\Proxy\Response;
*
* Response::setStatusCode(304);
* Response::setHeader('Location', '/index/index');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static string getProtocolVersion()
* @see Instance::getProtocolVersion()
*
* @method static string getStatusCode()
* @see Instance::getStatusCode()
* @method static void setStatusCode($code)
* @see Instance::setStatusCode()
*
* @method static void setReasonPhrase($phrase)
* @see Instance::setReasonPhrase()
* @method static string getReasonPhrase()
* @see Instance::getReasonPhrase()
*
* @method static string getHeader($header)
* @see Instance::getHeader()
* @method static array getHeaderAsArray($header)
* @see Instance::getHeaderAsArray()
* @method static bool hasHeader($header)
* @see Instance::hasHeader()
* @method static void setHeader($header, $value)
* @see Instance::setHeader()
* @method static void addHeader($header, $value)
* @see Instance::addHeader()
* @method static void removeHeader($header)
* @see Instance::removeHeader()
*
* @method static array getHeaders()
* @see Instance::getHeaders()
* @method static void setHeaders(array $headers)
* @see Instance::setHeaders()
* @method static void addHeaders(array $headers)
* @see Instance::addHeaders()
* @method static void removeHeaders()
* @see Instance::removeHeaders()
*
* @method static void setBody($phrase)
* @see Instance::setBody()
* @method static Controller getBody()
* @see Instance::getBody()
* @method static void clearBody()
* @see Instance::clearBody()
*
* @method static void setCookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $s = null, $h = null)
* @see Instance::setCookie()
* @method static array getCookie()
* @see Instance::getCookie()
*
* @method static string getType()
* @see Instance::getType()
* @method static void setType($type)
* @see Instance::setType()
*
* @method static void send()
* @see Instance::send()
*/
final class Response
{
use ProxyTrait;
/**
* Init instance
*
* @throws ComponentException
*/
private static function initInstance()
{
throw new ComponentException("Class `Proxy\\Request` required external initialization");
}
/**
* Redirect to URL
*
* @param string $url
*
* @return void
* @throws RedirectException
*/
public static function redirect(string $url): void
{
$redirect = new RedirectException();
$redirect->setUrl($url);
throw $redirect;
}
/**
* Redirect to controller
*
* @param string $module
* @param string $controller
* @param array $params
*
* @return void
* @throws RedirectException
*/
public static function redirectTo(string $module, string $controller = 'index', array $params = []): void
{
$url = Router::getFullUrl($module, $controller, $params);
self::redirect($url);
}
/**
* Reload current page please, be careful to avoid loop of reload
*
* @return void
* @throws RedirectException
*/
public static function reload(): void
{
self::redirect((string) Request::getUri());
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Layout.php | src/Proxy/Layout.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Container\RegularAccess;
use Bluz\Common\Exception\CommonException;
use Bluz\Layout\Layout as Instance;
use Bluz\View\View;
/**
* Proxy to Layout
*
* Example of usage
* <code>
* use Bluz\Proxy\Layout;
*
* Layout::title('Homepage');
* Layout::set('description', 'some page description');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static View getContent()
* @see Instance::getContent()
* @method static void setContent($content)
* @see Instance::setContent()
* @method static void setPath($path)
* @see View::setPath()
* @method static string getPath()
* @see View::getPath()
* @method static void setTemplate($file)
* @see View::setTemplate()
* @method static string getTemplate()
* @see View::getTemplate()
*
* @method static void set($key, $value)
* @see RegularAccess::set()
* @method static mixed get($key)
* @see RegularAccess::get()
* @method static bool contains($key)
* @see RegularAccess::contains()
* @method static void delete($key)
* @see RegularAccess::delete()
*
* @method static string ahref(string $text, mixed $href, array $attributes = [])
* @method static array|null breadCrumbs(array $data = [])
* @method static string|null headScript(string $src = null, array $attributes = [])
* @method static string|null headScriptBlock(string $code = null)
* @method static string|null headStyle(string $href = null, string $media = 'all')
* @method static string|null link(string $src = null, string $rel = 'stylesheet')
* @method static string|null meta(string $name = null, string $content = null)
* @method static string|null title(string $title = null)
* @method static string titleAppend(string $title, string $separator = ' :: ')
* @method static string titlePrepend(string $title, string $separator = ' :: ')
*/
final class Layout
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
* @throws CommonException
*/
private static function initInstance(): Instance
{
$instance = new Instance();
$instance->setOptions(Config::get('layout'));
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/ProxyTrait.php | src/Proxy/ProxyTrait.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Singleton;
/**
* ProxyTrait
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*/
trait ProxyTrait
{
use Singleton;
/**
* Set or replace instance
*
* @param mixed $instance
*
* @return void
*/
public static function setInstance($instance): void
{
static::$instance = $instance;
}
/**
* Handle dynamic, static calls to the object.
*
* @param string $method
* @param array $args
*
* @return mixed
*/
public static function __callStatic($method, $args)
{
if ($instance = static::getInstance()) {
return $instance->$method(...$args);
}
return false;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Acl.php | src/Proxy/Acl.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Acl\Acl as Instance;
/**
* Proxy to Acl
*
* Example of usage
* use Bluz\Proxy\Acl;
*
* if (!Acl::isAllowed('users', 'profile')) {
* throw new Exception('You do not have permission to access user profiles');
* }
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static bool isAllowed($module, $privilege)
* @see Instance::isAllowed()
*/
final class Acl
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
*/
private static function initInstance(): Instance
{
return new Instance();
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Config.php | src/Proxy/Config.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Exception\ComponentException;
use Bluz\Config\Config as Instance;
/**
* Proxy to Config
*
* Example of usage
* <code>
* use Bluz\Proxy\Config;
*
* if (!Config::get('db')) {
* throw new Exception('Configuration for `db` is missed');
* }
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static mixed get(...$keys)
* @see Instance::get()
*/
final class Config
{
use ProxyTrait;
/**
* Init instance
*
* @throws ComponentException
*/
private static function initInstance()
{
throw new ComponentException('Class `Proxy\\Config` required external initialization');
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Router.php | src/Proxy/Router.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Exception\ComponentException;
use Bluz\Router\Router as Instance;
/**
* Proxy to Router
*
* Example of usage
* <code>
* use Bluz\Proxy\Router;
*
* Router::getUrl('pages', 'index', ['alias' => 'about']); // for skeleton application is `/about.html`
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static string getBaseUrl()
* @see Instance::getBaseUrl()
* @method static void setBaseUrl($baseUrl)
* @see Instance::setBaseUrl()
*
* @method static string getUrl($module = 'index', $controller = 'index', $params = [])
* @see Instance::getUrl()
*
* @method static string getFullUrl($module = 'index', $controller = 'index', $params = [])
* @see Instance::getFullUrl()
*
* @method static string getCleanUri()
* @see Instance::getCleanUri()
*
* @method static void process()
* @see Instance::process()
*
* @method static string getDefaultModule()
* @see Instance::getDefaultModule()
*
* @method static string getDefaultController()
* @see Instance::getDefaultController()
*
* @method static string getErrorModule()
* @see Instance::getErrorModule()
*
* @method static string getErrorController()
* @see Instance::getErrorController()
*/
final class Router
{
use ProxyTrait;
/**
* Init instance
*
* @throws ComponentException
*/
private static function initInstance()
{
throw new ComponentException("Class `Proxy\\Router` required external initialization");
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/EventManager.php | src/Proxy/EventManager.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\EventManager\EventManager as Instance;
/**
* Proxy to EventManager
*
* Example of usage
* <code>
* use Bluz\Proxy\EventManager;
*
* EvenManager::attach('event name', function() {
* // ... some logic
* });
*
* EventManager::trigger('event name');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static Instance attach($eventName, $callback, $priority = 1)
* @see Instance::attach()
*
* @method static string|object trigger($event, $target = null, $params = null)
* @see Instance::trigger()
*/
final class EventManager
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
*/
private static function initInstance(): Instance
{
return new Instance();
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Cache.php | src/Proxy/Cache.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Exception\ComponentException;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface as Instance;
use Psr\Cache\InvalidArgumentException;
/**
* Proxy to Cache
*
* Example of usage
* use Bluz\Proxy\Cache;
*
* if (!$result = Cache::get('some unique id')) {
* $result = 2*2;
* Cache::set('some unique id', $result);
* }
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance|false getInstance()
*
* @method static bool delete($key)
* @see Instance::deleteItem()
*
* @method static bool clear()
* @see Instance::clear()
*/
final class Cache
{
use ProxyTrait;
/**
* No expiry TTL value
*/
public const TTL_NO_EXPIRY = 0;
/**
* @var array
*/
private static $pools = [];
/**
* Init cache instance
*
* @return Instance|false
* @throws ComponentException
*/
private static function initInstance()
{
$adapter = Config::get('cache', 'adapter');
return self::getAdapter($adapter);
}
/**
* Get Cache Adapter
*
* @param string $adapter
*
* @return Instance|false
* @throws ComponentException
*/
public static function getAdapter(string $adapter)
{
$config = Config::get('cache');
if ($config && $adapter && isset($config['enabled']) && $config['enabled']) {
if (!isset($config['pools'][$adapter])) {
throw new ComponentException("Class `Proxy\\Cache` required configuration for `$adapter` adapter");
}
if (!isset(Cache::$pools[$adapter])) {
Cache::$pools[$adapter] = $config['pools'][$adapter]();
}
return Cache::$pools[$adapter];
}
return false;
}
/**
* Get value of cache item
*
* @param string $key
*
* @return mixed
*/
public static function get(string $key)
{
if (!$cache = self::getInstance()) {
return false;
}
$key = self::prepare($key);
try {
if ($cache->hasItem($key)) {
$item = $cache->getItem($key);
if ($item->isHit()) {
return $item->get();
}
}
} catch (InvalidArgumentException $e) {
// something going wrong
Logger::error($e->getMessage());
}
return false;
}
/**
* Set value of cache item
*
* @param string $key
* @param mixed $data
* @param int $ttl
* @param string[] $tags
*
* @return bool
*/
public static function set(string $key, $data, int $ttl = self::TTL_NO_EXPIRY, array $tags = [])
{
if (!$cache = self::getInstance()) {
return false;
}
$key = self::prepare($key);
try {
$item = $cache->getItem($key);
$item->set($data);
if (self::TTL_NO_EXPIRY !== $ttl) {
$item->expiresAfter($ttl);
}
if (!empty($tags)) {
$item->tag($tags);
}
return $cache->save($item);
} catch (InvalidArgumentException $e) {
// something going wrong
Logger::error($e->getMessage());
}
return false;
}
/**
* Prepare key
*
* @param string $key
*
* @return string
*/
public static function prepare(string $key): string
{
return str_replace(['-', '/', '\\', '@', ':'], '_', $key);
}
/**
* Clear cache items by tag
*
* @param string $tag
*
* @return bool
*/
public static function clearTag(string $tag): bool
{
if (self::getInstance() instanceof TagAwareAdapterInterface) {
return self::getInstance()->invalidateTags([$tag]);
}
return false;
}
/**
* Clear cache items by tags
*
* @param array $tags
*
* @return bool
*/
public static function clearTags(array $tags): bool
{
if (self::getInstance() instanceof TagAwareAdapterInterface) {
return self::getInstance()->invalidateTags($tags);
}
return false;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Logger.php | src/Proxy/Logger.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Common\Nil;
use Bluz\Logger\Logger as Instance;
use Exception;
/**
* Proxy to Logger
*
* Example of usage
* <code>
* use Bluz\Proxy\Logger;
*
* Logger::error('Configuration not found');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static void alert($message, array $context = [])
* @see Instance::alert()
*
* @method static void critical($message, array $context = [])
* @see Instance::critical()
*
* @method static void debug($message, array $context = [])
* @see Instance::debug()
*
* @method static void emergency($message, array $context = [])
* @see Instance::emergency()
*
* @method static void error($message, array $context = [])
* @see Instance::error()
*
* @method static void info($message, array $context = [])
* @see Instance::info()
*
* @method static void notice($message, array $context = [])
* @see Instance::notice()
*
* @method static void warning($message, array $context = [])
* @see Instance::warning()
*
* @method static void log($level, $message, array $context = [])
* @see Instance::log()
*
* @method static array get($level)
* @see Instance::get()
*/
final class Logger
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance|Nil
*/
private static function initInstance()
{
if (Config::get('logger')) {
return new Instance();
}
return new Nil();
}
/**
* exception
*
* @param Exception $exception
*
* @return void
*/
public static function exception($exception): void
{
self::getInstance()->error(
$exception->getMessage() . ' [' .
$exception->getFile() . ':' .
$exception->getLine() . ']'
);
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Messages.php | src/Proxy/Messages.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Messages\Messages as Instance;
/**
* Proxy to Messages
*
* Example of usage
* <code>
* use Bluz\Proxy\Messages;
*
* Messages::addSuccess('All Ok!');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static Messages addNotice($message, ...$text)
* @see Instance::addNotice()
*
* @method static Messages addSuccess($message, ...$text)
* @see Instance::addSuccess()
*
* @method static Messages addError($message, ...$text)
* @see Instance::addError()
*
* @method static integer count()
* @see Instance::count()
*
* @method static \stdClass pop($type = null)
* @see Instance::pop()
*
* @method static \ArrayObject popAll()
* @see Instance::popAll()
*
* @method static void reset()
* @see Instance::reset()
*/
final class Messages
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
*/
private static function initInstance(): Instance
{
$instance = new Instance();
$instance->setOptions(Config::get('messages'));
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/Proxy/Session.php | src/Proxy/Session.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Proxy;
use Bluz\Session\Session as Instance;
/**
* Proxy to Session
*
* Example of usage
* <code>
* use Bluz\Proxy\Session;
*
* // lazy session loading
* Session::set('some key in session', 'value example');
* Session::get('some key in session');
* </code>
*
* @package Bluz\Proxy
* @author Anton Shevchuk
*
* @method static Instance getInstance()
*
* @method static void start()
* @see Instance::start()
* @method static void destroy()
* @see Instance::destroy()
* @method static void set($key, $value)
* @see Instance::set()
* @method static mixed get($key)
* @see Instance::get()
* @method static bool contains($key)
* @see Instance::contains()
* @method static void delete($key)
* @see Instance::delete()
* @method static string getId()
* @see Instance::getId()
* @method static bool regenerateId($deleteOldSession = true)
* @see Instance::regenerateId()
* @method static void setSessionCookieLifetime($ttl)
* @see Instance::setSessionCookieLifetime()
*
* @method static void expireSessionCookie()
*/
final class Session
{
use ProxyTrait;
/**
* Init instance
*
* @return Instance
*/
private static function initInstance(): Instance
{
$instance = new Instance();
$instance->setOptions(Config::get('session'));
return $instance;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/ViewException.php | src/View/ViewException.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View;
use Bluz\Common\Exception\CommonException;
/**
* Exception
*
* @package Bluz\View
* @author Anton Shevchuk
*/
class ViewException extends CommonException
{
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/ViewInterface.php | src/View/ViewInterface.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View;
/**
* View Interface
*
* @package Bluz\View
* @author Anton Shevchuk
*/
interface ViewInterface
{
/**
* Get path to templates
*
* Example of usage
* $view->getPath();
*
* @return string
*/
public function getPath(): ?string;
/**
* Setup path to templates
*
* Example of usage
* $view->setPath('/modules/users/views');
*
* @param string $path
*
* @return void
*/
public function setPath(string $path): void;
/**
* Get template
*
* Example of usage
* $view->getTemplate();
*
* @return string
*/
public function getTemplate(): ?string;
/**
* Setup template
*
* Example of usage
* $view->setTemplate('index.phtml');
*
* @param string $file
*
* @return void
*/
public function setTemplate(string $file): void;
/**
* Merge data from array
*
* @param array $data
*
* @return void
*/
public function setFromArray(array $data): void;
/**
* Get data as array
*
* @return array
*/
public function toArray(): array;
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/View.php | src/View/View.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View;
use Bluz\Auth\AbstractIdentity;
use Bluz\Common\Container;
use Bluz\Common\Exception\CommonException;
use Bluz\Common\Helper;
use Bluz\Common\Options;
use Bluz\Proxy\Logger;
use Bluz\Response\ResponseTrait;
/**
* View - simple template engine with native PHP syntax
*
* @package Bluz\View
* @author Anton Shevchuk
* @author ErgallM
* @link https://github.com/bluzphp/framework/wiki/View
*
* @see \Bluz\View\Helper\
*
* @method string ahref(string $text, mixed $href, array $attributes = [])
* @method string api(string $module, string $method, $params = [])
* @method string attributes(array $attributes = [])
* @method string baseUrl(string $file = null)
* @method string checkbox($name, $value = null, $checked = false, array $attributes = [])
* @method string|bool controller(string $controller = null)
* @method string|View dispatch($module, $controller, $params = [])
* @method string exception(\Exception $exception)
* @method string gravatar($email, $size = 80, $default = 'mm', $rate = 'g')
* @method bool hasModule(string $module)
* @method string|null headScript(string $src = null, array $attributes = [])
* @method string|null headScriptBlock(string $code = null)
* @method string|null headStyle(string $href = null, string $media = 'all')
* @method string|bool module(string $module = null)
* @method string partial($__template, $__params = [])
* @method string partialLoop($template, $data = [], $params = [])
* @method string radio($name, $value = null, $checked = false, array $attributes = [])
* @method string redactor($selector, array $settings = [])
* @method string script(string $src, array $attributes = [])
* @method string scriptBlock(string $code)
* @method string select($name, array $options = [], $selected = null, array $attributes = [])
* @method string style(string $href, $media = 'all')
* @method string styleBlock(string $code, $media = 'all')
* @method string|null url(string $module, string $controller, array $params = [], bool $checkAccess = false)
* @method AbstractIdentity|null user()
* @method void widget($module, $widget, $params = [])
*/
class View implements ViewInterface, \JsonSerializable
{
use Container\Container;
use Container\JsonSerialize;
use Container\MagicAccess;
use Options;
use Helper;
use ResponseTrait;
/**
* @var string base url
*/
protected $baseUrl;
/**
* @var string path to template
*/
protected $path;
/**
* @var array paths to partial
*/
protected $partialPath = [];
/**
* @var string template name
*/
protected $template;
/**
* Create view instance, initial default helper path
*
* @throws CommonException
*/
public function __construct()
{
// initial default helper path
$this->addHelperPath(__DIR__ . '/Helper/');
}
/**
* Render like string
*
* @return string
*/
public function __toString()
{
ob_start();
try {
if (
!file_exists($this->path . DIRECTORY_SEPARATOR . $this->template)
|| !is_file($this->path . DIRECTORY_SEPARATOR . $this->template)
) {
throw new ViewException("Template `{$this->template}` not found");
}
extract($this->container, EXTR_SKIP);
include $this->path . DIRECTORY_SEPARATOR . $this->template;
} catch (\Exception $e) {
// save error to log
Logger::exception($e);
// clean output
ob_clean();
}
return (string) ob_get_clean();
}
/**
* {@inheritdoc}
*
* @return string
*/
public function getPath(): ?string
{
return $this->path;
}
/**
* {@inheritdoc}
*
* @param string $path
*
* @return void
*/
public function setPath(string $path): void
{
$this->path = $path;
}
/**
* {@inheritdoc}
*
* @return string
*/
public function getTemplate(): ?string
{
return $this->template;
}
/**
* {@inheritdoc}
*
* @param string $file
*
* @return void
*/
public function setTemplate(string $file): void
{
$this->template = $file;
}
/**
* Add partial path for use inside partial and partialLoop helpers
*
* @param string $path
*
* @return void
*/
public function addPartialPath(string $path): void
{
$this->partialPath[] = $path;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/HasModule.php | src/View/Helper/HasModule.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Application\Application;
/**
* Check to isset module
*
* @param string|null $module
*
* @return bool
* @throws \ReflectionException
*/
return
function (?string $module = null) {
$modulePath = Application::getInstance()->getPath() . DIRECTORY_SEPARATOR .
'modules' . DIRECTORY_SEPARATOR . $module;
return file_exists($modulePath);
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Ahref.php | src/View/Helper/Ahref.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Proxy\Request;
use Bluz\Proxy\Translator;
use Bluz\View\View;
/**
* Generate HTML for <a> element
*
* @param string $text
* @param string|array $href
* @param array $attributes HTML attributes
*
* @return string
*@author ErgallM
*
*/
return
function (string $text, $href, array $attributes = []) {
// if href is settings for url helper
if (is_array($href)) {
$href = $this->url(...$href);
}
// href can be null, if access is denied
if (null === $href) {
return '';
}
$current = Request::getUri()->getPath();
if (Request::getUri()->getQuery()) {
$current .= sprintf('?%s', Request::getUri()->getQuery());
}
if ($href === $current) {
if (isset($attributes['class'])) {
$attributes['class'] .= ' active';
} else {
$attributes['class'] = 'active';
}
}
$attributes = $this->attributes($attributes);
return '<a href="' . $href . '" ' . $attributes . '>' . Translator::translate((string)$text) . '</a>';
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/ScriptBlock.php | src/View/Helper/ScriptBlock.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
/**
* Generate HTML for <script> element with inline code
*
* @param string $code
*
* @return string
*/
return
function (string $code) {
return "<script type=\"text/javascript\">\n"
. "<!--\n"
. "$code\n"
. "//-->\n"
. "</script>";
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Radio.php | src/View/Helper/Radio.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
/**
* Generate HTML for <input type="radio">
*
* @param string $name
* @param string|null $value
* @param bool $checked
* @param array $attributes
*
* @return string
*/
return
function (string $name, ?string $value = null, bool $checked = false, array $attributes = []) {
/**
* @var View $this
*/
if (true === $checked) {
$attributes['checked'] = 'checked';
}
if (null !== $value) {
$attributes['value'] = $value;
}
$attributes['name'] = $name;
$attributes['type'] = 'radio';
return '<input ' . $this->attributes($attributes) . '/>';
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Checkbox.php | src/View/Helper/Checkbox.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
/**
* Generate HTML for <input type="checkbox">
*
* @param string $name
* @param string|null $value
* @param bool $checked
* @param array $attributes
*
* @return string
*@author The-Who
*
*/
return
function (string $name, ?string $value = null, bool $checked = false, array $attributes = []) {
/** @var View $this */
if (true === $checked) {
$attributes['checked'] = 'checked';
} elseif (false !== $checked && ($checked === $value)) {
$attributes['checked'] = 'checked';
}
if (null !== $value) {
$attributes['value'] = $value;
}
$attributes['name'] = $name;
$attributes['type'] = 'checkbox';
return '<input ' . $this->attributes($attributes) . '/>';
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/HeadStyle.php | src/View/Helper/HeadStyle.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Application\Application;
use Bluz\Proxy\Layout;
use Bluz\View\View;
/**
* Set or generate <style> code for <head>
*
* @param string|null $href
* @param string|null $media
*
* @return string|null
*/
return
function (?string $href = null, ?string $media = 'all') {
/**
* @var View $this
*/
if (Application::getInstance()->useLayout()) {
return Layout::headStyle($href, $media);
}
// it's just alias to style() call
return $this->style($href, $media);
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Controller.php | src/View/Helper/Controller.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Proxy\Request;
/**
* Return controller name
* or check to current controller
*
* @param string|null $controller
*
* @return string|bool
*/
return
function (?string $controller = null) {
if (null === $controller) {
return Request::getController();
}
return Request::getController() === $controller;
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/User.php | src/View/Helper/User.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Auth\IdentityInterface;
use Bluz\Proxy\Auth;
/**
* Get current user
*
* @return IdentityInterface|null
*/
return
function () {
return Auth::getIdentity();
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Gravatar.php | src/View/Helper/Gravatar.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Application\Application;
use Bluz\Proxy\Layout;
use Bluz\View\View;
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*
* @param string $email The email address
* @param integer $size Size in pixels, defaults to 80px [ 1 - 2048 ]
* @param string $default Default set of images to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $rate Maximum rating (inclusive) [ g | pg | r | x ]
*
* @return String containing either just a URL or a complete image tag
* @source https://gravatar.com/site/implement/images/php/
*/
return
function (string $email, int $size = 80, string $default = 'mm', string $rate = 'g') {
$email = md5(strtolower(trim($email ?? '')));
return "https://www.gravatar.com/avatar/$email?s=$size&d=$default&r=$rate";
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Module.php | src/View/Helper/Module.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Proxy\Request;
/**
* Return module name
* or check to current module
*
* @param string|null $module
*
* @return string|bool
*/
return
function (?string $module = null) {
if (null === $module) {
return Request::getModule();
}
return Request::getModule() === $module;
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Attributes.php | src/View/Helper/Attributes.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
/**
* Generate HTML attributes
*
* @author The-Who
*
* @param array $attributes
*
* @return string
*/
return
function (array $attributes = []) {
if (empty($attributes)) {
return '';
}
$result = [];
foreach ($attributes as $key => $value) {
if (null === $value) {
// skip empty values
// input: [attribute=>null]
// output: ''
continue;
}
if (is_int($key)) {
// allow non-associative keys
// input: [checked, disabled]
// output: 'checked disabled'
$result[] = $value;
} else {
$result[] = $key . '="' . htmlspecialchars((string)$value, ENT_QUOTES) . '"';
}
}
return implode(' ', $result);
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/BaseUrl.php | src/View/Helper/BaseUrl.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Proxy\Router;
use Bluz\View\View;
/**
* Get baseUrl
*
* @param string|null $file
*
* @return string
*/
return
function (?string $file = null) {
// setup baseUrl
if (!$this->baseUrl) {
$this->baseUrl = Router::getBaseUrl();
// clean script name
if (
isset($_SERVER['SCRIPT_NAME'])
&& ($pos = strripos($this->baseUrl, basename($_SERVER['SCRIPT_NAME']))) !== false
) {
$this->baseUrl = substr($this->baseUrl, 0, $pos);
}
}
// Remove trailing slashes
if (null !== $file) {
$file = ltrim($file, '/\\');
}
return str_trim_end($this->baseUrl, '/') . $file;
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Script.php | src/View/Helper/Script.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
/**
* Generate HTML for <script> element
*
* @param string $src
* @param array $attributes HTML attributes
*
* @return string
*/
return
function (string $src, array $attributes = []) {
/**
* @var View $this
*/
if (
strpos($src, 'http://') !== 0
&& strpos($src, 'https://') !== 0
&& strpos($src, '//') !== 0
) {
$src = $this->baseUrl($src);
}
$attributes = $this->attributes($attributes);
return "<script src=\"$src\" $attributes></script>\n";
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Partial.php | src/View/Helper/Partial.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
use Bluz\View\ViewException;
/**
* Render partial file
*
* be careful, method rewrites the View variables with params
*
* @param string $__template
* @param array $__params
*
* @return string
* @throws ViewException
*/
return
function (string $__template, array $__params = []) {
/**
* @var View $this
*/
$__file = null;
if (file_exists($this->path . '/' . $__template)) {
$__file = $this->path . '/' . $__template;
} else {
foreach ($this->partialPath as $__path) {
if (file_exists($__path . '/' . $__template)) {
$__file = $__path . '/' . $__template;
break;
}
}
}
if ($__file === null) {
throw new ViewException("Template '{$__template}' not found");
}
if (count($__params)) {
extract($__params, EXTR_SKIP);
}
ob_start();
try {
include $__file;
} catch (\Exception $e) {
ob_end_clean();
throw new ViewException("Template '{$__template}' throw exception: " . $e->getMessage());
}
return ob_get_clean();
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Url.php | src/View/Helper/Url.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Controller\Controller;
use Bluz\Http\Exception\ForbiddenException;
use Bluz\Proxy\Request;
use Bluz\Proxy\Router;
use Bluz\View\View;
use Bluz\View\ViewException;
/**
* Generate URL
*
* @param string|null $module
* @param string|null $controller
* @param array|null $params
* @param bool $checkAccess
*
* @return null|string
* @throws ViewException
*/
return
function (?string $module, ?string $controller, ?array $params = [], bool $checkAccess = false) {
/**
* @var View $this
*/
try {
if ($checkAccess) {
try {
$controllerInstance = new Controller($module, $controller);
$controllerInstance->checkPrivilege();
} catch (ForbiddenException $e) {
return null;
}
}
} catch (\Exception $e) {
throw new ViewException('Url View Helper: ' . $e->getMessage());
}
if (null === $module) {
$module = Request::getModule();
}
if (null === $controller) {
$controller = Request::getController();
}
if (null === $params) {
$params = Request::getParams();
}
return Router::getUrl($module, $controller, $params);
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/StyleBlock.php | src/View/Helper/StyleBlock.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
/**
* Generate HTML for <style> or <link> element
*
* @param string $code
* @param string $media
*
* @return string
*/
return
function (string $code, string $media = 'all') {
return "<style type=\"text/css\" media=\"$media\">\n$code\n</style>\n";
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Redactor.php | src/View/Helper/Redactor.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
/**
* Generate HTML and JavaScript for WYSIWYG redactor
*
* @link http://imperavi.com/redactor/
*
* @param string $selector
* @param array $settings
*
* @return string
*/
return
function (string $selector, array $settings = []) {
/**
* @var View $this
*/
$defaultSettings = [
'imageUpload' => $this->url('media', 'upload'), // default media upload controller
'imageUploadParam' => 'files',
'imageManagerJson' => $this->url('media', 'list'), // default images list
'plugins' => ['imagemanager']
];
$settings = array_replace_recursive($defaultSettings, $settings);
$html = '';
$html .= $this->style('redactor/redactor.css');
$html .= $this->scriptBlock(
'require(["redactor", "imagemanager"], function($R) {
$R("' . $selector . '", ' . json_encode($settings) . ');
});'
);
return $html;
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Exception.php | src/View/Helper/Exception.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Application\Application;
/**
* Return Exception message
*
* @param \Exception $exception
*
* @return string
*/
return
function (\Exception $exception) {
if ($exception && Application::getInstance()->isDebug()) {
// @codeCoverageIgnoreStart
// exception message for developers
return
'<div class="alert alert-warning">' .
'<strong>Exception</strong>' .
'<p>' . esc($exception->getMessage()) . '</p>' .
'<code>' . $exception->getFile() . ':' . $exception->getLine() . '</code>' .
'</div>' .
'<pre>' . $exception->getTraceAsString() . '</pre>'
;
// @codeCoverageIgnoreEnd
}
return '';
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/PartialLoop.php | src/View/Helper/PartialLoop.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
use Bluz\View\ViewException;
/**
* Render partial script in loop
*
* Example of usage:
* <code>
* <?php
* $data = [2, 4, 6, 8];
* $this->partialLoop('tr.phtml', $data, ['colspan'=>2]);
* ?>
* <?php
* <tr>
* <th>
* <?=$key?>
* </th>
* <td colspan="<?=$colspan?>">
* <?=$value?>
* </td>
* </tr>
* ?>
* </code>
*
* @param string $template
* @param array|object $data
* @param array $params
*
* @return string
*/
return
function (string $template, $data = [], array $params = []) {
/**
* @var View $this
*/
if (
!is_array($data)
&& !($data instanceof \Traversable)
&& !(is_object($data) && method_exists($data, 'toArray'))
) {
throw new \InvalidArgumentException('PartialLoop helper requires iterable data');
}
if (
is_object($data)
&& (!$data instanceof \Traversable)
&& method_exists($data, 'toArray')
) {
$data = $data->toArray();
}
$result = [];
foreach ($data as $key => $value) {
$params['partialKey'] = $key;
$params['partialValue'] = $value;
$result[] = $this->partial($template, $params);
}
return implode('', $result);
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Dispatch.php | src/View/Helper/Dispatch.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Application\Application;
use Bluz\Http\Exception\ForbiddenException;
use Bluz\View\View;
/**
* Dispatch controller View Helper
*
* Example of usage:
* $this->dispatch($module, $controller, array $params);
*
* @param string $module
* @param string $controller
* @param array $params
*
* @return View|string|null
*/
return
function (string $module, string $controller, array $params = []) {
/**
* @var View $this
*/
try {
$view = Application::getInstance()->dispatch($module, $controller, $params);
} catch (ForbiddenException $e) {
// nothing for ForbiddenException
return null;
} catch (\Exception $e) {
return $this->exception($e);
}
// run closure
return value($view);
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Style.php | src/View/Helper/Style.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
/**
* Generate HTML for <style> or <link> element
*
* @param string $href
* @param string $media
*
* @return string
*/
return
function (string $href, string $media = 'all') {
/**
* @var View $this
*/
if (
strpos($href, 'http://') !== 0
&& strpos($href, 'https://') !== 0
&& strpos($href, '//') !== 0
) {
$href = $this->baseUrl($href);
}
return "<link href=\"$href\" rel=\"stylesheet\" media=\"$media\"/>\n";
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/Select.php | src/View/Helper/Select.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\View\View;
/**
* Generate HTML for <select> element
*
* Example of usage:
* <code>
* $this->select("car", [
* "none" => "No Car",
* "class-A" => [
* 'citroen-c1' => 'Citroen C1',
* 'mercedes-benz-a200' => 'Mercedes Benz A200',
* ],
* "class-B" => [
* 'audi-a1' => 'Audi A1',
* 'citroen-c3' => 'Citroen C3',
* ],
* ], "none", ["id"=>"car"]);
*
* <select name="car" id="car">
* <option value="none" selected="selected">No car</option>
* <optgroup label="class-A">
* <option value="citroen-c1">Citroen C1</option>
* <option value="mercedes-benz-a200">Mercedes Benz A200</option>
* </optgroup>
* <optgroup label="class-B">
* <option value="audi-a1">Audi A1</option>
* <option value="citroen-c3">Citroen C3</option>
* </optgroup>
* </select>
* </code>
*
* @param string $name
* @param array $options
* @param array|string $selected
* @param array $attributes
*
* @return string
*/
return
function (string $name, array $options = [], $selected = null, array $attributes = []) {
/**
* @var View $this
*/
$attributes['name'] = $name;
if (!is_array($selected)) {
if ($selected === null) {
// empty array
$selected = [];
} else {
// convert one option to an array
$selected = [(string)$selected];
}
} elseif (count($selected) > 1) {
$attributes['multiple'] = 'multiple';
}
/**
* @param $value
* @param $text
*
* @return string
*/
$buildOption = function ($value, $text) use ($selected) {
$value = (string)$value;
$option = ['value' => $value];
if (in_array($value, $selected, false)) {
$option['selected'] = 'selected';
}
return '<option ' . $this->attributes($option) . '>' . htmlspecialchars(
(string)$text,
ENT_QUOTES,
'UTF-8',
false
) . '</option>';
};
$result = [];
foreach ($options as $value => $text) {
if (is_array($text)) {
// optgroup support
// create a list of sub-options
$subOptions = [];
foreach ($text as $subValue => $subText) {
$subOptions[] = $buildOption($subValue, $subText);
}
// build string from array
$subOptions = "\n" . implode("\n", $subOptions) . "\n";
$result[] = '<optgroup ' . $this->attributes(['label' => $value]) . '>' . $subOptions . '</optgroup>';
} else {
$result[] = $buildOption($value, $text);
}
}
$result = "\n" . implode("\n", $result) . "\n";
return '<select ' . $this->attributes($attributes) . '>' . $result . '</select>';
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/src/View/Helper/HeadScript.php | src/View/Helper/HeadScript.php | <?php
/**
* Bluz Framework Component
*
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\View\Helper;
use Bluz\Application\Application;
use Bluz\Proxy\Layout;
use Bluz\View\View;
/**
* Set or generate <script> code for <head>
*
* @param string|null $src
* @param array $attributes
*
* @return null|string
*/
return
function (?string $src = null, array $attributes = []) {
/**
* @var View $this
*/
if (Application::getInstance()->useLayout()) {
return Layout::headScript($src, $attributes);
}
// it's just alias to script() call
return $this->script($src, $attributes);
};
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/_bootstrap.php | tests/_bootstrap.php | <?php
// This is global bootstrap for autoloading
// Environment
define('DEBUG', true);
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Paths
define('PATH_ROOT', realpath(dirname(__DIR__)));
define('PATH_APPLICATION', PATH_ROOT . DIRECTORY_SEPARATOR . 'tests');
define('PATH_VENDOR', PATH_ROOT . DIRECTORY_SEPARATOR . 'vendor');
// Use composer autoload
$loader = require PATH_ROOT . '/vendor/autoload.php';
$loader->addPsr4('Bluz\\Tests\\', __DIR__ . DIRECTORY_SEPARATOR . 'src');
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/FrameworkTestCase.php | tests/src/FrameworkTestCase.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
/**
* @namespace
*/
namespace Bluz\Tests;
use Bluz;
use Bluz\Http;
use Bluz\Proxy;
use Codeception\Test\Unit;
use Laminas\Diactoros\ServerRequest;
/**
* Bluz TestCase
*
* @package Bluz\Tests
*
* @author Anton Shevchuk
* @created 04.08.11 20:01
*/
class FrameworkTestCase extends Unit
{
/**
* Application entity
*
* @var \Bluz\Tests\BootstrapTest
*/
protected static $app;
/**
* Setup TestCase
*/
protected function setUp(): void
{
self::getApp();
}
/**
* Tear Down
*/
protected function tearDown(): void
{
self::resetApp();
}
/**
* Get Application instance
*
* @return BootstrapTest
* @throws Bluz\Application\Exception\ApplicationException
*/
protected static function getApp()
{
if (!self::$app) {
$env = getenv('BLUZ_ENV') ?: 'testing';
self::$app = BootstrapTest::getInstance();
self::$app->init($env);
}
return self::$app;
}
/**
* Reset layout and Request
*/
protected static function resetApp()
{
if (self::$app) {
self::$app::resetInstance();
self::$app = null;
}
Proxy\Acl::resetInstance();
Proxy\Auth::resetInstance();
Proxy\Cache::resetInstance();
Proxy\Config::resetInstance();
Proxy\Db::resetInstance();
Proxy\EventManager::resetInstance();
Proxy\HttpCacheControl::resetInstance();
Proxy\Layout::resetInstance();
Proxy\Logger::resetInstance();
Proxy\Mailer::resetInstance();
Proxy\Messages::resetInstance();
Proxy\Registry::resetInstance();
Proxy\Request::resetInstance();
Proxy\Request::resetAccept();
Proxy\Response::resetInstance();
Proxy\Router::resetInstance();
Proxy\Session::resetInstance();
Proxy\Translator::resetInstance();
}
/**
* Reset super-globals variables
*/
protected static function resetGlobals()
{
$_GET = $_POST = [];
unset($_SERVER['HTTP_X_REQUESTED_WITH'], $_SERVER['HTTP_ACCEPT']);
}
/**
* Assert one-level Arrays is Equals
*
* @param array $expected
* @param array $actual
* @param string $message
*/
protected static function assertEqualsArray($expected, $actual, $message = null)
{
self::assertSame(
array_diff($expected, $actual),
array_diff($actual, $expected),
$message ?: 'Failed asserting that two arrays is equals.'
);
}
/**
* Assert Array Size
*
* @param array|\ArrayObject $array
* @param integer $size
* @param string $message
*/
protected static function assertArrayHasSize($array, $size, $message = null)
{
self::assertCount(
$size,
$array,
$message ?: 'Failed asserting that array has size ' . $size . ' matches expected ' . count($array) . '.'
);
}
/**
* Assert Array Key has Size
*
* @param array|\ArrayObject $array
* @param string $key
* @param integer $size
* @param string $message
*/
protected static function assertArrayHasKeyAndSize($array, $key, $size, $message = null)
{
if (!$message) {
$message = 'Failed asserting that array has key ' . $key . ' with size ' . $size
. ' matches expected ' . count($array) . '.';
}
self::assertArrayHasKey($key, $array, $message);
self::assertCount($size, $array[$key], $message);
}
/**
* Set new Request instance
*
* @param string $path Path part of URI http://host/module/controller/path
* @param array $query $_GET params
* @param array $params $_POST params
* @param string $method HTTP method
* @param array $headers HTTP headers
* @param array $cookies
*
* @return \Psr\Http\Message\ServerRequestInterface|ServerRequest
*/
protected static function prepareRequest(
$path = '',
$query = [],
$params = [],
$method = Http\RequestMethod::GET,
$headers = [],
$cookies = []
) {
$uri = 'http://127.0.0.1/' . $path;
return new ServerRequest([], [], $uri, $method, 'php://input', $headers, $cookies, $query, $params);
}
/**
* Set new Request instance
*
* @param string $path Path part of URI http://host/module/controller/path
* @param array $query $_GET params
* @param array $params $_POST params
* @param string $method HTTP method
* @param array $headers HTTP headers
* @param array $cookies
*
* @return \Psr\Http\Message\ServerRequestInterface|ServerRequest
*/
protected static function setRequestParams(
$path = '',
$query = [],
$params = [],
$method = Http\RequestMethod::GET,
$headers = [],
$cookies = []
) {
$request = self::prepareRequest($path, $query, $params, $method, $headers, $cookies);
Proxy\Request::setInstance($request);
return $request;
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/BootstrapTest.php | tests/src/BootstrapTest.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
/**
* @namespace
*/
namespace Bluz\Tests;
use Bluz\Application\Application;
use Bluz\Controller\Controller;
use Bluz\Http\Exception\ForbiddenException;
use Bluz\Http\Exception\RedirectException;
use Bluz\Proxy\Layout;
use Bluz\Proxy\Request;
use Bluz\Proxy\Response;
/**
* Bootstrap
*
* @package Bluz\Tests
*
* @author Anton Shevchuk
* @created 20.07.11 17:38
*/
class BootstrapTest extends Application
{
/**
* Dispatched module name
*
* @var string
*/
protected $dispatchModule;
/**
* Dispatched controller name
*
* @var string
*/
protected $dispatchController;
/**
* @var \Exception
*/
protected $exception;
/**
* Get dispatched module name
*
* @return string|null
*/
public function getModule(): ?string
{
return $this->dispatchModule;
}
/**
* Get dispatched controller name
*
* @return string|null
*/
public function getController(): ?string
{
return $this->dispatchController;
}
/**
* setException
*
* @param \Exception $exception
*
* @return void
*/
public function setException($exception): void
{
$this->exception = $exception;
codecept_debug(' ## ' . $exception->getCode());
codecept_debug(' ## ' . $exception->getMessage());
}
/**
* getException
*
* @return \Exception|null
*/
public function getException(): ?\Exception
{
return $this->exception;
}
/**
* @inheritdoc
*/
protected function doProcess(): void
{
$module = Request::getModule();
$controller = Request::getController();
$params = Request::getParams();
// try to dispatch controller
try {
codecept_debug('');
codecept_debug(' >> ' . $module . '/' . $controller);
// dispatch controller
$result = $this->dispatch($module, $controller, $params);
} catch (ForbiddenException $e) {
$this->setException($e);
$result = $this->forbidden($e);
} catch (RedirectException $e) {
$this->setException($e);
$result = $this->redirect($e);
} catch (\Exception $e) {
$this->setException($e);
$result = $this->error($e);
}
if ($result instanceof Controller) {
$this->dispatchModule = $result->getModule();
$this->dispatchController = $result->getController();
codecept_debug(' << ' . $this->getModule() . '/' . $this->getController());
}
// setup layout, if needed
if ($this->useLayout()) {
// render view to layout
// needed for headScript and headStyle helpers
Layout::setContent($result->render());
Response::setBody(Layout::getInstance());
} else {
Response::setBody($result);
}
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/Fixtures/Db/ConcreteTable.php | tests/src/Fixtures/Db/ConcreteTable.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Tests\Fixtures\Db;
use Bluz\Db\Table;
use Bluz\Db\Traits\TableRelations;
/**
* Concrete realization of Table class.
*
* @category Tests
* @package Bluz\Db
*
* @author Eugene Zabolotniy <realbaziak@gmail.com>
*/
class ConcreteTable extends Table
{
use TableRelations;
protected $name = 'foo';
protected $primary = ['bar', 'baz'];
protected $rowClass = 'ConcreteRow';
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/Fixtures/Db/WrongTable.php | tests/src/Fixtures/Db/WrongTable.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Tests\Fixtures\Db;
use Bluz\Db\Table;
/**
* Wrong realization of Table class.
*
* @category Tests
* @package Bluz\Db
*
* @author Eugene Zabolotniy <realbaziak@gmail.com>
*/
class WrongTable extends Table
{
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/Fixtures/Db/ConcreteRowWithInvalidTable.php | tests/src/Fixtures/Db/ConcreteRowWithInvalidTable.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Tests\Fixtures\Db;
use Bluz\Db\Row;
/**
* Concrete realization of Table class with invalid table specified.
*
* @category Tests
* @package Bluz\Db
*
* @author Dmitriy Savchenko <login.was.here@gmail.com>
*/
class ConcreteRowWithInvalidTable extends Row
{
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/Fixtures/Db/ConcreteRow.php | tests/src/Fixtures/Db/ConcreteRow.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Tests\Fixtures\Db;
use Bluz\Db\Row;
use Bluz\Db\Traits\RowRelations;
/**
* Concrete realization of Table class.
*
* @category Tests
* @package Bluz\Db
*
* @property mixed someValue
*
* @author Eugene Zabolotniy <realbaziak@gmail.com>
*/
class ConcreteRow extends Row
{
use RowRelations;
/**
* {@inheritdoc}
*/
public function __construct(array $data = [])
{
parent::__construct($data);
$this->setTable(ConcreteTable::getInstance());
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/Fixtures/Db/ConcreteTableWithoutRowClass.php | tests/src/Fixtures/Db/ConcreteTableWithoutRowClass.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Tests\Fixtures\Db;
use Bluz\Db\Table;
/**
* Concrete realization of Table class without row class specified.
*
* @category Tests
* @package Bluz\Db
*
* @author Dmitriy Savchenko <login.was.here@gmail.com>
*/
class ConcreteTableWithoutRowClass extends Table
{
protected $name = 'foo';
protected $primary = ['bar', 'baz'];
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/Fixtures/Db/WrongKeysTable.php | tests/src/Fixtures/Db/WrongKeysTable.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/
declare(strict_types=1);
namespace Bluz\Tests\Fixtures\Db;
use Bluz\Db\Table;
/**
* Wrong realization of Table class.
*
* @category Tests
* @package Bluz\Db
*
* @author Eugene Zabolotniy <realbaziak@gmail.com>
*/
class WrongKeysTable extends Table
{
protected $name = 'foo';
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
bluzphp/framework | https://github.com/bluzphp/framework/blob/be908a41e27f50f3786bfa8919d5245efb0d9942/tests/src/Fixtures/Grid/ArrayGrid.php | tests/src/Fixtures/Grid/ArrayGrid.php | <?php
/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/skeleton
*/
/**
* @namespace
*/
namespace Bluz\Tests\Fixtures\Grid;
use Bluz\Grid\Grid;
use Bluz\Grid\Source\ArraySource;
/**
* Test Grid based on Array
*
* @category Application
* @package Test
*/
class ArrayGrid extends Grid
{
/**
* @var string
*/
protected $uid = 'arr';
/**
* Init ArraySource
*
* @return void
* @throws \Bluz\Grid\GridException
*/
public function init(): void
{
// Array
$adapter = new ArraySource();
$adapter->setSource(
[
['id' => 1, 'name' => 'Foo', 'email' => 'a@bc.com', 'status' => 'active'],
['id' => 2, 'name' => 'Bar', 'email' => 'd@ef.com', 'status' => 'active'],
['id' => 3, 'name' => 'Foo 2', 'email' => 'm@ef.com', 'status' => 'disable'],
['id' => 4, 'name' => 'Foo 3', 'email' => 'j@ef.com', 'status' => 'disable'],
['id' => 5, 'name' => 'Foo 4', 'email' => 'g@ef.com', 'status' => 'disable'],
['id' => 6, 'name' => 'Foo 5', 'email' => 'r@ef.com', 'status' => 'disable'],
['id' => 7, 'name' => 'Foo 6', 'email' => 'm@ef.com', 'status' => 'disable'],
['id' => 8, 'name' => 'Foo 7', 'email' => 'n@ef.com', 'status' => 'disable'],
['id' => 9, 'name' => 'Foo 8', 'email' => 'w@ef.com', 'status' => 'disable'],
['id' => 10, 'name' => 'Foo 9', 'email' => 'l@ef.com', 'status' => 'disable'],
]
);
$this->setAdapter($adapter);
$this->setDefaultLimit(4);
$this->setAllowOrders(['name', 'email', 'id']);
$this->setAllowFilters(['name', 'email', 'status', 'id']);
$this->addAlias('id', 'index');
}
}
| php | MIT | be908a41e27f50f3786bfa8919d5245efb0d9942 | 2026-01-05T04:45:21.018855Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.