Helpers

Helpers are functions that help the developer manipulate classes, without having to instantiate them.

Here you will find the helpers that exist in Solital Framework. Some specific helpers are not listed on this page, but you can find them on the next pages of the documentation.

Some helpers can be replaced by methods, as long as you use them inside a Controller.

HTTP

  • Handles the URI class. See more in routes.
/**
 * @param string $name
 * @param mixed $parameters
 * @param null|array $getParams
*/
url(?string $name = null, $parameters = null, ?array $getParams)
  • Handles the Response class.
response()
  • Handles the Request class.
request()
/**
 * @param string|null $index: Parameter index name
 * @param string|null $defaultValue: Default return value
 * @param array ...$methods: Default methods
 * 
 * @return mixed
 */
input(string $index = null, string $defaultValue = null, ...$methods)

# With method
$this->getRequestParams(string $index = null, string $defaultValue = null, ...$methods)
  • Redirect to another route.
/**
 * @param string $url: the route to which you will be redirected
 * @param int|null $code: HTTP code
 */
to_route(string $url, ?int $code = null)

# Or, use a method
$this->redirect(string $url, ?int $code = null)
  • Defines a limit on requests that can be made at a certain time
/**
 * @param string $key: key to identify the requisition 
 * @param int $limit: number of times the request can be made
 * @param int $seconds: waiting time until it is possible to make the request again. 
 * 
 * @return bool
*/
request_limit(string $key, int $limit = 5, int $seconds = 60)

# With method
$this->requestLimit(string $key, int $limit = 5, int $seconds = 60)
  • Checks if a value was previously sent in the requisition.
/**
 * @param string $key: key to identify the requisition 
 * @param string $value: value that will be added
 * 
 * @return bool
 */
request_repeat(string $key, string $value)

# With method
$this->requestRepeat(string $key, string $value)

Security

csrf_token()
  • Form method spoofing.
/**
 * @param string $method: GET, POST, PUT or DELETE
*/
spoofing(string $method)
/**
 * @param mixed $value: the user's password. 
 * @param int $cost: which denotes the algorithmic cost that should be used.
*/
pass_hash($value, int $cost = 10)
/**
 * @param mixed $value: the user's password. 
 * @param string $hash: a hash created by `pass_hash()`.
*/
pass_verify($value, string $hash)

Wolf Template

See Wolf Template to use Wolf helpers.

  • Load a CSS file into the public/assets/_css/ folder.
/**
 * @param string $asset: CSS file name
*/
load_css(string $asset)
  • Loads the minified CSS file created by the minify()->style() method.
load_min_css()
  • Load a Javascript file into the public/assets/_js/ folder.
/**
 * @param string $asset: javascript file name
*/
load_js(string $asset)
  • Loads the minified Javascript file created by the minify()->script() method.
load_min_js()
  • Load a image file into the public/assets/_img/ folder.
/**
 * @param string $asset: image file name
*/
load_img(string $asset)
  • Load a file into the public/assets/ folder.
/**
 * @param string $asset: external file name
*/
load_file(string $asset)

Output

  • Formatted var_dump.
/**
 * @param mixed $value: to format
*/
pre($value)
  • cloner uses Symfony VarCloner function. See more.
/**
 * @param mixed $var
 */
cloner($var)
  • Displays the variable formatted in string. true to return as an array.
/**
 * @param mixed $var
 * @param bool $length
 */
dumper($var, bool $length = false)
  • It is possible to make use of Symfony dump function.
dump($var)
  • export uses the Symfony VarExport function. See more.
/**
 * @param mixed $value
 */
export($value)
  • Convert an array to JSON and display an error message in case of failure.
/**
 * @param mixed $value: to JSON
*/
encodeJSON($value)
  • Convert a JSON to an object and display an error message in case of failure. true to convert JSON to an array.
/**
 * @param mixed $value: to JSON
 * @param bool $toArray: convert JSON object in array
*/
decodeJSON($value, bool $toArray = false)
  • Write any message in the browser LOG, which can be viewed at any time.
/**
 * @param mixed ...$messages
 * 
 * @return void
 */
console_log(...$messages)

Session

  • Handles PHP sessions.

To get a value from an existing session, leave the $value parameter empty. To create a new session, inform the session key in the first parameter, and the session value in the second parameter. See more in Session and Cookies.

/**
 * @param string $key: index that will identify the session
 * @param mixed $value: session value
 * @param mixed $defaultValue: array of values (see Session class documentation)
 * @param bool $delete: if the value is `true`, the session will be deleted.
 * @param bool $take: returns the requested value and removes it from the session.
 * 
 * @return mixed
 */
session(string $key, mixed $value = null, mixed $defaultValue = null, bool $delete = false, bool $take = false)

Others

  • Removes GET parameters in the URL and reloads the page without those parameters.
remove_param()

# With method
$this->removeParamsUrl()
  • Check if variable is JSON.
/**
 * @param mixed $string: verify if value is JSON
*/
is_json($string)
  • Get the current full URL.
/**
 * @param string $uri
 */
get_url(string $uri = null)
  • Returns trailing name component of path and get rid of trailing slashes/backslashes.
/**
 * @param string $path
 * 
 * @return string|null
 */
mb_basename(string $path)
  • Implode an array as key-value pairs. The third parameter is the symbol to be used between key and value.
/**
 * @param string $glue
 * @param array $array
 * @param string $symbol
 * 
 * @return string
 */
mapped_implode(string $glue, array $array, string $symbol = '=')
  • Manipulate the ArrayCollection class without having to instantiate it.
/**
 * @param mixed $value
 * 
 * @return ArrayCollection
 */
collection(mixed $value = null)
  • Manipulate the Str class without having to instantiate it.
/**
 * @param string $string
 * 
 * @return Str
 */
str(string $string)

What to see next?


Built with MkDocs.