PHP code example of buildcake / tools

1. Go to this page and download the library: Download buildcake/tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buildcake / tools example snippets




use BuildCake\Utils\Utils;

// Carrega variáveis de um arquivo .env
Utils::loadEnv(__DIR__ . '/.env');

// Agora você pode usar getenv() ou $_ENV
$dbHost = getenv('DB_HOST');

use BuildCake\Utils\Utils;

// Resposta de sucesso
Utils::sendResponse(200, ['user' => ['id' => 1, 'name' => 'João']], 'Usuário encontrado');

// Resposta de erro
Utils::sendResponse(400, [], 'Dados inválidos', ['email' => 'Email é obrigatório']);

use BuildCake\Utils\Utils;

// Inclui um arquivo (procura recursivamente se não encontrar)
Utils:: por Auth/services/UserService.php

use BuildCake\Utils\Utils;

$template = "Olá {{nome}}, seu email é {{email}}";
$data = [
    'nome' => 'João',
    'email' => '[email protected]'
];

$resultado = Utils::replaceFields($template, $data);
// Resultado: "Olá João, seu email é [email protected]"

use BuildCake\Utils\Utils;

$request = Utils::getFileRequest();
// Retorna array com informações sobre file, route, id e type

buildcake-tools/
├── src/
│   └── BuildCake/
│       └── Utils/
│           └── Utils.php
├── composer.json
├── README.md
└── .gitignore