Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
hungnguyenhp committed Sep 17, 2021
1 parent 688b6b7 commit e9ee226
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Instantiate the app
$settings = require SOURCE_PATH . 'settings.php';

/** @var object $app */
/** @var Slim\App $app */
$app = new Slim\App($settings);

// Set up dependencies
Expand Down
17 changes: 10 additions & 7 deletions src/dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


// DIC configuration

/**
* @var \Slim\App $app
*/
$container = $app->getContainer();

/**
Expand All @@ -29,14 +31,15 @@
};

/**
* monolog
* Function
*
* @author: 713uk13m <[email protected]>
* @time : 10/20/18 16:00
*
* @param object $c Container
* @param $c
*
* @return \Monolog\Logger
* @throws \Exception
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/17/2021 34:49
*/
$container['logger'] = function ($c) {
$settings = $c->get('settings')['logger'];
Expand All @@ -62,7 +65,7 @@
$pdo = new FaaPz\PDO\Database($settings['dsn'], $settings['username'], $settings['password']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Cấu hình dữ liệu trả về luôn ở dạng Object
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

return $pdo;
};
Expand Down
28 changes: 13 additions & 15 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @return bool|int|string
*/
function ipAddress($convertToInteger = FALSE)
function ipAddress($convertToInteger = false)
{
$ip_keys = [
0 => 'HTTP_X_FORWARDED_FOR',
Expand All @@ -30,14 +30,12 @@ function ipAddress($convertToInteger = FALSE)
8 => 'REMOTE_ADDR'
];
foreach ($ip_keys as $key) {
if (array_key_exists($key, $_SERVER) === TRUE) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
$ip = trim($ip);
if (ipValidate($ip)) {
if ($convertToInteger === TRUE) {
$result = ip2long($ip);

return $result;
if ($convertToInteger === true) {
return ip2long($ip);
}

return $ip;
Expand All @@ -46,7 +44,7 @@ function ipAddress($convertToInteger = FALSE)
}
}

return FALSE;
return false;
}

/**
Expand All @@ -61,11 +59,11 @@ function ipAddress($convertToInteger = FALSE)
*/
function ipValidate($ip)
{
if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
return FALSE;
if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
return false;
}

return TRUE;
return true;
}
}
if (!function_exists('arrayToObject')) {
Expand All @@ -80,16 +78,16 @@ function ipValidate($ip)
*
* @return array|bool|\stdClass
*/
function arrayToObject($array = [], $str_to_lower = FALSE)
function arrayToObject($array = [], $str_to_lower = false)
{
if (!is_array($array)) {
return $array;
}
$object = new \stdClass();
if (is_array($array) && count($array) > 0) {
$object = new stdClass();
if (count($array) > 0) {
foreach ($array as $name => $value) {
$name = trim($name);
if ($str_to_lower === TRUE) {
if ($str_to_lower === true) {
$name = strtolower($name);
}
if (!empty($name)) {
Expand All @@ -100,6 +98,6 @@ function arrayToObject($array = [], $str_to_lower = FALSE)
return $object;
}

return FALSE;
return false;
}
}
4 changes: 3 additions & 1 deletion src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Slim\Http\Request;
use Slim\Http\Response;

// Routes
/**
* @var \Slim\App $app
*/
$app->get('/', function (Request $request, Response $response, array $args) {
// Sample log message
$this->logger->info("Slim-Skeleton '/' route" . json_encode($request->getQueryParams()));
Expand Down
6 changes: 3 additions & 3 deletions src/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// Settings Data
return [
'settings' => [
'displayErrorDetails' => TRUE, // set to false in production
'addContentLengthHeader' => FALSE, // Allow the web server to send the content-length header
'displayErrorDetails' => true, // set to false in production
'addContentLengthHeader' => false, // Allow the web server to send the content-length header
// Site Url
'base_url' => '',
// Renderer settings
Expand All @@ -22,7 +22,7 @@
'logger' => [
'name' => 'app',
'path' => isset($_ENV['docker']) ? 'php://stdout' : LOGS_PATH . 'Log-' . date('Y-m-d') . '.log',
'level' => \Monolog\Logger::DEBUG,
'level' => Monolog\Logger::DEBUG,
],
// Cấu hình Database
'db' => [
Expand Down

0 comments on commit e9ee226

Please sign in to comment.