-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Improvements to the phpserver router #10500
Conversation
Thank you @aredridel for your contribution. I haven't used the phpserver myself but anything that makes Magento easier to develop with sounds very useful to me. Travis picked up some minor style nitpicks - would you mind taking a look at those. @Flyingmana I believe you provided the initial implementation. Any chance you are able to take a look? |
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.
That is a great addition and I like it a lot, that you found solutions to this problems.
At the moment I dont have something to test these, but from what I see the changes make sense and will be very useful for other users of the phpserver
phpserver/router.php
Outdated
|
||
$debug($path); | ||
$debug($route); | ||
$ext = @pathinfo($route)['extension']; |
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.
are there cases when pathinfo is throwing an error, or is it because the array access for 'extension' is sometimes not working?
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.
It's because there's not always an extension.
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.
Updated to not use @
phpserver/router.php
Outdated
'html' => 'text/html', | ||
]; | ||
|
||
$type = @$mimeTypes[$ext]; |
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 believe its still better to check via isset() instead of just surpressing the error here.
maybe outdated reference: https://stackoverflow.com/questions/12733666/which-is-better-in-php-suppress-warnings-with-or-run-extra-checks-with-isse
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.
Yeah. I prefer the shorter but not a problem to go the other way.
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.
updated to use isset
phpserver/router.php
Outdated
if ($type) { | ||
header("Content-Type: $type"); | ||
} | ||
return readfile($file); |
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.
is the return of readfile intended? I dont know how php handles the returned number of bytes
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.
Habit -- I always return the return value from things. Too long as a rubyist.
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.
Separated the return
@aredridel thanks for making those changes. This all looks good to me and I have put this in the queue to be processed for merging into develop. |
phpserver/router.php
Outdated
'html' => 'text/html', | ||
]; | ||
|
||
$type = isset($mimeTypes[$ext]) && $mimeTypes[$ext]; |
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.
This will return a boolean and not the mime type, I think this needs to become: $type = $mimeTypes[$ext] ?? '';
or something like that.
Haven't verified the rest of the code, this just popped out to me :)
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.
Thanks for pointing out!
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.
@aredridel apologies I had missed the above. Would you mind taking a look? This might be syntax borrowed from another language -
isset($mimeTypes[$ext])? $mimeTypes[$ext]:'';
might be more appropriate. Should anything happen if we encounter a file that is not in the list of file extensions?
Hi @aredridel just checking in if there is anything I can help with to get your pull request merged? |
phpserver/router.php
Outdated
$debug('file exists'); | ||
return false; | ||
} else if (file_exists($file)) { |
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.
Sadly it does not take into account other locales than en_US. e.g: the luma theme breaks with 404 errors when the store in in fr_FR.
I did a quick fix on my dev env, testing both fr_FR and en_US static files.
Great PR by the way
Apologies @aredridel in not getting this moved forward so far. As Magento had so far zero test coverage in this area I have added a couple of updates to your pull request to add some tests. Please let me know if anything in the latest changes looks out of place to you. @fuunnx I am keen to hear what additional changes you needed to make to enable a multi-locale environment (I am not sure if this is reliant on a particular setting - for example to add the store code to the url). If you are interested feel free to create a separate pull request once this one has merged. |
@fooman My locale was But I don't know the fallback logic magento use internally for this case so I'm not comfortable making a PR =) |
Oh nice! I've been intending to come back to this but haven't had time lately! |
- skipped the test for bamboo env
Is this a useful amendment? I'm happy to fix this up with suggestions, too, as I intend to use it for my daily development.