Browse Source

add multi-environment configuration support

main
ghost 1 year ago
parent
commit
073619b461
  1. 4
      .gitignore
  2. 5
      README.md
  3. 21
      src/config/bootstrap.php
  4. 14
      src/config/env.default.php
  5. 5
      src/crontab/export/feed.php
  6. 3
      src/crontab/export/push.php
  7. 6
      src/crontab/scrape.php
  8. 5
      src/crontab/sitemap.php
  9. 6
      src/public/action.php
  10. 6
      src/public/download.php
  11. 6
      src/public/edit.php
  12. 6
      src/public/faq.php
  13. 8
      src/public/index.php
  14. 8
      src/public/magnet.php
  15. 7
      src/public/node.php
  16. 6
      src/public/welcome.php

4
.gitignore vendored

@ -4,7 +4,9 @@
/database/yggtracker.mwb.bak /database/yggtracker.mwb.bak
/src/config/app.php /src/config/*.php
!/src/config/bootstrap.php
!/src/config/env.default.php
/src/public/api/manifest.json /src/public/api/manifest.json
/src/public/api/users.json /src/public/api/users.json

5
README.md

@ -24,7 +24,10 @@ Open trackers defined in [trackers.json](https://github.com/YGGverse/YGGtracker/
php8^ php8^
php-pdo php-pdo
php-mysql php-mysql
php-curl
php-memcached
sphinxsearch sphinxsearch
memcached
``` ```
#### Installation #### Installation
@ -37,7 +40,7 @@ sphinxsearch
* The web root dir is `/src/public` * The web root dir is `/src/public`
* Deploy the database using [MySQL Workbench](https://www.mysql.com/products/workbench) project presented in the `/database` folder * Deploy the database using [MySQL Workbench](https://www.mysql.com/products/workbench) project presented in the `/database` folder
* Install [Sphinx Search Server](https://sphinxsearch.com) * Install [Sphinx Search Server](https://sphinxsearch.com)
* Configuration examples presented at `/config` folder * Configuration examples presented at `/config` folder. When server environment not provided, setup `env.default.php`
* Make sure `/src/api` folder writable * Make sure `/src/api` folder writable
* Set up the `/src/crontab` by following [example](https://github.com/YGGverse/YGGtracker/blob/main/example/environment/crontab) * Set up the `/src/crontab` by following [example](https://github.com/YGGverse/YGGtracker/blob/main/example/environment/crontab)

21
src/config/bootstrap.php

@ -0,0 +1,21 @@
<?php
// PHP
declare(strict_types=1);
// Environment
if (!empty($_SERVER['PHP_ENV']) && file_exists(sprintf('%s/env.%s.php', __DIR__, $_SERVER['PHP_ENV'])))
{
require_once sprintf('%s/env.%s.php', __DIR__, $_SERVER['PHP_ENV']);
}
else require_once __DIR__ . '/env.default.php';
// Autoload
require_once __DIR__ . '/../../vendor/autoload.php';
// Local
require_once __DIR__ . '/../library/database.php';
require_once __DIR__ . '/../library/sphinx.php';
require_once __DIR__ . '/../library/scrapeer.php';
require_once __DIR__ . '/../library/time.php';

14
src/config/app.php.example → src/config/env.default.php

@ -23,8 +23,9 @@
* 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 example * Default configuration file
* Production name: app.php *
* 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
@ -33,9 +34,6 @@
* https://github.com/YGGverse/YGGtracker/issues * https://github.com/YGGverse/YGGtracker/issues
*/ */
// PHP
declare(strict_types=1);
// Debug // Debug
ini_set('display_errors', '1'); ini_set('display_errors', '1');
ini_set('display_startup_errors', '1'); ini_set('display_startup_errors', '1');
@ -52,6 +50,12 @@ define('DB_PASSWORD', '');
define('SPHINX_HOST', '127.0.0.1'); define('SPHINX_HOST', '127.0.0.1');
define('SPHINX_PORT', 9306); define('SPHINX_PORT', 9306);
// Memcached
define('MEMCACHED_PORT', 11211);
define('MEMCACHED_HOST', 'localhost');
define('MEMCACHED_NAMESPACE', 'yggtracker');
define('MEMCACHED_TIMEOUT', 60 * 5);
// Webapp // Webapp
define('WEBSITE_URL', ''); define('WEBSITE_URL', '');
define('WEBSITE_NAME', 'YGGtracker'); define('WEBSITE_NAME', 'YGGtracker');

