Giter VIP home page Giter VIP logo

g's Introduction

G. Another Full stack framework

instalation:

composer

{
    "require": {
        "gonzalo123/g": "dev-master"
    },
    "autoload": {
        "psr-0": {
            "": ["app/"]
        }
    }
}

index.php:

<?php

include __DIR__ . '/vendor/autoload.php';

$app = G\Application::factory([
        'config.path' => __DIR__ . '/config',
        'view.path'   => __DIR__ . '/views',
    ]);

$app->run();

config and view folders

mkdir config
mkdir view

/config/routes.yml

home:
  path: /
  defaults: { _controller: AppController::homeAction}

/config/services.yml

services:
  Symfony\Component\HttpFoundation\JSonResponse:
    class: Symfony\Component\HttpFoundation\JSonResponse

  Symfony\Component\HttpFoundation\Response:
    class: Symfony\Component\HttpFoundation\Response

Controller

<?php

class AppController
{
    public function homeAction()
    {
        return "AppController::home";
    }
}

Complex controller

another route:

hello:
  path: /hello/{name}
  defaults: { _controller: AppController::helloAction}
class AppController
{
    private $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function helloAction($name, JsonResponse $response)
    {
        return $response->setData([$name, 1, 2]);
    }
}

RESTFull controllers

we add to our services.yml:

restResources:
  book:
    path: /resource/book
    class: BookResource

And we define our BookResource

<?php
use G\RESTFull\Get;
use G\RESTFull\GetAll;
use G\RESTFull\Delete;
use G\RESTFull\Create;
use G\RESTFull\Update;

class BookResource implements Get, GetAll, Delete, Create, Update
{
    public function getAction($id)
    {
        return "BookResource:getAction " . $id;
    }

    public function getAllAction()
    {
        return "BookResource:getAllAction";
    }

    public function saveAction($id)
    {
        return "BookResource:saveAction " . $id;
    }

    public function addAction()
    {
        return "BookResource:addAction";
    }

    public function deleteAction($id)
    {
        return "BookResource:deleteAction " . $id;
    }
}

g's People

Contributors

gonzalo123 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.