Skip to content

Commit 3789f73

Browse files
committed
Loaded dotenv() support to use global variables instead. Using Composer now for third-party libraries.
1 parent c3116c8 commit 3789f73

File tree

7 files changed

+252
-6
lines changed

7 files changed

+252
-6
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ insert_final_newline = true
1111
trim_trailing_whitespace = true
1212

1313
# Specific changes for JavaScript, YAML and JSON files.
14-
[*.{yaml,json,js}]
14+
[*.{yaml,js}]
1515
indent_size = 2
1616

1717
# Markdown specific rules.

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
# You should have received a copy of the GNU Affero General Public License
1414
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1515

16-
########################
17-
### Custom Additions ###
18-
########################
19-
20-
16+
###########################
17+
### Application Ignores ###
18+
###########################
19+
/vendor/
20+
/config/.env
21+
/config/env.php
2122

2223
######################
2324
### macOS Specific ###

composer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "complete-php7-ecom-website",
3+
"description": "An advanced and complete PHP 7 eCommerce website along with MySQL database and Admin interface.",
4+
"homepage": "https://github.com/justinhartman/complete-php7-ecom-website",
5+
"keywords": ["cms", "ecommerce", "ecommerce admin", "ecommerce database", "ecommerce website", "php"],
6+
"authors": [{
7+
"name": "Justin Hartman",
8+
"email": "justin@hartman.me",
9+
"homepage": "https://justinhartman.blog"
10+
}],
11+
"type": "project",
12+
"license": "AGPL-3",
13+
"require": {
14+
"php": ">=7.0",
15+
"ext-mbstring": "*",
16+
"ext-openssl": "*",
17+
"ext-curl": "*",
18+
"ext-zip": "*",
19+
"ext-json": "*",
20+
"ext-exif": "*",
21+
"ext-apcu": "*",
22+
"ext-memcached": "*",
23+
"ext-redis": "*",
24+
"vlucas/phpdotenv": "^2.5"
25+
},
26+
"scripts": {
27+
"post-install-cmd": [
28+
"/bin/cp config/.env.prod config/.env"
29+
]
30+
},
31+
"prefer-stable": true,
32+
"config": {
33+
"sort-packages": true
34+
}
35+
}

composer.lock

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/.env.default

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Advanced PHP 7 eCommerce Website (https://22digital.agency)
4+
#
5+
# This file enables you to use environment variables to configure the aspects of
6+
# your application that vary by environment.
7+
#
8+
# In development .env files are parsed by PHP and set into the environment. This
9+
# provides a simpler development workflow over standard environment variables.
10+
#
11+
# This program is free software: you can redistribute it and/or modify
12+
# it under the terms of the GNU Affero General Public License as
13+
# published by the Free Software Foundation, either version 3 of the
14+
# License, or (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU Affero General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU Affero General Public License
22+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
23+
#
24+
# @copyright Copyright (c) 22 Digital (https://22digital.agency)
25+
# @copyright Copyright (c) Justin Hartman (https://justinhartman.blog)
26+
# @author Justin Hartman <justin@hartman.me> (https://justinhartman.blog)
27+
# @link https://github.com/justinhartman/complete-php7-ecom-website GitHub Project
28+
# @since 0.1.0
29+
# @license https://opensource.org/licenses/AGPL-3.0 AGPL-3.0
30+
31+
# Database configuration
32+
########################
33+
# export DB_HOST='localhost'
34+
# export DB_USERNAME='root'
35+
# export DB_PASSWORD=''
36+
# export DB_DATABASE='ecomphp'

config/.env.prod

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Advanced PHP 7 eCommerce Website (https://22digital.agency)
4+
#
5+
# This file enables you to use environment variables to configure the aspects of
6+
# your application that vary by environment.
7+
#
8+
# In development .env files are parsed by PHP and set into the environment. This
9+
# provides a simpler development workflow over standard environment variables.
10+
#
11+
# This program is free software: you can redistribute it and/or modify
12+
# it under the terms of the GNU Affero General Public License as
13+
# published by the Free Software Foundation, either version 3 of the
14+
# License, or (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU Affero General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU Affero General Public License
22+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
23+
#
24+
# @copyright Copyright (c) 22 Digital (https://22digital.agency)
25+
# @copyright Copyright (c) Justin Hartman (https://justinhartman.blog)
26+
# @author Justin Hartman <justin@hartman.me> (https://justinhartman.blog)
27+
# @link https://github.com/justinhartman/complete-php7-ecom-website GitHub Project
28+
# @since 0.1.0
29+
# @license https://opensource.org/licenses/AGPL-3.0 AGPL-3.0
30+
31+
# Database configuration
32+
########################
33+
# export DB_HOST='localhost'
34+
# export DB_USERNAME='root'
35+
# export DB_PASSWORD=''
36+
# export DB_DATABASE='ecomphp'

config/bootstrap.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Advanced PHP 7 eCommerce Website (https://22digital.agency)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @copyright Copyright (c) 22 Digital (https://22digital.agency)
19+
* @copyright Copyright (c) Justin Hartman (https://justinhartman.blog)
20+
* @author Justin Hartman <justin@hartman.me> (https://justinhartman.blog)
21+
* @link https://github.com/justinhartman/complete-php7-ecom-website GitHub Project
22+
* @since 0.1.0
23+
* @license https://opensource.org/licenses/AGPL-3.0 AGPL-3.0
24+
*/
25+
26+
/*
27+
* Configure paths required to find general filepath constants.
28+
*/
29+
require __DIR__ . '/paths.php';
30+
31+
/**
32+
* Include the composer autoloader.
33+
*/
34+
require VENDOR . 'autoload.php';
35+
36+
/**
37+
* To use `.env` file during development you should copy `config/.env.default`
38+
* to `config/.env` and set/modify the variables as required.
39+
*
40+
* Make sure that you also adjust the `config/.env.prod` file to your production
41+
* server's app specific details. When you install the app on a production
42+
* server, Composer copies this file to `config/.env` on post-install.
43+
*/
44+
if (file_exists(CONFIG . '.env')) {
45+
$dotenv = new Dotenv\Dotenv(CONFIG, '.env');
46+
$dotenv->load();
47+
// Check that the following variables have been defined.
48+
$dotenv->required(['DB_HOST', 'DB_USERNAME', 'DB_PASSWORD', 'DB_DATABASE']);
49+
}
50+
51+
/**
52+
* Start the session.
53+
*/
54+
session_start();
55+
56+
/**
57+
* Load the Database Connection.
58+
*/
59+
require_once CONFIG . 'connect.php';

0 commit comments

Comments
 (0)