PHP Classes

File: public_html/index.php

Recommend this page to a friend!
  Packages of Rodrigo Faustino   Projeto Loja   public_html/index.php   Download  
File: public_html/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Projeto Loja
Resize and compress uploaded images
Author: By
Last change:
Date: 2 months ago
Size: 1,976 bytes
 

Contents

Class file image Download
<?php
use Psr\Http\Message\ResponseInterface as Response;
use
Psr\Http\Message\ServerRequestInterface as Request;
use
Slim\Factory\AppFactory;
use
DI\ContainerBuilder; // Importante
use App\ProductController;
use
App\AssetManager;
require
__DIR__ . '/../api_core/vendor/autoload.php';

// 1. Carregar Variáveis de Ambiente (.env)
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../api_core');
$dotenv->load();

// 2. Configurar Container de Injeção de Dependência
$containerBuilder = new ContainerBuilder();

// Carrega nossas definições do arquivo dependencies.php
$dependencies = require __DIR__ . '/../api_core/dependencies.php';
$dependencies($containerBuilder);

$container = $containerBuilder->build();

// 3. Criar o App usando o Container
AppFactory::setContainer($container);
$app = AppFactory::create();

$app->addErrorMiddleware(true, true, true);

// --- ROTAS ---

$app->get('/', function (Request $request, Response $response) {
   
// Pega a tag do script correta (Dev ou Prod)
   
$scriptTag = AssetManager::getScriptTag();

   
$html = "
    <!DOCTYPE html>
    <html lang='pt-BR'>
    <head>
        <meta charset='UTF-8'>
        <meta name='viewport' content='width=device-width, initial-scale=1.0'>
        <title>Loja Integrada</title>
        </head>
    <body>
        <div id='app'>
            <h1>Upload de Produtos</h1>
           
            <input type='file' id='uploadInput' accept='image/*' />
           
            <div id='previews'>
                <img id='previewOriginal' style='max-width:200px' />
                <div id='infoOriginal'></div>
               
                <img id='previewCompressed' style='max-width:200px' />
                <div id='infoCompressed'></div>
            </div>
        </div>

       
{$scriptTag}
       
    </body>
    </html>
    "
;

   
$response->getBody()->write($html);
    return
$response;
});

$app->post('/products', [ProductController::class, 'create']);

$app->run();