Y
Y
Yurka Blokhin2017-02-28 14:35:46
symfony
Yurka Blokhin, 2017-02-28 14:35:46

How to load controller for symfony router?

For routing on the site, I decided to use SymfonyRoute, tell me how to autoload the class, now there is this code:

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;


try {
    $routes = new RouteCollection();
    $routes->add('pst_get', new Route('/pst/{suffix}', array('_controller' => 'Post::get', 'suffix' => ''), array('suffix' => '.*'), array(), '', array(), array('GET')));
    $routes->add('pst_post', new Route('/pst/{suffix}', array('_controller' => 'Post::post', 'suffix' => ''), array('suffix' => '.*'), array(), '', array(), array('POST')));

    $request = Request::createFromGlobals();
    $context = new RequestContext();
    $context->fromRequest($request);
    $matcher = new UrlMatcher($routes, $context);
    $parameters = $matcher->match($request->getRequestUri());
    $request->attributes->add($parameters);
    $attributes = $matcher->match($request->getPathInfo());
    $controller = $attributes['_controller'];
    $response = $controller();
    return $response;
} catch (ResourceNotFoundException $e) {
    $proxy = new Proxy();
    $proxy->setConfig($_config);
    $proxy->run();
}

The Post class never loads.
laravel has Illuminate\Support\ClassLoader::addDirectories(); where the download folder is indicated, but in Symfony I can not find a similar one.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question