PHPackages                             synapsestudios/synapse-base - 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. [API Development](/categories/api)
4. /
5. synapsestudios/synapse-base

AbandonedArchivedLibrary[API Development](/categories/api)

synapsestudios/synapse-base
===========================

Base code for the API template

v5.0.5(9y ago)211.2k3[21 issues](https://github.com/synapsestudios/synapse-base/issues)1MITPHP

Since Mar 26Pushed 9y ago38 watchersCompare

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

READMEChangelog (2)Dependencies (27)Versions (68)Used By (1)

Synapse Base
============

[](#synapse-base)

[![Build Status](https://camo.githubusercontent.com/7a2d09609c0f866c4e4292e27bce9ca037070f0f81f0db36eeb6ab1eeeed1fde/68747470733a2f2f6170692e736869707061626c652e636f6d2f70726f6a656374732f3534306537326632333437396335656138663965346663332f62616467653f6272616e63684e616d653d6d6173746572)](https://app.shippable.com/projects/540e72f23479c5ea8f9e4fc3/builds/latest)

Overview
--------

[](#overview)

Synapse Base is a bootstrapping library for PHP applications build in the [Silex](http://silex.sensiolabs.org/) microframework. It's intended for REST APIs that serve and consume JSON.

This library provides an opinionated, secure starting point for your REST API using the following tools and libraries:

- [Silex](https://github.com/silexphp/Silex)
- bshaffer's [OAuth2 server](https://github.com/bshaffer/oauth2-server-php)
- [Zend DB](https://github.com/zendframework/zend-db)
- chrisboulton's [php-resque](https://github.com/chrisboulton/php-resque)
- Mandrill [PHP SDK](https://bitbucket.org/mailchimp/mandrill-api-php.git) for emails
- [Symfony](https://github.com/symfony/symfony)'s Console, Security, and Validator components
- [Monolog](https://github.com/Seldaek/monolog) for logging
- [And many others](https://github.com/synapsestudios/synapse-base/blob/master/composer.json)

Setting up your Project
-----------------------

[](#setting-up-your-project)

### Quick Start

[](#quick-start)

For new projects, just clone the [API Template](https://github.com/synapsestudios/api-template) as a starting point and `composer install`.

### Expectations of the Library

[](#expectations-of-the-library)

#### Architectural Expectations

[](#architectural-expectations)

1. A MySQL server for app data
2. A Redis server for job queues

#### Project Codebase Expectations

[](#project-codebase-expectations)

(If you just use API Template, you don't need to know most of this.)

1. Some named constants are [expected to exist](https://github.com/synapsestudios/api-template/blob/master/public/index.php).
2. The `APP_ENV` environment variable should be set. (To `development`, `production`, or `staging`.)
3. Specific config files should be set up in `[APPDIR]/config/`. To set up environment-specific configuration overrides, put identical config files in `[APPDIR]/config/development/`, etc. [See API Template for examples.](https://github.com/synapsestudios/api-template/tree/master/config)

### Setting Up Required Config Files

[](#setting-up-required-config-files)

The [default config files](https://github.com/synapsestudios/api-template/tree/master/config) contain sufficient documentation in DocBlocks. Just read those.

Database Interaction
--------------------

[](#database-interaction)

### Database Installs and Migrations

[](#database-installs-and-migrations)

Use the [console](https://github.com/synapsestudios/api-template/blob/master/console) utility in API Template to perform DB installs and migrations.

- Install a clean copy of the database: `./console install:run --drop-tables`
- Create a migration: `./console migrations:create "Add inventory table"`
- Install any migrations that haven't been applied: `./console migrations:run` (Or just `./console install:run`)
- Generate a new database install file from the current state of the database: `./console install:generate`

When you create a new migration, it's created in `[APPDIR]/src/Application/Migrations/`. Use the Zend DB Adapter to perform queries [like this](https://github.com/synapsestudios/api-template/blob/a2163910a1033f3064d125bba366c2b556945aea/src/Application/Migrations/CreateUsertokentypesTable20140507193727.php).

**Note about Generating a Database Install File:** When you run `./console install:generate`, it generates 2 files -- (1) a `DbStructure.sql` file with the table structure based on the current snapshot of your database, and (2) a `DbData.sql` file with data from specific tables. Specify which tables in the [install config](https://github.com/synapsestudios/api-template/blob/master/config/install.php).

### How to Read/Write from the Database

[](#how-to-readwrite-from-the-database)

Use Mappers [like this](https://github.com/synapsestudios/synapse-base/commit/f905195c81a8786d47c32a0dadb1bf61e9107ccb#diff-06e71af6dcfaea597c8b184610d4f2fd) to perform database queries. Database results are returned as [Entities](https://github.com/synapsestudios/synapse-base/blob/aceb9e1dec716597e576ee22859ddc20e6a04d7b/src/Synapse/User/UserEntity.php).

Authentication / Login System
-----------------------------

[](#authentication--login-system)

bshaffer's [OAuth2 server](https://github.com/bshaffer/oauth2-server-php) is used for authentication. The user `POST`s to `/oauth/token` with their email/password and receives an access token which can be used to make requests. (Per the OAuth2 specification.)

In order to secure endpoints, the [Symfony Security](http://symfony.com/doc/current/book/security.html) module is used. [Firewalls](https://github.com/synapsestudios/synapse-base/blob/b3e3db0d17237de20cfa5a365b5822d34013c1f9/src/Synapse/User/UserServiceProvider.php#L138) are used to constrain an endpoint to logged in users or to make it public. [Access Rules](https://github.com/synapsestudios/synapse-base/blob/b3e3db0d17237de20cfa5a365b5822d34013c1f9/src/Synapse/User/UserServiceProvider.php#L160) are used to make an endpoint accessible only to users with certain roles. Read the Symfony Security docs for more details.

**Notes:**

1. When you specify a listener in a firewall (`'anonymous' => true`, `'oauth-optional' => true`), the code that runs is in the [Listeners](https://github.com/synapsestudios/synapse-base/tree/master/src/Synapse/Security/Firewall). (These are added in the [OAuth2\\SecurityServiceProvider](https://github.com/synapsestudios/synapse-base/blob/master/src/Synapse/OAuth2/SecurityServiceProvider.php).)
2. There is a [catch-all firewall](https://github.com/synapsestudios/synapse-base/blob/5cdd7abf7caddae16bbcb8d1ec5aee71a8aa907e/src/Synapse/Application/Services.php#L109) that constrains all endpoints to be protected by OAuth (non-public) unless specified otherwise. [More details here.](https://github.com/synapsestudios/synapse-base/blob/5355dc2c53e6398bc1ef8e1c8f8390224580e267/src/Synapse/Application/Services.php#L68)

Utility Classes
---------------

[](#utility-classes)

### [Array Helper](https://github.com/synapsestudios/synapse-base/blob/master/src/Synapse/Stdlib/Arr.php)

[](#array-helper)

```
$people = [
    ['name' => 'Linus',   'age' => 10],
    ['name' => 'Brendan', 'age' => 11],
    ['name' => 'Rasmus',  'age' => 12, 'colors' => ['Red', 'Green', 'Blue']],
];

Arr::get($people[0], 'name');     // Linus
Arr::get($people[3], 'name');     // null
Arr::pluck($people, 'name');      // ['Linux', 'Brendan', 'Rasmus'];
Arr::path($people, '2.colors.1'); // Green
```

### [DataObject](https://github.com/synapsestudios/synapse-base/blob/master/src/Synapse/Stdlib/DataObject.php)

[](#dataobject)

Use these to encapsulate concepts and typehint them in your app.

```
class Car extends DataObject
{
    protected $object = [
        'make'    => null,
        'model'   => null,
        'year'    => null,
        'totaled' => false,
    ];
}

$car = new Car(['make' => 'Toyota']);
$car->setModel('Corolla');
$car->getMake();    // Toyota
$car->getModel();   // Corolla
$car->getYear();    // null
$car->getTotaled(); // false

// These are helpful for typehinting purposes to make your code more robust
function purchaseCar(Car $car) {
    // Do stuff
}
```

### Test Helpers

[](#test-helpers)

Various [abstract PHPUnit test cases](https://github.com/synapsestudios/synapse-base/tree/master/src/Synapse/TestHelper) are available for controllers, mappers, etc., to make it easier to test them.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~17 days

Recently: every ~46 days

Total

60

Last Release

3399d ago

Major Versions

v1.4.2 → v2.1.02015-04-16

v2.1.2 → v3.0.02015-05-05

v3.0.2 → v4.0.02015-06-09

v2.0.1 → v4.0.42015-08-19

v4.1.1 → v5.0.02016-04-05

### Community

Maintainers

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

---

Top Contributors

[![zpchavez](https://avatars.githubusercontent.com/u/717690?v=4)](https://github.com/zpchavez "zpchavez (247 commits)")[![paulstatezny](https://avatars.githubusercontent.com/u/4662353?v=4)](https://github.com/paulstatezny "paulstatezny (207 commits)")[![spruce-bruce](https://avatars.githubusercontent.com/u/59978?v=4)](https://github.com/spruce-bruce "spruce-bruce (57 commits)")[![areida](https://avatars.githubusercontent.com/u/369030?v=4)](https://github.com/areida "areida (43 commits)")[![tdboone](https://avatars.githubusercontent.com/u/819455?v=4)](https://github.com/tdboone "tdboone (35 commits)")[![chrisshiplet](https://avatars.githubusercontent.com/u/933501?v=4)](https://github.com/chrisshiplet "chrisshiplet (30 commits)")[![bobeagan](https://avatars.githubusercontent.com/u/100226?v=4)](https://github.com/bobeagan "bobeagan (26 commits)")[![agerbens](https://avatars.githubusercontent.com/u/5374685?v=4)](https://github.com/agerbens "agerbens (16 commits)")[![bjyoungblood](https://avatars.githubusercontent.com/u/230542?v=4)](https://github.com/bjyoungblood "bjyoungblood (14 commits)")[![baohx2000](https://avatars.githubusercontent.com/u/486322?v=4)](https://github.com/baohx2000 "baohx2000 (13 commits)")[![pcavagna](https://avatars.githubusercontent.com/u/999600?v=4)](https://github.com/pcavagna "pcavagna (2 commits)")[![dmmcinty](https://avatars.githubusercontent.com/u/1359068?v=4)](https://github.com/dmmcinty "dmmcinty (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/synapsestudios-synapse-base/health.svg)

```
[![Health](https://phpackages.com/badges/synapsestudios-synapse-base/health.svg)](https://phpackages.com/packages/synapsestudios-synapse-base)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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