Download the PHP package laborra/passive-records without Composer

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

Passive Records for PHP

Build Status Coverage Status

This extension aims to provide a way to model read only databases. These kind of databases are useful when a software component needs to access data that doesn't change so often. For instance, if you have to model the list of all the world countries, you can choose between two solution:

The passive approach

This library tries to achieve the best of the two methods described above. We would like to have a developer friendly data access interface, with good performances and a maintainable data set.

The application interface is ispired to Yii2 framework Active Record and it is based on model class that describes data structure and data contents.

Model definition

To declare a PassiveRecord class you need to extend laborra\db\PassiveRecord and implement getSchema and getData methods like the following.

class Country extends PassiveRecord
{
    public static function getSchema ()
    {
        return array(
            'iso' => array('pk'),
            'label',
        );
    }

    public static function getData ()
    {
        return array(
            array('it', 'Italy'),
            array('us', 'United States'),
            ...
        );
    }
}

Accessing data

In the example we have a country data model that stores all countries we need. The structure is similar to relational databases: we have two columns, iso and label. The 'iso' property is the primary key of the model, so it has to be unique in the data set. The getData() function provides the data of the model. To access data we can use the ORM methods like:

// Find by primary key
$country = Country::find('it');
$this->assertInstanceOf('Country', $country);
$this->assertEquals('it', $country->iso);
$this->assertEquals('Italy', $country->label);

// Find by column condition
$countries = Country::find()->where('label', 'like', 'Ital%')->all();
$this->assertInstanceOf('Country', $countries[0]);

// Count by condition
$nCountries = Country::find()->where(array('label' => 'Italy'))->count();
$this->assertEquals($nCountries, 1);

The getSchema function declare the class schema and it can be expressed as array or as PassiveSchema. In this way we declare the properties our passive objects have, enabling read only access to them and allowing criteria search.

The getData function declare the content of the class passive record collection. It has to return an array matrix with the following syntax:

array(
    array('value 1 column 1', 'value 1 column 2', ...), // First row content
    array('value 2 column 1', 'value 2 column 2', ...), // Second row content
    ...
);

Each row is expressed by an array of values and the order is expected to be compliant with the return value of getSchema.

Adanced usage: mixing active and passive records

Consider an application that must be secured by classic access permission: users have roles and each role can access a set of application functionalities. We have to model the user, roles and functionality data. Thus, we have a meny to meny relationship between users and roles and another between roles and functionality. Obviously, user data must be kept in a read/write database, so we will use classic active records for users and user_role models. In this example, application roles are fixed and they cannot be modified at runtime. So, roles, functionalities and role_functionlity models will be implemented using passive records.

class Role extends PassiveRecord
{
    public static function getSchema ()
    {
        return array(
            'name' => array('PK'),
            'label',
        );
    }

    public static function getData ()
    {
        return array(
            array('ADMIN', 'Administrator'),
        );
    }
}

class Functionality extends PassiveRecord
{
    public static function getSchema ()
    {
        return array(
            'id' => array('PK'),
            'label',
        );
    }

    public static function getData ()
    {
        return array(
            array('func1', 'Basic functionality'),
            array('func2', 'Other functionality'),
            array('func3', 'Admin only functionality'),
        );
    }
}

class RoleFunctionality extends PassiveRecord
{
    public static function getSchema ()
    {
        return array(
            'id' => array('PK'),
            'label',
        );
    }
}

Documentation

Declaring passive record classes

[TBD]


All versions of passive-records 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 laborra/passive-records contains the following files

Loading the files please wait ....