Skip to content

Commit

Permalink
add change
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Oct 14, 2023
1 parent 98426e8 commit f6b0bc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "arrayaccess/traydigita",
"description": "Tray Digita System",
"version": "1.0.0",
"type": "project",
"license": "MIT",
"authors": [
Expand Down
26 changes: 17 additions & 9 deletions src/Bin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use ReflectionClass;
use Throwable;
use function chdir;
use function class_exists;
use function define;
Expand All @@ -35,10 +36,11 @@
use function realpath;
use function strlen;
use function substr;
use function var_dump;
use const DIRECTORY_SEPARATOR;
use const PHP_SAPI;
use const PHP_VERSION;
use const PHP_VERSION_ID;
use const TD_APP_DIRECTORY;
use const TD_ROOT_COMPOSER_DIR;

final class Bin
Expand All @@ -48,7 +50,12 @@ final private function __construct()
{
}

/** @noinspection PhpMissingReturnTypeInspection */
/**
* @noinspection PhpMissingReturnTypeInspection
* @noinspection PhpIssetCanBeReplacedWithCoalesceInspection
* @noinspection DuplicatedCode
* @throws Throwable
*/
final public static function run()
{
static $run = false;
Expand All @@ -66,7 +73,7 @@ final public static function run()
exit(255);
}

if (\PHP_VERSION_ID < 80200) {
if (PHP_VERSION_ID < 80200) {
echo "\n\033[0;31mPhp version is not meet requirements.\033[0m\n";
printf(
"\033[0;34mMinimum required php version is:\033[0m \033[0;33m%s\033[0m\n",
Expand Down Expand Up @@ -94,14 +101,15 @@ final public static function run()

if (class_exists(ClassLoader::class)) {
$classLoaderExists = true;
$exists = false;
$ref = new ReflectionClass(ClassLoader::class);
$vendor ??= dirname($ref->getFileName(), 2);
$vendor = $vendor?:dirname($ref->getFileName(), 2);
$v = $vendor;
$c = 3;
do {
$v = dirname($v);
} while (--$c > 0 && !($exists = file_exists($v . '/composer.json')));
$root = ($exists ?? false) ? $v : dirname($vendor);
$root = $exists ? $v : dirname($vendor);
$vendor = substr($vendor, strlen($root) + 1);
} else {
$root = dirname(__DIR__);
Expand All @@ -110,8 +118,8 @@ final public static function run()
if (is_file($root . '/composer.json')) {
$config = json_decode(file_get_contents($root . '/composer.json'), true);
$config = is_array($config) ? $config : [];
$config = $config['config'] ?? [];
$vendorDir = $config['vendor-dir'] ?? null;
$config = isset($config['config']) ? $config['config'] : [];
$vendorDir = isset($config['vendor-dir']) ? $config['vendor-dir'] : null;
if ($vendorDir && is_dir("$root/$vendorDir")) {
$vendor = $vendorDir;
}
Expand Down Expand Up @@ -153,14 +161,14 @@ final public static function run()
);
}

$appDir = $appDir ?? TD_ROOT_COMPOSER_DIR . DIRECTORY_SEPARATOR . 'app';
$appDir = isset($appDir) ? $appDir : TD_ROOT_COMPOSER_DIR . DIRECTORY_SEPARATOR . 'app';
/*if (!is_dir($appDir)) {
echo "\n\033[0;31mCould not detect application directory\033[0m\n";
echo "\n";
exit(255);
}*/
define('TD_APP_DIRECTORY', $appDir);
} elseif (!is_string(\TD_APP_DIRECTORY)) {
} elseif (!is_string(TD_APP_DIRECTORY)) {
echo "\n\033[0;31mConstant \033[0;0m`TD_APP_DIRECTORY`\033[0;31m is invalid\033[0m\n";
echo "\n";
exit(255);
Expand Down
3 changes: 1 addition & 2 deletions src/HttpKernel/Traits/HttpKernelServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ private function internalLoadController(
$kernel,
$this,
$router,
$route ?? null
$route ?? null
);
}
}
Expand Down Expand Up @@ -516,7 +516,6 @@ private function internalLoadMiddleware(
$kernel,
$this
);

} finally {
$manager?->dispatch(
'kernel.afterResolveMiddlewares',
Expand Down
18 changes: 11 additions & 7 deletions src/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use function substr;
use const DIRECTORY_SEPARATOR;
use const PHP_SAPI;
use const PHP_VERSION_ID;
use const TD_INDEX_FILE;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -68,6 +69,8 @@ final private function __construct()
/**
* @return ResponseInterface|false
* @noinspection PhpMissingReturnTypeInspection
* @noinspection PhpIssetCanBeReplacedWithCoalesceInspection
* @noinspection DuplicatedCode
*/
final public static function serve()
{
Expand All @@ -90,7 +93,7 @@ final public static function serve()
// START INIT EXCEPTION LISTENER
try {
// PHP VERSION MUST BE 8.2 OR LATER
if (\PHP_VERSION_ID < 80200) {
if (PHP_VERSION_ID < 80200) {
throw new RuntimeException(
"Php version is not meet requirement. Minimum required php version is: 8.2"
);
Expand All @@ -110,14 +113,15 @@ final public static function serve()

if (class_exists(ClassLoader::class)) {
$classLoaderExists = true;
$exists = false;
$ref = new ReflectionClass(ClassLoader::class);
$vendor ??= dirname($ref->getFileName(), 2);
$vendor = $vendor?:dirname($ref->getFileName(), 2);
$v = $vendor;
$c = 3;
do {
$v = dirname($v);
} while (--$c > 0 && !($exists = file_exists($v . '/composer.json')));
$root = ($exists ?? false) ? $v : dirname($vendor);
$root = $exists ? $v : dirname($vendor);
$vendor = substr($vendor, strlen($root) + 1);
} else {
$root = dirname(__DIR__);
Expand All @@ -126,8 +130,8 @@ final public static function serve()
if (is_file($root . '/composer.json')) {
$config = json_decode(file_get_contents($root . '/composer.json'), true);
$config = is_array($config) ? $config : [];
$config = $config['config'] ?? [];
$vendorDir = $config['vendor-dir'] ?? null;
$config = isset($config['config']) ? $config['config'] : [];
$vendorDir = isset($config['vendor-dir']) ? $config['vendor-dir'] : null;
if ($vendorDir && is_dir("$root/$vendorDir")) {
$vendor = $vendorDir;
}
Expand All @@ -142,8 +146,8 @@ final public static function serve()
);
}

$publicFile = null;
if (!defined('TD_INDEX_FILE')) {
$publicFile = null;
if (isset($_SERVER['SCRIPT_FILENAME'])) {
$publicFile = realpath($_SERVER['SCRIPT_FILENAME']);
}
Expand All @@ -164,7 +168,7 @@ final public static function serve()
'Public file does not exists!'
);
}
$publicFile ??= realpath(TD_INDEX_FILE);
$publicFile = $publicFile ?: realpath(TD_INDEX_FILE);
$publicDir = dirname($publicFile);
// HANDLE CLI-SERVER
if (php_sapi_name() === 'cli-server') {
Expand Down

0 comments on commit f6b0bc7

Please sign in to comment.