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

Added more information about project installed #64

Merged
merged 1 commit into from
Dec 4, 2014

Conversation

saro0h
Copy link
Contributor

@saro0h saro0h commented Nov 30, 2014

Before enhancement:
capture d ecran 2014-11-30 a 21 05 49

After enhancement:
capture d ecran 2014-12-03 a 22 16 26


private function getInstalledProjectVersion()
{
$getVersion = new Process('php ./'.$this->projectName.'/app/console --version');
Copy link
Member

Choose a reason for hiding this comment

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

use PhpExecutableFinder instead of calling directly php

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

@saro0h saro0h force-pushed the more-information branch 2 times, most recently from 485af40 to ac42f19 Compare November 30, 2014 23:40
@@ -378,4 +391,24 @@ private function getErrorMessage(\Requirement $requirement, $lineSize = 70)

return $errorMessage;
}

private function getInstalledProjectVersion()
Copy link
Member

Choose a reason for hiding this comment

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

For now it's OK to use this method to get the installed version ... but soon, when we improve the way we get the Symfony version to be installed, this code will be unnecessary because we already know the exact version before installing Symfony.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I feel that way is "safer" as we are obsolutely sure about the version of has been installed.

@javiereguiluz
Copy link
Member

@saro0h I really like the idea of displaying the exact installed version of Symfony. That's a nice improvement! Thank you.

However, I don't like the idea to make the result message longer with so many lines. We're completely obsessed with streamlining the installation experience as much as possible and therefore, every line counts. That's why I propose you to simplify a bit your proposal as follows:

installer_display_more_information

If you agree, this is the patch with the required changes:

diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php
index 56b11f8..1603b41 100755
--- a/src/Symfony/Installer/NewCommand.php
+++ b/src/Symfony/Installer/NewCommand.php
@@ -295,27 +295,18 @@ class NewCommand extends Command
     private function displayInstallationResult()
     {
         if (empty($this->requirementsErrors)) {
-            $versionInstalled = $this->getInstalledProjectVersion();
-            $folderInstalled = $this->getProjectFolder();
-            $tick = defined('PHP_WINDOWS_VERSION_BUILD') ? 'OK' : '✔';
-
             $this->output->writeln(sprintf(
-                " <info>%s</info>  Symfony was <info>successfully installed</info>.\n".
-                " <info>%s</info>  Your new project is using <info>%s</info>.\n".
-                " <info>%s</info>  Your project is here: <comment>%s</comment>.\n\n".
-                " Now you can:",
-                $tick,
-                $tick,
-                $versionInstalled,
-                $tick,
-                $folderInstalled
+                " <info>%s</info>  Symfony %s was <info>successfully installed</info>. Now you can:\n",
+                defined('PHP_WINDOWS_VERSION_BUILD') ? 'OK' : '✔',
+                $this->getInstalledSymfonyVersion()
             ));
         } else {
             $this->output->writeln(sprintf(
-                " <comment>%s</comment>  Symfony was <info>successfully installed</info> but your system doesn't meet its\n".
+                " <comment>%s</comment>  Symfony %s was <info>successfully installed</info> but your system doesn't meet its\n".
                 "     technical requirements! Fix the following issues before executing\n".
                 "     your Symfony application:\n",
-                defined('PHP_WINDOWS_VERSION_BUILD') ? 'FAILED' : '✕'
+                defined('PHP_WINDOWS_VERSION_BUILD') ? 'FAILED' : '✕',
+                $this->getInstalledSymfonyVersion()
             ));

             foreach ($this->requirementsErrors as $helpText) {
@@ -331,13 +322,13 @@ class NewCommand extends Command
         }

         $this->output->writeln(sprintf(
-            "    * Change your current directory to %s.\n".
+            "    * Change your current directory to <comment>%s</comment>\n\n".
             "    * Configure your application in <comment>app/config/parameters.yml</comment> file.\n\n".
             "    * Run your application:\n".
             "        1. Execute the <comment>php app/console server:run</comment> command.\n".
             "        2. Browse to the <comment>http://localhost:8000</comment> URL.\n\n".
             "    * Read the documentation at <comment>http://symfony.com/doc</comment>\n",
-            $this->projectName
+            $this->projectDir
         ));

         return $this;
@@ -392,7 +383,12 @@ class NewCommand extends Command
         return $errorMessage;
     }

-    private function getInstalledProjectVersion()
+    /**
+     * It returns the full Symfony version number of the project by executing
+     * the '$ ./app/console --version' command, which outputs the following:
+     * Symfony version X.Y.Z - app/dev/debug
+     */
+    private function getInstalledSymfonyVersion()
     {
         $phpExecutableFinder = new PhpExecutableFinder();
         $php = $phpExecutableFinder->find();
@@ -404,11 +400,6 @@ class NewCommand extends Command
             throw new \RuntimeException($getVersion->getErrorOutput());
         }

-        return substr($getVersion->getOutput(), 0, strlen($getVersion->getOutput())-17);
-    }
-
-    private function getProjectFolder()
-    {
-        return str_replace("\n", '', getcwd().'/'.$this->projectName);
+        return substr($getVersion->getOutput(), 16, 5);
     }
 }

