PHP Classes
elePHPant
Icontem

PHP Expressive: Base class for Object Relational Mapping

Recommend this page to a friend!
  Info   View files Documentation   View files View files (44)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-04-08 (5 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 74 All time: 9,167 This week: 513Up
Version License PHP version Categories
php-expressive 1.2.8The PHP License7Databases, Design Patterns, PHP 7
Description Author

This package provides a base class for Object Relational Mapping.

The base class provide basic ORM operations and should be extended by actual entity classes that define the properties to be saved to a database.

The package also provides a trait to map magic methods to access property values.

Name: Rafael Becker <contact>
Classes: 1 package by
Country: Brazil Brazil

Details

Expressive

Codacy Badge Codacy Badge Latest Stable Version License Build Status

Expressive é uma biblioteca para mapeamento objeto relacional construída sobre o illuminate/database, com definições de objetos baseada em arquivos de schema.

Install

Esse pacote foi estruturado para ser instalado por meio do composer.

composer require solis/expressive

Usage

Defina a estrutura de um objeto de acordo com as especificações do phpschema.

{
  "database": {
    "repository": "pessoa",
    "keys": "ID"
  },
  "properties": [
    {
      "alias": "proID",
      "property": "ID",      
      "type": "int",
      "behavior": {        
        "required": "false",
        "autoIncrement": "true"
      }
    },
    {
      "alias": "proNome",
      "property": "nome",      
      "type": "string"
    },
    {
      "alias": "proInscricaoFederal",
      "property": "inscricaoFederal",      
      "type": "string"
    },
    {
      "alias": "proTipo",
      "property": "tipo",      
      "type": "int"
    },
    {
      "alias": "proSituacao",
      "property": "situacao",      
      "type": "int",
      "behavior": {
        "required":"false"
      }
    }
  ]
}

Uma Classe que utiliza a funcionalidade ORM fornecida pela biblioteca deve extender a class abstrata Expressive e ter em si declaradas as propriedades especificadas no schema json.

use Solis\Expressive\Classes\Illuminate\Expressive;
use Solis\Expressive\Magic\Concerns\HasMagic;

class Pessoa extends Expressive
{
    use HasMagic;

    protected $ID;
    protected $nome;
    protected $inscricaoFederal;
    protected $tipo;
    protected $situacao;
    
    /
     * Pessoa constructor.
     */
    public function __construct()
    {
        parent::__construct();

        $this->start(dirname(__FILE__) . '/Pessoa.json');
    }
}   

O método start é responsável por construir um objeto Schema a partir do caminho fornecido e atribuir a respectiva classe.

Uma classe extendo Expressive deve utilizar a trait HasMagic de modo ater acesso a funcionalidade de atribuição dinâmica por meio do método make.

$Pessoa = Pessoa::make([
      "proNome"             => 'Fulano - ' . uniqid(rand()),
      "proInscricaoFederal" => '' . rand(11111111111111, 99999999999999) . '',
      "proTipo"             => 1      
]);

O método make retorna uma instância de ExpressiveAbstract com acesso as operações de persistência disponibilizadas pela biblioteca.

Operations

Relação de operações de persistência que podem ser utilizadas por uma instância de ExpressiveAbstract

Count

Retorna um valor inteiro representando a contagem de registros na persistência.

$count = (new Pessoa()) ->count()

//$count = Pessoa::make([])->last($arguments = []);

Create

Cria um novo registro na persistência de acordo com os valores fornecidos para construção do objeto por meio do make.

Pessoa::make([
      "proNome"             => 'Fulano - ' . uniqid(rand()),
      "proInscricaoFederal" => '' . rand(11111111111111, 99999999999999) . '',
      "proTipo"             => 1      
])->create();

Delete

Deleta um registro na persistência de acordo com as informações atribuidas ao active record.

Pessoa::make([
        'proID' => 1
])->search()->delete();

Last

Retorna o último registro na persistencia de acordo com as informações atribuidas ao active record.

(new Pessoa())->last()

//Pessoa::make([])->last();

Replicate

Replica um registro existente na persistência de acordo com as informações atribuidas ao active record.

$instance = Pessoa::make([
    'proID' => 1,
])->last();

$instance->replicate();    

Search

Retorna um registro existente na persistência de acordo com as informações atribuidas ao active record.

$instance = Pessoa::make([
    'proID' => 1
])->search();

Select

Retorna uma relação de registros existentes na persistência de acordo a relação de argumentos e opções fornecidas.

$result = (new Pessoa())->select();

//$result = Pessoa::make([])->select($arguments = [], $options = []);

Update

Atualiza um registro existente na persistência de acordo com as informações atribuidas ao active record.

$instance = Pessoa::make(
    [
        'proID' => 1,        
    ]
)->search();

$instance->proNome = 'UPDATE TEST [ ' . Date('Y-m-d H:m:s') . ']';

$instance->update();

Change log

Acompanhe o CHANGELOG para informações sobre atualizações recentes.

Testing

$ composer test

License

The MIT License (MIT). Verifique LICENSE para mais informações.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 3 directories)
Files folder imagetests (2 directories)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.MD Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageAbstractions (2 files)
Files folder imageClasses (1 directory)
Files folder imageContracts (2 files)
  Plain text file Exception.php Class Class source

  Files folder image Files  /  src  /  Abstractions  
