PHPackages                             brewinteractive/fakend - 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. brewinteractive/fakend

AbandonedArchivedLibrary[API Development](/categories/api)

brewinteractive/fakend
======================

0.2.2(8y ago)934MITPHPPHP ^5.3.3|^7.0

Since Oct 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/osmanorhan/fakend)[ Packagist](https://packagist.org/packages/brewinteractive/fakend)[ RSS](/packages/brewinteractive-fakend/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (6)Versions (8)Used By (0)

Fakend
======

[](#fakend)

---

Fakend provides mock api from json schemas. It has been written in PHP and sits on a couple of great php libs such as thephpleague's fractal\[1\], fzaninotto's faker\[2\] and memio's generator lib\[3\].

1.
2.
3.

It had been designed to provide mock API specifically for ember-data but this update changes model notation from ember-data model to global JSON notation to provide more flexible mock API backend for all frontend apps.

#### How to get

[](#how-to-get)

```
# Install Fakend
curl -s https://osmanorhan.github.io/fakend/install.php | php
```

##### Quick Look:

[](#quick-look)

[![Fakend Install Gif](https://raw.githubusercontent.com/osmanorhan/fakend/master/docs/fakend-install.gif)](https://raw.githubusercontent.com/osmanorhan/fakend/master/docs/fakend-install.gif)

#### How to define models for Fakend

[](#how-to-define-models-for-fakend)

You need to generate model files first. You have to place model files to **/api/Models/** directory then you need to add class properties as shown:

post.js
=======

[](#postjs)

```
{
    "attrs": [
        {
            "fieldName": "title",
            "attributeType": "title",
            "parameters": {"length":4}
        },
        {
            "fieldName": "body",
            "attributeType": "description",
            "parameters": {"length":200,"html":true}
        },
        {
            "fieldName": "tag",
            "attributeType": "random",
            "parameters": {"values": ["human","robot","android"]}
        },
        {
            "fieldName": "date",
            "attributeType": "date",
            "parameters": {"from":"-4 year","to":"+1 year"}
        },
        {
            "fieldName": "count",
            "attributeType": "numberBetween",
            "parameters": {"min":10,"max":1000}
        },
        {
            "fieldName": "url",
            "attributeType": "url",
            "parameters": "{}"
        }
    ],
    "belongsTo": [
        {
            "fieldName": "author",
            "attributeType": "author",
            "parameters": {"required":true}
        }
    ],
    "hasMany": [
        {
            "fieldName": "comments",
            "attributeType": "comment",
            "parameters": {"required":false}
        }
    ]
}
```

### To resolve belongsTo:

[](#to-resolve-belongsto)

author.js
=========

[](#authorjs)

```
{
    "attrs": [
        {
            "fieldName": "firstName",
            "attributeType": "firstName",
            "parameters": {}
        },
        {
            "fieldName": "lastName",
            "attributeType": "lastName",
            "parameters": {}
        },
        {
            "fieldName": "avatar",
            "attributeType": "imageURL",
            "parameters": {"type":"avatar","required":false}
        }
    }
}
```

### To resolve hasMany:

[](#to-resolve-hasmany)

comment.js
==========

[](#commentjs)

```
{
    "attrs": [
        {
            "fieldName": "comment",
            "attributeType": "description",
            "parameters": {"length":50}
        }
    },
    "belongsTo": [
        {
            "fieldName": "post",
            "attributeType": "post",
            "parameters": {"required":true}
        }
    ]
}
```

### Parameters

[](#parameters)

OptionParametersDescriptionid-return id for recordtitlelength\[integer\]title formatted stringdescriptionlength\[integer\], html\[boolean\]long text formatted stringnumberBetweenmin\[integer\], max\[integer\]provides a number in given rangedatefrom\[string\], e.g: -4 year, to\[string\] e.g +1 dayreturns a iso\_8601 date in given rangeboolean -returns boolean value in 50% changerandom vales\[array\]return selected value from given arrayurl-returns random ruljson--imageUrlrequired\[boolean\], type\['avatar or default'\]returns a random image url from lorempixel.commimeType-returns mime type for filesfirstname-returns real namelastName-returns real lastnamehtml-returns html formatted text#### How to generate model class

[](#how-to-generate-model-class)

First, you "parser" executable symbolic link has been generated during install progress in first step. When you navigate to root directory folder then you can execute following command to generate schema files.

```
php parser generate [modelName]
```

If you do not provide modelName, fakend will generate php schema classes for all models. **modelName** is single model name to generate/update single model file.

```
#Example command
php parser post.js
```

This will generate **/api/Schema/Post.php** and will consist of model's attributes.

#### How to use

[](#how-to-use)

Fakend ships with basic silex app at api/ directory and each Fakend provides CRUD metods(GET/POST/PUT/DELETE) endpoint will be generated and placed at this file. New endpoints will be append end of this file.

If you want to optimize or change methods you can use followings. In index.php:

```
use Fakend\FakendFactory;
```

This adds fakend base class.

Fakend uses League's Fractal library for serializations. You can use following default fractal serializers or you can use your own custom serializer class to format your response data.

```
use League\Fractal\Serializer\JsonApiSerializer;
use League\Fractal\Serializer\DataArraySerializer;
use League\Fractal\Serializer\ArraySerializer;
```

A basic custom .NET web api serializer has been added to project as an example.

```
use Fakend\Presentation\Serializers\WebApiSerializer;
```

Then you need to initialize related model class and need to pass serializer.

```
$post = FakendFactory::create('post');
$post->setSerializer(new JsonApiSerializer());
$return = $post->setMeta(array('totalCount' => 11))->getMany(5);
```

From **$post** variable, you can call:

MethodDescription`setMeta(array)`to set metadata.`get(id)`to get an record for provided id.`getMany(limit)`to get number of records from api.`setBelongsTo(belongsToObject)`to set same belongsTo item for all requested records.`setBelongsToByName(name, belongsToObject)`to set belongsto property by name.`setParentObject(parent)`to set same parent object for all recursive models.### Docker

[](#docker)

We provide a docker container(PHP &amp; NGINX) at root directory. You just need to build &amp; up.

### Silex example

[](#silex-example)

```
$app->match('/posts', function(Request $request) use ($app) {
    if($request->getMethod() == 'OPTIONS') {
        return new Response('', 200);
    }
    $post = FakendFactory::create('post');
    $post->setSerializer(new JsonApiSerializer());
    $return = $post->setMeta(array('totalCount' => 11))->getMany(5);
    return new Response($return, 200, array(
        'Content-Type' => 'application/json',
    ));
})->method('GET|OPTIONS');
$app->match('/posts/{id}', function($id, Request $request) use ($app) {
    if($request->getMethod() == 'OPTIONS') {
        return new Response('', 200);
    }
    $post = FakendFactory::create('post');
    $post->setSerializer(new JsonApiSerializer());
    $return = $post->get($id);
    return new Response($return, 200, array(
        'Content-Type' => 'application/json',
    ));
})->method('GET|OPTIONS');
$app->match('/posts/{id}', function($id, Request $request) use ($app) {
    if($request->getMethod() == 'OPTIONS') {
        return new Response('', 200);
    }
    $return = json_encode(array());
    return new Response($return, 200, array(
        'Content-Type' => 'application/json',
    ));
})->method('DELETE|OPTIONS');
```

You can find sample outputs for this example in `samples/` folder.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~80 days

Recently: every ~101 days

Total

6

Last Release

3148d ago

### Community

Maintainers

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

---

Top Contributors

[![osmanorhan](https://avatars.githubusercontent.com/u/172629?v=4)](https://github.com/osmanorhan "osmanorhan (25 commits)")

---

Tags

fixturesdataemberfakendmock-api

### Embed Badge

![Health badge](/badges/brewinteractive-fakend/health.svg)

```
[![Health](https://phpackages.com/badges/brewinteractive-fakend/health.svg)](https://phpackages.com/packages/brewinteractive-fakend)
```

PHPackages © 2026

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