@saro0h saro0h force-pushed the more-information branch 2 times, most recently from 8eaa715 to 6f9b2f8 Compare December 1, 2014 21:59
throw new \RuntimeException('The php binary cannot be found.');
}

$getVersion = new Process($php.' ./'.$this->projectName.'/app/console --version');

Choose a reason for hiding this comment

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

You should use the ProcessBuilder here, in order to escape these arguments. In case $this->projectName contains special chars or space, this command could fail.

Copy link
Member

Choose a reason for hiding this comment

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

Why don't use composer directly ?

<?php

function get_symfony_version()
{
    $composer = json_decode(file_get_contents(__DIR__.'/composer.lock'), true);

    foreach ($composer['packages'] as $package) {
        if ('symfony/symfony' !== $package['name']) {
            continue;
        }

        return $package['version'];
    }
}

echo get_symfony_version();

Copy link
Member

Choose a reason for hiding this comment

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

I think @lyrixx's proposal is really the way to go: simple, fast and it should always work without problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok i'll do that.

@romainneutron
Copy link

Nice job !

@saro0h saro0h force-pushed the more-information branch 2 times, most recently from fc38bad to 1b35f2a Compare December 3, 2014 21:15
@saro0h
Copy link
Contributor Author

saro0h commented Dec 3, 2014

Here you go. Thanks @lyrixx for the tip :)

@saro0h saro0h force-pushed the more-information branch 2 times, most recently from f9a3313 to 6cffdd9 Compare December 3, 2014 21:23
@javiereguiluz
Copy link
Member

👍

Thank you Sarah for improving the installer!

@hhamon
Copy link

hhamon commented Dec 3, 2014

👍


/**
* Returns the full Symfony version number of the project by getting
* it in the composer.lock file.
Copy link
Member

Choose a reason for hiding this comment

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

[...] getting it from the [...]?

@fabpot
Copy link
Member

fabpot commented Dec 4, 2014

Thank you @saro0h.

@fabpot fabpot merged commit 83c8b2d into symfony:master Dec 4, 2014
fabpot added a commit that referenced this pull request Dec 4, 2014
This PR was merged into the 1.0-dev branch.

Discussion
----------

Added more information about project installed

Before enhancement:
![capture d ecran 2014-11-30 a 21 05 49](https://cloud.githubusercontent.com/assets/667519/5239116/bf08c954-78d4-11e4-9d46-01767681be37.png)

After enhancement:
![capture d ecran 2014-12-03 a 22 16 26](https://cloud.githubusercontent.com/assets/667519/5288968/1b20e6a6-7b3a-11e4-99da-98fdca151ba7.png)

Commits
-------

83c8b2d Added more information about project installed
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.

9 participants