Author: Shivam Mathur (shivammathur)
Date: 2024-10-07T20:15:00+05:30
Commit: Remove env support and use getenv directly · php/web-downloads@c61433a · GitHub
Raw diff: https://github.com/php/web-downloads/commit/c61433a73612c02115e8ed8e535e4379de4a0642.diff
Remove env support and use getenv directly
Environment variables will be configured directly in the Apache config, so we do not need .env file
Changed paths:
D .env.example
D .gitignore
D composer.json
D composer.lock
M README.md
M bootstrap.php
M public/index.php
M src/Auth.php
M src/PeclHandler.php
M src/PhpHandler.php
M src/WinlibsHandler.php
Diff:
diff --git a/.env.example b/.env.example
deleted file mode 100644
index 68c7f6f..0000000
--- a/.env.example
+++ /dev/null
@@ -1,2 +0,0 @@
-AUTH_TOKEN=
-BUILDS_DIRECTORY=
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 3d5163b..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/vendor/
-.env
diff --git a/README.md b/README.md
index 0254061..3d2cf3c 100644
--- a/README.md
+++ b/README.md
@@ -4,14 +4,6 @@ This project is a collection of scripts to handle downloading builds to the down
## Set up
-- Copy `env.example` to `.env` and set the `AUTH_TOKEN` and `BUILDS_DIRECTORY` values.
-
-- Install dependencies.
-
-```bash
-composer install
-```
-
- Set up a virtual host in Apache to point to the `public` directory as the `DocumentRoot`.
- Set up the `ErrorDocument` for 404 to point to `public/redirect.php` in the virtual host configuration.
diff --git a/bootstrap.php b/bootstrap.php
index 54248d2..4c219e9 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -1,10 +1,3 @@
<?php
-require_once __DIR__.'/vendor/autoload.php';
-
-use Dotenv\Dotenv;
-
-$dotenv = Dotenv::createImmutable(__DIR__);
-$dotenv->load();
-
require_once __DIR__.'/routes.php';
diff --git a/composer.json b/composer.json
deleted file mode 100644
index d5eb926..0000000
--- a/composer.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "name": "php/web-downloads",
- "description": "Scripts for downloads.php.net",
- "type": "project",
- "license": "MIT",
- "autoload": {
- "psr-4": {
- "App\\": "src/"
- }
- },
- "require": {
- "php": "^8.2",
- "vlucas/phpdotenv": "^5.6.1",
- "ext-curl": "*",
- "ext-zip": "*",
- "ext-fileinfo": "*"
- }
-}
diff --git a/composer.lock b/composer.lock
deleted file mode 100644
index f354f58..0000000
--- a/composer.lock
+++ /dev/null
@@ -1,484 +0,0 @@
-{
- "_readme": [
- "This file locks the dependencies of your project to a known state",
- "Read more about it at Basic usage - Composer,
- "This file is @generated automatically"
- ],
- "content-hash": "86fdb4a7f08015412baf414833597905",
- "packages": [
- {
- "name": "graham-campbell/result-type",
- "version": "v1.1.3",
- "source": {
- "type": "git",
- "url": "https://github.com/GrahamCampbell/Result-Type.git",
- "reference": "3ba905c11371512af9d9bdd27d99b782216b6945"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/3ba905c11371512af9d9bdd27d99b782216b6945",
- "reference": "3ba905c11371512af9d9bdd27d99b782216b6945",
- "shasum": ""
- },
- "require": {
- "php": "^7.2.5 || ^8.0",
- "phpoption/phpoption": "^1.9.3"
- },
- "require-dev": {
- "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "GrahamCampbell\\ResultType\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Graham Campbell",
- "email": "hello@gjcampbell.co.uk",
- "homepage": "https://github.com/GrahamCampbell"
- }
- ],
- "description": "An Implementation Of The Result Type",
- "keywords": [
- "Graham Campbell",
- "GrahamCampbell",
- "Result Type",
- "Result-Type",
- "result"
- ],
- "support": {
- "issues": "https://github.com/GrahamCampbell/Result-Type/issues",
- "source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.1.3"
- },
- "funding": [
- {
- "url": "https://github.com/GrahamCampbell",
- "type": "github"
- },
- {
- "url": "How to connect Tidelift with GitHub | Tidelift,
- "type": "tidelift"
- }
- ],
- "time": "2024-07-20T21:45:45+00:00"
- },
- {
- "name": "phpoption/phpoption",
- "version": "1.9.3",
- "source": {
- "type": "git",
- "url": "https://github.com/schmittjoh/php-option.git",
- "reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/e3fac8b24f56113f7cb96af14958c0dd16330f54",
- "reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54",
- "shasum": ""
- },
- "require": {
- "php": "^7.2.5 || ^8.0"
- },
- "require-dev": {
- "bamarni/composer-bin-plugin": "^1.8.2",
- "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
- },
- "type": "library",
- "extra": {
- "bamarni-bin": {
- "bin-links": true,
- "forward-command": false
- },
- "branch-alias": {
- "dev-master": "1.9-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "PhpOption\\": "src/PhpOption/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "Apache-2.0"
- ],
- "authors": [
- {
- "name": "Johannes M. Schmitt",
- "email": "schmittjoh@gmail.com",
- "homepage": "https://github.com/schmittjoh"
- },
- {
- "name": "Graham Campbell",
- "email": "hello@gjcampbell.co.uk",
- "homepage": "https://github.com/GrahamCampbell"
- }
- ],
- "description": "Option Type for PHP",
- "keywords": [
- "language",
- "option",
- "php",
- "type"
- ],
- "support": {
- "issues": "https://github.com/schmittjoh/php-option/issues",
- "source": "https://github.com/schmittjoh/php-option/tree/1.9.3"
- },
- "funding": [
- {
- "url": "https://github.com/GrahamCampbell",
- "type": "github"
- },
- {
- "url": "How to connect Tidelift with GitHub | Tidelift,
- "type": "tidelift"
- }
- ],
- "time": "2024-07-20T21:41:07+00:00"
- },
- {
- "name": "symfony/polyfill-ctype",
- "version": "v1.30.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/polyfill-ctype.git",
- "reference": "0424dff1c58f028c451efff2045f5d92410bd540"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540",
- "reference": "0424dff1c58f028c451efff2045f5d92410bd540",
- "shasum": ""
- },
- "require": {
- "php": ">=7.1"
- },
- "provide": {
- "ext-ctype": "*"
- },
- "suggest": {
- "ext-ctype": "For best performance"
- },
- "type": "library",
- "extra": {
- "thanks": {
- "name": "symfony/polyfill",
- "url": "https://github.com/symfony/polyfill"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ],
- "psr-4": {
- "Symfony\\Polyfill\\Ctype\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Gert de Pagter",
- "email": "BackEndTea@gmail.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony polyfill for ctype functions",
- "homepage": "https://symfony.com",
- "keywords": [
- "compatibility",
- "ctype",
- "polyfill",
- "portable"
- ],
- "support": {
- "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "How to connect Tidelift with GitHub | Tidelift,
- "type": "tidelift"
- }
- ],
- "time": "2024-05-31T15:07:36+00:00"
- },
- {
- "name": "symfony/polyfill-mbstring",
- "version": "v1.30.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/polyfill-mbstring.git",
- "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c",
- "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c",
- "shasum": ""
- },
- "require": {
- "php": ">=7.1"
- },
- "provide": {
- "ext-mbstring": "*"
- },
- "suggest": {
- "ext-mbstring": "For best performance"
- },
- "type": "library",
- "extra": {
- "thanks": {
- "name": "symfony/polyfill",
- "url": "https://github.com/symfony/polyfill"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ],
- "psr-4": {
- "Symfony\\Polyfill\\Mbstring\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Nicolas Grekas",
- "email": "p@tchwork.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony polyfill for the Mbstring extension",
- "homepage": "https://symfony.com",
- "keywords": [
- "compatibility",
- "mbstring",
- "polyfill",
- "portable",
- "shim"
- ],
- "support": {
- "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "How to connect Tidelift with GitHub | Tidelift,
- "type": "tidelift"
- }
- ],
- "time": "2024-06-19T12:30:46+00:00"
- },
- {
- "name": "symfony/polyfill-php80",
- "version": "v1.30.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/polyfill-php80.git",
- "reference": "77fa7995ac1b21ab60769b7323d600a991a90433"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433",
- "reference": "77fa7995ac1b21ab60769b7323d600a991a90433",
- "shasum": ""
- },
- "require": {
- "php": ">=7.1"
- },
- "type": "library",
- "extra": {
- "thanks": {
- "name": "symfony/polyfill",
- "url": "https://github.com/symfony/polyfill"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ],
- "psr-4": {
- "Symfony\\Polyfill\\Php80\\": ""
- },
- "classmap": [
- "Resources/stubs"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Ion Bazan",
- "email": "ion.bazan@gmail.com"
- },
- {
- "name": "Nicolas Grekas",
- "email": "p@tchwork.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
- "homepage": "https://symfony.com",
- "keywords": [
- "compatibility",
- "polyfill",
- "portable",
- "shim"
- ],
- "support": {
- "source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "How to connect Tidelift with GitHub | Tidelift,
- "type": "tidelift"
- }
- ],
- "time": "2024-05-31T15:07:36+00:00"
- },
- {
- "name": "vlucas/phpdotenv",
- "version": "v5.6.1",
- "source": {
- "type": "git",
- "url": "https://github.com/vlucas/phpdotenv.git",
- "reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/a59a13791077fe3d44f90e7133eb68e7d22eaff2",
- "reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2",
- "shasum": ""
- },
- "require": {
- "ext-pcre": "*",
- "graham-campbell/result-type": "^1.1.3",
- "php": "^7.2.5 || ^8.0",
- "phpoption/phpoption": "^1.9.3",
- "symfony/polyfill-ctype": "^1.24",
- "symfony/polyfill-mbstring": "^1.24",
- "symfony/polyfill-php80": "^1.24"
- },
- "require-dev": {
- "bamarni/composer-bin-plugin": "^1.8.2",
- "ext-filter": "*",
- "phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
- },
- "suggest": {
- "ext-filter": "Required to use the boolean validator."
- },
- "type": "library",
- "extra": {
- "bamarni-bin": {
- "bin-links": true,
- "forward-command": false
- },
- "branch-alias": {
- "dev-master": "5.6-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Dotenv\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Graham Campbell",
- "email": "hello@gjcampbell.co.uk",
- "homepage": "https://github.com/GrahamCampbell"
- },
- {
- "name": "Vance Lucas",
- "email": "vance@vancelucas.com",
- "homepage": "https://github.com/vlucas"
- }
- ],
- "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
- "keywords": [
- "dotenv",
- "env",
- "environment"
- ],
- "support": {
- "issues": "https://github.com/vlucas/phpdotenv/issues",
- "source": "https://github.com/vlucas/phpdotenv/tree/v5.6.1"
- },
- "funding": [
- {
- "url": "https://github.com/GrahamCampbell",
- "type": "github"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
- "type": "tidelift"
- }
- ],
- "time": "2024-07-20T21:52:34+00:00"
- }
- ],
- "packages-dev": ,
- "aliases": ,
- "minimum-stability": "stable",
- "stability-flags": ,
- "prefer-stable": false,
- "prefer-lowest": false,
- "platform": {
- "php": "^8.2",
- "ext-curl": "*",
- "ext-zip": "*",
- "ext-fileinfo": "*"
- },
- "platform-dev": ,
- "plugin-api-version": "2.6.0"
-}
diff --git a/public/index.php b/public/index.php
index f2fe731..5882b78 100644
--- a/public/index.php
+++ b/public/index.php
@@ -1,7 +1,4 @@
<?php
-// Register the Composer autoloader...
-require_once __DIR__.'/../vendor/autoload.php';
-
// Init
require_once __DIR__ . '/../bootstrap.php';
diff --git a/src/Auth.php b/src/Auth.php
index 26dd4b6..1ade3e1 100644
--- a/src/Auth.php
+++ b/src/Auth.php
@@ -9,6 +9,6 @@ public function authenticate(): bool
$authHeader = $_SERVER['HTTP_AUTHORIZATION'] ?? '';
$authToken = str_replace('Bearer ', '', $authHeader);
- return $authToken === $_ENV['AUTH_TOKEN'];
+ return $authToken === getenv('AUTH_TOKEN');
}
}
diff --git a/src/PeclHandler.php b/src/PeclHandler.php
index 03bb7eb..4329f45 100644
--- a/src/PeclHandler.php
+++ b/src/PeclHandler.php
@@ -51,7 +51,7 @@ private function fetchExtension(string $extension, string $ref, string $url, str
throw new Exception('Failed to fetch the extension');
}
- $destinationDirectory = $_ENV['BUILDS_DIRECTORY'] . "/pecl/releases";
+ $destinationDirectory = getenv('BUILDS_DIRECTORY') . "/pecl/releases";
if(!is_dir($destinationDirectory)) {
mkdir($destinationDirectory, 0755, true);
diff --git a/src/PhpHandler.php b/src/PhpHandler.php
index 1c02964..7c9a1d0 100644
--- a/src/PhpHandler.php
+++ b/src/PhpHandler.php
@@ -85,7 +85,7 @@ private function getDestinationDirectory(string $tempDirectory): string
$testPackFile = basename(glob($tempDirectory . '/php-test-pack-*.zip')[0]);
$testPackFileName = str_replace('.zip', '', $testPackFile);
$version = explode('-', $testPackFileName)[3];
- return $_ENV['BUILDS_DIRECTORY'] . (preg_match('/^\d+\.\d+\.\d+$/', $version) ? '/releases' : '/qa');
+ return getenv('BUILDS_DIRECTORY') . (preg_match('/^\d+\.\d+\.\d+$/', $version) ? '/releases' : '/qa');
}
/**
@@ -177,7 +177,7 @@ private function generateListing(string $directory): void
}
$this->updateReleasesJson($releases, $directory);
- if($directory === $_ENV['BUILDS_DIRECTORY'] . '/releases') {
+ if($directory === getenv('BUILDS_DIRECTORY') . '/releases') {
$this->updateLatestBuilds($releases, $directory);
}
}
diff --git a/src/WinlibsHandler.php b/src/WinlibsHandler.php
index d7177ac..4625c10 100644
--- a/src/WinlibsHandler.php
+++ b/src/WinlibsHandler.php
@@ -61,7 +61,7 @@ private function parseFiles(array $files): array
private function copyFiles(array $files, $library, $ref, $vs_version_targets): void
{
- $baseDirectory = $_ENV['BUILDS_DIRECTORY'] . "/php-sdk/deps";
+ $baseDirectory = getenv('BUILDS_DIRECTORY') . "/php-sdk/deps";
if(!is_dir($baseDirectory)) {
mkdir($baseDirectory, 0755, true);
}
@@ -81,7 +81,7 @@ private function updateSeriesFiles($files, $library, $ref, $php_versions, $vs_ve
$vs_version_targets = explode(',', $vs_version_targets);
$stability_values = explode(',', $stability);
- $baseDirectory = $_ENV['BUILDS_DIRECTORY'] . "/php-sdk/deps/series";
+ $baseDirectory = getenv('BUILDS_DIRECTORY') . "/php-sdk/deps/series";
foreach ($php_versions as $php_version) {
foreach ($vs_version_targets as $vs_version_target) {