File Role Description
  Plain text file DatabaseContainerAbstract.php Class Class source
  Plain text file ExpressiveAbstract.php Class Class source

  Files folder image Files  /  src  /  Classes  
File Role Description
Files folder imageIlluminate (4 files, 8 directories)

  Files folder image Files  /  src  /  Classes  /  Illuminate  
File Role Description
Files folder imageDelete (2 files)
Files folder imageInsert (2 files)
Files folder imagePatch (2 files)
Files folder imageQuery (2 files)
Files folder imageReplicate (1 file)
Files folder imageSelect (2 files)
Files folder imageUpdate (2 files)
Files folder imageUtil (1 file)
  Plain text file Database.php Class Class source
  Plain text file Diglett.php Class Class source
  Plain text file Expressive.php Class Class source
  Plain text file Wrapper.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Delete  
File Role Description
  Plain text file DeleteBuilder.php Class Class source
  Plain text file RelationshipBuilder.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Insert  
File Role Description
  Plain text file InsertBuilder.php Class Class source
  Plain text file RelationshipBuilder.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Patch  
File Role Description
  Plain text file PatchBuilder.php Class Class source
  Plain text file RelationshipBuilder.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Query  
File Role Description
  Plain text file Builder.php Class Class source
  Plain text file SearchStmt.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Replicate  
File Role Description
  Plain text file ReplicateBuilder.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Select  
File Role Description
  Plain text file RelationshipBuilder.php Class Class source
  Plain text file SelectBuilder.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Update  
File Role Description
  Plain text file RelationshipBuilder.php Class Class source
  Plain text file UpdateBuilder.php Class Class source

  Files folder image Files  /  src  /  Classes  /  Illuminate  /  Util  
File Role Description
  Plain text file Actions.php Class Class source

  Files folder image Files  /  src  /  Contracts  
File Role Description
  Plain text file DatabaseContainerContract.php Class Class source
  Plain text file ExpressiveContract.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageFixtures (1 directory)
Files folder imageIntegration (8 files)

  Files folder image Files  /  tests  /  Fixtures  
File Role Description
Files folder imageIntegrationTest (7 files)

  Files folder image Files  /  tests  /  Fixtures  /  IntegrationTest  
File Role Description
  Plain text file DatabaseBuilder.php Class Class source
  Accessible without login Plain text file Endereco.json Data Auxiliary data
  Plain text file Endereco.php Class Class source
  Accessible without login Plain text file JsonEndereco.json Data Auxiliary data
  Plain text file JsonEndereco.php Class Class source
  Accessible without login Plain text file Pessoa.json Data Auxiliary data
  Plain text file Pessoa.php Class Class source

  Files folder image Files  /  tests  /  Integration  
File Role Description
  Plain text file AbstractIntegrationTest.php Class Class source
  Plain text file CreateIntegrationTest.php Class Class source
  Plain text file DeleteIntegrationTest.php Class Class source
  Plain text file HasManyIntegrationTest.php Class Class source
  Plain text file PatchIntegrationTest.php Class Class source
  Plain text file ReplicateIntegrationTest.php Class Class source
  Plain text file SelectIntegrationTest.php Class Class source
  Plain text file UpdateIntegrationTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:74
This week:0
All time:9,167
This week:513Up