ongr-io / ElasticsearchBundle

Symfony bundle for Elasticsearch with steroids
MIT License
313 stars 189 forks source link

Fail to install #952

Open yo1nick opened 4 years ago

yo1nick commented 4 years ago

I try to install this bundle on windows using Symfony 4.4 and I receive this error: Class App\src\Kernel does not exist in MappingPass.php line 65:

bogdaniel commented 4 years ago

Have you managed to install it ? If it's an yes can you provide the solution? Thanks

yo1nick commented 4 years ago

You can say that, I managed to get rid of the error in question, this is what I have done: step 1: from composer remove "post-install-cmd": [ "@auto-scripts" ], "post-update-cmd": [ "@auto-scripts" ] step 2: run composer require ongr/elasticsearch-bundle step 3: put back post-install and post-update step 4: edit vendor/ongr/elasticsearch-bundle/DependencyInjection/Compiler/MappingPass.php I've made 2 changes to that file first in private function getFullNamespace($filename) I add trim to preg_match like that: preg_match('/^namespace (.*);$/', trim($namespaceLine), $match); and the second change is in private function getClassname($filename) I replace $directoriesAndFilename = explode('/', $filename); with $directoriesAndFilename = explode(DIRECTORY_SEPARATOR, $filename);

Hope that helps you!

bogdaniel commented 4 years ago

Thank you I will try it.

LE: It Worked smooth the way you did it :-) thank you for the fix but I encountered another problem. After looking over the issues and everything I finally made it to work with the following changes

https://github.com/ongr-io/ElasticsearchBundle/issues/899 https://github.com/ongr-io/ElasticsearchBundle/issues/952

    private function getFullNamespace($filename)
    {
        $lines = preg_grep('/^namespace /', file($filename));
        $namespaceLine = array_shift($lines);
        $match = array();
        preg_match('/^namespace (.*);$/', trim($namespaceLine), $match);
        $fullNamespace = array_pop($match);

        return $fullNamespace;
    }

    private function getClassname($filename)
    {
        $directoriesAndFilename = explode(DIRECTORY_SEPARATOR, $filename);
        $filename = array_pop($directoriesAndFilename);
        $nameAndExtension = explode('.', $filename);
        $className = array_shift($nameAndExtension);

        return $className;
    }
mjvanmiddelaar commented 4 years ago

See also #958

you could also add something similar to:

ongr_elasticsearch:
    source_directories: [/src/Document]

in packages/ongr_elasticsearch.yaml

Orest983 commented 2 years ago

MappingPass.php

function getFullNamespace line 169: preg_match('/^namespace (.*);$/', $namespaceLine, $match);

$namespaceLine - in some cases is a string with '\r\n' at the end, for example "namespace App\Twig;\r\n" thus preg_match returns null, that causes an error "In MappingPass.php line 65: Class \AppExtension does not exist"

It isn't right, but I solved this problem by wrapping the argument into a function rtrim($namespaceLine)