Download the PHP package 3nr1c/structure without Composer

On this page you can find all versions of the php package 3nr1c/structure. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package structure

Structure Build Status

Structure provides a set of classes to check the data type and format of your variables.

Table of Contents

License
Installation
Introduction
Documentation
Static shortcuts
Class ScalarS
Class NumericS
Classes IntegerS and FloatS
Class StringS
Class ArrayS
Working with Value Sets
Further info
Changelog
Planned features

License

Structure is provided under the MIT License.

Installation

You can install Structure into your project using Composer. Using the latest release is highly recommendable. You can start using it by adding the following to your composer.json:

You can also use the version at your own risk. The code in this version may change at any time.

Introduction

Have you ever had to check the structure of some variable? (maybe it's an array that must have certain keys and value types, or an integer that must be within a certain range). If so, you probably have written some code like this:

And that's only the beginning! I suppose that for each key, you also have to check for other keys, and data types. Structure helps you with these issues. The previous code becomes:

Here are some more examples:

Documentation

All Structure classes have the same constructor:

The $null argument allows the data to be null when running the method. All classes have also the following methods:

The argument of lets you create a variable that will tell you why this method returned false. You can access to the last error information, and erase it, with the static methods and . The possible values for this failure variables are specified in their section below.

Static shortcuts

The main Structure class provides four static methods to quickly generate checkers:

All these methods return respectively an ArrayS, NumericS, IntegerS, FloatS or StringS object, with the properties set as passed by the arguments.

Class ScalarS

This class runs the test to a variable. If the result is , the var will show the type of the tested variable.

Usage:

This class and all its children have the method, which lets you define possible values for the data to be checked. This method can take either a variable number of arguments, or a string with values separated by commas between curly brackets and :

and tokens evaluate to booleans If you need the strings "true" and "false", escape them

If the tested variable is scalar but isn't in the defined set, the var will be .

Class NumericS

This class runs the test against a variable. A range property can be defined, with the following syntax:

That is, it uses the mathematical notation:

The term is used to indicate infinities. It has limitations: the left value can only be , and the right value either or .

The parser will raise an if the syntax is not correct. Here are a couple of examples:

The left number must be less than or equal to the right number.

If the type of the tested variable is correct, but the range isn't, the variable will have the value .

Classes IntegerS and FloatS

They both inherit from . The only difference is that the check method of IntegerS uses
(is stricter), and uses . Notice this:

As you can see in the examples above, and are strict regarding s of numbers. You can use the attribute (set to by default) to avoid this strictness:

If the type of the tested variable is correct, but the range isn't, the variable will be either or .

Class StringS

This class runs the test against a variable.

Usage:

Min and max length can be required using :

If the test data is a string but does not match the length, the var will have the value .

Class ArrayS

This class has the following methods (plus all the methods inherited from ):

setFormat

The $format argument can have many forms. The type must always be or . The string type is used to define simple arrays, such as

The characters and can also be used to test simple arrays. Something like "[3..5]" can be used to express variable array size. The following expressions are valid:

Types can be mixed using the vertical bar :

And the token can be "nested", to define multidimensional arrays

The array type is used to represent more complex array structures. If you expect an array to be sequential (i.e., not key-value), the format should be an array of types. Again, if all array elements have to be of the same type, the syntax above is recommended.

Finally, you can define required keys for an associative array. Warning: if the array has some keys you do not want to check, make sure you run the command.

As you can see, it has a recursive definition.

Working with Value Sets

Sometimes you want to check if a variable has a value that you know. Let's imagine that we want to check if a number is 3 or 7. It's not possible using the mathematical notation supported by Structure (we'd need to use unions and intersections of mathematical entities). Value Sets in Structure provide this feature.

This feature is available for all Structure types. When (, , , , and ) is inherited a method is available.

When working with arrays, the Value Set information can be embedded within the format declaration.

This feature can also be used to check whether a variable matches a single value, which can be quite useful in an array context. For example, you could check bools, or integers:

Further info

You can read more documentation by running (phpdoc needed) and by looking at the test cases.

Changelog

0.6.0

0.5.0

Planned features


All versions of structure with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package 3nr1c/structure contains the following files

Loading the files please wait ....