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

[FrameworkBundle] Fixed server:start --router relative path issue #14124 #14129

Closed
wants to merge 5 commits into from

Conversation

abulford
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14124
License MIT
Doc PR -

This ensures that a relative path can be used to specify the router script, and that if the router script cannot be found an error is reported and the command fails.

The file path for the router script is now determined and checked prior to the child process being forked, which seems cleaner. The same change could be made in ServerRunCommand.php, or possibly in the ServerCommand base class; to keep the scope small, though, this wasn't done as part of this bug fix.

->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
;
} else {
if (!file_exists($router)) {
Copy link
Member

Choose a reason for hiding this comment

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

Please merge both lines into a single elseif.

Copy link
Member

Choose a reason for hiding this comment

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

By the way, will this work if the user used a relative path?

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, will merge to elseif.

Yep, I've tried this with a relative path and it seems to work fine. This was actually the main point of this change, and resembles how file checking is done in ServerRunCommand.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.

@xabbuh - I've changed to elseif in 898f97a.

abulford added a commit to abulford/symfony that referenced this pull request Apr 1, 2015
symfony#14129

* Changed `if` nested in `else` to `elseif`
* Modified `determineRouterScript` function prototype so that just the `router` argument is passed, rather than the whole `InputInterface`
@@ -177,25 +182,44 @@ private function isOtherServerProcessRunning($address)
}

/**
* Determine the absolute file path for the router script based on user input and the environment.
Copy link
Member

Choose a reason for hiding this comment

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

This sentence needs to be changed as the user input isn't passed 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.

OK, I've updated the comment to be more specific in 4be3757.

…fony#14124

This ensures that a relative path can be used to specify the router script, and that if the router script cannot be found an error is reported and the command fails.

The file path for the router script is now determined and checked prior to the child process being forked, which seems cleaner.  The same change could be made in ServerRunCommand.php, or possibly in the ServerCommand base class; to keep the scope small, though, this wasn't done as part of this bug fix.
symfony#14129

* Changed `if` nested in `else` to `elseif`
* Modified `determineRouterScript` function prototype so that just the `router` argument is passed, rather than the whole `InputInterface`
symfony#14129

* Tweaked `determineRouterScript` function comment to better describe what the function is doing
* Removed the usage of `file_exists` and instead made use of the `realpath` result to determine if the specified router file exists
@@ -129,7 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

if (null === $process = $this->createServerProcess($output, $address, $documentRoot, $input->getOption('router'), $env, null)) {
if (null === $process = $this->createServerProcess($output, $address, $documentRoot, $router, null)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can avoid explicitly set null to the timeout argument as it's the default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, the null there isn't necessary. I was tempted to remove it but didn't want to meddle with the code any more than I needed to. @xabbuh - as the author of this class, would you like me to remove it?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see anything wrong with you removing this as it is really useless.

Copy link
Contributor

Choose a reason for hiding this comment

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

// before
$this->createServerProcess($output, $address, $documentRoot, $router, null)
// after
$this->createServerProcess($output, $address, $documentRoot, $router)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, I was just wary of changing more than was necessary - I'm pretty new to GitHub so wasn't sure if I would be committing a faux pas!
All done in 139191f.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you. Could also completely remove the $timeout parameter from the createServerProcess() method? It's not used anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could do, though the null would still need passing to the Process constructor, otherwise the timeout will be set to 60 seconds:

private function createServerProcess(OutputInterface $output, $address, $documentRoot, $router)
{
    ...
    ...
    return new Process('exec '.$script, $documentRoot, null, null, null);
}

It doesn't seem to do any harm leaving the option there for future use, but then, you're right, it's currently not being used to doesn't need to be there. Let me know if you'd prefer for it to be removed and, if so, I'll take it out.

Copy link
Member

Choose a reason for hiding this comment

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

Yes please :)

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, done in a8c29c4.

…ymfony#14129

* Removed unnecessary `null` from `createServerProcess` call
…ony#14129

* Removed unused `timeout` argument from `createServerProcess` function
@xabbuh
Copy link
Member

xabbuh commented Apr 6, 2015

👍

@abulford
Copy link
Contributor Author

@xabbuh - Is there anything else I need to do in order for this PR to be accepted?

@xabbuh
Copy link
Member

xabbuh commented Apr 10, 2015

@abulford Looks good to me.

ping @symfony/deciders

@willdurand
Copy link
Contributor

👍

1 similar comment
@Tobion
Copy link
Contributor

Tobion commented Apr 13, 2015

👍

@fabpot
Copy link
Member

fabpot commented Apr 13, 2015

Thank you @abulford.

fabpot added a commit that referenced this pull request Apr 13, 2015
…h issue #14124 (abulford)

This PR was squashed before being merged into the 2.6 branch (closes #14129).

Discussion
----------

[FrameworkBundle] Fixed server:start --router relative path issue #14124

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14124
| License       | MIT
| Doc PR        | -

This ensures that a relative path can be used to specify the router script, and that if the router script cannot be found an error is reported and the command fails.

The file path for the router script is now determined and checked prior to the child process being forked, which seems cleaner.  The same change could be made in ServerRunCommand.php, or possibly in the ServerCommand base class; to keep the scope small, though, this wasn't done as part of this bug fix.

Commits
-------

0c1b9ba [FrameworkBundle] Fixed server:start --router relative path issue #14124
@fabpot fabpot closed this Apr 13, 2015
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.

6 participants