velsym/universal-pack
Connector for velsym packages.
composer require velsym/universal-packVelsym\Communication
Request
A static class containing current request info.
Methods
method- returns name of the HTTP method used in the current request. e.g.GET,POST...Returns:
stringurl- returns info about url.Returns:
UrlInfo
UrlInfo
A readonly class:
Properties
path- string value containing path e.g./user/21.query- a key-value array containing query string of the requested URI.
Methods
__construct(URI)- constructs UrlInfo.Returns:
UrlInfoParams:
URI- string containing URI.
Response
A singleton which is used to set response content.
You shouldn't use any of the methods unless you're making a package or you know exactly what you're doing. If you are using Velsym on it's own, be aware that you can achieve all of it's capabilities in a more safe and elegant way.
Methods
getInstance()- returns instance of the Response.Returns:
selfaddHeader(header, value)- sets HTTP header.Returns:
selfParams:
header- name of the header.value- value of the header (after colon).
addHeaders(headers[])- add multiple headers at once using an array.Returns:
selfParams:
headers- key-value array. Key is name of the header and value is the value of the header.
getHeaders()- returns key-value array of all headers.Returns:
arraysetBody(body)- takes string as the body of the response.Returns:
voidParams:
body- body of the response.
getBody()- returns body.Returns:
stringsetResponseCode(responseCode)- sets HTTP status code.Returns:
voidParams:
responseCode- an integer of the response code.
getResponseCode()- returns integer representing HTTP status code.Returns:
intgetRedirectRouteName()- returns name of redirect route if set.Returns:
NULL|stringsetRedirectRouteName(redirectRouteName)- sets the route that client should be redirected to.Returns:
selfParams:
redirectRouteName- string containing name of the route or NULL if want to unredirect.
Examples
use Velsym\Communication\Response;
$response = Response::getInstance();
$response->addHeader("Location", "/home/");
// ^ Sets HTTP Header: Location: /home/
$headers = [
"Content-Encoding" => "gzip",
"Connection" => "close"
];
$response->addHeaders($headers);Velsym\Dependency
DependencyBuilder
Class simplifying construction of dependencies.
Methods
addDependency(dependency)- entrypoint for every dependency.Returns:
selfParams:
dependency- fully qualified class name that represents an underlying class.
setClass(class)- sets the real class.Returns:
selfParams:
class- fully qualified class name of class that will be resolved.
setParam(paramName, value)- when real class requires some kind of parameters in the constructor, you can set the default parameter value here.Returns:
selfParams:
paramName- name of the parameter defined in the constructor of the real class.value- value that will be passed to the parameter of nameparamName.
getDependencies()- returns an array that stores all of the dependencies and can be read by DependencyManager.Returns:
array
Examples
use Velsym\Dependency\DependencyBuilder;
//Interface doesn't contain anything and acts as a label on which parameters to use.
interface Male
{
}
interface Female
{
}
class Person
{
public function __construct(string $name, int $age)
{
// ...
}
// ...
}
$builder = (new DependencyBuilder("The awesome dependencies!"))
->addDependency(Male::class) // Interface
->setClass(Person::class) // Real Class
->setParam("name", "John")
->setParam("age", 21)
->addDependency(Female::class)
->setClass(Person::class)
->setParam("name", "Julia")
->setParam("age", 19)
->addDependency("Abstract\\Class")
->setClass("Real\\Class")
->setParam("path", "/unix/path/to/file.php")
->setParam("array", ['the', 'array', 'number', 1])
;Velsym\Routing
BaseMiddleware
This class is must be extended by every middleware.
Methods
handle()- method that is implemented by extended class. Router is responsble of executing this method. Do not call it unless you know what you're doing.Returns:
voidredirect(path)- redirects client to another url.Returns:
voidParams:
path- string path to which client should be redirected.
Last updated