/www/wwwroot/idc.lc/modules/News/Api/Guest.php
*
* @return array
*/
public function get($data)
{
if (!isset($data['id']) && !isset($data['slug'])) {
throw new \FOSSBilling\Exception('ID or slug is missing');
}
$id = $data['id'] ?? null;
$slug = $data['slug'] ?? null;
if ($id) {
$model = $this->getService()->findOneActiveById($id);
} else {
$model = $this->getService()->findOneActiveBySlug($slug);
}
if (!$model || $model->status !== 'active') {
throw new \FOSSBilling\Exception('News item not found');
}
return $this->getService()->toApiArray($model);
}
}
Arguments
/www/wwwroot/idc.lc/library/Api/Handler.php
}
$bb_mod = $this->di['mod']($mod);
$api->setDi($this->di);
$api->setMod($bb_mod);
$api->setIdentity($this->identity);
$api->setIp($this->di['request']->getClientIp());
if ($bb_mod->hasService()) {
$api->setService($this->di['mod_service']($mod));
}
if (!method_exists($api, $method_name) || !is_callable([$api, $method_name])) {
$reflector = new ReflectionClass($api);
if (!$reflector->hasMethod('__call')) {
throw new FOSSBilling\Exception(':type API call :method does not exist in module :module', [':type' => ucfirst($this->type), ':method' => $method_name, ':module' => $mod], 740);
}
}
return $api->{$method_name}($arguments);
}
}
/www/wwwroot/idc.lc/modules/News/Controller/Client.php
public function getDi(): ?\Pimple\Container
{
return $this->di;
}
public function register(\Box_App &$app)
{
$app->get('/news', 'get_news', [], static::class);
$app->get('/news/:slug', 'get_news_item', ['slug' => '[a-z0-9-]+'], static::class);
}
public function get_news(\Box_App $app)
{
return $app->render('mod_news_index');
}
public function get_news_item(\Box_App $app, $slug)
{
$post = $this->di['api_guest']->news_get(['slug' => $slug]);
return $app->render('mod_news_post', ['post' => $post]);
}
}
/www/wwwroot/idc.lc/library/Box/App.php
{
$this->debugBar['time']->startMeasure('executeShared', 'Reflecting module controller (shared mapping)');
$class = new $classname();
if ($class instanceof InjectionAwareInterface) {
$class->setDi($this->di);
}
$reflection = new ReflectionMethod($class::class, $methodName);
$args = [];
$args[] = $this; // first param always app instance
foreach ($reflection->getParameters() as $param) {
if (isset($params[$param->name])) {
$args[$param->name] = $params[$param->name];
} elseif ($param->isDefaultValueAvailable()) {
$args[$param->name] = $param->getDefaultValue();
}
}
$this->debugBar['time']->stopMeasure('executeShared');
return $reflection->invokeArgs($class, $args);
}
protected function execute($methodName, $params, $classname = null): string
{
$this->debugBar['time']->startMeasure('execute', 'Reflecting module controller');
$reflection = new ReflectionMethod(static::class, $methodName);
$args = [];
foreach ($reflection->getParameters() as $param) {
if (isset($params[$param->name])) {
$args[$param->name] = $params[$param->name];
} elseif ($param->isDefaultValueAvailable()) {
$args[$param->name] = $param->getDefaultValue();
}
}
$this->debugBar['time']->stopMeasure('execute');
return $reflection->invokeArgs($this, $args);
/www/wwwroot/idc.lc/library/Box/App.php
$exc = new FOSSBilling\InformationException('The system is undergoing maintenance. Please try again later', [], 503);
$apiController = new Box\Mod\Api\Controller\Client();
$apiController->setDi($this->di);
return $apiController->renderJson(null, $exc);
} else {
return $this->render('mod_system_maintenance');
}
}
}
$this->debugBar['time']->startMeasure('sharedMapping', 'Checking shared mappings');
$sharedCount = count($this->shared);
for ($i = 0; $i < $sharedCount; ++$i) {
$mapping = $this->shared[$i];
$url = new Box_UrlHelper($mapping[0], $mapping[1], $mapping[3], $this->url);
if ($url->match) {
$this->debugBar['time']->stopMeasure('sharedMapping');
return $this->executeShared($mapping[4], $mapping[2], $url->params);
}
}
$this->debugBar['time']->stopMeasure('sharedMapping');
// this class mappings
$this->debugBar['time']->startMeasure('mapping', 'Checking mappings');
$mappingsCount = count($this->mappings);
for ($i = 0; $i < $mappingsCount; ++$i) {
$mapping = $this->mappings[$i];
$url = new Box_UrlHelper($mapping[0], $mapping[1], $mapping[3], $this->url);
if ($url->match) {
$this->debugBar['time']->stopMeasure('mapping');
return $this->execute($mapping[2], $url->params);
}
}
$this->debugBar['time']->stopMeasure('mapping');
$e = new FOSSBilling\InformationException('Page :url not found', [':url' => $this->url], 404);
/www/wwwroot/idc.lc/library/Box/App.php
public function delete(string $url, string $methodName, ?array $conditions = [], ?string $class = null): void
{
$this->event('delete', $url, $methodName, $conditions, $class);
}
public function run(): string
{
$this->debugBar['time']->startMeasure('registerModule', 'Registering module routes');
$this->registerModule();
$this->debugBar['time']->stopMeasure('registerModule');
$this->debugBar['time']->startMeasure('init', 'Initializing the app');
$this->init();
$this->debugBar['time']->stopMeasure('init');
$this->debugBar['time']->startMeasure('checkperm', 'Checking access to module');
$this->checkPermission();
$this->debugBar['time']->stopMeasure('checkperm');
return $this->processRequest();
}
/**
* @param string $path
*/
public function redirect($path): never
{
$location = $this->di['url']->link($path);
header("Location: $location");
exit;
}
public function render($fileName, $variableArray = []): string
{
return 'Rendering ' . $fileName;
}
public function sendFile($filename, $contentType, $path): false|int
{
header("Content-type: $contentType");
/www/wwwroot/idc.lc/index.php
// If HTTP error code has been passed, handle it.
if (!is_null($http_err_code)) {
switch ($http_err_code) {
case '404':
$e = new FOSSBilling\Exception('Page :url not found', [':url' => $url], 404);
echo $app->show404($e);
break;
default:
$http_err_code = intval($http_err_code);
http_response_code($http_err_code);
$e = new FOSSBilling\Exception('HTTP Error :err_code occurred while attempting to load :url', [':err_code' => $http_err_code, ':url' => $url], $http_err_code);
echo $app->render('error', ['exception' => $e]);
}
exit;
}
// If no HTTP error passed, run the app.
echo $app->run();
exit;