graphene/graphene

PHP rest framework

0.3.4 2018-11-17 12:29 UTC

This package is auto-updated.

Last update: 2024-05-16 10:20:23 UTC


README

This framework allows you to create Action Oriented REST services with less lines of code, like this:

class HelloWorld extends Action{
	public function run ()
	{
		$this->sendMessage('Hello world');
	}
}

Install Graphene with composer

Graphene is can be installed using composer:

composer require graphene/graphene

after install you can bootstrap you application doing

cp ./vendor/graphene/graphene/_installation/* .

this command extracts from downloaded graphene library:

  • index.php Contains simple graphene launcher
  • settings.php Contains basic settings for logging and persistence
  • cli.php Simple CLI adapter for graphene
  • .htaccess Apache file with url rewriting and redirecting to index.php
  • web.config same with .htaccess, for windows ISS

Graphene settings file

[work in progress]

Action approach

Any http request to Graphene matches an "action". In graphene action mapping is quick and smart, ball actions are collected in separate modules.

Defining module

you can define your module creating folder in your moduleUrl, definded in settings.json.

{
    "v" :  "0.1.1",
    "info": {
        "version"   : "0.0.0.1",
        "name"      : "com.profile",
        "namespace" : "profiles",
        "author"    : "Me [me@mail.com]",
        "support"   : "meMod.com"
    },
    "actions": []
}

in this case we have created a module named "com.profile", with "profiles" as namespace. this module does not have any action.

Creating actions

now we can ceate a simple action "HELLO_WORLD", mapping that on request GET host/profiles/hello you can add this action creating this entry in your module manifest:

{"name":"HELLO_WORLD", "query":"hello"}

and creating profiles.HELLO_WORLD.php file in actions folder like this:

namespace profiles;

class HelloWorld extends Action{
    public function run ()
    {
        $this->sendMessage('Hello world');
    }
}

Model

Graphene supports model checking and storage doc work in progress

Scaffolding

When you create a new module, we recomends this directory structure for your models and actions

_module namespace_
 +--manifest.json
 +--models
 |   |--ModelClassA.php 
 |   |--ModelClassB.php 
 |   |--Mod...
 +--actions
 |   |--namespace.ACTION_NAME_A.php 
 |   |--namespace.ACTION_NAME_B.php
 |   |--namespace...

Wiki

we are very excited that you want to use Graphene therefore we are working so that you can use it to its full potential by writing up to date wiki. Go to Graphene wiki

HowTo

Hello world tutorial