Skip to content
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

Merged
merged 10 commits into from
Apr 2, 2019

Conversation

kokspflanze
Copy link
Contributor

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 missing

that i fixed with this change

@coveralls
Copy link

coveralls commented Mar 21, 2019

Coverage Status

Coverage increased (+1.3%) to 84.211% when pulling 0abec27 on kokspflanze:feature/default_locale into ddc7f55 on basz:master.

Copy link
Collaborator

@svycka svycka left a 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

@kokspflanze
Copy link
Contributor Author

what you mean with basePath?

if you access the page with directories? like page stay in /page/public and you have to call it with page/public ?
because that was not working before, but i want to add the support for this too^^

@svycka
Copy link
Collaborator

svycka commented Mar 22, 2019

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

@svycka
Copy link
Collaborator

svycka commented Mar 22, 2019

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.

@kokspflanze
Copy link
Contributor Author

i was using it^^ and first i was searching for the error^^
i will add a way to support it no way, i hope until end of next week.

@svycka
Copy link
Collaborator

svycka commented Mar 26, 2019

@kokspflanze should I merge this or you are still working with this working?

@kokspflanze
Copy link
Contributor Author

@svycka let it open, as reminder for me todo the base stuff =)
i will do this this week, not sure today or friday.

@kokspflanze
Copy link
Contributor Author

kokspflanze commented Mar 26, 2019

resolve now
#40
#47

$actual = $this->event->getUri()->getPath();

$this->assertSame($expected, $actual);
$this->assertSame('/en/foo/bar/baz', $this->event->getUri()->getPath());
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

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?

Copy link
Contributor Author

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/...

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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')) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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?

Copy link
Contributor Author

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()
Copy link
Collaborator

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

Copy link
Contributor Author

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
Copy link
Collaborator

@svycka svycka left a 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());
Copy link
Collaborator

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.

@svycka svycka changed the base branch from master to develop April 2, 2019 07:54
@svycka svycka self-assigned this Apr 2, 2019
@svycka
Copy link
Collaborator

svycka commented Apr 2, 2019

okay 🚢

@svycka svycka merged commit c085ed7 into basz:develop Apr 2, 2019
@kokspflanze kokspflanze deleted the feature/default_locale branch April 2, 2019 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants