leocavalcante / siler
Siler is a set of general purpose high-level abstractions aiming an API for declarative programming in PHP.
Fund package maintenance!
leocavalcante
Installs: 58 979
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1 124
Watchers: 49
Forks: 90
Open Issues: 28
Requires
- php: >=7.3 || >= 8.0
Requires (Dev)
- cboden/ratchet: ^0.4.1
- cocur/slugify: ^4.0
- doctrine/annotations: ^1.10
- doctrine/cache: ^1.10
- gabordemooij/redbean: ^5.5
- google/protobuf: ^3.12
- grpc/grpc: ^1.30
- laminas/laminas-config: ^3.4
- laminas/laminas-config-aggregator: ^1.3
- laminas/laminas-diactoros: ^2.2
- laminas/laminas-httphandlerrunner: ^1.1
- laminas/laminas-stratigility: ^3.2
- monolog/monolog: ^2.1
- phpunit/phpunit: ^9.2
- psr/event-dispatcher: ^1.0
- squizlabs/php_codesniffer: ^3.5
- swiftmailer/swiftmailer: ^6.2
- swoole/ide-helper: ^4.5
- textalk/websocket: ^1.2
- twig/twig: ^3.0
- vimeo/psalm: ^3.12 || ^4.0
- vlucas/phpdotenv: ^5.0
- webonyx/graphql-php: ^14.0
- dev-main
- v1.8.x-dev
- v1.7.9
- v1.7.8
- v1.7.7
- v1.7.6
- v1.7.5
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- 1.7.0
- v1.6.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- dev-dependabot/composer/main/vlucas/phpdotenv-5.4.1
- dev-dependabot/composer/main/doctrine/annotations-1.13.2
- dev-dependabot/composer/main/react/promise-2.9.0
- dev-dependabot/composer/main/vimeo/psalm-4.20.0
- dev-dependabot/composer/main/swoole/ide-helper-4.8.6
- dev-dependabot/composer/main/monolog/monolog-2.3.5
- dev-dependabot/composer/main/squizlabs/php_codesniffer-3.6.2
- dev-php-8.1
- dev-dependabot/composer/main/vlucas/phpdotenv-5.3.1
- dev-dependabot/composer/main/swoole/ide-helper-4.7.1
- dev-dependabot/composer/main/vimeo/psalm-4.8.1
- dev-dependabot/composer/main/doctrine/annotations-1.13.1
This package is auto-updated.
Last update: 2022-03-13 14:15:38 UTC
README
⚠️ I'm afraid that I'm not being able to keep Siler up-to-date as it deserves, so it's repository has been archived.
As an alternative for Siler, something lightweight and simple that works as a library with Swoole out-of-the-box, I highly recommend Nano! Check it out: https://nano.hyperf.wiki/#/en/
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.
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() */ public static 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
- MIT license
- Copyright 2020 © LC