Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":2,"defects":[],"times":{"Tests\\Api\\OneTest::testConfigs":6.205,"Tests\\Api\\OneTest::testIndex":0.195,"Tests\\Api\\OneTest::testAbout":0.04,"Tests\\Api\\OneTest::testNotFound":0.038}}
{"version":2,"defects":[],"times":{"Tests\\Api\\OneTest::testConfigs":3.588,"Tests\\Api\\OneTest::testIndex":0.139,"Tests\\Api\\OneTest::testAbout":0.043,"Tests\\Api\\OneTest::testNotFound":0.031}}
10 changes: 9 additions & 1 deletion App.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
<?php declare(strict_types=1);
class App extends Framework\MVC\App {}
/*
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class App extends Framework\MVC\App
{
}
18 changes: 9 additions & 9 deletions app/Commands/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class Index extends \Framework\CLI\Commands\Index
protected function showHeader() : void
{
$banner = <<<'EOL'
$$\ $$\ $$$$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$$\ $$$$$$$$\ $$$$$$$\ $$$$$$\
$$ | $\ $$ |$$ _____|$$ __$$\ \_$$ _|$$ __$$\\__$$ __|$$ _____|$$ __$$\ $$ __$$\
$$ |$$$\ $$ |$$ | $$ | $$ | $$ | $$ / \__| $$ | $$ | $$ | $$ |$$ / \__|
$$ $$ $$\$$ |$$$$$\ $$$$$$$\ | $$ | \$$$$$$\ $$ | $$$$$\ $$$$$$$ |\$$$$$$\
$$$$ _$$$$ |$$ __| $$ __$$\ $$ | \____$$\ $$ | $$ __| $$ __$$< \____$$\
$$$ / \$$$ |$$ | $$ | $$ | $$ | $$\ $$ | $$ | $$ | $$ | $$ |$$\ $$ |
$$ / \$$ |$$$$$$$$\ $$$$$$$ |$$$$$$\ \$$$$$$ | $$ | $$$$$$$$\ $$ | $$ |\$$$$$$ |
\__/ \__|\________|\_______/ \______| \______/ \__| \________|\__| \__| \______/
EOL;
$$\ $$\ $$$$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$$\ $$$$$$$$\ $$$$$$$\ $$$$$$\
$$ | $\ $$ |$$ _____|$$ __$$\ \_$$ _|$$ __$$\\__$$ __|$$ _____|$$ __$$\ $$ __$$\
$$ |$$$\ $$ |$$ | $$ | $$ | $$ | $$ / \__| $$ | $$ | $$ | $$ |$$ / \__|
$$ $$ $$\$$ |$$$$$\ $$$$$$$\ | $$ | \$$$$$$\ $$ | $$$$$\ $$$$$$$ |\$$$$$$\
$$$$ _$$$$ |$$ __| $$ __$$\ $$ | \____$$\ $$ | $$ __| $$ __$$< \____$$\
$$$ / \$$$ |$$ | $$ | $$ | $$ | $$\ $$ | $$ | $$ | $$ | $$ |$$\ $$ |
$$ / \$$ |$$$$$$$$\ $$$$$$$ |$$$$$$\ \$$$$$$ | $$ | $$$$$$$$\ $$ | $$ |\$$$$$$ |
\__/ \__|\________|\_______/ \______| \______/ \__| \________|\__| \__| \______/
EOL;
CLI::write($banner, 'green');
}
}
8 changes: 4 additions & 4 deletions app/Controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

final class Home extends RouteActions
{
public function index(): Response
public function index() : Response
{
return success_response([
'message' => 'API is running.',
'status' => HealthModel::status(),
]);
}

public function about(): Response
public function about() : Response
{
return success_response([
'message' => 'API project powered by Webisters framework.',
'version' => HealthModel::version(),
]);
}

public function notFound(): Response
public function notFound() : Response
{
return respond_not_found();
}
}
}
2 changes: 1 addition & 1 deletion app/Languages/en/home.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of Api Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion app/Languages/es/home.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of Api Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion app/Languages/pt-br/home.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of Api Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion app/Models/HealthModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public static function version() : string
{
return '1.0.0';
}
}
}
2 changes: 1 addition & 1 deletion boot/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
require_once ROOT_DIR . 'App.php';
}

return new App(CONFIG_DIR, IS_DEV);
return new App(CONFIG_DIR, IS_DEV);
20 changes: 10 additions & 10 deletions boot/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,68 @@
* The current environment name.
*/
if (!defined('ENVIRONMENT')) {
define('ENVIRONMENT', $_SERVER['ENVIRONMENT'] ?? 'production');
define('ENVIRONMENT', $_SERVER['ENVIRONMENT'] ?? 'production');
}

