Browse Source

auto-init environment configuration file

main
ghost 1 year ago
parent
commit
e9adc780ad
  1. 2
      .gitignore
  2. 26
      src/config/bootstrap.php
  3. 4
      src/config/env.example.php

2
.gitignore vendored

@ -6,7 +6,7 @@
/src/config/*.php /src/config/*.php
!/src/config/bootstrap.php !/src/config/bootstrap.php
!/src/config/env.default.php !/src/config/env.example.php
/src/public/api/manifest.json /src/public/api/manifest.json
/src/public/api/users.json /src/public/api/users.json

26
src/config/bootstrap.php

@ -3,19 +3,29 @@
// PHP // PHP
declare(strict_types=1); declare(strict_types=1);
// Environment // Init environment
if (!empty($_SERVER['PHP_ENV']) && file_exists(sprintf('%s/env.%s.php', __DIR__, $_SERVER['PHP_ENV']))) if (empty($_SERVER['PHP_ENV']))
{ {
require_once sprintf('%s/env.%s.php', __DIR__, $_SERVER['PHP_ENV']); $_SERVER['PHP_ENV'] = 'default';
} }
else require_once __DIR__ . '/env.default.php'; // Generate configuration file if not exists
if (!file_exists(sprintf('%s/env.%s.php', __DIR__, $_SERVER['PHP_ENV'])))
{
copy(
__DIR__ . '/env.example.php',
sprintf('%s/env.%s.php', __DIR__, $_SERVER['PHP_ENV'])
);
}
// Autoload // Load environment configuration
require_once __DIR__ . '/../../vendor/autoload.php'; require_once sprintf('%s/env.%s.php', __DIR__, $_SERVER['PHP_ENV']);
// Local // Local internal dependencies
require_once __DIR__ . '/../library/database.php'; require_once __DIR__ . '/../library/database.php';
require_once __DIR__ . '/../library/sphinx.php'; require_once __DIR__ . '/../library/sphinx.php';
require_once __DIR__ . '/../library/scrapeer.php'; require_once __DIR__ . '/../library/scrapeer.php';
require_once __DIR__ . '/../library/time.php'; require_once __DIR__ . '/../library/time.php';
// Vendors autoload
require_once __DIR__ . '/../../vendor/autoload.php';

4
src/config/env.default.php → src/config/env.example.php

@ -23,10 +23,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
* *
* Default configuration file
*
* For different environments, use separated env.NAME.php files
*
* Project home page * Project home page
* https://github.com/YGGverse/YGGtracker * https://github.com/YGGverse/YGGtracker
* *
Loading…
Cancel
Save