fyre/engine
Composer 安装命令:
composer require fyre/engine
包简介
An engine library.
README 文档
README
FyreEngine is a free, open-source engine library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/engine
In PHP:
use Fyre\Engine\Engine;
Basic Usage
$loaderis a Loader.
$engine = new Engine($loader);
Methods
This class extends the Container class.
Boot
Boot the application.
$engine->boot();
Middleware
Build application middleware.
$queueis a MiddlewareQueue.
$middleware = $engine->middleware($queue);
Attributes
Attributes can be used to provide context when resolving values from the Container.
Cache
Load a shared Cacher instance.
use Fyre\Cache\Cacher; use Fyre\Engine\Attributes\Cache; $engine->call(function(#[Cache] Cacher $cache): void { }); $engine->call(function(#[Cache('default')] Cacher $cache): void { });
Config
Retrieve a value from the config using "dot" notation.
use Fyre\Engine\Attributes\Config; $engine->call(function(#[Config('App.value')] string $value): void { });
Current User
Get the current user.
use Fyre\Engine\Attributes\CurrentUser; use Fyre\Entity\Entity; $engine->call(function(#[CurrentUser] Entity|null $user): void { });
DB
Load a shared Connection instance.
use Fyre\DB\Connection; use Fyre\Engine\Attributes\DB; $engine->call(function(#[DB] Connection $connection): void { }); $engine->call(function(#[DB('default')] Connection $connection): void { });
Encryption
Load a shared Encrypter instance.
use Fyre\Encryption\Encrypter; use Fyre\Engine\Attributes\Encryption; $engine->call(function(#[Encryption] Encrypter $encrypter): void { }); $engine->call(function(#[Encryption('default')] Encrypter $encrypter): void { });
Log
Load a shared Logger instance.
use Fyre\Log\Logger; use Fyre\Engine\Attributes\Log; $engine->call(function(#[Log] Logger $logger): void { }); $engine->call(function(#[Log('default')] Logger $logger): void { });
Load a shared Mailer instance.
use Fyre\Mail\Mailer; use Fyre\Engine\Attributes\Mail; $engine->call(function(#[Mail] Mailer $mailer): void { }); $engine->call(function(#[Mail('default')] Mailer $mailer): void { });
ORM
Load a shared Model instance.
use Fyre\ORM\Model; use Fyre\Engine\Attributes\ORM; $engine->call(function(#[ORM] Model $model): void { }); $engine->call(function(#[ORM('default')] Model $model): void { });
Route Argument
Retrieve an argument from the loaded route.
use Fyre\Engine\Attributes\RouteArgument; $engine->call(function(#[RouteArgument('id')] int $id): void { });
Global Functions
__
Get a language value.
$keyis a string representing the key to lookup.$datais an array containing data to insert into the language string.
$lang = __($key, $data);
Abort
Throw an Exception.
$codeis a number representing the status code, and will default to 500.$messageis a string representing the error message, and will default to "".
abort($code, $message);
App
Load a shared Engine instance.
$app = app();
You can also load other shared class instances.
$aliasis a string representing the alias.$argumentsis an array containing the named arguments for the class constructor.
$instance = app($alias, $arguments);
Asset
Generate a URL for an asset path.
$pathis a string representing the asset path.$optionsis an array containing the route options.fullBaseis a boolean indicating whether to use the full base URI and will default to false.
$url = asset($path);
Auth
Load a shared Auth instance.
$auth = auth();
Authorize
Authorize an access rule.
$ruleis a string representing the access rule name or Policy method.
Any additional arguments supplied will be passed to the access rule callback or Policy method.
authorize($rule, ...$args);
Cache
Load a shared Cacher instance.
$keyis a string representing the Cacher key, and will default toCache::DEFAULT.
$cacher = cache($key);
Can
Check whether an access rule is allowed.
$ruleis a string representing the access rule name or Policy method.
Any additional arguments supplied will be passed to the access rule callback or Policy method.
$result = can($rule, ...$args);
Can Any
Check whether any access rule is allowed.
$rulesis an array containing access rule names or Policy methods.
Any additional arguments supplied will be passed to the access rule callbacks or Policy methods.
$result = can_any($rules, ...$args);
Can None
Check whether no access rule is allowed.
$rulesis an array containing access rule names or Policy methods.
Any additional arguments supplied will be passed to the access rule callbacks or Policy methods.
$result = can_none($rule, ...$args);
Cannot
Check whether an access rule is not allowed.
$ruleis a string representing the access rule name or Policy method.
Any additional arguments supplied will be passed to the access rule callback or Policy method.
$result = cannot($rule, ...$args);
Collect
Create a new Collection.
$sourcecan be either an array, a Closure that returns a Generator, or a Traversable or JsonSerializable object.
$collection = collect($source);
Config
Load a shared Config instance.
$config = config();
You can also retrieve a value from the config using "dot" notation.
$keyis a string representing the key to lookup.$defaultis the default value to return, and will default to null.
$value = config($key, $default);
DB
Load a shared Connection instance.
$keyis a string representing the Connection key, and will default toConnectionManager::DEFAULT.
$connection = db($key);
DD
Dump and die.
dd(...$data);
Dump
Dump data.
dump(...$data);
Create an Email.
$keyis a string representing the Mailer key, and will default to Mail::DEFAULT.
$email = email($key);
Encryption
Load a shared Encrypter instance.
$keyis a string representing the Encrypter key, and will default toEncryption::DEFAULT.
$encrypter = encryption($key);
Env
Retrieve an environment variable.
$nameis a string representing the variable name.$defaultis the default value to return, and will default to null.
$value = env($name, $default);
Escape
Escape characters in a string for use in HTML.
$stringis the string to escape.
$escaped = escape($string);
Json
Create a new ClientResponse with JSON data.
$datais the data to send.
$response = json($data);
Log Message
Log a message.
$typeis a string representing the log level.$messageis a string representing the log message.$datais an array containing data to insert into the message string.
log_message($type, $message, $data);
The $type must be one of the supported log levels.
Logged In
Determine if the current user is logged in.
$loggedIn = logged_in();
Model
Load a shared Model instance.
$aliasis a string representing the model alias.
$model = model($alias);
Now
Create a new DateTime set to now.
$now = now();
Queue
Push a job to a Queue.
$classNameis a string representing the job class.$argumentsis an array containing arguments that will be passed to the job.$optionsis an array containing options for the Message.configis a string representing the configuration key, and will default to "default".queueis a string representing the Queue name, and will default to "default".methodis a string representing the class method, and will default to "run".delayis a number representing the number of seconds before the job should run, and will default to 0.expiresis a number representing the number of seconds after which the job will expire, and will default to 0.
queue($className, $arguments, $options);
Redirect
Create a new RedirectResponse.
$uriis a Uri or string representing the URI to redirect to.$codeis a number representing the header status code, and will default to 302.$optionsis an array containing configuration options.
$response = redirect($uri, $code, $options);
Request
Load a shared ServerRequest instance.
$request = request();
You can also retrieve value from the $_POST array by passing arguments to this function.
$keyis a string representing the array key using "dot" notation.$asis a string representing the value type, and will default to null.
$value = request($key, $as);
Response
Create a new ClientResponse.
$response = response();
Route
Generate a URL for a named Route.
$nameis a string representing the route alias.$argumentsis an array containing the route arguments.?is an array containing route query parameters.#is a string representing the fragment component of the URI.
$optionsis an array containing the route options.fullBaseis a boolean indicating whether to use the full base URI and will default to false.
$route = route($name, $arguments, $options);
Session
Load a shared Session instance.
$session = session();
Retrieve a value from the session.
$keyis a string representing the session key.
$value = session($key);
You can also set a session value by including a second argument.
session($key, $value);
Type
Load a shared TypeParser instance.
$parser = type();
You can also get the mapped Type class for a value type.
$typeis a string representing the value type.
$typeClass = type($type);
User
Get the current user.
$user = user();
View
Render a View template.
$templateis a string representing the template file.$datais an array containing data to pass to the template.$layoutis a string representing the layout file, and will default to null.
$view = view($template, $data, $layout);
If the $layout is set to null, it will use the App.defaultLayout option from the Config.
fyre/engine 适用场景与选型建议
fyre/engine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fyre/engine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fyre/engine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-08