/**
* True if it is in development environment, otherwise false.
*/
if (!defined('IS_DEV')) {
define('IS_DEV', ENVIRONMENT === 'development');
define('IS_DEV', ENVIRONMENT === 'development');
}

/**
* Path to the root directory.
*/
if (!defined('ROOT_DIR')) {
define('ROOT_DIR', dirname(__DIR__) . \DIRECTORY_SEPARATOR);
define('ROOT_DIR', dirname(__DIR__) . \DIRECTORY_SEPARATOR);
}

/**
* Path to the app directory.
*/
if (!defined('APP_DIR')) {
define('APP_DIR', ROOT_DIR . 'app' . \DIRECTORY_SEPARATOR);
define('APP_DIR', ROOT_DIR . 'app' . \DIRECTORY_SEPARATOR);
}

/**
* Path to the boot directory.
*/
if (!defined('BOOT_DIR')) {
define('BOOT_DIR', ROOT_DIR . 'boot' . \DIRECTORY_SEPARATOR);
define('BOOT_DIR', ROOT_DIR . 'boot' . \DIRECTORY_SEPARATOR);
}

/**
* Path to the config directory.
*/
if (!defined('CONFIG_DIR')) {
define('CONFIG_DIR', ROOT_DIR . 'config' . \DIRECTORY_SEPARATOR);
define('CONFIG_DIR', ROOT_DIR . 'config' . \DIRECTORY_SEPARATOR);
}

/**
* Path to the public directory.
*/
if (!defined('PUBLIC_DIR')) {
define('PUBLIC_DIR', ROOT_DIR . 'public' . \DIRECTORY_SEPARATOR);
define('PUBLIC_DIR', ROOT_DIR . 'public' . \DIRECTORY_SEPARATOR);
}

/**
* Path to the storage directory.
*/
if (!defined('STORAGE_DIR')) {
define('STORAGE_DIR', ROOT_DIR . 'storage' . \DIRECTORY_SEPARATOR);
define('STORAGE_DIR', ROOT_DIR . 'storage' . \DIRECTORY_SEPARATOR);
}

/**
* Path to the vendor directory.
*/
if (!defined('VENDOR_DIR')) {
define('VENDOR_DIR', ROOT_DIR . 'vendor' . \DIRECTORY_SEPARATOR);
define('VENDOR_DIR', ROOT_DIR . 'vendor' . \DIRECTORY_SEPARATOR);
}

/**
* Path to the webisters directory.
*/
if (!defined('WEBISTERS_DIR')) {
define('WEBISTERS_DIR', VENDOR_DIR . 'webisters' . \DIRECTORY_SEPARATOR);
define('WEBISTERS_DIR', VENDOR_DIR . 'webisters' . \DIRECTORY_SEPARATOR);
}
35 changes: 17 additions & 18 deletions boot/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
* @package api
*/

use Framework\Helpers\ArraySimple;
use Framework\HTTP\Response;

