-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix locale url change, from default locale to other locale #105
Conversation
…efault_locale # Conflicts: # tests/SlmLocaleTest/Strategy/UriPathStrategyTest.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if this will be used with basepath? also, this strategy became a bit complex and hard to follow and I think needs refactor.
But I don't have time for this unless you can do it I will merge this if it works for you
what you mean with basePath? if you access the page with directories? like page stay in |
Yes, I mean https://exampe.com/base/path/en/foo/bar I am not sure this worked before. I don't use this maybe you are right it does not work but would be nice if you could make it work |
If it will be too hard to support basepath I guess we can throw an exception if base bath is set and we don't support it if it does not work anyway. Anyway, I don't know if anyone using this. |
i was using it^^ and first i was searching for the error^^ |
@kokspflanze should I merge this or you are still working with this working? |
@svycka let it open, as reminder for me todo the base stuff =) |
$actual = $this->event->getUri()->getPath(); | ||
|
||
$this->assertSame($expected, $actual); | ||
$this->assertSame('/en/foo/bar/baz', $this->event->getUri()->getPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strategies should not change base path. Should have been /nl/en/foo/bar/baz
instead of /en/foo/bar/baz
we can't modify base path as it is just folder name and not an application route.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nl
is the language, it has to be changed to en
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but also it is base path $this->strategy->getRouter()->setBaseUrl('/nl');
baseurl is often alias or folder name where the application is installed and changing it will result in not found response. @kokspflanze what if you set $this->strategy->getRouter()->setBaseUrl('/my-app');
what url it will generate?
@basz am I right here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will add a test for this (when im home)
Document_root /my-app
Request /my-app/nl/...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added 2 tests for this, with default language to other language and without default language
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
install your app in '/var/www/my-app'
set your document_root to '/var/www'
than you should access your app via 'http://192.1.1.1.1/my-app/public'
thats all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so as I understand baseurl is my-app/public
and you can't change it. But in tests you changing it.
let's say if you would have app in my-app/en
instead of my-app/public
now you would redirect to my-app/nl
and it does not exist. Does make sense?
Do I still not understand something? please rename your public folder so mething like nl
or someting and test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more tests, like testAssembleWithBasePathWithMatchingLanguageName
if you rename your public directory to nl
and you use the default
configuration, sure it would not work and mostly bug.
but it works without the default
configuration, but i dont think that someone is doing this kind of stuff.
i also added the testAssembleWithBasePathWithMatchingLanguageName
in master and i get my-app/nl/en/nl/foo/bar/baz
instead of /my-app/nl/en/foo/bar/baz
. the problem also exist with the public
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I looked deeper and now understand why you append language and change base path. As I understand that because you testing assemble
event but then maybe you can also add tests for found
event? Because found
event is used for redirect and also alters baseUrl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added tests for found
$result = $this->router->getBaseUrl(); | ||
} | ||
|
||
if (null === $result && null !== $request && method_exists($request, 'getBasePath')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why router does not have baseUrl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check #40
i had the same problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then we can remove $this->router->getBaseUrl();
if we can get it from request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and no, to get it from the router is much better, as to use it from the request, should just be a fallback.
/** | ||
* @return SimpleRouteStack | ||
*/ | ||
public function getRouter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't add gettters/setters we already have it in the constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, i changed it in tests too
added test for base
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe we could make all strategies final. Would reduce BC break chances.
$actual = $this->event->getUri()->getPath(); | ||
|
||
$this->assertSame($expected, $actual); | ||
$this->assertSame('/en/foo/bar/baz', $this->event->getUri()->getPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't understand how changing baseUrl works for you. As I understand if you change baseUrl you should not be able to access your app at all. unless you have another app installed with that URL or have an alias to the previous one.
because I think correct behavior should be like this:
baseUrl: /
default: nl
locale: en
request: /foo/bar redirects to /en/foo/bar
baseUrl: /
default: de
locale: en
request: /nl/foo/bar redirects to /en/foo/bar
baseUrl: /base/url/en
default: nl
locale: en
request: /base/url/en/foo/bar redirects to /base/url/en/en/foo/bar
yes it's .../en/en/.. because /base/url/en is base path and we can't change it
baseUrl: /base/url/en
default: nl
locale: nl
request: /base/url/en/foo/bar does not redirect to default locale
Can you share your apache or nginx config for this baseUrl? I would like to understand what you want to achieve.
okay 🚢 |
sry had a little bug, with locale url change generation
current url:
/
url for en:
/en
current url:
/currency/foobar
url for en:
/en/foobar
// wrong currency was missingthat i fixed with this change