Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/vendor/*
/vendor/
.phpunit.result.cache
.phpunit.cache
.phpunit
auth.json
composer.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This README would normally document whatever steps are necessary to get your app

### How do I get set up? ###

* Summary of set up
* Summary of setup
* Configuration
* Dependencies
* Database configuration
Expand Down
264 changes: 131 additions & 133 deletions backend/class/app.php
Original file line number Diff line number Diff line change
@@ -1,155 +1,153 @@
<?php

namespace codename\core\ui;

use codename\core\exception;
use codename\core\generator\urlGenerator;
use codename\core\generator\urlGeneratorInterface;
use codename\core\response\http;
use ReflectionException;

/**
* [app description]
* app override class for ui purposes
* app override class for ui purposes,
* this class may not be initialized or run, at all.
*/
class app extends \codename\core\app {

/**
* Exception thrown if you call a method in this overridden class
* that shouldn't be called
* @var string
*/
public const EXCEPTION_CORE_UI_APP_ILLEGAL_CALL = 'EXCEPTION_CORE_UI_APP_ILLEGAL_CALL';

/**
* @inheritDoc
* this class may not be run
*/
public function run()
{
throw new exception(self::EXCEPTION_CORE_UI_APP_ILLEGAL_CALL, exception::$ERRORLEVEL_FATAL);
}
class app extends \codename\core\app
{
/**
* Exception thrown if you call a method in this overridden class
* that shouldn't be called
* @var string
*/
public const string EXCEPTION_CORE_UI_APP_ILLEGAL_CALL = 'EXCEPTION_CORE_UI_APP_ILLEGAL_CALL';
/**
* [protected description]
* @var array
*/
protected static array $requireJsAssets = [];
/**
* [protected description]
* @var bool [type]
*/
protected static bool $requireJsAdded = false;
/**
* [protected description]
* @var null|urlGeneratorInterface
*/
protected static ?urlGeneratorInterface $urlGenerator = null;

/**
* @inheritDoc
* this class may not be constructed/initialized
*/
public function __CONSTRUCT()
{
throw new exception(self::EXCEPTION_CORE_UI_APP_ILLEGAL_CALL, exception::$ERRORLEVEL_FATAL);
}

/**
* [protected description]
* @var array
*/
protected static $requireJsAssets = array();
/**
* {@inheritDoc}
* this class may not be constructed/initialized
*/
public function __construct()
{
throw new exception(self::EXCEPTION_CORE_UI_APP_ILLEGAL_CALL, exception::$ERRORLEVEL_FATAL);
}

/**
* [protected description]
* @var [type]
*/
protected static $requireJsAdded = false;
/**
* [requireAsset description]
* @param string $type [description]
* @param array|string $asset [description]
* @throws ReflectionException
* @throws exception
*/
public static function requireAsset(string $type, array|string $asset): void
{
$response = app::getResponse();
if (!($response instanceof http)) {
return;
}

/**
* [requireAsset description]
* @param string $type [description]
* @param string|string[] $asset [description]
*/
public static function requireAsset(string $type, $asset) {
if($type === 'requirejs') {
// add requireJS if not already added
if(!self::$requireJsAdded) {
app::getResponse()->requireResource('js', '/assets/requirejs/require.js', 0);
app::getResponse()->requireResource('js', '/assets/require.config.js', 1);
// requirecss must be issued earlier, if used
// app::getResponse()->requireResource('js', '/assets/require-css/css.js', 2);
// app::getResponse()->requireResource('script',
// "require(['require-css']);", 1
// );
/* app::getResponse()->requireResource('script',
"requirejs.config({
baseUrl: 'library',
});", 0
);*/
self::$requireJsAdded = true;
}
if ($type === 'requirejs') {
// add requireJS if not already added
if (!self::$requireJsAdded) {
$response->requireResource('js', '/assets/requirejs/require.js', 0);
$response->requireResource('js', '/assets/require.config.js?t=' . time(), 1);
self::$requireJsAdded = true;
}

$assets = [];
if(is_array($asset)) {
$assets = $asset;
} else {
$assets = [$asset];
}
if (is_array($asset)) {
$assets = $asset;
} else {
$assets = [$asset];
}

foreach($assets as $a) {
if(!in_array($a, self::$requireJsAssets)) {
app::getResponse()->requireResource('script', "require(['{$a}'])");
self::$requireJsAssets[] = $a;
foreach ($assets as $a) {
if (!in_array($a, self::$requireJsAssets)) {
$response->requireResource('script', "require(['$a'])");
self::$requireJsAssets[] = $a;
}
}
} elseif ($type === 'requirecss') {
$type = 'css';
if (is_array($asset)) {
foreach ($asset as $a) {
$response->requireResource($type, $a);
}
} else {
$response->requireResource($type, $asset);
}
} elseif (is_array($asset)) {
// TODO: require each resource?
foreach ($asset as $a) {
$response->requireResource($type, $a);
}
} else {
$response->requireResource($type, $asset);
}
}
}

} else if($type === 'requirecss') {
$type = 'css';
if(is_array($asset)) {
foreach($asset as $a) {
app::getResponse()->requireResource($type, $a);
}
} else {
app::getResponse()->requireResource($type, $asset);
}
} else {
// TODO: require each resource?
if(is_array($asset)) {
foreach($asset as $a) {
app::getResponse()->requireResource($type, $a);
/**
* [getUrlGenerator description]
* @return urlGeneratorInterface [description]
*/
public static function getUrlGenerator(): urlGeneratorInterface
{
if (self::$urlGenerator == null) {
self::$urlGenerator = new urlGenerator();
}
} else {
app::getResponse()->requireResource($type, $asset);
}
return self::$urlGenerator;
}
}

/**
* [protected description]
* @var \codename\core\generator\urlGeneratorInterface
*/
protected static $urlGenerator = null;

/**
* [getUrlGenerator description]
* @return \codename\core\generator\urlGeneratorInterface [description]
*/
public static function getUrlGenerator() : \codename\core\generator\urlGeneratorInterface {
if(self::$urlGenerator == null) {
self::$urlGenerator = new \codename\core\generator\urlGenerator();
/**
* [setUrlGenerator description]
* @param urlGeneratorInterface $generator [description]
*/
public static function setUrlGenerator(urlGeneratorInterface $generator): void
{
self::$urlGenerator = $generator;
}
return self::$urlGenerator;
}

/**
* [setUrlGenerator description]
* @param \codename\core\generator\urlGeneratorInterface $generator [description]
*/
public static function setUrlGenerator(\codename\core\generator\urlGeneratorInterface $generator) {
self::$urlGenerator = $generator;
}

/**
* returns the current server/FE endpoint
* including Protocol and Port (on need)
*
* @return string [description]
*/
public static function getCurrentServerEndpoint() : string {
// url base prefix preparation
//
// vendors and services like AWS (especially ELBs)
// also provide a non-standard header like X-Forwarded-Port
// which is the same as with the protocol, but for ports
//
// NOTE: we handle X-Forwarded-Proto separately during request object creation (request\http)
//
$port = $_SERVER['HTTP_X_FORWARDED_PORT'] ?? $_SERVER['SERVER_PORT'] ?? null;
$proto = (($_SERVER['HTTPS'] ?? null) === 'on') ? 'https' : 'http';
$portSuffix = (($proto === 'https' && $port != 443) || ($proto === 'http' && $port != 80)) ? (':'.$port) : '';
$urlBase = $proto.'://'.$_SERVER['SERVER_NAME'].$portSuffix;
return $urlBase;
}
/**
* returns the current server/FE endpoint
* including Protocol and Port (on a need)
*
* @return string [description]
*/
public static function getCurrentServerEndpoint(): string
{
// url base prefix preparation
//
// vendors and services like AWS (especially ELBs)
// also provide a non-standard header like X-Forwarded-Port
// which is the same as with the protocol, but for ports
//
// NOTE: we handle X-Forwarded-Proto separately during request object creation (request\http)
//
$port = $_SERVER['HTTP_X_FORWARDED_PORT'] ?? $_SERVER['SERVER_PORT'] ?? null;
$proto = (($_SERVER['HTTPS'] ?? null) === 'on') ? 'https' : 'http';
$portSuffix = (($proto === 'https' && $port != 443) || ($proto === 'http' && $port != 80)) ? (':' . $port) : '';
return $proto . '://' . $_SERVER['SERVER_NAME'] . $portSuffix;
}

/**
* {@inheritDoc}
* this class may not be run
*/
public function run(): void
{
throw new exception(self::EXCEPTION_CORE_UI_APP_ILLEGAL_CALL, exception::$ERRORLEVEL_FATAL);
}
}
Loading