API Documentation
Namespaces
Interfaces, Classes and Traits
- BooleanField
- This class represents a column in the database capable of holding boolean data.
- DatetimeField
- Represents a table's field in a database. Contains information about the table the field belongs to, the name of the field and if it is (or not) a primary key or auto-increment field.
- EnumField
- Represents a table's field in a database. Contains information about the table the field belongs to, the name of the field and if it is (or not) a primary key or auto-increment field.
- FileField
- Represents a table's field in a database. Contains information about the table the field belongs to, the name of the field and if it is (or not) a primary key or auto-increment field.
- FloatField
- Represents a table's field in a database. Contains information about the table the field belongs to, the name of the field and if it is (or not) a primary key or auto-increment field.
- ManyToManyField
- TextField
- Represents a field holding a big chunk of text. The essential difference between those is the way they are stored in the database and requested from the user.
- plugins
- This files contains all the classes that help improving nLive or the software based on it without altering the framework itself.
- plugin
- registry
- This class is basically an Array cache, this means that you can define stuff to use it later.
- m3w_parser
- This allows us to parse and obtain data from .m3w containers.
- FailTest
Table of Contents
- spitfire() : SpitFire
- This is a quick hand method to use Spitfire's main App class as a singleton.
- app() : App
- Registers a new Application in Spitfire, allowing it to handle requests directed to it.
- boot() : KernelInterface
- Ths function will boot a kernel, instancing it and executing the necessary scripts to initialize it.
- assume() : void
- Raises an exception whenever the application runs into an scenario that was not expected. This function functions in a very similar manner to an assertion (with the exception of this being executed in production).
- fail() : void
- This function allows the developer to stop the execution of the application.
- db() : DB
- Shorthand function to create / retrieve the model the application is using to store data. We could consider this a little DB handler factory.
- view() : StreamInterface
- Creates a view. This function will automatically locate the appropriate file containing the template for the view, generate a template and render it to generate a response.
- response() : Response
- This function provides a shorthand way of creating a response to a request, this is very useful in combination with the view() function, allowing you to respond from a controller with something like this:
- _q() : type
- Escapes quotes from HTML. This will replace both ' and " with ' and " respectively. This does not escape the other HTML entities, for that refer to _e();
- _e() : string
- Escapes the HTML from a string. This function will not escape the quotes, please refer to the _q wrapper for that.
- _u() : string
- Helper to convert URLs in text to actual links. By default, the application will translate the URL to a pure HTML link, but you can pass a callable to the system to change the output.
- __() : string
- Returns HTML escaped string and if desired it adds ellipsis. If the string is numeric it will reduce unnecessary decimals.
- _t() : string|DomainGroup
- Translation helper.
- console() : mixed
- validate() : void
- Tests a value against a provided set of rules, if the
- getPathInfo() : string
- Retrieves the current path from the request. This will retrieve the path without query string or document root.
- _def() : mixed
- collect() : Collection
- This function is a shorthand for "new Collection" which also allows fluent usage of the collection in certain environments where the PHP version still limits that behavior.
- url() : mixed
- Creates a new URL. Use this class to generate dynamic URLs or to pass URLs as parameters. For consistency (double base prefixes and this kind of misshaps aren't funny) use this object to pass or receive URLs as paramaters.
- clamp() : number
- The clamp function is a math function that receives three arguments, a minimum, a bias and a maximum. Clamp will either return the bias or the closest value whenever the bias is outside the range of maximum and minimum.
- within() : number
- This is the deprecated naming for the clamp function.
- media() : mixed
- storage() : DriveDispatcher|NodeInterface
- mime() : mixed
- event() : EventDispatcher
- Allows the application to manage a central event dispatching system, instead of relying on every component to build a custom one. If your component doesn't wish to share it's hooks and plugins please @see Target
- lock() : FileLockFactory
- asset() : string
- defer() : void
- Convenience method for accessing the TaskFactory for deferring tasks. You can pass a task class to be deferred, a bunch of settings and a time to execute this task at.
- config() : mixed
- Returns an application configuration. Note that configuration in Spitfire is tiered, configuration and environments.
- env() : string|null
- This function should ONLY be invoked from the config files. This data is not cached, and therefore not always available during runtime.
- cli() : bool
- Allows the application to reliably determine whether it is running in a console or on a web server environment.
Functions
spitfire()
This is a quick hand method to use Spitfire's main App class as a singleton.
spitfire() : SpitFire
It allows you to quickly access many of the components the framework provides to make it easier to read and maintain the code being created.
Tags
Return values
SpitFire —app()
Registers a new Application in Spitfire, allowing it to handle requests directed to it.
app(string $name, string $namespace) : App
Parameters
- $name : string
-
The name of the Application
- $namespace : string
-
The namespace in which the requests will be sent to the application.
Return values
App —The App created by the system, use this to pass parameters and configuration to the application.
boot()
Ths function will boot a kernel, instancing it and executing the necessary scripts to initialize it.
boot(class-string<\KernelInterface> $kernel) : KernelInterface
Parameters
- $kernel : class-string<\KernelInterface>
-
The name of the kernel to boot
Tags
Return values
KernelInterface —assume()
Raises an exception whenever the application runs into an scenario that was not expected. This function functions in a very similar manner to an assertion (with the exception of this being executed in production).
assume(bool $condition, string|Closure|Exception $failure) : void
The second parameter contains the name of the exception to be raised on failure, an exception instance or a closure to be executed, which should then either end execution or throw an exception itself.
This is intended to reduce the boilerplate on code that looks like this: if (!$condition) { throw new Exception(); }
The code becomes a bit more readable and drops the negation, making it look like this: assume($condition, Exception::class);
Overall reducing the strain of visually analyzing the code.
Parameters
- $condition : bool
-
If the condition is true, the code will continue being executed
- $failure : string|Closure|Exception
Return values
void —fail()
This function allows the developer to stop the execution of the application.
fail(int $status[, string $message = '' ]) : void
It raises a failure exception that will prevent the code from continuing and display a message to the end user that explains the situation.
Whenever your application runs into a more specific issue, you should avoid using this and instead raise a custom exception that offers the user support to resolve the issue or additional information.
Parameters
- $status : int
- $message : string = ''
Tags
Return values
void —db()
Shorthand function to create / retrieve the model the application is using to store data. We could consider this a little DB handler factory.
db() : DB
Return values
DB —view()
Creates a view. This function will automatically locate the appropriate file containing the template for the view, generate a template and render it to generate a response.
view(string|null $identifier, array<string|int, mixed> $data) : StreamInterface
Right now it does a very simplistic job, intializing a pug engine that will allow us to generate an output.
Parameters
- $identifier : string|null
- $data : array<string|int, mixed>
Tags
Return values
StreamInterface —response()
This function provides a shorthand way of creating a response to a request, this is very useful in combination with the view() function, allowing you to respond from a controller with something like this:
response(StreamInterface $stream[, int $code = 200 ][, array<string|int, array<string|int, string>> $headers = [] ]) : Response
return response(view('home'));
Or something along the lines of:
`return response(view('notfound'), 404);
Parameters
- $stream : StreamInterface
- $code : int = 200
- $headers : array<string|int, array<string|int, string>> = []
Return values
Response —_q()
Escapes quotes from HTML. This will replace both ' and " with ' and " respectively. This does not escape the other HTML entities, for that refer to _e();
_q(type $str) : type
Usually you should use this function like _q(_e($str));
Parameters
- $str : type
Return values
type —_e()
Escapes the HTML from a string. This function will not escape the quotes, please refer to the _q wrapper for that.
_e(string $str) : string
Parameters
- $str : string
Tags
Return values
string —_u()
Helper to convert URLs in text to actual links. By default, the application will translate the URL to a pure HTML link, but you can pass a callable to the system to change the output.
_u(string $str[, Closure|callable $cb = null ]) : string
Parameters
- $str : string
- $cb : Closure|callable = null
Return values
string —__()
Returns HTML escaped string and if desired it adds ellipsis. If the string is numeric it will reduce unnecessary decimals.
__(string $str[, int $maxlength = false ]) : string
Parameters
- $str : string
- $maxlength : int = false
Return values
string —_t()
Translation helper.
_t() : string|DomainGroup
Depending on the arguments this function receives, it will have one of several behaviors.
If the first argument is a spitfire\locale\Locale and the function receives a optional second parameter, then it will assign the locale to either the global domain / the domain provided in the second parameter.
Otherwise, if the first parameter is a string, it will call the default locale's say method. Which will translate the string using the standard locale.
If no parameters are provided, this function returns a DomainGroup object, which provides access to the currency and date functions as well as the other domains that the system has for translations.
Return values
string|DomainGroup —console()
console() : mixed
Return values
mixed —validate()
Tests a value against a provided set of rules, if the
validate(mixed $value, mixed $rules) : void
Parameters
- $value : mixed
- $rules : mixed
Return values
void —getPathInfo()
Retrieves the current path from the request. This will retrieve the path without query string or document root.
getPathInfo() : string
Tags
Return values
string —_def()
_def(mixed &$a, mixed $b) : mixed
Parameters
- $a : mixed
- $b : mixed
Return values
mixed —collect()
This function is a shorthand for "new Collection" which also allows fluent usage of the collection in certain environments where the PHP version still limits that behavior.
collect([mixed $elements = [] ]) : Collection
Parameters
- $elements : mixed = []
Return values
Collection —url()
Creates a new URL. Use this class to generate dynamic URLs or to pass URLs as parameters. For consistency (double base prefixes and this kind of misshaps aren't funny) use this object to pass or receive URLs as paramaters.
url() : mixed
Please note that when passing a URL that contains the URL as a string like "/hello/world?a=b&c=d" you cannot pass any other parameters. It implies that you already have a full URL.
You can pass any amount of parameters to this class, the constructor will try to automatically parse the URL as good as possible.
- Arrays are used as _GET
- App objects are used to identify the namespace
- Strings that contain / or ? will be parsed and added to GET and path
- The rest of strings will be pushed to the path.
Return values
mixed —clamp()
The clamp function is a math function that receives three arguments, a minimum, a bias and a maximum. Clamp will either return the bias or the closest value whenever the bias is outside the range of maximum and minimum.
clamp(number $min, number $bias, number $max) : number
The first and the last parameter delimit the range. The second parameter is the bias being tested.
within(1, 50, 100); //Outputs: 50
within(1, 500, 100); //Outputs: 100
within(1, -50, 100); //Outputs: 1
Parameters
- $min : number
- $bias : number
- $max : number
Return values
number —within()
This is the deprecated naming for the clamp function.
within(number $min, number $val, number $max) : number
Parameters
- $min : number
- $val : number
- $max : number
Tags
Return values
number —media()
media() : mixed
Return values
mixed —storage()
storage() : DriveDispatcher|NodeInterface
Tags
Return values
DriveDispatcher|NodeInterface —mime()
mime(mixed $file) : mixed
Parameters
- $file : mixed
Return values
mixed —event()
Allows the application to manage a central event dispatching system, instead of relying on every component to build a custom one. If your component doesn't wish to share it's hooks and plugins please @see Target
event([Event $event = null ]) : EventDispatcher
Parameters
- $event : Event = null
Tags
Return values
EventDispatcher —lock()
lock([FileLockFactory $set = null ]) : FileLockFactory
Parameters
- $set : FileLockFactory = null
Tags
Return values
FileLockFactory —asset()
asset(string $name[, string $scope = 'assets/' ]) : string
Parameters
- $name : string
- $scope : string = 'assets/'
-
A directory to scope this to. If an application builds it's own assets and generates a manifest file, it will be located here. The mix-manifest file is required to be located in the root of this directory.
Note that the scope must be relative to the public directory, if this is not the case, the system will generate bad URLs or fail to locate the manifests.
If, for example, your application publishes it's assets to the assets/vendor/myapp older within public folder, this is exactly the string it should pass
Return values
string —defer()
Convenience method for accessing the TaskFactory for deferring tasks. You can pass a task class to be deferred, a bunch of settings and a time to execute this task at.
defer(string $task, mixed $options, int $defer[, int $ttl = 10 ]) : void
Please refer to the documentation to enable the daemon required to process the queue.
Parameters
- $task : string
- $options : mixed
- $defer : int
- $ttl : int = 10
Tags
Return values
void —config()
Returns an application configuration. Note that configuration in Spitfire is tiered, configuration and environments.
config(string $key[, mixed $fallback = null ]) : mixed
You as the developer should establish the configuration so the components you add to your application work as expected, and should expose the environment to the person deploying the application so they can customize the behavior.
Parameters
- $key : string
-
The key in the configuration
- $fallback : mixed = null
-
The value to return if the configuration does not contain the key
Return values
mixed —The data for this configuration entry
env()
This function should ONLY be invoked from the config files. This data is not cached, and therefore not always available during runtime.
env(string $param) : string|null
Reads a value from the current environment.
Parameters
- $param : string
Return values
string|null —cli()
Allows the application to reliably determine whether it is running in a console or on a web server environment.
cli() : bool