As the name says, it is made to be basic and direct.
Basicis\Basicis - Main class Basicis framework
Basicis\Http\Server\RequestHandlerInterface
Name | Description |
---|---|
__construct | Function __construct |
Construct a instanceof Basicis\Basicis lovingly named $app | |
__invoke | Function runAndResponse |
Run app pipe line and return a instance of ResponseInterface | |
auth | Function auth |
Get the app Auth/User by authorization token, it is receive a class Basicis\Auth\AuthInterface | |
cache | Function cache |
cacheIsEnabled | Function cacheIsEnabled |
Check if app cache is enabled and return boolean | |
clientFileDownload | Function clientFileDownload |
Send a file in the body of the http response to the client | |
clientFileUpload | Function clientFileUpload |
Upload one or more files in the body of the http server request from the client | |
closure | Function closure |
Instantiate a Closure object and execute | |
controller | Function controller |
Instantiate a Basicis\Controller\Controller object and execute the defined method or the standard index method. | |
createApp | Function createApp Factory |
Create a instanceof Basicis\Basicis and return it is | |
createSymLink | Function createSymLink |
Create a symlink default from storage/assets to public/ as assets | |
enableCache | Function enableCache |
Enable application cache $enable true | |
error | Function error |
Return a view error reporting html or json | |
extractCallbackToArray | Function extractCallbackToArray |
Extract and return a array with controller name/class and method or null | |
getController | Function getController |
Get a controller by classname | |
getDescription | Function getDescription |
Getting App description string | |
getMiddlewares | Function getMiddlewares |
Getting middlewares by type [‘before’, ‘route’, ‘after’ or null to all]. | |
getRequest | Function getRequest |
Get current server request of app | |
getResourceInput | Function getResourceInput |
Get app default resource input | |
getResourceOutput | Function getResourceOutput |
Get app default resource output | |
getResponse | Function getResponse |
Get current response of app | |
getRoute | Function getRoute |
Get requested Route on router engine instance according to servervrequest. | |
getRouter | Function getRouter |
Get the app Router engine instance | |
handle | handle function |
Handles the callback function returned by routing engineering and executes it, this return a ResponseInterface | |
handleError | Function handleError |
Returns a template view with errors occurred during the execution of the application according to http response | |
input | Function input |
Open a Stream Resource in Read mode and returns its content | |
json | Function json |
Set a array data and status code for write in the http response | |
loadEnv | Function loadEnv |
Load enviroment variables for use from app | |
output | Function output |
Open a Stream Resource in Recording mode and write a text in it, sending headers | |
path | Function path |
Return app project root path | |
pipeLine | Function pipeLine |
Run set and middlewares levels pipeline and return a instanceof ResponseInterface | |
redirect | Function redirect |
Redirect a Server Request with url, method and optional array of data | |
request | Function request |
Set and/or get current server request of app | |
response | Function response |
Set and/or get current server response of app | |
run | Function run |
Finally execute the app instance passed as parameters to standard input and output for php application. | |
setAfterMiddlewares | Function setAfterMiddlewares |
Setting after middlewares These are executed in the order they were defined. | |
setBeforeMiddlewares | Function setBeforeMiddlewares |
Setting before middlewares for app These are executed in the order they were defined. | |
setControllers | Function setControllers |
Setting all controller for app | |
setMiddlewares | Function setMiddlewares |
Set all middlewares for the app at once | |
setRequest | Function setRequest |
Set current server request of app | |
setRequestByArray | Function setRequestByArray |
Set current server request of app by a array argument | |
setResourceInput | Function setResourceInput |
Set app default resource input | |
setResourceOutput | Function setResourceOutput |
Set app default resource output | |
setResponse | Function setResponse |
Get current response of app | |
setRoute | Function setRoute |
Set a new route in the app router object | |
setRouteMiddlewares | Function setRouteMiddlewares |
Setting route middlewares for app | |
setRoutesByAnnotations | Function setRoutesByAnnotations |
Receives a class as an argument, and works with the comment blocks as @Route | |
setRoutesByControllers | Function setRoutesByControllers |
Receives a array of Controller[] with classnames like this ‘[App\ExampleController, …]’ | |
setViewFilters | Function setViewFilters |
Setting filters functions for use into template | |
view | Function view |
Set a template name, optional data and a optional path for write in the http response. | |
write | Function write |
Set a string and status code for write in the http response |
Description
public __construct (\ServerRequestInterface $request)
Function __construct Construct a instanceof Basicis\Basicis lovingly named $app
Parameters
(\ServerRequestInterface) $request
Return Values
void
Description
public __invoke (\ServerRequestInterface $request, \ResponseInterface $response, callable $next)
Function runAndResponse Run app pipe line and return a instance of ResponseInterface
Parameters
(\ServerRequestInterface) $request
(\ResponseInterface) $response
(callable) $next
Return Values
\ResponseInterface
Description
public auth (string $authClass)
Function auth Get the app Auth/User by authorization token, it is receive a class Basicis\Auth\AuthInterface
Parameters
(string) $authClass
Return Values
\Auth|null
Description
public cache (void)
Function cache
Get the app CacheItemPool engine instance
Parameters
This function has no parameters.
Return Values
\CacheItemPool|null
Description
public cacheIsEnabled (void)
Function cacheIsEnabled Check if app cache is enabled and return boolean
Parameters
This function has no parameters.
Return Values
bool
Description
public clientFileDownload (string $filename, bool $forced)
Function clientFileDownload Send a file in the body of the http response to the client
Parameters
(string) $filename
(bool) $forced
Return Values
\ResponseInterface
Description
public clientFileUpload (\UploadedFileInterface $infile, string $outfile)
Function clientFileUpload Upload one or more files in the body of the http server request from the client
Parameters
(\UploadedFileInterface) $infile
(string) $outfile
Return Values
array|null
Description
public closure (\Closure $callback, string|int|array|object|null $args)
Function closure Instantiate a Closure object and execute
Parameters
(\Closure) $callback
(string|int|array|object|null) $args
Return Values
\ResponseInterface
Description
public controller (\ServerRequestInterface $request, \ResponseInterface $response, string $callback)
Function controller Instantiate a Basicis\Controller\Controller object and execute the defined method or the standard index method.
The key for the controller or class name must be separated from the method name to be executed by @
or ::
.
$app->controller("example@functionName", $args = [object, array or null]);
//or
$app->controller("Namespace\Example::functionName", $args = [object, array or null]);
Parameters
(\ServerRequestInterface) $request
(\ResponseInterface) $response
(string) $callback
Return Values
\ResponseInterface
Description
public static createApp (\ServerRequestInterface|array $request)
Function createApp Factory Create a instanceof Basicis\Basicis and return it is
Parameters
(\ServerRequestInterface|array) $request
Return Values
\Basicis
Description
public static createSymLink (string $src, string $dst)
Function createSymLink Create a symlink default from storage/assets to public/ as assets
Parameters
(string) $src
(string) $dst
Return Values
bool
Description
public enableCache (bool $enable, string $cacheFile)
Function enableCache Enable application cache $enable true
Parameters
(bool) $enable
(string) $cacheFile
Return Values
\Basicis
Description
public error (int $code, string $message)
Function error Return a view error reporting html or json
Parameters
(int) $code
(string) $message
Return Values
\Psr\Http\Message\ResponseInterface
Description
public extractCallbackToArray (string $callback)
Function extractCallbackToArray Extract and return a array with controller name/class and method or null
Parameters
(string) $callback
Return Values
array|null
Description
public getController (string $arg)
Function getController Get a controller by classname
Parameters
(string) $arg
Return Values
\Controller|null
Description
public getDescription (string $descriptionDefault)
Function getDescription Getting App description string
Parameters
(string) $descriptionDefault
Return Values
string
Description
public getMiddlewares (string $type)
Function getMiddlewares Getting middlewares by type [‘before’, ‘route’, ‘after’ or null to all].
This return a array with especifieds middleware type or all if $type argument is equals null
Parameters
(string) $type
Return Values
array
Description
public getRequest (void)
Function getRequest Get current server request of app
Parameters
This function has no parameters.
Return Values
\ServerRequestInterface
Description
public getResourceInput (void)
Function getResourceInput Get app default resource input
Parameters
This function has no parameters.
Return Values
string
Description
public getResourceOutput (void)
Function getResourceOutput Get app default resource output
Parameters
This function has no parameters.
Return Values
string
Description
public getResponse (void)
Function getResponse Get current response of app
Parameters
This function has no parameters.
Return Values
\ResponseInterface
Description
public getRoute (void)
Function getRoute Get requested Route on router engine instance according to servervrequest.
A ResponseInterface object can be obtained by the getRequest function in the Router instance.
Parameters
This function has no parameters.
Return Values
\Route|null
Description
public getRouter (void)
Function getRouter Get the app Router engine instance
Parameters
This function has no parameters.
Return Values
\Router
Description
public handle (\ServerRequestInterface $request, \ResponseInterface $response, callable $next)
handle function Handles the callback function returned by routing engineering and executes it, this return a ResponseInterface
Parameters
(\ServerRequestInterface) $request
(\ResponseInterface) $response
(callable) $next
Return Values
\ResponseInterface
Throws Exceptions
\InvalidArgumentException
Description
public handleError (string $name)
Function handleError Returns a template view with errors occurred during the execution of the application according to http response
Parameters
(string) $name
Return Values
\ResponseInterface
Description
public static input (string $resourceFileName)
Function input Open a Stream Resource in Read mode and returns its content
Parameters
(string) $resourceFileName
Return Values
void
Description
public json (array $data, int $statusCode)
Function json Set a array data and status code for write in the http response
return $app->json(["test" => "Test with status code default!"]);
//or
return $app->json(["test" => "Test with status code ok!", "success" => true], 200);
Parameters
(array) $data
(int) $statusCode
Return Values
\ResponseInterface
Description
public static loadEnv (void)
Function loadEnv Load enviroment variables for use from app
Parameters
This function has no parameters.
Return Values
bool
Description
public static output (\ResponseInterface $response, string $resourceFileName)
Function output Open a Stream Resource in Recording mode and write a text in it, sending headers
Parameters
(\ResponseInterface) $response
(string) $resourceFileName
Return Values
int
size of stream writed content or “0”
Description
public static path (void)
Function path Return app project root path
Parameters
This function has no parameters.
Return Values
string
Description
public pipeLine (\ServerRequestInterface $request, \ResponseInterface|null $response, callable $next)
Function pipeLine Run set and middlewares levels pipeline and return a instanceof ResponseInterface
Parameters
(\ServerRequestInterface) $request
(\ResponseInterface|null) $response
(callable) $next
Return Values
\ResponseInterface
Description
public redirect (string $url, string $method, array $data)
Function redirect Redirect a Server Request with url, method and optional array of data
Parameters
(string) $url
(string) $method
(array) $data
Return Values
\ResponseInterface
Description
public request (void)
Function request Set and/or get current server request of app
Parameters
This function has no parameters.
Return Values
\ServerRequestInterface
Description
public response (int|\ResponseInterface $code, string $reasonPhrase)
Function response Set and/or get current server response of app
Parameters
(int|\ResponseInterface) $code
(string) $reasonPhrase
Return Values
\ResponseInterface
Description
public run (string $inputResource, string $outputResource)
Function run Finally execute the app instance passed as parameters to standard input and output for php application.
By definition the values are respectively “php://input” for input and “php://output” for output.
Parameters
(string) $inputResource
(string) $outputResource
Return Values
int
Description
public setAfterMiddlewares (array $middlewares)
Function setAfterMiddlewares Setting after middlewares These are executed in the order they were defined.
These are executed after the route middleware and main app handler,
if the ResponseInterface returned contains status codes greater than 200 or less than 206
$app->setAfterMiddlewares([
//key no is required
"App\\Middlewares\\AfterExample",
//...
]);
Parameters
(array) $middlewares
Return Values
void
Description
public setBeforeMiddlewares (array $middlewares)
Function setBeforeMiddlewares Setting before middlewares for app These are executed in the order they were defined.
These are executed before the route middleware and main app handler.
$app->setBeforeMiddlewares([
//key no is required
"App\\Middlewares\\BeforeExample",
//...
]);
Parameters
(array) $middlewares
Return Values
void
Description
public setControllers (array $controllers)
Function setControllers Setting all controller for app
$app->setControllers([
//Key required if from use in direct calls via Basicis App instance
"example" => "App/Controllers/Example",
//..
]);
$app->controller("example@functionName", $args = [object, array or null]);
Parameters
(array) $controllers
Return Values
\Basicis
Description
public setMiddlewares (void)
Function setMiddlewares Set all middlewares for the app at once
$app->setMiddlewares(
[
//key no is required
"App\\Middlewares\\BeforeExample",
//...
],
[
//only here, key is required
"guest" => "App\\Middlewares\\Guest",
"auth" => "App\\Middlewares\\Auth",
"example" => "App\\Middlewares\\Example",
//...
],
[
//key no is required
"App\\Middlewares\\AfterExample",
//...
]
);
Parameters
This function has no parameters.
Return Values
void
Description
public setRequest (\ServerRequestInterface $request)
Function setRequest Set current server request of app
Parameters
(\ServerRequestInterface) $request
Return Values
\Basicis
Description
public setRequestByArray (array $request)
Function setRequestByArray Set current server request of app by a array argument
Parameters
(array) $request
Return Values
\Basicis
Description
public setResourceInput (string $resourceInput)
Function setResourceInput Set app default resource input
Parameters
(string) $resourceInput
Return Values
\Basicis
Description
public setResourceOutput (string $resourceOutput)
Function setResourceOutput Set app default resource output
Parameters
(string) $resourceOutput
Return Values
\Basicis
Description
public setResponse (int|null $code, string $reasonPhrase)
Function setResponse Get current response of app
Parameters
(int|null) $code
(string) $reasonPhrase
Return Values
\Basicis
Description
public setRoute (string|array $url, string|array $method, string|\ControllerInterface|\Clousure $callback, string|array $middlewares)
Function setRoute Set a new route in the app router object
Parameters
(string|array) $url
(string|array) $method
(string|\ControllerInterface|\Clousure) $callback
(string|array) $middlewares
Return Values
\Basicis
Description
public setRouteMiddlewares (array $middlewares)
Function setRouteMiddlewares Setting route middlewares for app
$app->setRouteMiddlewares([
//only here, key is required
"guest" => "App\\Middlewares\\Guest",
"auth" => "App\\Middlewares\\Auth",
"example" => "App\\Middlewares\\Example",
//...
]);
@Route("/url", "method1", "middleware")
or@Route("/url, ...", "method1, ...", "middleware1, middleware2, ...")
/** @Route("/", "get", "example, guest") *\/
public function index($app, $args)
{
return $app->view("welcome");
}
/** @Route("/dashboard", "get", "auth") *\/
public function painel($app, $args)
{
return $app->view("welcome");
}
Parameters
(array) $middlewares
Return Values
void
Description
public setRoutesByAnnotations (string $class)
Function setRoutesByAnnotations Receives a class as an argument, and works with the comment blocks as @Route
Parameters
(string) $class
Return Values
\Basicis
Description
public setRoutesByControllers (array|\Controller[] $controllers)
Function setRoutesByControllers Receives a array of Controller[] with classnames like this ‘[App\ExampleController, …]’
Parameters
(array|\Controller[]) $controllers
Return Values
\Basicis
Description
public setViewFilters (array|\TwigFunction[] $filters)
Function setViewFilters Setting filters functions for use into template
$app->setViewFilters([
//here, key is required
"isTrue" => function ($value = true) {
return $value;
}
]);
<p>Var is True: <p>
or
Parameters
(array|\TwigFunction[]) $filters
Return Values
void
Description
public view (string $name, array $data, string $customPath)
Function view Set a template name, optional data and a optional path for write in the http response.
If template especified no not found, a ResponseInterface with status code 404 is returned.
Starting from the idea that we have a template called welcome.[html, php or twig]
inside storage/templates/
or my-custom/path/
, we have the following code to return this view:
return $app->view("welcome", $args = ["test" => "Test ok!"]);
//or
return $app->view("welcome", $args = ["test" => true, "test2" => "Test ok!"], "my-custom/path/");
<p></p>
<p>Var is True: </p>
Parameters
(string) $name
(array) $data
(string) $customPath
Return Values
\ResponseInterface
Description
public write (string $text, int|null $statusCode)
Function write Set a string and status code for write in the http response
return $app->write("My text with status code default!");
//or
return $app->write("My text with status code 200!", 200);
Parameters
(string) $text
(int|null) $statusCode
Return Values
\ResponseInterface