Answer the question
In order to leave comments, you need to log in
How to check why null is being passed?
Please help me figure out why this error occurs.
( ! ) Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Routing\Matcher\UrlMatcher::__construct() must be an instance of Symfony\Component\Routing\RouteCollection, null given, called in D:\OSPanel\domains\route.loc\src\System\App.php on line 77 and defined in D:\OSPanel\domains\route.loc\vendor\symfony\routing\Matcher\UrlMatcher.php on line 59
( ! ) TypeError: Argument 1 passed to Symfony\Component\Routing\Matcher\UrlMatcher::__construct() must be an instance of Symfony\Component\Routing\RouteCollection, null given, called in D:\OSPanel\domains\route.loc\src\System\App.php on line 77 in D:\OSPanel\domains\route.loc\vendor\symfony\routing\Matcher\UrlMatcher.php on line 59
<?Php
require "../vendor/autoload.php";
$app = require_once __DIR__ .'/../bootstrap/app.php';
$app->run();
?>
<?Php
define( "BASEPATH",dirname( __DIR__ ));
$app = \App\System\App::getInstance( BASEPATH );
return $app;
?>
<?Php
namespace App\System;
use Symfony\Component\Routing;
use Symfony\Component\HttpKernel;
use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\Controller;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
Class App {
private $router;
private $routes;
private $request;
private $basePath;
private $arguments;
private $controller;
private $requestContext;
public static $instance = null;
public static function getInstance( $basePath ) {
if ( is_null( static::$instance )) {
static::$instance = new static( $basePath );
}
return static::$instance;
}
private function __constructor( $basePath ) {
$this->basePath = $basePath;
$this->setRequest();
$this->setRequestContext();
$this->setRouter();
$this->routes = $this->router->getRouteCollection();
}
private function setRequest() {
$this->request = Request::createFromGlobals();
}
private function setRequestContext() {
$this->requestContext = new RequestContext();
$this->requestContext->fromRequest( $this->request );
}
private function getRequest() {
return $this->request;
}
59 private function getRequestContext() {
return $this->requestContext;
}
private function setRouter() {
$fileLocator = new FileLocator( array( __DIR__ ));
$this->router = new Router(
new YamlFileLoader( $fileLocator ),
$this->basePath .'/config/routes.yaml',
array( 'cache_dir' => $this->basePath .'/storage/cache' )
);
}
public function getController() {
return ( new ControllerResolver())->getController( $this->request );
}
public function run() {
77 $matcher = new Routing\Matcher\UrlMatcher( $this->routes, $this->requestContext );
try {
$this->request->attributes->add( $matcher->match( $this->request->getPathInfo()));
$controller = $this->getController();
dd($controller);
//$arguments = $this->getArguments($controller);
} catch ( \Exception $e ) {
exit( 'error' );
}
}
}
?>
index_route:
path: /
defaults: { _controller: 'App\Http\IndexController::indexAction' }
page_route:
path: /page/{alias}
defaults: { _controller: 'App\Http\PageController::showAction' }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question