I had a project running on phalcon 5.3.0. But after upgrading to phalcon 5.3.1 with php 8.2 i'm facing some errors. and unable fix it. i did no change but errors are occurred. Also i did not get any change record related with router / request in phalcon 5.3.1. please tell me what i'm doing wrong?
[ERROR]
A dependency injection container is required to access the 'request' servicePhalcon\Mvc\Router\Exception:: A dependency injection container is required to access the 'request' service File=phalcon/Mvc/Router.zep Line=724 Trace=Array Previous= Line=0 #0 /var/www/html/f/apps/config/routes.php(52): Phalcon\Mvc\Router->handle()
#1 [internal function]: Closure->{closure}()
#2 [internal function]: Phalcon\Di\Service->resolve()
#3 [internal function]: Phalcon\Di\Di->get()
#4 [internal function]: Phalcon\Di\Di->getShared()
#5 /var/www/html/f/public/index.php(46): Phalcon\Mvc\Application->handle()
#6 {main}
[ROUTER]
use Phalcon\Mvc\Router;
$di->set('router', function(){
$router = new Router();
#
$router->setDefaultModule('front');
$router->setDefaultNamespace('F\Front\Controllers');
$router->setDefaultController('index');
$router->setDefaultAction('index');
# Remove Extra Trailing Slashes
$router->removeExtraSlashes(true);
# FRONTEND
$router->add('/f/', array(
'module' => 'front',
'namespace' => 'F\Front\Controllers',
'controller' => 1,
'action' => 2,
'params' => 3,
))->setName('front-default');
# BACKEND
$router->add('/back', [
'module' => 'back',
'namespace' => 'F\Back\Controllers',
'controller' => 'index',
'action' => 'index'
])->setName('back-default');
$router->add('/back/:controller/:action/:params', [
'module' => 'back',
'namespace' => 'F\Back\Controllers',
'controller' => 1,
'action' => 2,
'params' => 3
])->setName('back-full');
$router->add('/back/:controller/:action', [
'module' => 'back',
'namespace' => 'F\Back\Controllers',
'controller' => 1,
'action' => 2,
])->setName('back-short');
$router->add('/back/:controller', [
'module' => 'back',
'namespace' => 'F\Back\Controllers',
'controller' => 1
])->setName('backend-mini');
#
$uri = str_replace($_SERVER["SCRIPT_NAME"], "", $_SERVER["REQUEST_URI"]);
$router->handle($uri);
return $router;
});
[BOOTSTRAP]
<?php declare(strict_types=1);
error_reporting(E_ALL);
setlocale(LC_ALL, 'en_US.UTF-8');
mb_internal_encoding('UTF-8');
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Application;
(new \Phalcon\Support\Debug())->listen();
defined('BASE_PATH') || define('BASE_PATH', dirname(__DIR__));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/apps');
$di = new FactoryDefault();
require_once(APP_PATH . '/config/routes.php');
$app = new Application($di);
$app->registerModules(
array(
'front' => array(
'className' => \F\Front\Module::class,
'path' => APP_PATH . '/front/Module.php',
),
'back' => array(
'className' => \F\Back\Module::class,
'path' => APP_PATH . '/back/Module.php',
)
)
);
try {
$response = $app->handle(substr($_SERVER["REQUEST_URI"], strlen('/f/')-1));
$response->send();
} catch (\Exception $e) {
echo($e->getMessage());
echo get_class($e),':: ',$e->getMessage(), PHP_EOL;
echo " File=", $e->getFile(), PHP_EOL;
echo " Line=", $e->getLine(), PHP_EOL;
echo " Trace=", $e->getTrace(), PHP_EOL;
echo " Previous=", $e->getPrevious(), PHP_EOL;
echo " Line=", $e->getCode(), PHP_EOL;
echo nl2br(htmlentities($e->getTraceAsString()));
}
I believe that the 'Fix memory leak in Router::handle() #16431' within the Phalcon 5.3.1 update is causing the confusion. See: https://github.com/phalcon/cphalcon/pull/16431 The solution is quite simple fortunately: