Giter Site home page Giter Site logo

alvarlaigna / siler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leocavalcante/siler

0.0 2.0 0.0 1.74 MB

:zap: Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.

Home Page: https://siler.leocavalcante.dev

License: MIT License

PHP 100.00%

siler's Introduction









Build Status Phan codecov Latest Stable Version Total Downloads License SensioLabsInsight

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

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

Join the chat at https://gitter.im/leocavalcante/siler

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.

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

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

siler's People

Contributors

leocavalcante avatar trollboy avatar eghojansu avatar lex111 avatar carusogabriel avatar symm avatar muglug avatar petemcfarlane avatar sauliusugintas avatar quadrifolia avatar gitter-badger avatar arysom avatar eaverdeja avatar userlond 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.