PHPackages                             hamboldt/silk-orm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. hamboldt/silk-orm

ActiveLibrary[Database &amp; ORM](/categories/database)

hamboldt/silk-orm
=================

Object Relational Mapper for zend-db

v1.1.2(10y ago)1521[1 issues](https://github.com/hamboldt/silk-orm/issues)MITPHP

Since Aug 12Pushed 10y ago1 watchersCompare

[ Source](https://github.com/hamboldt/silk-orm)[ Packagist](https://packagist.org/packages/hamboldt/silk-orm)[ RSS](/packages/hamboldt-silk-orm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (10)Used By (0)

silk-orm
========

[](#silk-orm)

[![License](https://camo.githubusercontent.com/95c9d52c0043d590d5f07bb64039b8c76eaf3d0f0ec9a1b57fef685965ff812c/68747470733a2f2f706f7365722e707567782e6f72672f68616d626f6c64742f73696c6b2d6f726d2f6c6963656e7365)](https://packagist.org/packages/hamboldt/silk-orm) [![Build Status](https://camo.githubusercontent.com/9246456c1e4eceb8683b7ae424aadf0279c10d9a3014c6703ea6d7103e16b4ff/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f68616d626f6c64742f73696c6b2d6f726d2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/hamboldt/silk-orm/build-status/master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/2cd05e79f68fda887be1b4b6dc8356f5d924612b32c3829c45b0194bf2d851d9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f68616d626f6c64742f73696c6b2d6f726d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/hamboldt/silk-orm/?branch=master) [![Total Downloads](https://camo.githubusercontent.com/0741526629957ac2ef7912fd6a413322ed03545cb3275add1eb81984f4db311f/68747470733a2f2f706f7365722e707567782e6f72672f68616d626f6c64742f73696c6b2d6f726d2f646f776e6c6f616473)](https://packagist.org/packages/hamboldt/silk-orm) [![Latest Stable Version](https://camo.githubusercontent.com/58eb257b9211eb679a99a99c03d0fb0f81e683da54b976a4cdc3e114f2a74e7e/68747470733a2f2f706f7365722e707567782e6f72672f68616d626f6c64742f73696c6b2d6f726d2f762f737461626c65)](https://packagist.org/packages/hamboldt/silk-orm)

O ORM Silk (seda em inglês) é um sistema de mapeamento de objetos integrado com a estrutura do Zend Framework 2 que foi pensado para ser prático, leve, e de fácil configuração. Ele permite transformar tabela em objetos e posteriormente acessar os dados utilizando o padrão de busca SQL do Zend. Em outras palavras, o papel dele é mapear seus objetos apenas em nível de arrays. Todo o resto fica com o Zend - transação de arrays com o banco de dados.

`composer require hamboldt/silk-orm`

### Como funciona

[](#como-funciona)

- [Configure um banco de dados](https://gist.github.com/hamboldt/b873f19576623f06607a)
- [Configure um objeto](https://gist.github.com/hamboldt/ad2ed7cf50c028b57373)
- [Configure um objeto relacionado](https://gist.github.com/hamboldt/463eab6bbb92559ee2cb)

### Configurações

[](#configurações)

##### Classes

[](#classes)

- `@configure {"table":"table_name"}` - Especifica qual é a tabela do objeto no banco de dados.
- `@configure {"primary_key":"idtable"}` - Especifica qual é a chave primária da tabela.

##### Propriedades

[](#propriedades)

- `@configure {"ignore":true}` - Ignora a propriedade do objeto na construção das queries.
- `@configure {"ignoreIfNull":true}` - Ignora a propriedade do objeto, apenas se nula.
- `@configure {"alias":"somecolumn"}` - Especifica o nome da coluna da propriedade na tabela.
- `@configure {"type":"\\Garage\\Car"}` - Instanciamento automático de objetos mapeáveis.

### Como usar

[](#como-usar)

#### Instanciamento

[](#instanciamento)

O exemplo abaixo deve ser seguido quando formos instanciar apenas um objeto. Pode-se usar perfeitamente as clausulas where do Zend tal como usa-se em seus TableGateways, afinal, o Silk usa o TableGateway do ZF2 para construir seus resultados.

```
$user = new User(1); // pelo valor da chave primária
$user = new User(["name"=>"lucas"]); // por um where com array
$user = new User(function(Select $select){ /* ... */ }); // Pelo select do zf2
```

#### Multipla seleção

[](#multipla-seleção)

O exemplo abaixo deve ser seguido quando formos instanciar múltiplos objetos. Para armazenar coleções de objetos, usamos a biblioteca [easyframework/collections](https://github.com/italolelis/collections).

```
$collection = User::select(["name"=>"lucas"]);
$collection = User::select(function(Select $select){ /* ... */ });

$collection->map(function(User $user){
   echo $user->getCompany()->getName() . "\n";
});
```

#### Inserindo novo registro

[](#inserindo-novo-registro)

Quando o objeto é instanciado e não se passa nenhum valor no construtor como parâmetro ele é criado vazio, isto é, não vai ter nenhum valor, nem uma id definida para o mesmo. Quando o objeto tem um id nulo (`$company->getId() == null`) ao chamar o método *save()* um novo registro será inserido no banco. Se ele ja tiver um id definido, o registro será atualizado.

```
$company = new Company();
$company->setName("Softwerk");
$company->save();

echo $company->getId(); // 1
```

[![](https://camo.githubusercontent.com/493104bfd23d5dbf9cb18b6ff06834f126e336b7c580fa06973d76686510392f/687474703a2f2f692e696d6775722e636f6d2f4a5231554f49762e706e673f31)](https://camo.githubusercontent.com/493104bfd23d5dbf9cb18b6ff06834f126e336b7c580fa06973d76686510392f/687474703a2f2f692e696d6775722e636f6d2f4a5231554f49762e706e673f31)

#### Atualizando um registro

[](#atualizando-um-registro)

Quando o objeto já possui uma id definida, e chamamos o método `save()`o registro cuja chave primária for a id do objeto será atualizado no banco de dados, conforme o exemplo abaixo.

##### Instanciamento por chave primária

[](#instanciamento-por-chave-primária)

```
$company = new Company(1);
$company->setName("Softwerk LTDA");
$company->save();
```

##### Instanciamento por array explicita

[](#instanciamento-por-array-explicita)

```
$company = new Company(['idcompany' => 1]);
$company->setName("Softwerk LTDA");
$company->save();
```

##### Instanciamento por where do ZF2

[](#instanciamento-por-where-do-zf2)

```
$company = new Company(function(Select $select){
   $select->where->equalTo('idcompany', '1');
   $select->limit(1);
});
$company->setName("Softwerk LTDA");
$company->save();
```

##### Atualizando múltiplos registros

[](#atualizando-múltiplos-registros)

Atualiza todos os registros onde a coluna nome tiver o valor 'Softwerk'.

```
Company::select(['name' => 'Softwerk'])->map(function(Company $company){
   $company->setName('The name has changed!');
   $company->save();
});
```

#### Removendo um registro

[](#removendo-um-registro)

Um objeto só será removido quando o sua id estiver definida, assim como nas operações de atualização. Para remover um registro do banco de dados basta chamar o método `delete()` do objeto, assim como no exemplo abaixo.

```
$company = new Company(1);
$company->setName("Softwerk LTDA");
$company->delete();
```

##### Removendo vários registros

[](#removendo-vários-registros)

Exemplo abaixo irá remover todos os objetos onde o valor da coluna `name` for igual a `Softwerk`.

```
Company::select(['name' => 'Softwerk'])->map(function(Company $company){
   $company->delete();
});
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Recently: every ~24 days

Total

7

Last Release

3833d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2bcc2e83e3aa7c9b2b1f5e9b0fd9444580a5e97a12ffae9c88903040360be76?d=identicon)[hamboldt](/maintainers/hamboldt)

---

Top Contributors

[![lucasdearaujo](https://avatars.githubusercontent.com/u/2407611?v=4)](https://github.com/lucasdearaujo "lucasdearaujo (53 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")

### Embed Badge

![Health badge](/badges/hamboldt-silk-orm/health.svg)

```
[![Health](https://phpackages.com/badges/hamboldt-silk-orm/health.svg)](https://phpackages.com/packages/hamboldt-silk-orm)
```

###  Alternatives

[hounddog/doctrine-data-fixture-module

Zend Framework 2 Module that provides Doctrine Data-Fixture functionality

37335.4k9](/packages/hounddog-doctrine-data-fixture-module)[mamuz/mamuz-blog

Provides blog feature for ZF2 with Doctrine

101.1k1](/packages/mamuz-mamuz-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
