GithubHelp home page GithubHelp logo

sensorario / resources Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 1.62 MB

A library to validate requests for web api

License: MIT License

PHP 99.69% Shell 0.10% Makefile 0.21%
php-validator php-validation php-value-objects php-7 json-schema

resources's Introduction

resources's People

Contributors

sensorario avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

resources's Issues

Define a property as a scalar

I can define only Object types and not scalar ones. I need to define that a property should be an array or an integer (or other scalar types)

  • type should define if is an object or a scalar
  • accept 'object' type and 'array' type

Allow parameters, only if others has specific value

In case of API, a Request could have some allowed parameters. But the presence of a specific value, could remove to allowed others. Example:

type=[category|categoryGroup]
name
[categoryGroup]

categoryGroup is allowed only when type is categoryGroup.

For example, a parameter could allow others.

ValueObject::allow()
{
    return [
        'type' => 'category',
        'allow' => 'categoryGroup',
    ];
}

github pages from bash

As Developer,
I want to run bash commands,
so then I can reach GitHub web site pages directly from bash

Mandatory properties in case of another property value

Suppose to have an api to search some value. And suppose you can d search for Peoples or Balls. When you search for People, you must define the name. When you search for Balls, you must define the color.

    Search::box([
        'what' => 'People'
    ]);

should through an exception, because name is missing. Correct search request values are:

    Search::box([
        'what' => 'People',
        'name' => 'Simone',
    ]);

Otherwise, id you search for balls, will get an exception because name is not mandatory nor allowed.

    Search::box([
        'what' => 'Balls',
        'name' => 'Simone',
    ]);

This is the right call

    Search::box([
        'what' => 'Balls',
        'color' => 'red',
    ]);

Get the value of current VO

Implement, for example, toJson, toXml, toYaml methods. By default, could work with allowed.mandatory attributes.

Show the type that a property should be

The exception should explain class name of this object. This error occurs when you define that a property must have a type with ValueObjec::types(), but this message does not explain which type.

Global constraints

In this example, a developer needs to define an allowed attribute for all resources:

  return new Container([
    'resources' => [
      'p' => [
        'constraints' => [
          'allowed' => [
            'resource_name',
          ],
          'mandatory' => [
            'uno',
            'due',
            'tre',
          ],
          'defaults' => [
            'uno' => 'bar',
            'due' => 33333,
            'tre' => 'mello',
          ],
        ]
      ],
      'foo' => [
        'constraints' => [
          'allowed' => [
            'resource_name',
          ],
          'mandatory' => [
            'foo',
            'ciao',
            'friend',
          ],
          'defaults' => [
            'foo' => 'bar',
            'ciao' => 33333,
            'friend' => 'mello',
          ],
          'allowedValues' => [
            'foo' => [
              42,
              'bar'
            ],
          ],
        ]
      ]
    ]
  ]);

There should be a global 'constratints' configuration, to allow all responses to inherit some attributes.

Improve contributing rules

When an update is made, CHANGELOG should be updated and the added content should be the same of the commit message.

clean metadata

Remove all 2.X metadata information like UPGRADE files and CHANGELOG

unecessary classes just for test purpose

All the classes created just for test purpose can be removed. Actually is not necessary a real class: instead of a real class, right configuration is enough. All classes inside tests/Resources folder could be replaced with Resource::box(). Starting from version 4.0 is not necessary a real instanced object. Resource::box accept a second parameter that accept the resource configuration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.