Git Product home page Git Product logo

siler's Introduction









Build codecov Psalm coverage Latest Stable Version Total Downloads License Dependabot Status

Siler is a set of general purpose high-level abstractions aiming an API for declarative programming in PHP.

  • 💧 Files and functions as first-class citizens
  • 🔋 Zero dependency, everything is on top of PHP built-in functions
  • Blazing fast, no additional overhead - benchmark 1, benchmark 2 and benchmark 3

Use with Swoole

Flat files and plain-old PHP functions rocking on a production-grade, high-performance, scalable, concurrent and non-blocking HTTP server.

Read the tutorial.

Getting started

Installation

$ composer require leocavalcante/siler

That is it. Actually, Siler is a library, not a framework (maybe a micro-framework), the overall program flow of control is dictated by you. So, no hidden configs or predefined directory structures.

Hello, World!

use Siler\Functional as λ; // Just to be cool, don't use non-ASCII identifiers ;)
use Siler\Route;

Route\get('/', λ\puts('Hello, World!'));

Nothing more, nothing less. You don't need even tell Siler to run or something like that (puts works like a lazily evaluated echo).

JSON

use Siler\Route;
use Siler\Http\Response;

Route\get('/', fn() => Response\json(['message' => 'Hello, World!']));

The Response\json function will automatically add Content-type: application/json in the response headers.

Swoole

Siler provides first-class support for Swoole. You can regularly use Route, Request and Response modules for a Swoole HTTP server.

use Siler\Http\Response;
use Siler\Route;
use Siler\Swoole;

$handler = function () {
    Route\get('/', fn() => Response\json('Hello, World!'));
};

$port = 8000;
echo "Listening on port $port\n";
Swoole\http($handler, $port)->start();

GraphQL

Install peer-dependency:

composer require webonyx/graphql-php

Schema-first

type Query {
    hello: String
}
use Siler\Route;
use Siler\GraphQL;

$type_defs = file_get_contents(__DIR__ . '/schema.graphql');
$resolvers = [
    'Query' => [
        'hello' => fn ($root, $args, $context, $info) => 'Hello, World!'
    ]
];

$schema = GraphQL\schema($type_defs, $resolvers);

Route\post('/graphql', fn() => GraphQL\init($schema));

Code-first

Another peer-dependency:

composer require doctrine/annotations

Then:

/**
 * @\Siler\GraphQL\Annotation\ObjectType()
 */
final class Query
{
    /**
     * @\Siler\GraphQL\Annotation\Field()
     */
    static public function hello($root, $args, $context, $info): string
    {
        return 'Hello, World!';
    }
}
use Siler\GraphQL;
use Siler\Route;

$schema = GraphQL\annotated([Query::class]);

Route\post('/graphql', fn() => GraphQL\init($schema));

Object type name will be guessed from class name, same for field name, and it's return type (i.e.: PHP string scalar === GraphQL String scalar).

What is next?

License

License

siler's People

Contributors

arysom avatar carusogabriel avatar cmdlucas avatar deadphoenix8091 avatar dependabot-preview[bot] avatar eaverdeja avatar eghojansu avatar francisfontoura avatar gitter-badger avatar juliend2 avatar leocavalcante avatar lex111 avatar marcokuoni avatar muglug avatar petemcfarlane avatar quadrifolia avatar sauliusugintas avatar segy avatar spawnia avatar symm avatar trollboy avatar userlond 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.