-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from nox7/2.0.0
2.0.0
- Loading branch information
Showing
52 changed files
with
1,311 additions
and
886 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
<?php | ||
require_once __DIR__ . "/../../vendor/autoload.php"; | ||
require_once __DIR__ . "/../nox-env.php"; | ||
|
||
use \Nox\ORM\Abyss; | ||
use Nox\ClassLoader\ClassLoader; | ||
use Nox\Nox; | ||
use Nox\ORM\Abyss; | ||
use Nox\ORM\DatabaseCredentials; | ||
|
||
// Load the source directory | ||
$nox = new Nox(); | ||
$nox->setSourceCodeDirectory(__DIR__ . "/../src"); | ||
|
||
// Get the model reflections | ||
$modelReflections = ClassLoader::$modelClassReflections; | ||
|
||
// Load the credentials for any and all databases used by the models | ||
Abyss::addCredentials(new DatabaseCredentials( | ||
host: NoxEnv::MYSQL_HOST, | ||
username: NoxEnv::MYSQL_USERNAME, | ||
password: NoxEnv::MYSQL_PASSWORD, | ||
database: NoxEnv::MYSQL_DB_NAME, | ||
port: NoxEnv::MYSQL_PORT, | ||
)); | ||
|
||
// Setup Abyss from this directory. | ||
// This is only necessary when not being used with the Router | ||
// such as from CLI (this script) or on its own | ||
Abyss::loadConfig(__DIR__ . "/.."); | ||
$abyss = new Abyss(); | ||
|
||
// Sync the models to the current local MySQL database | ||
$abyss->syncModels(); | ||
print("Synchronizing Models to MySQL database.\n"); | ||
$abyss->syncModels($modelReflections); | ||
print("Synchronization finished.\n"); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,74 @@ | ||
<?php | ||
|
||
use Nox\Nox; | ||
use Nox\ORM\Abyss; | ||
use Nox\ORM\DatabaseCredentials; | ||
use Nox\Router\BaseController; | ||
use Nox\Router\Exceptions\NoMatchingRoute; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
require_once __DIR__ . "/nox-env.php"; | ||
|
||
$requestPath = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); | ||
$requestMethod = $_SERVER['REQUEST_METHOD']; | ||
$nox = new Nox(); | ||
BaseController::$noxInstance = $nox; | ||
|
||
// Load the router | ||
$router = new Nox\Router\Router( | ||
requestPath:$requestPath, | ||
requestMethod:$requestMethod, | ||
); | ||
$router->loadAll( | ||
fromDirectory: __DIR__, | ||
// Set a static file serving directory | ||
$nox->addStaticDirectory( | ||
uriStub: "/", | ||
directoryPath: __DIR__ . "/resources/static", | ||
); | ||
|
||
// Load the Abyss ORM configuration | ||
// Comment this out to disable using Abyss and require a MySQL connection | ||
Abyss::loadConfig(__DIR__); | ||
// Support static file mime types so the browser can recognize the static files | ||
$nox->mapExtensionToMimeType("css", "text/css"); | ||
$nox->mapExtensionToMimeType("map", "text/plain"); | ||
$nox->mapExtensionToMimeType("png", "image/png"); | ||
$nox->mapExtensionToMimeType("jpg", "image/jpeg"); | ||
$nox->mapExtensionToMimeType("jpeg", "image/jpeg"); | ||
$nox->mapExtensionToMimeType("js", "text/javascript"); | ||
$nox->mapExtensionToMimeType("mjs", "text/javascript"); | ||
$nox->mapExtensionToMimeType("gif", "image/gif"); | ||
$nox->mapExtensionToMimeType("weba", "audio/webm"); | ||
$nox->mapExtensionToMimeType("webm", "video/webm"); | ||
$nox->mapExtensionToMimeType("webp", "image/webp"); | ||
$nox->mapExtensionToMimeType("pdf", "application/pdf"); | ||
$nox->mapExtensionToMimeType("svg", "image/svg+xml"); | ||
|
||
// Mime caches | ||
$nox->addCacheTimeForMime("image/png", 86400 * 60); | ||
$nox->addCacheTimeForMime("image/jpeg", 86400 * 60); | ||
$nox->addCacheTimeForMime("text/css", 86400 * 60); | ||
$nox->addCacheTimeForMime("text/plain", 86400 * 60); | ||
$nox->addCacheTimeForMime("text/javascript", 86400 * 60); | ||
$nox->addCacheTimeForMime("text/gif", 86400 * 60); | ||
$nox->addCacheTimeForMime("text/svg", 86400 * 60); | ||
$nox->addCacheTimeForMime("image/webp", 86400 * 60); | ||
|
||
// Process static files before anything else, to keep static file serving fast | ||
$nox->router->processRequestAsStaticFile(); | ||
|
||
// If the code gets here, then it's not a static file. Load the rest of the setting directories | ||
$nox->setViewsDirectory(__DIR__ . "/resources/views"); | ||
$nox->setLayoutsDirectory(__DIR__ . "/resources/layouts"); | ||
$nox->setSourceCodeDirectory(__DIR__ . "/src"); | ||
|
||
// Load the request handler | ||
$requestHandler = new \Nox\Router\RequestHandler($router); | ||
\Nox\Router\BaseController::$requestHandler = $requestHandler; | ||
// Setup the Abyss ORM (MySQL ORM) | ||
// Comment the Abyss credentials out if you do not need MySQL | ||
// Multiple credentials can be added if you have multiple databases/schemas | ||
Abyss::addCredentials(new DatabaseCredentials( | ||
host: NoxEnv::MYSQL_HOST, | ||
username: NoxEnv::MYSQL_USERNAME, | ||
password: NoxEnv::MYSQL_PASSWORD, | ||
database: NoxEnv::MYSQL_DB_NAME, | ||
port: NoxEnv::MYSQL_PORT, | ||
)); | ||
|
||
// Process the request | ||
$requestHandler->processRequest(); | ||
// Process the request as a routable request | ||
try { | ||
$nox->router->processRoutableRequest(); | ||
} catch (NoMatchingRoute $e) { | ||
// 404 | ||
http_response_code(404); | ||
// Process a new routable request, but change the path to our known 404 controller method route | ||
$nox->router->requestPath = "/404"; | ||
$nox->router->processRoutableRequest(); | ||
} |
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
example/layouts/base.php → example/resources/layouts/base.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
namespace Nox\ClassLoader; | ||
|
||
use Nox\ClassLoader\Exceptions\ControllerMissingExtension; | ||
use Nox\ORM\Attributes\Model; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
|
||
class ClassLoader{ | ||
|
||
/** @var string[] All classes loaded by the Nox framework from the user's app */ | ||
public static array $allAppLoadedClasses = []; | ||
|
||
/** @var ReflectionClass[] Reflections of classes identified as Controllers */ | ||
public static array $controllerClassReflections = []; | ||
|
||
/** @var ReflectionClass[] Reflections of classes identified as Models */ | ||
public static array $modelClassReflections = []; | ||
|
||
/** | ||
* Will loop through self::$allAppLoadedClasses and determine which type of Nox-identified class | ||
* they are. E.g., a Controller or a Model class. Then it will sort them into the necessary static properties | ||
* @return void | ||
* @throws ControllerMissingExtension | ||
* @throws ReflectionException | ||
* @throws Exceptions\ModelMissingImplementation | ||
*/ | ||
public static function runClassFiltersAndSorting(){ | ||
$controllerClassIdentifier = new ControllerClassIdentifier(); | ||
$modelClassIdentifier = new ModelClassIdentifier(); | ||
self::$controllerClassReflections = $controllerClassIdentifier->getControllerClassReflections(self::$allAppLoadedClasses); | ||
self::$modelClassReflections = $modelClassIdentifier->getModelClassReflections(self::$allAppLoadedClasses); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
namespace Nox\ClassLoader; | ||
|
||
class ClassScopeHelper{ | ||
|
||
/** @var string[] Of currently declared classnames after cacheCurrentClassNames is called */ | ||
public static array $currentClassNameCache = []; | ||
|
||
public static function cacheCurrentClassNames(): void{ | ||
self::$currentClassNameCache = get_declared_classes(); | ||
} | ||
|
||
public static function getNewClassNamesDefined(): array{ | ||
$nowDefinedClasses = get_declared_classes(); | ||
return array_diff($nowDefinedClasses, self::$currentClassNameCache); | ||
} | ||
} |
Oops, something went wrong.