PHP code example of wagnermontanini / goomerapi
1. Go to this page and download the library: Download wagnermontanini/goomerapi 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/ */
wagnermontanini / goomerapi example snippets
/**
* DATABASE
*/
define("DATA_LAYER_CONFIG", [
"driver" => "mysql",
"host" => "localhost",
"port" => "3306",
"dbname" => "goomerapi",
"username" => "root",
"passwd" => "",
"options" => [
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_CASE => PDO::CASE_NATURAL
]
]);
/**
* PROJECT URLs
*/
define("CONF_URL_BASE", "https://www.goomerapi.com.br");
define("CONF_URL_TEST", "http://goomerapi.test");
/**
* UPLOAD
*/
define("CONF_UPLOAD_DIR", "storage");
define("CONF_UPLOAD_IMAGE_DIR", "images");
define("CONF_UPLOAD_FILE_DIR", "files");
define("CONF_UPLOAD_MEDIA_DIR", "medias");
/**
* IMAGES
*/
define("CONF_IMAGE_CACHE", CONF_UPLOAD_DIR . "/" . CONF_UPLOAD_IMAGE_DIR . "/cache");
define("CONF_IMAGE_SIZE", 2000);
define("CONF_IMAGE_QUALITY", ["jpg" => 75, "png" => 5]);
ob_start();
"/Config.php";
/**
* BOOTSTRAP
*/
use CoffeeCode\Router\Router;
/**
* API ROUTES
* index
*/
$route = new Router(url(), ":");
$route->namespace("WagnerMontanini\GoomerApi\Api");
//restaurants
$route->group("/v1");
$route->get("/restaurants", "Restaurants:index");
$route->post("/restaurants", "Restaurants:create");
$route->get("/restaurants/{restaurant_id}", "Restaurants:read");
$route->put("/restaurants/{restaurant_id}", "Restaurants:update");
$route->delete("/restaurants/{restaurant_id}", "Restaurants:delete");
//categories
$route->get("/restaurants/{restaurant_id}/categories", "ProductsCategories:index");
$route->post("/restaurants/{restaurant_id}/categories", "ProductsCategories:create");
$route->get("/restaurants/{restaurant_id}/categories/{product_category_id}", "ProductsCategories:read");
$route->put("/restaurants/{restaurant_id}/categories/{product_category_id}", "ProductsCategories:update");
$route->delete("/restaurants/{restaurant_id}/categories/{product_category_id}", "ProductsCategories:delete");
//products
$route->get("/restaurants/{restaurant_id}/products", "Products:index");
$route->post("/restaurants/{restaurant_id}/products", "Products:create");
$route->get("/restaurants/{restaurant_id}/products/{product_id}", "Products:read");
$route->put("/restaurants/{restaurant_id}/products/{product_id}", "Products:update");
$route->delete("/restaurants/{restaurant_id}/products/{product_id}", "Products:delete");
/**
* ROUTE
*/
$route->dispatch();
/**
* ERROR REDIRECT
*/
if ($route->error()) {
header('Content-Type: application/json; charset=UTF-8');
http_response_code(404);
echo json_encode([
"errors" => [
"type " => "endpoint_not_found",
"message" => "Não foi possível processar a requisição"
]
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}
ob_end_flush();
`nginxconfig
location / {
if ($script_filename !~ "-f"){
rewrite ^(.*)$ /index.php?route=/$1 break;
}
}