Can i use Symfony’s Route Annotation in Non-Symfony Project

I already tried things here https://symfony.com/doc/master/components/routing.html
But i couldn’t make it.

<?php
use DoctrineCommonAnnotationsAnnotationReader;
use SymfonyBundleFrameworkBundleRoutingAnnotatedRouteControllerLoader;
use SymfonyComponentConfigFileLocator;
use SymfonyComponentRoutingLoaderAnnotationDirectoryLoader;
use ComposerAutoloadClassLoader;
use DoctrineCommonAnnotationsAnnotationRegistry;

/** @var ClassLoader $loader */
$loader = require __DIR__.'/vendor/autoload.php';

AnnotationRegistry::registerLoader([$loader, 'loadClass']);

$loader = new AnnotationDirectoryLoader(
    new FileLocator(__DIR__.'/app/Controller/'),
    new AnnotatedRouteControllerLoader(
        new AnnotationReader()
    )
);

$routes = $loader->load(__DIR__.'/app/Controller/');

When i do that i get these mistakes

Fatal error: Uncaught Error: Class 'SymfonyComponentConfigLoaderFileLoader' not found in C:xampphtdocsMyFwvendorsymfonyroutingLoaderAnnotationFileLoader.php:25 Stack trace: #0 C:xampphtdocsMyFwvendorcomposerClassLoader.php(444): include() #1 C:xampphtdocsMyFwvendorcomposerClassLoader.php(322): ComposerAutoloadincludeFile('C:xampphtdocs...') #2 [internal function]: ComposerAutoloadClassLoader->loadClass('SymfonyCompone...') #3 C:xampphtdocsMyFwvendorsymfonyroutingLoaderAnnotationDirectoryLoader.php(23): spl_autoload_call('SymfonyCompone...') #4 C:xampphtdocsMyFwvendorcomposerClassLoader.php(444): include('C:xampphtdocs...') #5 C:xampphtdocsMyFwvendorcomposerClassLoader.php(322): ComposerAutoloadincludeFile('C:xampphtdocs...') #6 [internal function]: ComposerAutoloadClassLoader->loadClass('SymfonyCompone...') #7 C:xampphtdocsMyFwindex.php(14): spl_autoload_call('SymfonyCompone...') #8 {main} thrown in C:xampphtdocsMyFwvendorsymfonyroutingLoaderAnnotationFileLoader.php on line 25

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *