2017 © Pedro Peláez
 

library parameter-validator

Framework for specifying and enforcing rules on key/value pairs

image

hgg/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  • Thursday, November 26, 2015
  • by hglattergotz
  • Repository
  • 1 Watchers
  • 4 Stars
  • 32,142 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 4 % Grown

The README.md

Framework for specifying and enforcing rules on key/value pairs, (*1)

Build Status Latest Stable Version Total Downloads License, (*2)

Installation

Using Composer:, (*3)

{
    "require": {
        "hgg/parameter-validator": "dev-master"
    }
}

Use Cases

Url Query String Parameters

A framework like Symfony 2 provides the Request object from which one can obtain the query string parameters either one by one, (*4)

$param = $request->query->get('name-of-parameter');

or all at once, (*5)

$params = $request->query->all();

This is really convenient but the validation of these parameters is still left to the developer and becomes really tedious. You still have to ensure that all required parameters are present and that the values for them are of the correct type, etc., (*6)

This framework allows the definition of rules for the parameters and can even validate the values for these parameters., (*7)

Example - Url Query String Parameter Validation in Symfony 2

SomeApiMethod.php, (*8)

<?php

namespace HGG\ParameterValidator\Test;

use HGG\ParameterValidator\Parameter\NumberParameter;
use HGG\ParameterValidator\ParameterDefinition;
use HGG\ParameterValidator\Input;

class SomeApiMethod
{
    protected $def;

    public function __construct()
    {
        $this->def = new ParameterDefinition();
        $this->def
            ->addParameter(
                new NumberParameter(
                    'id',
                    Parameter::REQUIRED,
                    'This is a required numeric parameter',
                    'Some more details could go here'
                )
            );
    }

    public function execute($parameters)
    {
        $input = new Input($parameters, $this->def);

        $validatedParameters = $input->getParameters();

        // Do some work here and create a result

        return $result;
    }
}

SomeController.php, (*9)

<?php

class SomeController
{
    public function someAction()
    {
        $method = new SomeApiMethod();

        return $method->execute($this->getRequest()->query->all());
    }
}

The Versions

26/11 2015

dev-master

9999999-dev http://github.com/hglattergotz/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

validator http parameters query string

26/11 2015

dev-develop

dev-develop http://github.com/hglattergotz/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

validator http parameters query string

26/11 2015

v0.1.4

0.1.4.0 http://github.com/hglattergotz/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

validator http parameters query string

26/11 2015

v0.1.3

0.1.3.0 http://github.com/hglattergotz/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

validator http parameters query string

20/05 2014

v0.1.2

0.1.2.0 http://github.com/hglattergotz/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

validator http parameters query string

05/11 2013

v0.1.1

0.1.1.0 http://github.com/hglattergotz/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

validator http parameters query string

16/10 2013

v0.1.0

0.1.0.0 http://github.com/hglattergotz/parameter-validator

Framework for specifying and enforcing rules on key/value pairs

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

validator http parameters query string