Skip to content

Commit

Permalink
Corrected the class name and added commenting to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jedi58 committed Jan 21, 2016
1 parent 22a6d1f commit 55a682a
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/Wol.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
<?php

class WOL {
/**
* Class for handling WOL requests
*/
class Wol
{
/**
* Default constructor for Wol. If IP and MAC addresses are specified
* it will call the Wol::wake()
* @param string $ip The broadcast IP address to use
* @param string $mac The MAC address of the device to wake
* @param int $protocol The type of IP to use. Deafult AF_INET
*/
public function __construct($ip = '', $mac = '', $protocol = AF_INET)
{
$this->wake($ip, $mac, $protocol);
if (!empty($ip) && !empty($mac)) {
$this->wake($ip, $mac, $protocol);
}
}

/**
* Sends a magic packet to the specified IP/MAC address using the specified
* address protocol.
* @param string $ip The broadcast IP address to use
* @param string $mac The MAC address of the device to wake
* @param int $protocol The type of IP to use. Deafult AF_INET
* @return int|bool The result of sending the packet
*/
public static function wake($ip, $mac, $protocol = AF_INET)
{
if (empty($ip) || empty($mac)) {
Expand Down Expand Up @@ -34,14 +54,23 @@ public static function wake($ip, $mac, $protocol = AF_INET)
socket_strerror(socket_last_error()) . PHP_EOL);
}
}

/**
* Converts the specified MAC address into a character representation
* by converted each octet into decimal and appending the resulting
* character to the string
* @param string $mac The MAC address to convert
* @return string The converted MAC address
*/
private function convertMacAddress($mac)
{
return implode('', array_map(function ($part) {
return chr(hexdec($part));
}, preg_split('/[:\-]/', $mac)));
}

/**
* Generates a magic packet (6 * FF) to be used in WOL request
* @return string The contents of the mahic packet to send
*/
private function generateMagicPacket()
{
return str_repeat(chr(255), 6);
Expand Down

0 comments on commit 55a682a

Please sign in to comment.