if (!function_exists('helpers')) {
function helpers(array | string $helper): array
function helpers(array | string $helper) : array
{
if (is_array($helper)) {
$files = [];
Expand All @@ -31,15 +30,15 @@ function helpers(array | string $helper): array
}

if (!function_exists('asset')) {
function asset(string $path): string
function asset(string $path) : string
{
$path = trim($path, '/');
$documentRoot = rtrim($_SERVER['DOCUMENT_ROOT'] ?? '', '/\\');
if ($documentRoot !== '') {
$direct = $documentRoot . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
$direct = $documentRoot . \DIRECTORY_SEPARATOR . str_replace('/', \DIRECTORY_SEPARATOR, $path);
if (!is_file($direct)) {
$public = $documentRoot . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR
. str_replace('/', DIRECTORY_SEPARATOR, $path);
$public = $documentRoot . \DIRECTORY_SEPARATOR . 'public' . \DIRECTORY_SEPARATOR
. str_replace('/', \DIRECTORY_SEPARATOR, $path);
if (is_file($public)) {
return '/public/' . str_replace('\\', '/', $path);
}
Expand All @@ -61,18 +60,18 @@ function asset(string $path): string
*
* @return Response
*/
function json_response($data, int $code = 200, array $headers = []): Response
function json_response($data, int $code = 200, array $headers = []) : Response
{
$response = App::response();
$response->setStatusCode($code);

foreach ($headers as $name => $value) {
$response->setHeader($name, $value);
}

$response->setHeader('Content-Type', 'application/json; charset=UTF-8');
$response->setBody(json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT));

return $response;
}

Expand All @@ -85,18 +84,18 @@ function json_response($data, int $code = 200, array $headers = []): Response
*
* @return Response
*/
function error_response(string $message, int $code = 400, $details = null): Response
function error_response(string $message, int $code = 400, $details = null) : Response
{
$data = [
'success' => false,
'message' => $message,
'code' => $code,
];

if ($details !== null) {
$data['details'] = $details;
}

return json_response($data, $code);
}

Expand All @@ -109,17 +108,17 @@ function error_response(string $message, int $code = 400, $details = null): Resp
*
* @return Response
*/
function success_response($data, int $code = 200, ?string $message = null): Response
function success_response($data, int $code = 200, ?string $message = null) : Response
{
$response = [
'success' => true,
'data' => $data,
];

if ($message !== null) {
$response['message'] = $message;
}

return json_response($response, $code);
}

Expand All @@ -129,7 +128,7 @@ function success_response($data, int $code = 200, ?string $message = null): Resp
* @return string
*/
if (!function_exists('current_url')) {
function current_url(): string
function current_url() : string
{
return App::request()->getUrl()->toString();
}
Expand Down Expand Up @@ -163,7 +162,7 @@ function env(string $key, $default = null)
* @return Response
*/
if (!function_exists('respond_not_found')) {
function respond_not_found(): Response
function respond_not_found() : Response
{
return error_response('Not Found', 404, [
'path' => App::request()->getUrl()->getPath(),
Expand Down
6 changes: 3 additions & 3 deletions boot/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

App::router()->serve(
null,
static function (RouteCollection $routes): void {
$routes->namespace('Api\\Controllers', [
static function (RouteCollection $routes) : void {
$routes->namespace('Api\Controllers', [
$routes->get('/', 'Home::index', 'api.home.index'),
$routes->get('/about', 'Home::about', 'api.home.about'),
]);
$routes->notFound(static fn () => respond_not_found());
}
);
);
2 changes: 1 addition & 1 deletion config/antiCsrf.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion config/autoloader.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion config/cache.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
4 changes: 2 additions & 2 deletions config/console.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -20,7 +20,7 @@
Webisters\Commands\MakeView::class,
Webisters\Commands\RouteList::class,
] as $command) {
if (\class_exists($command)) {
if (class_exists($command)) {
$commands[] = $command;
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/database.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion config/debugger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion config/exceptionHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion config/language.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* This file is part of App Project.
* This file is part of API Project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
Loading
Loading