Download the PHP package brewinteractive/fakend without Composer
On this page you can find all versions of the php package brewinteractive/fakend. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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].
- https://github.com/thephpleague/fractal
- https://github.com/fzaninotto/Faker
- https://github.com/memio/memio
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
Quick Look:
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
To resolve belongsTo:
author.js
To resolve hasMany:
comment.js
Parameters
Option | Parameters | Description |
---|---|---|
id | - | return id for record |
title | length[integer] | title formatted string |
description | length[integer], html[boolean] | long text formatted string |
numberBetween | min[integer], max[integer] | provides a number in given range |
date | from[string], e.g: -4 year, to[string] e.g +1 day | returns a iso_8601 date in given range |
boolean | - | returns boolean value in 50% change |
random | vales[array] | return selected value from given array |
url | - | returns random rul |
json | - | - |
imageUrl | required[boolean], type['avatar or default'] | returns a random image url from lorempixel.com |
mimeType | - | returns mime type for files |
firstname | - | returns real name |
lastName | - | returns real lastname |
html | - | returns html formatted text |
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.
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.
This will generate /api/Schema/Post.php and will consist of model's attributes.
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:
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.
A basic custom .NET web api serializer has been added to project as an example.
Then you need to initialize related model class and need to pass serializer.
From $post variable, you can call:
Method | Description |
---|---|
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
We provide a docker container(PHP & NGINX) at root directory. You just need to build & up.
Silex example
You can find sample outputs for this example in samples/
folder.
All versions of fakend with dependencies
league/fractal Version ~0.17.0
fzaninotto/faker Version *
danielstjules/stringy Version ~3.1.0
memio/memio Version ~2.0
symfony/console Version *
silex/silex Version ~2.0