He creado un fichero en la ruta app/Helpers/helper.php
donde quiero incluir los helpers que necesito para mi proyecto en lumen, de momento tengo este código
<?php
namespace App\Helpers;
/**
* Generate a "random" alpha-numeric string.
*
* @param int $length
* @return string
*
* @throws \RuntimeException
*/
function randomStr($length = 60)
{
if (!function_exists('openssl_random_pseudo_bytes')) {
throw new RuntimeException('OpenSSL extension is required.');
}
$bytes = openssl_random_pseudo_bytes($length * 2);
if ($bytes === false) {
throw new RuntimeException('Unable to generate random string.');
}
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
}
En el fichero composer.json he añadido la siguiente clave
"files": [
"app/Helpers/Helper.php"
],
Y para hacer la llamada a la función lo hago desde un controlador de esta forma
$token = \App\Helpers\randomStr(30);
Y el error que recibo es
Call to undefined function App\Helpers\randomStr()