Skip to content

XY-TEAM/siler

 
 

Repository files navigation

Build Status codecov StyleCI PHPStan Latest Unstable Version License SensioLabsInsight

Siler

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

Getting Started

Installation

$ composer require leocavalcante/siler dev-master

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.

Or you can start by bootstrapping
$ composer create-project siler/project hello-siler

It's a minimal project template, just with Siler and a convenient serve script:

$ cd hello-siler/
$ composer serve

Hello World

use Siler\Functional as λ;
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.

As said before, Siler aims to use PHP files and functions as first-class citizens, so no Controllers here. If you want to call something more self-container instead of a Closure, you can simply give a PHP filename then Siler will require it for you.

index.php

use Siler\Route;

Route\get('/', 'pages/home.php');

pages/home.php

echo 'Hello World';

Namespaces

Siler doesn't try to be a fully-featured framework - don't even aim to be a framework - instead it embraces component based architectures and offers helper functions to work with this components under PHP namespaces.

Twig

Is one of the libraries that has helpers functions making work with templates quite simple.

$ composer require twig/twig
use Siler\Functional as F;
use Siler\Route;
use Siler\Twig;

Twig\init('path/to/templates');
Route\get('/', F\puts(Twig\render('template.twig')));

Dotenv

Siler also brings helper functions for vlucas/phpdotenv, so you can easily acomplish twelve-factor apps.

$ composer require vlucas/phpdotenv

.env

TWIG_DEBUG=true

index.php

use Siler\Dotenv;
use Siler\Route;
use Siler\Twig;

Dotenv\init('path/to/.env');
Twig\init('path/to/templates', 'path/to/templates/cache', Dotenv\env('TWIG_DEBUG'));
Route\get('/', 'pages/home.php');

Ratchet

Real-time web apps using WebSockets.

$ composer require cboden/ratchet
use Siler\Ratchet;

Ratchet\connected(function ($conn) {
    print("New connection\n");
});

Ratchet\inbox(function ($from, $message) {
    printf("New message: %s\n", $message);
});

print("Listen on 3333\n");
Ratchet\init(3333);

GraphQL

A query language for your API.

$ composer require webonyx/graphql-php
use Siler\Graphql;

$query = Graphql\type('Query')([
    Graphql\str('foo')(function ($root, $args) {
        return 'bar'.$root['baz'];
    }),
]);

$mutation = Graphql\type('Mutation')([
    Graphql\int('sum')(function ($root, $args) {
        return $args['x'] + $args['y'];
    }, [Graphql\int('x')(), Graphql\int('y')()])
]);

$root = ['baz' => 'qux'];

Graphql\init(new \GraphQL\Schema(['query' => $query(), 'mutation' => $mutation()]), $root);

⚠️This is a work in progress, API may change 🚧

But if you give a try, I'd love the get some feedback

MIT 2017

About

⚡ Flat-files and plain-old PHP functions rockin'on

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%