5
src/crontab/export/feed.php

@ -8,9 +8,8 @@ if (false === sem_acquire($semaphore, true))
exit (PHP_EOL . 'yggtracker.crontab.export.feed process locked by another thread.' . PHP_EOL); exit (PHP_EOL . 'yggtracker.crontab.export.feed process locked by another thread.' . PHP_EOL);
} }
// Load system dependencies // Bootstrap
require_once(__DIR__ . '/../../config/app.php'); require_once __DIR__ . '/../../config/bootstrap.php';
require_once(__DIR__ . '/../../library/database.php');
// Init Debug // Init Debug
$debug = $debug =

3
src/crontab/export/push.php

@ -1,3 +1,6 @@
<?php <?php
// Bootstrap
require_once __DIR__ . '/../../config/bootstrap.php';
// @TODO implementation for active API sync using push notifications from memcache // @TODO implementation for active API sync using push notifications from memcache

6
src/crontab/scrape.php

@ -8,10 +8,8 @@ if (false === sem_acquire($semaphore, true)) {
exit (PHP_EOL . 'yggtracker.crontab.scrape process locked by another thread.' . PHP_EOL); exit (PHP_EOL . 'yggtracker.crontab.scrape process locked by another thread.' . PHP_EOL);
} }
// Load system dependencies // Bootstrap
require_once(__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once(__DIR__ . '/../library/database.php');
require_once(__DIR__ . '/../library/scrapeer.php');
// Init Debug // Init Debug
$debug = [ $debug = [

5
src/crontab/sitemap.php

@ -8,9 +8,8 @@ if (false === sem_acquire($semaphore, true)) {
exit (PHP_EOL . 'yggtracker.crontab.sitemap process locked by another thread.' . PHP_EOL); exit (PHP_EOL . 'yggtracker.crontab.sitemap process locked by another thread.' . PHP_EOL);
} }
// Load system dependencies // Bootstrap
require_once(__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once(__DIR__ . '/../library/database.php');
// Init Debug // Init Debug
$debug = [ $debug = [

6
src/public/action.php

@ -1,9 +1,7 @@
<?php <?php
// Load dependencies // Bootstrap
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect database // Connect database
try { try {

6
src/public/download.php

@ -1,9 +1,7 @@
<?php <?php
// Load dependencies // Bootstrap
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect database // Connect database
try { try {

6
src/public/edit.php

@ -1,9 +1,7 @@
<?php <?php
// Load dependencies // Bootstrap
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect database // Connect database
try { try {

6
src/public/faq.php

@ -1,10 +1,8 @@
<?php <?php
// Load dependencies // Bootstrap
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect database // Connect database
try { try {

8
src/public/index.php

@ -1,11 +1,7 @@
<?php <?php
// Load dependencies // Bootstrap dependencies
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/sphinx.php');
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../library/time.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect Sphinx // Connect Sphinx
try { try {

8
src/public/magnet.php

@ -1,11 +1,7 @@
<?php <?php
// Load dependencies // Bootstrap
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/sphinx.php');
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../library/time.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect Sphinx // Connect Sphinx
try { try {

7
src/public/node.php

@ -1,11 +1,8 @@
<?php <?php
// Load dependencies // Bootstrap
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/time.php');
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect database // Connect database
try { try {

6
src/public/welcome.php

@ -1,10 +1,8 @@
<?php <?php
// Load dependencies // Bootstrap
require_once (__DIR__ . '/../config/app.php'); require_once __DIR__ . '/../config/bootstrap.php';
require_once (__DIR__ . '/../library/database.php');
require_once (__DIR__ . '/../../vendor/autoload.php');
// Connect database // Connect database
try { try {

Loading…
Cancel
Save