Download the PHP package silvanus/structs without Composer

On this page you can find all versions of the php package silvanus/structs. 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 structs

Structs

Structs for PHP. Simple data transfer objects.

Install

Via Composer:

composer require silvanus/structs

To use autoloading mechanism, you must include vendor/autoload.php file in your code.

Motivation

PHP does not have real structs. They are feature in many other languages like C++, Rust or Go. Typescripts interfaces also bear resemblence to structs. Structs would serve a purpose for simple data that has a shape, like data transfer objects.

In PHP you can't demand properties with Interfaces, only methods. Therefore interfaces for struct-like objects do not make much sense. But if you just use a class that has public properties, you'll still let clients just declare new properties on the fly. It would be preferable to keep the shape of data just the way the struct was defined.

This library aims to solve this by providing AbstractStruct class with sensible defaults to stop dynamically assigning new or incorrect class properties/members.

Usage

Declare new struct.

Use the new struct

You can also populate the struct straight in creation.

Immutable version

You can also use a version of struct that does not allow modification of data once it is set.

Create immutable struct:

Use immutable struct

Whats the advantage over just using default class or an array

How does it work?

Nothing fancy! Just writes final __set and final __get methods on abstract parent. They block getting & creating non-declared properties. Child classes can still add public properties, as calling a public property does not trigger __get or __set

The immutable version does things a bit differently. It first sets given properties in the public properties to trigger PHP type validation (if 7.4 or higher), but after that removes the values and only stores them in single array. __get automatically uses this $properties array to serve the values.


All versions of structs with dependencies

PHP Build Version
Package Version
No informations.
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 silvanus/structs contains the following files

Loading the files please wait ....