fyre/engine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

$engine = new Engine($loader);

Methods

This class extends the Container class.

Boot

Boot the application.

$engine->boot();

Middleware

Build application middleware.

$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 { });

Mail

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.

  • $key is a string representing the key to lookup.
  • $data is an array containing data to insert into the language string.
$lang = __($key, $data);

Abort

Throw an Exception.

  • $code is a number representing the status code, and will default to 500.
  • $message is 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.

  • $alias is a string representing the alias.
  • $arguments is an array containing the named arguments for the class constructor.
$instance = app($alias, $arguments);

Asset

Generate a URL for an asset path.

  • $path is a string representing the asset path.
  • $options is an array containing the route options.
    • fullBase is 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.

  • $rule is 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.

  • $key is a string representing the Cacher key, and will default to Cache::DEFAULT.
$cacher = cache($key);

Can

Check whether an access rule is allowed.

  • $rule is 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.

  • $rules is 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.

  • $rules is 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.

  • $rule is 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.

  • $source can 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.

  • $key is a string representing the key to lookup.
  • $default is the default value to return, and will default to null.
$value = config($key, $default);

DB

Load a shared Connection instance.

  • $key is a string representing the Connection key, and will default to ConnectionManager::DEFAULT.
$connection = db($key);

DD

Dump and die.

dd(...$data);

Dump

Dump data.

dump(...$data);

Email

Create an Email.

  • $key is a string representing the Mailer key, and will default to Mail::DEFAULT.
$email = email($key);

Encryption

Load a shared Encrypter instance.

  • $key is a string representing the Encrypter key, and will default to Encryption::DEFAULT.
$encrypter = encryption($key);

Env

Retrieve an environment variable.

  • $name is a string representing the variable name.
  • $default is the default value to return, and will default to null.
$value = env($name, $default);

Escape

Escape characters in a string for use in HTML.

  • $string is the string to escape.
$escaped = escape($string);

Json

Create a new ClientResponse with JSON data.

  • $data is the data to send.
$response = json($data);

Log Message

Log a message.

  • $type is a string representing the log level.
  • $message is a string representing the log message.
  • $data is 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.

  • $alias is 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.

  • $className is a string representing the job class.
  • $arguments is an array containing arguments that will be passed to the job.
  • $options is an array containing options for the Message.
    • config is a string representing the configuration key, and will default to "default".
    • queue is a string representing the Queue name, and will default to "default".
    • method is a string representing the class method, and will default to "run".
    • delay is a number representing the number of seconds before the job should run, and will default to 0.
    • expires is 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.

  • $uri is a Uri or string representing the URI to redirect to.
  • $code is a number representing the header status code, and will default to 302.
  • $options is 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.

  • $key is a string representing the array key using "dot" notation.
  • $as is 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.

  • $name is a string representing the route alias.
  • $arguments is an array containing the route arguments.
    • ? is an array containing route query parameters.
    • # is a string representing the fragment component of the URI.
  • $options is an array containing the route options.
    • fullBase is 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.

  • $key is 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.

  • $type is a string representing the value type.
$typeClass = type($type);

User

Get the current user.

$user = user();

View

Render a View template.

  • $template is a string representing the template file.
  • $data is an array containing data to pass to the template.
  • $layout is 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 fyre/engine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 76
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-08