Basicis - Core

Logo

As the name says, it is made to be basic and direct.

View the Project on GitHub basicis/core

Basicis\Basicis

Basicis\Basicis - Main class Basicis framework

Implements:

Basicis\Http\Server\RequestHandlerInterface

Methods

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  

Basicis::__construct

Description

public __construct (\ServerRequestInterface $request)

Function __construct Construct a instanceof Basicis\Basicis lovingly named $app

Parameters

Return Values

void


Basicis::__invoke

Description

public __invoke (\ServerRequestInterface $request, \ResponseInterface $response, callable $next)

Function runAndResponse Run app pipe line and return a instance of ResponseInterface

Parameters

Return Values

\ResponseInterface


Basicis::auth

Description

public auth (string $authClass)

Function auth Get the app Auth/User by authorization token, it is receive a class Basicis\Auth\AuthInterface

Parameters

Return Values

\Auth|null


Basicis::cache

Description

public cache (void)

Function cache

Get the app CacheItemPool engine instance

Parameters

This function has no parameters.

Return Values

\CacheItemPool|null


Basicis::cacheIsEnabled

Description

public cacheIsEnabled (void)

Function cacheIsEnabled Check if app cache is enabled and return boolean

Parameters

This function has no parameters.

Return Values

bool


Basicis::clientFileDownload

Description

public clientFileDownload (string $filename, bool $forced)

Function clientFileDownload Send a file in the body of the http response to the client

Parameters

Return Values

\ResponseInterface


Basicis::clientFileUpload

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

Return Values

array|null


Basicis::closure

Description

public closure (\Closure $callback, string|int|array|object|null $args)

Function closure Instantiate a Closure object and execute

Parameters

Return Values

\ResponseInterface


Basicis::controller

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

Return Values

\ResponseInterface


Basicis::createApp

Description

public static createApp (\ServerRequestInterface|array $request)

Function createApp Factory Create a instanceof Basicis\Basicis and return it is

Parameters

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

Return Values

bool


Basicis::enableCache

Description

public enableCache (bool $enable, string $cacheFile)

Function enableCache Enable application cache $enable true

Parameters

Return Values

\Basicis


Basicis::error

Description

public error (int $code, string $message)

Function error Return a view error reporting html or json

Parameters

Return Values

\Psr\Http\Message\ResponseInterface


Basicis::extractCallbackToArray

Description

public extractCallbackToArray (string $callback)

Function extractCallbackToArray Extract and return a array with controller name/class and method or null

Parameters

Return Values

array|null


Basicis::getController

Description

public getController (string $arg)

Function getController Get a controller by classname

Parameters

Return Values

\Controller|null


Basicis::getDescription

Description

public getDescription (string $descriptionDefault)

Function getDescription Getting App description string

Parameters

Return Values

string


Basicis::getMiddlewares

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

Return Values

array


Basicis::getRequest

Description

public getRequest (void)

Function getRequest Get current server request of app

Parameters

This function has no parameters.

Return Values

\ServerRequestInterface


Basicis::getResourceInput

Description

public getResourceInput (void)

Function getResourceInput Get app default resource input

Parameters

This function has no parameters.

Return Values

string


Basicis::getResourceOutput

Description

public getResourceOutput (void)

Function getResourceOutput Get app default resource output

Parameters

This function has no parameters.

Return Values

string


Basicis::getResponse

Description

public getResponse (void)

Function getResponse Get current response of app

Parameters

This function has no parameters.

Return Values

\ResponseInterface


Basicis::getRoute

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


Basicis::getRouter

Description

public getRouter (void)

Function getRouter Get the app Router engine instance

Parameters

This function has no parameters.

Return Values

\Router


Basicis::handle

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

Return Values

\ResponseInterface

Throws Exceptions

\InvalidArgumentException


Basicis::handleError

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

Return Values

\ResponseInterface


Basicis::input

Description

public static input (string $resourceFileName)

Function input Open a Stream Resource in Read mode and returns its content

Parameters

Return Values

void


Basicis::json

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

Return Values

\ResponseInterface


Basicis::loadEnv

Description

public static loadEnv (void)

Function loadEnv Load enviroment variables for use from app

Parameters

This function has no parameters.

Return Values

bool


Basicis::output

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

Return Values

int

size of stream writed content or “0”


Basicis::path

Description

public static path (void)

Function path Return app project root path

Parameters

This function has no parameters.

Return Values

string


Basicis::pipeLine

Description

public pipeLine (\ServerRequestInterface $request, \ResponseInterface|null $response, callable $next)

Function pipeLine Run set and middlewares levels pipeline and return a instanceof ResponseInterface

Parameters

Return Values

\ResponseInterface


Basicis::redirect

Description

public redirect (string $url, string $method, array $data)

Function redirect Redirect a Server Request with url, method and optional array of data

Parameters

Return Values

\ResponseInterface


Basicis::request

Description

public request (void)

Function request Set and/or get current server request of app

Parameters

This function has no parameters.

Return Values

\ServerRequestInterface


Basicis::response

Description

public response (int|\ResponseInterface $code, string $reasonPhrase)

Function response Set and/or get current server response of app

Parameters

Return Values

\ResponseInterface


Basicis::run

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

Return Values

int


Basicis::setAfterMiddlewares

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

Return Values

void


Basicis::setBeforeMiddlewares

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

Return Values

void


Basicis::setControllers

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

Return Values

\Basicis


Basicis::setMiddlewares

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


Basicis::setRequest

Description

public setRequest (\ServerRequestInterface $request)

Function setRequest Set current server request of app

Parameters

Return Values

\Basicis


Basicis::setRequestByArray

Description

public setRequestByArray (array $request)

Function setRequestByArray Set current server request of app by a array argument

Parameters

Return Values

\Basicis


Basicis::setResourceInput

Description

public setResourceInput (string $resourceInput)

Function setResourceInput Set app default resource input

Parameters

Return Values

\Basicis


Basicis::setResourceOutput

Description

public setResourceOutput (string $resourceOutput)

Function setResourceOutput Set app default resource output

Parameters

Return Values

\Basicis


Basicis::setResponse

Description

public setResponse (int|null $code, string $reasonPhrase)

Function setResponse Get current response of app

Parameters

Return Values

\Basicis


Basicis::setRoute

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

Return Values

\Basicis


Basicis::setRouteMiddlewares

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("/", "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

Return Values

void


Basicis::setRoutesByAnnotations

Description

public setRoutesByAnnotations (string $class)

Function setRoutesByAnnotations Receives a class as an argument, and works with the comment blocks as @Route

Parameters

Return Values

\Basicis


Basicis::setRoutesByControllers

Description

public setRoutesByControllers (array|\Controller[] $controllers)

Function setRoutesByControllers Receives a array of Controller[] with classnames like this ‘[App\ExampleController, …]’

Parameters

Return Values

\Basicis


Basicis::setViewFilters

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

Return Values

void


Basicis::view

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/");  

Parameters

Return Values

\ResponseInterface


Basicis::write

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

Return Values

\ResponseInterface