railt/railt

The Railt Framework

1.3.7 2019-02-24 14:15 UTC

README

Railt

Travis CI 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f30376230366535666339376563626661616662362f746573745f636f766572616765 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f30376230366535666339376563626661616662362f6d61696e7461696e6162696c697479

PHP 7.1+ railt.org Discord Latest Stable Version Total Downloads License MIT

Introduction

Project idea is clean and high-quality code. Unlike most (all at the moment) implementations, like webonyx, youshido or digitalonline the Railt contains a completely own implementation of the GraphQL SDL parser which is based on EBNF-like grammar. This opportunity allows not only to have the original implementation of the language and to keep it always up to date, but also to implement a new backward compatible functionality that is not available to other implementations.

Goal of Railt:

  • Do not repeat the mistakes made in the JS-based implementations.
  • Implement a modern and convenient environment for PHP developers.
  • Implement easy integration into any ready-made solutions based on PSR.
  • Provide familiar functionality (including dependency injection, routing, etc.).

Installation

Via Composer:

  • Add into your composer.json:
{
    "scripts": {
        "post-autoload-dump": [
            "Railt\\Discovery\\Manifest::discover"
        ]
    }
}
  • composer require railt/railt

Quick Start

Let's create our first GraphQL schema!

schema {
    query: Example
}

type Example {
    say(message: String = "Hello"): String! 
        @route(action: "ExampleController@say")
}

In order to return the correct answer from the say field let's create an ExampleController controller with the desired method say.

class ExampleController
{
    public function say(string $message): string
    {
        return $message;
    }
}

That's all we need to know 🚀

But I think we should still run the application. For the Symfony and Laravel there are appropriate packages, but if you do not use (or do not want to use) frameworks, it is not difficult to do it from scratch.

The index.php is the main file that handles all requests to the application. So let's create it and write a simple logic:

<?php
use Phplrt\Io\File;
use Railt\Http\Factory;
use Railt\Foundation\Application;
use Railt\Http\Provider\GlobalsProvider;

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

// Creating a new Application in debug mode information
// about which is passed in the first argument.
$app = new Application(true);

// Create a connection
$connection = $app->connect(File::fromPathname(__DIR__ . '/schema.graphqls'));

// Processing of HTTP Request
$responses = $connection->request(Factory::create(new GlobalsProvider()));

// And send the HTTP Response
$responses->send();

...send request

{
    say(message: "Something is awesome!")
}

...and get the answer!

{
    "say": "Something is awesome!"
}

That's how simple it is 🎈

Learning Railt

This documentation can contain NOT RELEVANT information and currently in progress.

Contributing

Thank you for considering contributing to the Railt Framework! The contribution guide can be found in the documentation.

Security Vulnerabilities

If you discover a security vulnerability within Railt, please send an e-mail to maintainer at nesk@xakep.ru. All security vulnerabilities will be promptly addressed.

License

The Railt Framework is open-sourced software licensed under the MIT license.

Help & Community Discord

Join our Discord community if you run into issues or have questions. We love talking to you!

68747470733a2f2f686162726173746f726167652e6f72672f776562742f6d682f73342f68672f6d687334686732656230726f616978376967616b307379686365772e706e67

Supported By

JetBrains Rambler&Co