fyre / engine
An engine library.
Requires
- fyre/auth: ^3.0
- fyre/cache: ^5.1
- fyre/collection: ^1.0
- fyre/command: ^6.0
- fyre/config: ^4.0
- fyre/container: ^1.0
- fyre/csp: ^7.0
- fyre/csrf: ^5.0
- fyre/db: ^6.0
- fyre/encryption: ^5.0
- fyre/entity: ^5.0
- fyre/error: ^6.0
- fyre/forge: ^5.0
- fyre/formatter: ^4.1
- fyre/iterator: ^5.0
- fyre/lang: 5.0
- fyre/log: ^5.1
- fyre/mail: ^4.0
- fyre/make: ^2.0
- fyre/middleware: ^6.0
- fyre/migration: ^5.0
- fyre/orm: ^10.0
- fyre/queue: ^3.0
- fyre/router: ^7.0
- fyre/server: ^4.0
- fyre/session: ^5.0
- fyre/timer: ^4.0
- fyre/view: ^10.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^11
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
$loader
is a Loader.
$engine = new Engine($loader);
Methods
This class extends the Container class.
Boot
Boot the application.
$engine->boot();
Middleware
Build application middleware.
$queue
is a MiddlewareQueue.
$middleware = $engine->middleware($queue);
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 toCache::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 toConnectionManager::DEFAULT
.
$connection = db($key);
DD
Dump and die.
dd(...$data);
Dump
Dump data.
dump(...$data);
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 toEncryption::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.$filter
is a number representing the filter to apply, and will default to FILTER_DEFAULT.$options
is a number or array containing flags to use when filtering, and will default to 0.
$value = request($key, $filter, $options);
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.