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

Improvements to the phpserver router #10500

Merged
merged 4 commits into from
Nov 8, 2017

Conversation

aredridel
Copy link
Contributor

@aredridel aredridel commented Aug 11, 2017

  • handles versioned static assets
  • our own mime handling for those, since php's built in web server's mime table isn't accessible from userland
  • works with a magento instance set up with use-rewrites=1

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.

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Aug 11, 2017

CLA assistant check
All committers have signed the CLA.

@ishakhsuvarov ishakhsuvarov self-assigned this Aug 11, 2017
@ishakhsuvarov ishakhsuvarov added this to the August 2017 milestone Aug 11, 2017
@fooman
Copy link
Contributor

fooman commented Aug 16, 2017

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?

Copy link
Member

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


$debug($path);
$debug($route);
$ext = @pathinfo($route)['extension'];
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to not use @

'html' => 'text/html',
];

$type = @$mimeTypes[$ext];
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use isset

if ($type) {
header("Content-Type: $type");
}
return readfile($file);
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated the return

@fooman
Copy link
Contributor

fooman commented Aug 19, 2017

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

@ishakhsuvarov ishakhsuvarov removed their assignment Aug 19, 2017
'html' => 'text/html',
];

$type = isset($mimeTypes[$ext]) && $mimeTypes[$ext];
Copy link
Contributor

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out!

Copy link
Contributor

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?

@fooman
Copy link
Contributor

fooman commented Sep 4, 2017

Hi @aredridel just checking in if there is anything I can help with to get your pull request merged?

$debug('file exists');
return false;
} else if (file_exists($file)) {
Copy link

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

@fooman
Copy link
Contributor

fooman commented Oct 16, 2017

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.

@fuunnx
Copy link

fuunnx commented Oct 16, 2017

@fooman My locale was fr_FR so I hardcoded the following change:
In this code if neither $origFile nor $file exist then check for alternative file by replacing fr_FR in the file path by en_US. Then it works :)

But I don't know the fallback logic magento use internally for this case so I'm not comfortable making a PR =)

@aredridel
Copy link
Contributor Author

Oh nice! I've been intending to come back to this but haven't had time lately!

@magento-engcom-team magento-engcom-team changed the base branch from develop to 2.3-develop October 20, 2017 15:32
@okorshenko okorshenko self-assigned this Oct 24, 2017
@okorshenko okorshenko modified the milestones: October 2017, November 2017 Nov 1, 2017
@okorshenko okorshenko merged commit 0c2df2e into magento:2.3-develop Nov 8, 2017
okorshenko pushed a commit that referenced this pull request Nov 8, 2017
okorshenko pushed a commit that referenced this pull request Nov 8, 2017
@aredridel aredridel deleted the improve-phpserver branch November 10, 2017 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants