siler

:zap: Flat-files and plain-old PHP functions rockin'on

Github星跟踪图

Build
codecov
Psalm coverage
Latest Stable Version
Total Downloads
License

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 A and benchmark B

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 function Siler\{Functional\puts, Route\get};

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).

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');

Monolog

Monolog sends your logs to files, sockets, inboxes, databases and various web services. See the complete list of handlers here. Special handlers allow you to build advanced logging strategies.

$ composer require monolog/monolog
use Siler\Monolog as Log;

Log\handler(Log\stream(__DIR__.'/siler.log'));

Log\debug('debug', ['level' => 'debug']);
Log\info('info', ['level' => 'info']);
Log\notice('notice', ['level' => 'notice']);
Log\warning('warning', ['level' => 'warning']);
Log\error('error', ['level' => 'error']);
Log\critical('critical', ['level' => 'critical']);
Log\alert('alert', ['level' => 'alert']);
Log\emergency('emergency', ['level' => 'emergency']);

GraphQL

A query language for your API. Thanks to webonyx/graphql-php you can build you Schema from a
type definitions string and thanks to Siler you can tie them to resolvers:

$ composer require webonyx/graphql-php

schema.graphql

type Query {
  message: String
}

type Mutation {
  sum(a: Int, b: Int): Int
}

index.php

use Siler\GraphQL;
use Siler\Http\Response;

// Enable CORS for GraphiQL
Response\header('Access-Control-Allow-Origin', '*');
Response\header('Access-Control-Allow-Headers', 'content-type');

$typeDefs = file_get_contents('path/to/schema.graphql');

$resolvers = [
    'Query' => [
        'message' => 'foo',
    ],
    'Mutation' => [
        'sum' => function ($root, $args) {
            return $args['a'] + $args['b'];
        },
    ],
];

GraphQL\init(GraphQL\schema($typeDefs, $resolvers));

MIT 2019

概览

名称与所有者leocavalcante/siler
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证MIT License
发布数22
最新版本名称v1.7.9 (发布于 )
第一版名称v1.0.0 (发布于 )
创建于2016-12-02 02:01:48
推送于2022-02-13 14:04:09
最后一次提交2021-10-11 08:03:06
星数1.1k
关注者数50
派生数90
提交数2.1k
已启用问题?
问题数169
打开的问题数14
拉请求数601
打开的拉请求数14
关闭的拉请求数108
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?
去到顶部