Skip to content

Commit

Permalink
Update & Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
localzet committed Apr 19, 2024
1 parent 14fd815 commit b00d6ec
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 38 deletions.
5 changes: 1 addition & 4 deletions .idea/Web.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

return [
'listen' => 'http://0.0.0.0:88',
'listen' => 'http://0.0.0.0:8000',
'transport' => 'tcp',
'context' => [],
'name' => 'Triangle',
Expand Down
40 changes: 30 additions & 10 deletions master
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,57 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use support\Container;
use Triangle\Console;
use Triangle\Console\Util;
use Triangle\Engine\Config;

require_once __DIR__ . '/vendor/autoload.php';

if (!in_array($argv[1] ?? '', ['start', 'restart', 'stop', 'status', 'reload', 'connections'])) {
require_once __DIR__ . '/support/bootstrap.php';
} else {
if (class_exists('support\App')) {
support\App::loadAllConfig(['route']);
if (class_exists('Support\App')) {
Support\App::loadAllConfig(['route']);
} else {
Config::load(config_path(), ['route', 'container']);
}
}

$cli = new Console();
$cli->setName('Triangle CLI');
if (is_dir($command_path = app_path('command'))) {
$cli->installInternalCommands();
if (is_dir($command_path = Util::guessPath(app_path(), '/command', true))) {
$cli->installCommands($command_path);
}

foreach (config('plugin', []) as $firm => $projects) {
if (config("plugin.$firm.app", false)) continue;
if (isset($projects['app'])) {
if ($command_str = Util::guessPath(base_path() . "/plugin/$firm", 'command')) {
$command_path = base_path() . "/plugin/$firm/$command_str";
$cli->installCommands($command_path, "plugin\\$firm\\$command_str");
}
}
foreach ($projects as $name => $project) {
foreach ($project['command'] ?? [] as $command) {
$cli->add(new $command);
if (!is_array($project)) {
continue;
}
foreach ($project['command'] ?? [] as $class_name) {
$reflection = new ReflectionClass($class_name);
if ($reflection->isAbstract()) {
continue;
}
$properties = $reflection->getStaticProperties();
$name = $properties['defaultName'];
if (!$name) {
throw new RuntimeException("Command {$class_name} has no defaultName");
}
$description = $properties['defaultDescription'] ?? '';
$command = Container::get($class_name);
$command->setName($name)->setDescription($description);
$cli->add($command);
}
}
}

try {
$cli->run();
} catch (Exception $e) {
}
$cli->run();
18 changes: 10 additions & 8 deletions support/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

/**
* @package Triangle Engine (FrameX Project)
* @link https://github.com/localzet/FrameX FrameX Project v1-2
* @link https://github.com/Triangle-org/Engine Triangle Engine v2+
* @package Triangle Engine
* @link https://github.com/Triangle-org/Engine Triangle Engine (v2+)
* @link https://github.com/localzet-archive/FrameX-Public FrameX (v1-2)
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2018-2024 Localzet Group
* @license https://www.gnu.org/licenses/agpl AGPL-3.0 license
* @copyright Copyright (c) 2018-2024 Zorin Projects S.P.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand All @@ -21,6 +21,8 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* For any questions, please contact <creator@localzet.com>
*/

use Dotenv\Dotenv;
Expand Down
26 changes: 15 additions & 11 deletions support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use localzet\Server\Connection\TcpConnection;
use localzet\Server\Protocols\Http\Session;
use support\Container;
use support\Env;
use support\Response;
use support\Translation;
use Triangle\Engine\App;
Expand Down Expand Up @@ -79,14 +80,7 @@ function response(mixed $body = '', int $status = 200, array $headers = [], bool
*/
function responseBlob(string $blob, string $type = 'image/png'): Response
{
return new Response(
200,
[
'Content-Type' => $type,
'Content-Length' => strlen($blob)
],
$blob
);
return new Response(200, ['Content-Type' => $type], $blob);
}

/**
Expand Down Expand Up @@ -451,14 +445,24 @@ function locale(string $locale = null): string

/**
* @param string|null $key
* @param $default
* @return array|mixed|null
* * @param mixed|null $default
* @return mixed
*/
function config(string $key = null, $default = null): mixed
function config(string $key = null, mixed $default = null): mixed
{
return Config::get($key, $default);
}

/**
* @param string|null $key
* @param mixed|null $default
* @return mixed
*/
function env(string $key = null, mixed $default = null): mixed
{
return Env::get($key, $default);
}

/**
* @return TcpConnection|null
*/
Expand Down

0 comments on commit b00d6ec

Please sign in to comment.