Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Improved the way we display the executed installer command #88

Closed

Conversation

javiereguiluz
Copy link
Member

This PR tries to solve #80 for the most used case. Around 80% of users use Linux or Mac and most of them will install the installer in /usr/local/bin/, so we can easily improve commands' output.

@@ -562,6 +562,9 @@ private function getExecutedCommand()
$version = $this->version;
}

return sprintf('%s new %s %s', $_SERVER['PHP_SELF'], $this->projectName, $version);
$executedCommand = $_SERVER['PHP_SELF'];
$executedCommand = preg_replace('~/usr/local/bin/~', '', $executedCommand);
Copy link
Member

Choose a reason for hiding this comment

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

We could be even smarter and check if dirname() of $_SERVER['PHP_SELF'] is one of the paths in $_SERVER['PATH']. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! Done in 860c9b9.

*/
private function getExecutedCommand()
{
$pathDirs = explode(':', $_SERVER['PATH']);
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 colon also used on Windows? I thought it was a semicolon there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch Christian. I've just replaced this by a preg_split() call.

Copy link
Member

Choose a reason for hiding this comment

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

But wouldn't this now break on Windows with paths containing something like C:\...?

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course :( I'm really ashamed of my self for not having used PATH_SEPARATOR constant from the very beginning. Hopefully this is fixed for real now.

$executedCommandDir = dirname($executedCommand);

if (in_array($executedCommandDir, $pathDirs)) {
$executedCommand = str_replace($executedCommandDir, '', $executedCommand);
Copy link
Member

Choose a reason for hiding this comment

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

Using str_replace() here is dangerous if the user stores the installer, for example, in /symfony/symfony. executedCommand will then be an empty string in the end. You could use basename() instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree! Your proposal is the right thing to do. Thanks!

@xabbuh
Copy link
Member

xabbuh commented Dec 22, 2014

👍

@javiereguiluz javiereguiluz changed the title Improved the way we display the executed isntaller command Improved the way we display the executed installer command Dec 22, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants