PHP Classes

File: src/Helpers/Validator.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Polr Admin Dashboard   src/Helpers/Validator.php   Download  
File: src/Helpers/Validator.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Polr Admin Dashboard
Another admin dashboard for the Polr URL shortener
Author: By
Last change:
Date: 6 years ago
Size: 4,163 bytes
 

Contents

Class file image Download
<?php

namespace Lagdo\Polr\Admin\Helpers;

use
Valitron\Validator as ValitronValidator;

class
Validator
{
   
/**
     * Validate dates for stats
     *
     * @param array $dates
     *
     * @return boolean
     */
   
public function validateStatsDate(array $dates)
    {
       
$validator = new ValitronValidator($dates);
       
$validator->rule('date', ['right_bound', 'left_bound']);
        return
$validator->validate();
    }

   
/**
     * Validate link ending
     *
     * @param string $ending
     *
     * @return boolean
     */
   
public function validateLinkEnding($ending)
    {
       
$values = [
           
'ending' => $ending,
        ];
       
$rules = array(
           
'ending' => [['required'], ['slug']],
        );
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }

   
/**
     * Validate link
     *
     * @param array $values
     * @param boolean $endingRequired
     *
     * @return boolean
     */
   
public function validateLinkUrl(array $values, $endingRequired)
    {
       
$rules = array(
           
'ending' => [['slug']],
           
'url' => [['required'], ['url']],
        );
        if((
$endingRequired))
        {
           
$rules['ending'][] = ['required'];
        }
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }

   
/**
     * Validate link status
     *
     * @param array $values
     *
     * @return boolean
     */
   
public function validateLinkStatus(array $values)
    {
       
$rules = array(
           
'ending' => [['required'], ['slug']],
           
'status' => [['required'], ['in', [0, 1]]],
        );
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }

   
/**
     * Validate end point name
     *
     * @param string $endpoint
     *
     * @return boolean
     */
   
public function validateEndpoint($endpoint)
    {
       
$values = [
           
'endpoint' => $endpoint,
        ];
       
$rules = array(
           
'endpoint' => [['required'], ['slug']],
        );
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }

   
/**
     * Validate an id (integer)
     *
     * @param integer $id
     *
     * @return boolean
     */
   
public function validateId($id)
    {
       
$values = ['id' => $id];
       
$rules = [
           
'id' => [['required'], ['integer']],
        ];
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }

   
/**
     * Validate user quota
     *
     * @param array $values
     *
     * @return boolean
     */
   
public function validateUserQuota(array $values)
    {
       
$rules = [
           
'id' => [['required'], ['integer']],
           
'quota' => [['required'], ['integer']],
        ];
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }

   
/**
     * Validate user status
     *
     * @param array $values
     *
     * @return boolean
     */
   
public function validateUserStatus(array $values)
    {
       
$rules = [
           
'id' => [['required'], ['integer']],
           
'status' => [['required'], ['integer'], ['in', [0, 1]]],
        ];
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }

   
/**
     * Validate user role
     *
     * @param array $values
     *
     * @return boolean
     */
   
public function validateUserRole(array $values)
    {
       
$rules = [
           
'id' => [['required'], ['integer']],
           
'role' => [['required'], ['alphaNum'], ['lengthBetween', 1, 16]],
        ];
       
$validator = new ValitronValidator($values);
       
$validator->mapFieldsRules($rules);
        return
$validator->validate();
    }
}