-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add parameters to Server object #20
Conversation
I am not really satisfied with what I have done but it's working. Feel free to make some changes.
I've added a couple of thing in that PR. Now, it's supposed to read parameters from CLI and change the server behavior accordingly. |
Ok I will take a look at this later today when I get the chance. |
unset($argv[$posValue]); | ||
continue; | ||
} | ||
} |
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.
@aledeg I am guessing this foreach loop is used because $argv
is passed in the Hooks::loadHooks
???
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.
@ddelnano Yep. There is no easy way to do it. Or at least, I am not aware of one if it exists.
I figured it wasn't a big deal since it is done only once during the server initialization process.
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.
@aledeg I am thinking it might be cleaner to parse the hooks like you did for the other cli options / flags and then change Hooks::loadHooks($hooks)
rather than passing the entire argv variable in.
What do you think about that? It was honestly a mistake that I wrote it to accept $argv
I should have originally parsed it from the flags.
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.
@ddelnano For sure, it will be better and probably testable. I will look at it tonight.
Do you know how dredd starts the server? Does it append the hookfiles property after the language property? So if you happen to have
# dredd.yml
hookfiles: /path/to/hooks
language: bin/dredd-hooks-php
does it trigger the server like?
bin/dredd-hooks-php /path/to/hooks
If so it would be a good idea to have the script running like this to separate options from input
bin/dredd-hooks-php --host 0.0.0.0 --port 12345 --force -- /path/to/hooks
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 can confirm that dredd launch the following:
php bin/dredd-hooks-php /path/to/hooks
@aledeg I am thinking it just passes it the path directly otherwise my |
@ddelnano So I guess, it will be easier to parse the data on the input. I will look into it tonight. I'll keep you posted |
Before, I've added a lot of unnecessary code to clean argv array. It turns out that it wasn't needed due to the use of glob while loading hooks. Now, the code is more minimal and still works the same.
@ddelnano So I simplified the code I wrote. It turns out your method of parsing the arguments was good enough to discard extra arguments. So I reverted my code to simplify it and changed variables names to reflect their content. Let me know if I should do something more. |
@aledeg awesome, yea looks much cleaner. The only suggestion I have is I am not a huge fan of setters such as I would rather have the constructor accept both of those arguments (host and port) and then remove the default values like so. To me, it makes sense that when a "server" is created it should already have its host and port. And for the life of the server they should not change. Could you update your PR with the following and then ill be happy to merge it :) ...
private $host;
private $port;
public function __construct($host = '127.0.0.1', $port = 61321)
{
$this->host = $host;
$this->port = $port;
$this->runner = new Runner;
} Then in the bin/dredd-hooks-php file $host = array_key_exists('host', $options)
? $options['host']
: '127.0.0.1';
$port = array_key_exists('port', $options)
? $options['port']
: '127.0.0.1';
$server = new Server($host, $port); |
Before the host and the port were set with setters. Now they are needed to start the server.
@ddelnano good idea! I think also it's a cleaner way. I didn't think of that yesterday :) |
@ddelnano it passed CI. I think it's good now :) |
👍 just gonna give it one last look over really quick. |
Cool merging now. Awesome work! |
@aledeg I am on mobile now but will tag a new release when I get in front of a computer. |
I added the parameters in the server class to support what we talked about in #18 and #19.
I didn't add it in the script that initialize the server since I don't know how to deal efficiently with the parameters.
If I find something clever before you do, I will update my PR.