-
Notifications
You must be signed in to change notification settings - Fork 8
Refactors #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Refactors #29
Changes from 51 commits
03c44ad
86250f9
d2bb4c3
16fbe8f
81dfe72
83bcc1c
3c26c75
6844c95
8dce425
19d1d5a
294ed2d
c045a59
75e8a9e
fac2984
1ae39b4
fa09cc3
10a22a5
7245c72
7608763
08955d2
6f5d0cc
e3d92c5
d36fc8b
31cf17f
e7a3ac2
a319e99
c46a506
d7b7b5a
c1c3d05
76abc35
d63d2df
dfafd26
568b234
30d7038
eab7601
e240bb0
101fbac
f343b80
ffaa83a
56cea79
4dddbe1
da82b9e
3a4e624
edea803
fe292fb
f1a24db
00f736c
4a028c3
d7005be
54d6b75
b65d78f
af4d9de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ app/cache/ | |
*.sublime-* | ||
biome.* | ||
.runway-config.json | ||
apm.db* | ||
apm.db* | ||
apm_fallback.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,30 +6,32 @@ | |
* for every request made to the application. | ||
*/ | ||
|
||
$ds = DIRECTORY_SEPARATOR; | ||
require_once __DIR__ . $ds . '..' . $ds . '..' . $ds . 'vendor' . $ds . 'autoload.php'; | ||
use app\utils\CustomEngine; | ||
use app\utils\SwooleServerDriver; | ||
use flight\Container; | ||
use flight\Engine; | ||
|
||
if (file_exists(__DIR__ . $ds . 'config.php') === false) { | ||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
if (!file_exists(__DIR__ . '/config.php')) { | ||
Flight::halt(500, 'Config file not found. Please create a config.php file in the app/config directory to get started.'); | ||
} | ||
|
||
// this has to be hard code required because autoload hasn't been registered yet. | ||
require_once __DIR__ . $ds . '..' . $ds . 'utils' . $ds . 'CustomFlight.php'; | ||
|
||
// It is better practice to not use static methods for everything. It makes your | ||
// app much more difficult to unit test easily. | ||
$app = Flight::app(); | ||
$app = Container::getInstance()->get(CustomEngine::class); | ||
Flight::setEngine($app); | ||
|
||
/* | ||
* Load the config file | ||
* P.S. When you require a php file and that file returns an array, the array | ||
* will be returned by the require statement where you can assign it to a var. | ||
*/ | ||
$config = require __DIR__ . $ds . 'config.php'; | ||
$app->set('config', $config); | ||
$config = require __DIR__ . '/config.php'; | ||
Flight::set('config', $config); | ||
|
||
// Whip out the ol' router and we'll pass that to the routes file | ||
$router = $app->router(); | ||
$router = Flight::router(); | ||
|
||
/* | ||
* Load the routes file. the $router variable above is passed into the routes.php | ||
|
@@ -38,7 +40,7 @@ | |
* When someone hits that URL, you point them to a function or method | ||
* that will handle the request. | ||
*/ | ||
require_once __DIR__ . $ds . 'routes.php'; | ||
require_once __DIR__ . '/routes.php'; | ||
|
||
/* | ||
* You additionally could just define the routes in this file. It's up to you. | ||
|
@@ -55,33 +57,40 @@ | |
* Need caching? You can setup a Redis service | ||
* Need to send email? You can setup a mailgun/sendgrid/whatever service to send emails. | ||
* Need to send SMS? You can setup a Twilio service. | ||
* | ||
* | ||
* All the services and how they are configured are setup in the services file. | ||
* In many cases, services are all attached to something called a "services container" | ||
* or more simply, a "container". The container manages if you should share the same | ||
* service, or if you should create a new instance of the service every time you need it. | ||
* That's a discussion for another day. Suffice to say, that Flight has a basic concept | ||
* of a services container by registering classes to the Engine class. | ||
*/ | ||
require_once __DIR__ . $ds . 'services.php'; | ||
require_once __DIR__ . '/services.php'; | ||
|
||
// At this point, your app should have all the instructions it needs and it'll | ||
// "start" processing everything. This is where the magic happens. | ||
|
||
// This is where swoole will start listening for requests and processing them. | ||
if(!defined("NOT_SWOOLE")) { | ||
// Require the SwooleServerDriver class since we're running in Swoole mode. | ||
require_once(__DIR__.'/../utils/SwooleServerDriver.php'); | ||
if (!defined("NOT_SWOOLE")) { | ||
if (!class_exists('Swoole\Runtime')) { | ||
throw new Exception('Swoole is not installed. Please install Swoole or define the NOT_SWOOLE constant in public/index.php to run without Swoole.'); | ||
} | ||
|
||
call_user_func('Swoole\Runtime', 'enableCoroutine'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this better than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LSP-intelephense shows me an error because Swoole classes aren't recognized There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather go for end user readability than making an LSP error go away. This just raises questions as to why it's call_user_func() like is there some hidden functionality with it that the user isn't aware of. |
||
|
||
$swooleServerDriver = new SwooleServerDriver( | ||
'127.0.0.1', | ||
9501, | ||
Container::getInstance()->get(Engine::class) | ||
); | ||
|
||
Swoole\Runtime::enableCoroutine(); | ||
$Swoole_Server = new app\utils\SwooleServerDriver('127.0.0.1', 9501, $app); | ||
$Swoole_Server->start(); | ||
$swooleServerDriver->start(); | ||
} else { | ||
$app->start(); | ||
Flight::start(); | ||
} | ||
/* | ||
.----..---. .--. .----. .---. .---. .-. .-. .--. .---. .----. .-. .-..----. .----..-. .-. | ||
{ {__ {_ _}/ {} \ | {} }{_ _} {_ _}| {_} | / {} \{_ _} | {} }| { } || {} }| {} }\ \/ / | ||
.-._} } | | / /\ \| .-. \ | | | | | { } |/ /\ \ | | | .--' | {_} || .--' | .--' } { | ||
`----' `-' `-' `-'`-' `-' `-' `-' `-' `-'`-' `-' `-' `-' `-----'`-' `-' `--' | ||
{ {__ {_ _}/ {} \ | {} }{_ _} {_ _}| {_} | / {} \{_ _} | {} }| { } || {} }| {} }\ \/ / | ||
.-._} } | | / /\ \| .-. \ | | | | | { } |/ /\ \ | | | .--' | {_} || .--' | .--' } { | ||
`----' `-' `-' `-'`-' `-' `-' `-' `-' `-'`-' `-' `-' `-' `-----'`-' `-' `--' | ||
*/ |
Uh oh!
There was an error while loading. Please reload this page.