hoaproject / Irc

The Hoa\Irc library.
https://hoa-project.net
25 stars 9 forks source link

Extract useful information from connection url #30

Open shulard opened 7 years ago

shulard commented 7 years ago

Work on the #25 issue about URL details extraction.

This PR must allow the library to extract connection URL details and use it during connection :

Example :

$uri    = 'irc://user:pass@irc.efnet.org:194/#channel?key=abcd';
$client = new Hoa\Irc\Client(new Hoa\Socket\Client($uri));

The given code is valid and can be used to join the channel #channel with the option key=abcd.

Hywan commented 7 years ago

Hello @shulard!

Is it ready for a review?

shulard commented 7 years ago

Hello @Hywan,

I haven't worked on Connection implementation for the moment, only on URL information extraction. You can take a look if you want, this first part is ready for a review 😄.

shulard commented 7 years ago

Hello @Hywan,

Sorry for the delay but I've worked on that PR this week 😄.

Now, if you use something like that, it works (User is used and Channel is joined) :

$socket = new Hoa\Socket\Client('irc://Gordon:password@chat.freenode.net/#hoaproject-random');
$client = new Hoa\Irc\Client($socket);
$client->run();

It works with secured account, guest account. I still need to handle some options / flags, I make that changes ASAP.

I've used event handlers (on open) to set specific connection details, do you think it's the right thing to do ?

Hywan commented 7 years ago

Please, stop being sorry for “delay”. This is open source. We all have a life, with different constraints. I am the first to be concerned…

THANK YOU for your contribution!

Hywan commented 7 years ago

Yes, the open listener is the best one to call the join method I guess.

shulard commented 7 years ago

Hello,

I've pushed new changes to handle all the described properties.

Now you can use that kind of code :

//Ask to connect as "gordon" then join channel
$socket = new Hoa\Socket\Client('irc://chat.freenode.net/gordon,isuser');
$client = new Hoa\Irc\Client($socket);
$client->on('open', function($bucket) {
    $bucket->getSource()->setChannel('#hoaproject-random');
});
$client->run();

//Directly connect on the "#hoaproject-random" channel as "gordon"
$socket = new Hoa\Socket\Client('irc://gordon:@chat.freenode.net/#hoaproject-random');
$client = new Hoa\Irc\Client($socket);
$client->run();

//Connect using a protected username on "#hoaproject-random" channel
$socket = new Hoa\Socket\Client('irc://gordon:password@chat.freenode.net/#hoaproject-random');
$client = new Hoa\Irc\Client($socket);
$client->run();

I've also updated unit tests, removed TODOs in the code (because they are done now) and used named groups in regex. Maybe the commit history needs a little cleanup but the code is working for me.

In Socket.php I've added a new regex to parse a nickname with optional part. I saw that there is one in Client.php but the 3 parts are mandatory (nick, user, host). Maybe we can merge the two in a helper function, I don't know if they must be mandatory or not 😄.