id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
40,800
dapphp/radius
src/EAPPacket.php
EAPPacket.mschapv2
public static function mschapv2(\Dapphp\Radius\MsChapV2Packet $chapPacket, $id = null) { $packet = new self(); $packet->setId($id); $packet->code = self::CODE_RESPONSE; $packet->type = self::TYPE_EAP_MS_AUTH; $packet->data = $chapPacket->__toString(); return $packet->__toString(); }
php
public static function mschapv2(\Dapphp\Radius\MsChapV2Packet $chapPacket, $id = null) { $packet = new self(); $packet->setId($id); $packet->code = self::CODE_RESPONSE; $packet->type = self::TYPE_EAP_MS_AUTH; $packet->data = $chapPacket->__toString(); return $packet->__toString(); }
[ "public", "static", "function", "mschapv2", "(", "\\", "Dapphp", "\\", "Radius", "\\", "MsChapV2Packet", "$", "chapPacket", ",", "$", "id", "=", "null", ")", "{", "$", "packet", "=", "new", "self", "(", ")", ";", "$", "packet", "->", "setId", "(", "$...
Helper function for sending an MSCHAP v2 packet encapsulated in an EAP packet @param \Dapphp\Radius\MsChapV2Packet $chapPacket The MSCHAP v2 packet to send @param int $id The CHAP packet identifier (random if omitted) @return string An EAP-MSCHAPv2 packet
[ "Helper", "function", "for", "sending", "an", "MSCHAP", "v2", "packet", "encapsulated", "in", "an", "EAP", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/EAPPacket.php#L54-L63
40,801
dapphp/radius
src/EAPPacket.php
EAPPacket.fromString
public static function fromString($packet) { // TODO: validate incoming packet better $p = new self(); $p->code = ord($packet[0]); $p->id = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $length = array_shift($temp); if (strlen($packet) != $length) { return false; } $p->type = ord(substr($packet, 4, 1)); $p->data = substr($packet, 5); return $p; }
php
public static function fromString($packet) { // TODO: validate incoming packet better $p = new self(); $p->code = ord($packet[0]); $p->id = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $length = array_shift($temp); if (strlen($packet) != $length) { return false; } $p->type = ord(substr($packet, 4, 1)); $p->data = substr($packet, 5); return $p; }
[ "public", "static", "function", "fromString", "(", "$", "packet", ")", "{", "// TODO: validate incoming packet better", "$", "p", "=", "new", "self", "(", ")", ";", "$", "p", "->", "code", "=", "ord", "(", "$", "packet", "[", "0", "]", ")", ";", "$", ...
Convert a raw EAP packet into a structure @param string $packet The EAP packet @return \Dapphp\Radius\EAPPacket The parsed packet structure
[ "Convert", "a", "raw", "EAP", "packet", "into", "a", "structure" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/EAPPacket.php#L71-L89
40,802
dapphp/radius
src/EAPPacket.php
EAPPacket.setId
public function setId($id = null) { if ($id == null) { $this->id = mt_rand(0, 255); } else { $this->id = (int)$id; } return $this; }
php
public function setId($id = null) { if ($id == null) { $this->id = mt_rand(0, 255); } else { $this->id = (int)$id; } return $this; }
[ "public", "function", "setId", "(", "$", "id", "=", "null", ")", "{", "if", "(", "$", "id", "==", "null", ")", "{", "$", "this", "->", "id", "=", "mt_rand", "(", "0", ",", "255", ")", ";", "}", "else", "{", "$", "this", "->", "id", "=", "("...
Set the ID of the EAP packet @param int $id The EAP packet ID @return \Dapphp\Radius\EAPPacket Fluent interface
[ "Set", "the", "ID", "of", "the", "EAP", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/EAPPacket.php#L96-L105
40,803
dapphp/radius
src/Radius.php
Radius.setPassword
public function setPassword($password) { $this->password = $password; $encryptedPassword = $this->getEncryptedPassword($password, $this->getSecret(), $this->getRequestAuthenticator()); $this->setAttribute(2, $encryptedPassword); return $this; }
php
public function setPassword($password) { $this->password = $password; $encryptedPassword = $this->getEncryptedPassword($password, $this->getSecret(), $this->getRequestAuthenticator()); $this->setAttribute(2, $encryptedPassword); return $this; }
[ "public", "function", "setPassword", "(", "$", "password", ")", "{", "$", "this", "->", "password", "=", "$", "password", ";", "$", "encryptedPassword", "=", "$", "this", "->", "getEncryptedPassword", "(", "$", "password", ",", "$", "this", "->", "getSecre...
Set the User-Password for PAP authentication. Do not use this if you will be using CHAP-MD5, MS-CHAP v1 or MS-CHAP v2 passwords. @param string $password The plain text password for authentication @return \Dapphp\Radius\Radius
[ "Set", "the", "User", "-", "Password", "for", "PAP", "authentication", ".", "Do", "not", "use", "this", "if", "you", "will", "be", "using", "CHAP", "-", "MD5", "MS", "-", "CHAP", "v1", "or", "MS", "-", "CHAP", "v2", "passwords", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L397-L405
40,804
dapphp/radius
src/Radius.php
Radius.getEncryptedPassword
public function getEncryptedPassword($password, $secret, $requestAuthenticator) { $encryptedPassword = ''; $paddedPassword = $password; if (0 != (strlen($password) % 16)) { $paddedPassword .= str_repeat(chr(0), (16 - strlen($password) % 16)); } $previous = $requestAuthenticator; for ($i = 0; $i < (strlen($paddedPassword) / 16); ++$i) { $temp = md5($secret . $previous); $previous = ''; for ($j = 0; $j <= 15; ++$j) { $value1 = ord(substr($paddedPassword, ($i * 16) + $j, 1)); $value2 = hexdec(substr($temp, 2 * $j, 2)); $xor_result = $value1 ^ $value2; $previous .= chr($xor_result); } $encryptedPassword .= $previous; } return $encryptedPassword; }
php
public function getEncryptedPassword($password, $secret, $requestAuthenticator) { $encryptedPassword = ''; $paddedPassword = $password; if (0 != (strlen($password) % 16)) { $paddedPassword .= str_repeat(chr(0), (16 - strlen($password) % 16)); } $previous = $requestAuthenticator; for ($i = 0; $i < (strlen($paddedPassword) / 16); ++$i) { $temp = md5($secret . $previous); $previous = ''; for ($j = 0; $j <= 15; ++$j) { $value1 = ord(substr($paddedPassword, ($i * 16) + $j, 1)); $value2 = hexdec(substr($temp, 2 * $j, 2)); $xor_result = $value1 ^ $value2; $previous .= chr($xor_result); } $encryptedPassword .= $previous; } return $encryptedPassword; }
[ "public", "function", "getEncryptedPassword", "(", "$", "password", ",", "$", "secret", ",", "$", "requestAuthenticator", ")", "{", "$", "encryptedPassword", "=", "''", ";", "$", "paddedPassword", "=", "$", "password", ";", "if", "(", "0", "!=", "(", "strl...
Get a RADIUS encrypted password from a plaintext password, shared secret, and request authenticator. This method should generally not need to be called directly. @param string $password The plain text password @param string $secret The RADIUS shared secret @param string $requestAuthenticator 16 byte request authenticator @return string The encrypted password
[ "Get", "a", "RADIUS", "encrypted", "password", "from", "a", "plaintext", "password", "shared", "secret", "and", "request", "authenticator", ".", "This", "method", "should", "generally", "not", "need", "to", "be", "called", "directly", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L426-L451
40,805
dapphp/radius
src/Radius.php
Radius.getChapPassword
public function getChapPassword($password, $chapId, $requestAuthenticator) { return md5(pack('C', $chapId) . $password . $requestAuthenticator, true); }
php
public function getChapPassword($password, $chapId, $requestAuthenticator) { return md5(pack('C', $chapId) . $password . $requestAuthenticator, true); }
[ "public", "function", "getChapPassword", "(", "$", "password", ",", "$", "chapId", ",", "$", "requestAuthenticator", ")", "{", "return", "md5", "(", "pack", "(", "'C'", ",", "$", "chapId", ")", ".", "$", "password", ".", "$", "requestAuthenticator", ",", ...
Generate a CHAP password. There is generally no need to call this method directly. @param string $password The password to hash using CHAP @param int $chapId The CHAP packet ID @param string $requestAuthenticator The request authenticator value @return string The hashed CHAP password
[ "Generate", "a", "CHAP", "password", ".", "There", "is", "generally", "no", "need", "to", "call", "this", "method", "directly", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L522-L525
40,806
dapphp/radius
src/Radius.php
Radius.setNasPort
public function setNasPort($port = 0) { $this->nasPort = intval($port); $this->setAttribute(5, $this->nasPort); return $this; }
php
public function setNasPort($port = 0) { $this->nasPort = intval($port); $this->setAttribute(5, $this->nasPort); return $this; }
[ "public", "function", "setNasPort", "(", "$", "port", "=", "0", ")", "{", "$", "this", "->", "nasPort", "=", "intval", "(", "$", "port", ")", ";", "$", "this", "->", "setAttribute", "(", "5", ",", "$", "this", "->", "nasPort", ")", ";", "return", ...
Set the physical port number of the NAS which is authenticating the user. @param number $port The NAS port @return \Dapphp\Radius\Radius
[ "Set", "the", "physical", "port", "number", "of", "the", "NAS", "which", "is", "authenticating", "the", "user", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L597-L603
40,807
dapphp/radius
src/Radius.php
Radius.getReadableReceivedAttributes
public function getReadableReceivedAttributes() { $attributes = ''; if (isset($this->attributesReceived)) { foreach($this->attributesReceived as $receivedAttr) { $info = $this->getAttributesInfo($receivedAttr[0]); $attributes .= sprintf('%s: ', $info[0]); if (26 == $receivedAttr[0]) { $vendorArr = $this->decodeVendorSpecificContent($receivedAttr[1]); foreach($vendorArr as $vendor) { $attributes .= sprintf('Vendor-Id: %s, Vendor-type: %s, Attribute-specific: %s', $vendor[0], $vendor[1], $vendor[2]); } } else { $attribues = $receivedAttr[1]; } $attributes .= "<br>\n"; } } return $attributes; }
php
public function getReadableReceivedAttributes() { $attributes = ''; if (isset($this->attributesReceived)) { foreach($this->attributesReceived as $receivedAttr) { $info = $this->getAttributesInfo($receivedAttr[0]); $attributes .= sprintf('%s: ', $info[0]); if (26 == $receivedAttr[0]) { $vendorArr = $this->decodeVendorSpecificContent($receivedAttr[1]); foreach($vendorArr as $vendor) { $attributes .= sprintf('Vendor-Id: %s, Vendor-type: %s, Attribute-specific: %s', $vendor[0], $vendor[1], $vendor[2]); } } else { $attribues = $receivedAttr[1]; } $attributes .= "<br>\n"; } } return $attributes; }
[ "public", "function", "getReadableReceivedAttributes", "(", ")", "{", "$", "attributes", "=", "''", ";", "if", "(", "isset", "(", "$", "this", "->", "attributesReceived", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesReceived", "as", "$", "r...
For debugging purposes. Print the attributes from the last received packet as a readble string @return string The RADIUS packet attributes in human readable format
[ "For", "debugging", "purposes", ".", "Print", "the", "attributes", "from", "the", "last", "received", "packet", "as", "a", "readble", "string" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L717-L741
40,808
dapphp/radius
src/Radius.php
Radius.getAttribute
public function getAttribute($type) { $value = null; if (is_array($this->attributesReceived)) { foreach($this->attributesReceived as $attr) { if (intval($type) == $attr[0]) { $value = $attr[1]; break; } } } return $value; }
php
public function getAttribute($type) { $value = null; if (is_array($this->attributesReceived)) { foreach($this->attributesReceived as $attr) { if (intval($type) == $attr[0]) { $value = $attr[1]; break; } } } return $value; }
[ "public", "function", "getAttribute", "(", "$", "type", ")", "{", "$", "value", "=", "null", ";", "if", "(", "is_array", "(", "$", "this", "->", "attributesReceived", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesReceived", "as", "$", "a...
Get the value of an attribute from the last received RADIUS response packet. @param int $type The attribute ID to get @return NULL|string NULL if no such attribute was set in the response packet, or the data of that attribute
[ "Get", "the", "value", "of", "an", "attribute", "from", "the", "last", "received", "RADIUS", "response", "packet", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L749-L763
40,809
dapphp/radius
src/Radius.php
Radius.getRadiusPacketInfo
public function getRadiusPacketInfo($info_index) { if (isset($this->radiusPackets[intval($info_index)])) { return $this->radiusPackets[intval($info_index)]; } else { return ''; } }
php
public function getRadiusPacketInfo($info_index) { if (isset($this->radiusPackets[intval($info_index)])) { return $this->radiusPackets[intval($info_index)]; } else { return ''; } }
[ "public", "function", "getRadiusPacketInfo", "(", "$", "info_index", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "radiusPackets", "[", "intval", "(", "$", "info_index", ")", "]", ")", ")", "{", "return", "$", "this", "->", "radiusPackets", "[",...
Gets the name of a RADIUS packet from the numeric value. This is only used for debugging functions @param number $info_index The packet type number @return mixed|string
[ "Gets", "the", "name", "of", "a", "RADIUS", "packet", "from", "the", "numeric", "value", ".", "This", "is", "only", "used", "for", "debugging", "functions" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L772-L779
40,810
dapphp/radius
src/Radius.php
Radius.getAttributesInfo
public function getAttributesInfo($info_index) { if (isset($this->attributesInfo[intval($info_index)])) { return $this->attributesInfo[intval($info_index)]; } else { return array('', ''); } }
php
public function getAttributesInfo($info_index) { if (isset($this->attributesInfo[intval($info_index)])) { return $this->attributesInfo[intval($info_index)]; } else { return array('', ''); } }
[ "public", "function", "getAttributesInfo", "(", "$", "info_index", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attributesInfo", "[", "intval", "(", "$", "info_index", ")", "]", ")", ")", "{", "return", "$", "this", "->", "attributesInfo", "[",...
Gets the info about a RADIUS attribute identifier such as the attribute name and data type. This is used internally for encoding packets and debug output. @param number $info_index The RADIUS packet attribute number @return array 2 element array with Attibute-Name and Data Type
[ "Gets", "the", "info", "about", "a", "RADIUS", "attribute", "identifier", "such", "as", "the", "attribute", "name", "and", "data", "type", ".", "This", "is", "used", "internally", "for", "encoding", "packets", "and", "debug", "output", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L788-L795
40,811
dapphp/radius
src/Radius.php
Radius.setAttribute
public function setAttribute($type, $value) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { $index = $i; break; } } } $temp = null; if (isset($this->attributesInfo[$type])) { switch ($this->attributesInfo[$type][1]) { case 'T': // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'S': // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'A': // Address, 32 bit value, most significant octet first. $ip = explode('.', $value); $temp = chr($type) . chr(6) . chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]); break; case 'I': // Integer, 32 bit unsigned value, most significant octet first. $temp = chr($type) . chr(6) . chr(($value / (256 * 256 * 256)) % 256) . chr(($value / (256 * 256)) % 256) . chr(($value / (256)) % 256) . chr($value % 256); break; case 'D': // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC) $temp = null; break; default: $temp = null; } } if ($index > -1) { if ($type == 26) { // vendor specific $this->attributesToSend[$index][] = $temp; $action = 'Added'; } else { $this->attributesToSend[$index] = $temp; $action = 'Modified'; } } else { $this->attributesToSend[] = ($type == 26 /* vendor specific */) ? array($temp) : $temp; $action = 'Added'; } $info = $this->getAttributesInfo($type); $this->debugInfo("{$action} Attribute {$type} ({$info[0]}), format {$info[1]}, value <em>{$value}</em>"); return $this; }
php
public function setAttribute($type, $value) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { $index = $i; break; } } } $temp = null; if (isset($this->attributesInfo[$type])) { switch ($this->attributesInfo[$type][1]) { case 'T': // Text, 1-253 octets containing UTF-8 encoded ISO 10646 characters (RFC 2279). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'S': // String, 1-253 octets containing binary data (values 0 through 255 decimal, inclusive). $temp = chr($type) . chr(2 + strlen($value)) . $value; break; case 'A': // Address, 32 bit value, most significant octet first. $ip = explode('.', $value); $temp = chr($type) . chr(6) . chr($ip[0]) . chr($ip[1]) . chr($ip[2]) . chr($ip[3]); break; case 'I': // Integer, 32 bit unsigned value, most significant octet first. $temp = chr($type) . chr(6) . chr(($value / (256 * 256 * 256)) % 256) . chr(($value / (256 * 256)) % 256) . chr(($value / (256)) % 256) . chr($value % 256); break; case 'D': // Time, 32 bit unsigned value, most significant octet first -- seconds since 00:00:00 UTC, January 1, 1970. (not used in this RFC) $temp = null; break; default: $temp = null; } } if ($index > -1) { if ($type == 26) { // vendor specific $this->attributesToSend[$index][] = $temp; $action = 'Added'; } else { $this->attributesToSend[$index] = $temp; $action = 'Modified'; } } else { $this->attributesToSend[] = ($type == 26 /* vendor specific */) ? array($temp) : $temp; $action = 'Added'; } $info = $this->getAttributesInfo($type); $this->debugInfo("{$action} Attribute {$type} ({$info[0]}), format {$info[1]}, value <em>{$value}</em>"); return $this; }
[ "public", "function", "setAttribute", "(", "$", "type", ",", "$", "value", ")", "{", "$", "index", "=", "-", "1", ";", "if", "(", "is_array", "(", "$", "this", "->", "attributesToSend", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesToS...
Set an arbitrary RADIUS attribute to be sent in the next packet. @param number $type The number of the RADIUS attribute @param mixed $value The value of the attribute @return \Dapphp\Radius\Radius
[ "Set", "an", "arbitrary", "RADIUS", "attribute", "to", "be", "sent", "in", "the", "next", "packet", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L804-L872
40,812
dapphp/radius
src/Radius.php
Radius.getAttributesToSend
public function getAttributesToSend($type = null) { if (is_array($this->attributesToSend)) { if ($type == null) { return $this->attributesToSend; } else { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { return $this->decodeAttribute(substr($tmp, 2), $type); } } return null; } } return array(); }
php
public function getAttributesToSend($type = null) { if (is_array($this->attributesToSend)) { if ($type == null) { return $this->attributesToSend; } else { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { return $this->decodeAttribute(substr($tmp, 2), $type); } } return null; } } return array(); }
[ "public", "function", "getAttributesToSend", "(", "$", "type", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "attributesToSend", ")", ")", "{", "if", "(", "$", "type", "==", "null", ")", "{", "return", "$", "this", "->", "attr...
Get one or all set attributes to send @param int|null $type RADIUS attribute type, or null for all @return mixed array of attributes to send, or null if specific attribute not found, or
[ "Get", "one", "or", "all", "set", "attributes", "to", "send" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L880-L901
40,813
dapphp/radius
src/Radius.php
Radius.setVendorSpecificAttribute
public function setVendorSpecificAttribute($vendorId, $attributeType, $attributeValue) { $data = pack('N', $vendorId); $data .= chr($attributeType); $data .= chr(2 + strlen($attributeValue)); $data .= $attributeValue; $this->setAttribute(26, $data); return $this; }
php
public function setVendorSpecificAttribute($vendorId, $attributeType, $attributeValue) { $data = pack('N', $vendorId); $data .= chr($attributeType); $data .= chr(2 + strlen($attributeValue)); $data .= $attributeValue; $this->setAttribute(26, $data); return $this; }
[ "public", "function", "setVendorSpecificAttribute", "(", "$", "vendorId", ",", "$", "attributeType", ",", "$", "attributeValue", ")", "{", "$", "data", "=", "pack", "(", "'N'", ",", "$", "vendorId", ")", ";", "$", "data", ".=", "chr", "(", "$", "attribut...
Adds a vendor specific attribute to the RADIUS packet @param number $vendorId The RADIUS vendor ID @param number $attributeType The attribute number of the vendor specific attribute @param mixed $attributeValue The data for the attribute @return \Dapphp\Radius\Radius
[ "Adds", "a", "vendor", "specific", "attribute", "to", "the", "RADIUS", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L911-L921
40,814
dapphp/radius
src/Radius.php
Radius.removeAttribute
public function removeAttribute($type) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { unset($this->attributesToSend[$i]); break; } } } return $this; }
php
public function removeAttribute($type) { $index = -1; if (is_array($this->attributesToSend)) { foreach($this->attributesToSend as $i => $attr) { if (is_array($attr)) { $tmp = $attr[0]; } else { $tmp = $attr; } if ($type == ord(substr($tmp, 0, 1))) { unset($this->attributesToSend[$i]); break; } } } return $this; }
[ "public", "function", "removeAttribute", "(", "$", "type", ")", "{", "$", "index", "=", "-", "1", ";", "if", "(", "is_array", "(", "$", "this", "->", "attributesToSend", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributesToSend", "as", "$", ...
Remove an attribute from a RADIUS packet @param number $type The attribute number to remove @return \Dapphp\Radius\Radius
[ "Remove", "an", "attribute", "from", "a", "RADIUS", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L929-L947
40,815
dapphp/radius
src/Radius.php
Radius.decodeVendorSpecificContent
public function decodeVendorSpecificContent($rawValue) { $result = array(); $offset = 0; $vendorId = (ord(substr($rawValue, 0, 1)) * 256 * 256 * 256) + (ord(substr($rawValue, 1, 1)) * 256 * 256) + (ord(substr($rawValue, 2, 1)) * 256) + ord(substr($rawValue, 3, 1)); $offset += 4; while ($offset < strlen($rawValue)) { $vendorType = (ord(substr($rawValue, 0 + $offset, 1))); $vendorLength = (ord(substr($rawValue, 1 + $offset, 1))); $attributeSpecific = substr($rawValue, 2 + $offset, $vendorLength); $result[] = array($vendorId, $vendorType, $attributeSpecific); $offset += $vendorLength; } return $result; }
php
public function decodeVendorSpecificContent($rawValue) { $result = array(); $offset = 0; $vendorId = (ord(substr($rawValue, 0, 1)) * 256 * 256 * 256) + (ord(substr($rawValue, 1, 1)) * 256 * 256) + (ord(substr($rawValue, 2, 1)) * 256) + ord(substr($rawValue, 3, 1)); $offset += 4; while ($offset < strlen($rawValue)) { $vendorType = (ord(substr($rawValue, 0 + $offset, 1))); $vendorLength = (ord(substr($rawValue, 1 + $offset, 1))); $attributeSpecific = substr($rawValue, 2 + $offset, $vendorLength); $result[] = array($vendorId, $vendorType, $attributeSpecific); $offset += $vendorLength; } return $result; }
[ "public", "function", "decodeVendorSpecificContent", "(", "$", "rawValue", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "offset", "=", "0", ";", "$", "vendorId", "=", "(", "ord", "(", "substr", "(", "$", "rawValue", ",", "0", ",", "1", ...
Decodes a vendor specific attribute in a response packet @param string $rawValue The raw packet attribute data as seen on the wire @return array Array of vendor specific attributes in the response packet
[ "Decodes", "a", "vendor", "specific", "attribute", "in", "a", "response", "packet" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L978-L997
40,816
dapphp/radius
src/Radius.php
Radius.accessRequest
public function accessRequest($username = '', $password = '', $timeout = 0, $state = null) { $this->clearDataReceived() ->clearError() ->setPacketType(self::TYPE_ACCESS_REQUEST); if (0 < strlen($username)) { $this->setUsername($username); } if (0 < strlen($password)) { $this->setPassword($password); } if ($state !== null) { $this->setAttribute(24, $state); } else { $this->setAttribute(6, 1); // 1=Login } if (intval($timeout) > 0) { $this->setTimeout($timeout); } $packetData = $this->generateRadiusPacket(); $conn = $this->sendRadiusRequest($packetData); if (!$conn) { $this->debugInfo(sprintf( 'Failed to send packet to %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } $receivedPacket = $this->readRadiusResponse($conn); @fclose($conn); if (!$receivedPacket) { $this->debugInfo(sprintf( 'Error receiving response packet from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if (!$this->parseRadiusResponsePacket($receivedPacket)) { $this->debugInfo(sprintf( 'Bad RADIUS response from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if ($this->radiusPacketReceived == self::TYPE_ACCESS_REJECT) { $this->errorCode = 3; $this->errorMessage = 'Access rejected'; } return (self::TYPE_ACCESS_ACCEPT == ($this->radiusPacketReceived)); }
php
public function accessRequest($username = '', $password = '', $timeout = 0, $state = null) { $this->clearDataReceived() ->clearError() ->setPacketType(self::TYPE_ACCESS_REQUEST); if (0 < strlen($username)) { $this->setUsername($username); } if (0 < strlen($password)) { $this->setPassword($password); } if ($state !== null) { $this->setAttribute(24, $state); } else { $this->setAttribute(6, 1); // 1=Login } if (intval($timeout) > 0) { $this->setTimeout($timeout); } $packetData = $this->generateRadiusPacket(); $conn = $this->sendRadiusRequest($packetData); if (!$conn) { $this->debugInfo(sprintf( 'Failed to send packet to %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } $receivedPacket = $this->readRadiusResponse($conn); @fclose($conn); if (!$receivedPacket) { $this->debugInfo(sprintf( 'Error receiving response packet from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if (!$this->parseRadiusResponsePacket($receivedPacket)) { $this->debugInfo(sprintf( 'Bad RADIUS response from %s; error: %s', $this->server, $this->getErrorMessage()) ); return false; } if ($this->radiusPacketReceived == self::TYPE_ACCESS_REJECT) { $this->errorCode = 3; $this->errorMessage = 'Access rejected'; } return (self::TYPE_ACCESS_ACCEPT == ($this->radiusPacketReceived)); }
[ "public", "function", "accessRequest", "(", "$", "username", "=", "''", ",", "$", "password", "=", "''", ",", "$", "timeout", "=", "0", ",", "$", "state", "=", "null", ")", "{", "$", "this", "->", "clearDataReceived", "(", ")", "->", "clearError", "(...
Issue an Access-Request packet to the RADIUS server. @param string $username Username to authenticate as @param string $password Password to authenticate with using PAP @param number $timeout The timeout (in seconds) to wait for a response packet @param string $state The state of the request (default is Service-Type=1) @return boolean true if the server sent an Access-Accept packet, false otherwise
[ "Issue", "an", "Access", "-", "Request", "packet", "to", "the", "RADIUS", "server", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1008-L1074
40,817
dapphp/radius
src/Radius.php
Radius.accessRequestList
public function accessRequestList($serverList, $username = '', $password = '', $timeout = 0, $state = null) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequest($username, $password, $timeout, $state); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
php
public function accessRequestList($serverList, $username = '', $password = '', $timeout = 0, $state = null) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequest($username, $password, $timeout, $state); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
[ "public", "function", "accessRequestList", "(", "$", "serverList", ",", "$", "username", "=", "''", ",", "$", "password", "=", "''", ",", "$", "timeout", "=", "0", ",", "$", "state", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "ser...
Perform an accessRequest against a list of servers. Each server must share the same RADIUS secret. This is useful if you have more than one RADIUS server. This function tries each server until it receives an Access-Accept or Access-Reject response. That is, it will try more than one server in the event of a timeout or other failure. @see \Dapphp\Radius\Radius::accessRequest() @param array $serverList Array of servers to authenticate against @param string $username Username to authenticate as @param string $password Password to authenticate with using PAP @param number $timeout The timeout (in seconds) to wait for a response packet @param string $state The state of the request (default is Service-Type=1) @return boolean true if the server sent an Access-Accept packet, false otherwise
[ "Perform", "an", "accessRequest", "against", "a", "list", "of", "servers", ".", "Each", "server", "must", "share", "the", "same", "RADIUS", "secret", ".", "This", "is", "useful", "if", "you", "have", "more", "than", "one", "RADIUS", "server", ".", "This", ...
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1093-L1119
40,818
dapphp/radius
src/Radius.php
Radius.accessRequestEapMsChapV2List
public function accessRequestEapMsChapV2List($serverList, $username, $password) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequestEapMsChapV2($username, $password); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
php
public function accessRequestEapMsChapV2List($serverList, $username, $password) { if (!is_array($serverList)) { $this->errorCode = 127; $this->errorMessage = sprintf( 'server list passed to accessRequestl must be array; %s given', gettype($serverList) ); return false; } foreach($serverList as $server) { $this->setServer($server); $result = $this->accessRequestEapMsChapV2($username, $password); if ($result === true) { break; // success } elseif ($this->getErrorCode() === self::TYPE_ACCESS_REJECT) { break; // access rejected } else { /* timeout or other possible transient error; try next host */ } } return $result; }
[ "public", "function", "accessRequestEapMsChapV2List", "(", "$", "serverList", ",", "$", "username", ",", "$", "password", ")", "{", "if", "(", "!", "is_array", "(", "$", "serverList", ")", ")", "{", "$", "this", "->", "errorCode", "=", "127", ";", "$", ...
Perform a EAP-MSCHAP v2 4-way authentication against a list of servers. Each server must share the same RADIUS secret. @see \Dapphp\Radius\Radius::accessRequestEapMsChapV2() @see \Dapphp\Radius\Radius::accessRequestList() @param array $serverList Array of servers to authenticate against @param string $username The username to authenticate as @param string $password The plain text password that will be hashed using MS-CHAPv2 @return boolean true if negotiation resulted in an Access-Accept packet, false otherwise
[ "Perform", "a", "EAP", "-", "MSCHAP", "v2", "4", "-", "way", "authentication", "against", "a", "list", "of", "servers", ".", "Each", "server", "must", "share", "the", "same", "RADIUS", "secret", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1312-L1338
40,819
dapphp/radius
src/Radius.php
Radius.sendRadiusRequest
private function sendRadiusRequest($packetData) { $packetLen = strlen($packetData); $conn = @fsockopen('udp://' . $this->server, $this->authenticationPort, $errno, $errstr); if (!$conn) { $this->errorCode = $errno; $this->errorMessage = $errstr; return false; } $sent = fwrite($conn, $packetData); if (!$sent || $packetLen != $sent) { $this->errorCode = 55; // CURLE_SEND_ERROR $this->errorMessage = 'Failed to send UDP packet'; return false; } if ($this->debug) { $this->debugInfo( sprintf( '<b>Packet type %d (%s) sent to %s</b>', $this->radiusPacket, $this->getRadiusPacketInfo($this->radiusPacket), $this->server ) ); foreach($this->attributesToSend as $attrs) { if (!is_array($attrs)) { $attrs = array($attrs); } foreach($attrs as $attr) { $attrInfo = $this->getAttributesInfo(ord(substr($attr, 0, 1))); $this->debugInfo( sprintf( 'Attribute %d (%s), length (%d), format %s, value <em>%s</em>', ord(substr($attr, 0, 1)), $attrInfo[0], ord(substr($attr, 1, 1)) - 2, $attrInfo[1], $this->decodeAttribute(substr($attr, 2), ord(substr($attr, 0, 1))) ) ); } } } return $conn; }
php
private function sendRadiusRequest($packetData) { $packetLen = strlen($packetData); $conn = @fsockopen('udp://' . $this->server, $this->authenticationPort, $errno, $errstr); if (!$conn) { $this->errorCode = $errno; $this->errorMessage = $errstr; return false; } $sent = fwrite($conn, $packetData); if (!$sent || $packetLen != $sent) { $this->errorCode = 55; // CURLE_SEND_ERROR $this->errorMessage = 'Failed to send UDP packet'; return false; } if ($this->debug) { $this->debugInfo( sprintf( '<b>Packet type %d (%s) sent to %s</b>', $this->radiusPacket, $this->getRadiusPacketInfo($this->radiusPacket), $this->server ) ); foreach($this->attributesToSend as $attrs) { if (!is_array($attrs)) { $attrs = array($attrs); } foreach($attrs as $attr) { $attrInfo = $this->getAttributesInfo(ord(substr($attr, 0, 1))); $this->debugInfo( sprintf( 'Attribute %d (%s), length (%d), format %s, value <em>%s</em>', ord(substr($attr, 0, 1)), $attrInfo[0], ord(substr($attr, 1, 1)) - 2, $attrInfo[1], $this->decodeAttribute(substr($attr, 2), ord(substr($attr, 0, 1))) ) ); } } } return $conn; }
[ "private", "function", "sendRadiusRequest", "(", "$", "packetData", ")", "{", "$", "packetLen", "=", "strlen", "(", "$", "packetData", ")", ";", "$", "conn", "=", "@", "fsockopen", "(", "'udp://'", ".", "$", "this", "->", "server", ",", "$", "this", "-...
Send a RADIUS packet over the wire using UDP. @param string $packetData The raw, complete, RADIUS packet to send @return boolean|resource false if the packet failed to send, or a socket resource on success
[ "Send", "a", "RADIUS", "packet", "over", "the", "wire", "using", "UDP", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1346-L1395
40,820
dapphp/radius
src/Radius.php
Radius.readRadiusResponse
private function readRadiusResponse($conn) { stream_set_blocking($conn, false); $read = array($conn); $write = null; $except = null; $receivedPacket = ''; $packetLen = null; $elapsed = 0; do { // Loop until the entire packet is read. Even with small packets, // not all data might get returned in one read on a non-blocking stream. $t0 = microtime(true); $changed = stream_select($read, $write, $except, $this->timeout); $t1 = microtime(true); if ($changed > 0) { $data = fgets($conn, 1024); // Try to read as much data from the stream in one pass until 4 // bytes are read. Once we have 4 bytes, we can determine the // length of the RADIUS response to know when to stop reading. if ($data === false) { // recv could fail due to ICMP destination unreachable $this->errorCode = 56; // CURLE_RECV_ERROR $this->errorMessage = 'Failure with receiving network data'; return false; } $receivedPacket .= $data; if (strlen($receivedPacket) < 4) { // not enough data to get the size // this will probably never happen continue; } if ($packetLen == null) { // first pass - decode the packet size from response $packetLen = unpack('n', substr($receivedPacket, 2, 2)); $packetLen = (int)array_shift($packetLen); if ($packetLen < 4 || $packetLen > 65507) { $this->errorCode = 102; $this->errorMessage = "Bad packet size in RADIUS response. Got {$packetLen}"; return false; } } } elseif ($changed === false) { $this->errorCode = 2; $this->errorMessage = 'stream_select returned false'; return false; } else { $this->errorCode = 28; // CURLE_OPERATION_TIMEDOUT $this->errorMessage = 'Timed out while waiting for RADIUS response'; return false; } $elapsed += ($t1 - $t0); } while ($elapsed < $this->timeout && strlen($receivedPacket) < $packetLen); return $receivedPacket; }
php
private function readRadiusResponse($conn) { stream_set_blocking($conn, false); $read = array($conn); $write = null; $except = null; $receivedPacket = ''; $packetLen = null; $elapsed = 0; do { // Loop until the entire packet is read. Even with small packets, // not all data might get returned in one read on a non-blocking stream. $t0 = microtime(true); $changed = stream_select($read, $write, $except, $this->timeout); $t1 = microtime(true); if ($changed > 0) { $data = fgets($conn, 1024); // Try to read as much data from the stream in one pass until 4 // bytes are read. Once we have 4 bytes, we can determine the // length of the RADIUS response to know when to stop reading. if ($data === false) { // recv could fail due to ICMP destination unreachable $this->errorCode = 56; // CURLE_RECV_ERROR $this->errorMessage = 'Failure with receiving network data'; return false; } $receivedPacket .= $data; if (strlen($receivedPacket) < 4) { // not enough data to get the size // this will probably never happen continue; } if ($packetLen == null) { // first pass - decode the packet size from response $packetLen = unpack('n', substr($receivedPacket, 2, 2)); $packetLen = (int)array_shift($packetLen); if ($packetLen < 4 || $packetLen > 65507) { $this->errorCode = 102; $this->errorMessage = "Bad packet size in RADIUS response. Got {$packetLen}"; return false; } } } elseif ($changed === false) { $this->errorCode = 2; $this->errorMessage = 'stream_select returned false'; return false; } else { $this->errorCode = 28; // CURLE_OPERATION_TIMEDOUT $this->errorMessage = 'Timed out while waiting for RADIUS response'; return false; } $elapsed += ($t1 - $t0); } while ($elapsed < $this->timeout && strlen($receivedPacket) < $packetLen); return $receivedPacket; }
[ "private", "function", "readRadiusResponse", "(", "$", "conn", ")", "{", "stream_set_blocking", "(", "$", "conn", ",", "false", ")", ";", "$", "read", "=", "array", "(", "$", "conn", ")", ";", "$", "write", "=", "null", ";", "$", "except", "=", "null...
Wait for a UDP response packet and read using a timeout. @param resource $conn The connection resource returned by fsockopen @return boolean|string false on failure, or the RADIUS response packet
[ "Wait", "for", "a", "UDP", "response", "packet", "and", "read", "using", "a", "timeout", "." ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/Radius.php#L1403-L1469
40,821
dapphp/radius
src/MsChapV2Packet.php
MsChapV2Packet.fromString
public static function fromString($packet) { if (strlen($packet) < 5) { return false; } $p = new self(); $p->opcode = ord($packet[0]); $p->msChapId = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $p->msLength = array_shift($temp); $p->valueSize = ord($packet[4]); switch($p->opcode) { case 1: // challenge $p->challenge = substr($packet, 5, 16); $p->name = substr($packet, -($p->msLength + 5 - $p->valueSize - 10)); break; case 2: // response break; case 3: // success break; case 4: // failure $p->response = substr($packet, 4); break; } return $p; }
php
public static function fromString($packet) { if (strlen($packet) < 5) { return false; } $p = new self(); $p->opcode = ord($packet[0]); $p->msChapId = ord($packet[1]); $temp = unpack('n', substr($packet, 2, 2)); $p->msLength = array_shift($temp); $p->valueSize = ord($packet[4]); switch($p->opcode) { case 1: // challenge $p->challenge = substr($packet, 5, 16); $p->name = substr($packet, -($p->msLength + 5 - $p->valueSize - 10)); break; case 2: // response break; case 3: // success break; case 4: // failure $p->response = substr($packet, 4); break; } return $p; }
[ "public", "static", "function", "fromString", "(", "$", "packet", ")", "{", "if", "(", "strlen", "(", "$", "packet", ")", "<", "5", ")", "{", "return", "false", ";", "}", "$", "p", "=", "new", "self", "(", ")", ";", "$", "p", "->", "opcode", "=...
Parse an MSCHAP v2 packet into a structure @param string $packet Raw MSCHAP v2 packet string @return \Dapphp\Radius\MsChapV2Packet The parsed packet structure
[ "Parse", "an", "MSCHAP", "v2", "packet", "into", "a", "structure" ]
1954c34cd67f8a581b0a4c77241f472db0ef8199
https://github.com/dapphp/radius/blob/1954c34cd67f8a581b0a4c77241f472db0ef8199/src/MsChapV2Packet.php#L32-L63
40,822
wapmorgan/Mp3Info
src/Mp3Info.php
Mp3Info.readId3v1Body
private function readId3v1Body($fp) { $this->tags1['song'] = trim(fread($fp, 30)); $this->tags1['artist'] = trim(fread($fp, 30)); $this->tags1['album'] = trim(fread($fp, 30)); $this->tags1['year'] = trim(fread($fp, 4)); $this->tags1['comment'] = trim(fread($fp, 28)); fseek($fp, 1, SEEK_CUR); $this->tags1['track'] = ord(fread($fp, 1)); $this->tags1['genre'] = ord(fread($fp, 1)); return 128; }
php
private function readId3v1Body($fp) { $this->tags1['song'] = trim(fread($fp, 30)); $this->tags1['artist'] = trim(fread($fp, 30)); $this->tags1['album'] = trim(fread($fp, 30)); $this->tags1['year'] = trim(fread($fp, 4)); $this->tags1['comment'] = trim(fread($fp, 28)); fseek($fp, 1, SEEK_CUR); $this->tags1['track'] = ord(fread($fp, 1)); $this->tags1['genre'] = ord(fread($fp, 1)); return 128; }
[ "private", "function", "readId3v1Body", "(", "$", "fp", ")", "{", "$", "this", "->", "tags1", "[", "'song'", "]", "=", "trim", "(", "fread", "(", "$", "fp", ",", "30", ")", ")", ";", "$", "this", "->", "tags1", "[", "'artist'", "]", "=", "trim", ...
Reads id3v1 tag. @return int Returns length of id3v1 tag.
[ "Reads", "id3v1", "tag", "." ]
491bee5706683193b8965122755bd12c47f90560
https://github.com/wapmorgan/Mp3Info/blob/491bee5706683193b8965122755bd12c47f90560/src/Mp3Info.php#L353-L363
40,823
wapmorgan/Mp3Info
src/Mp3Info.php
Mp3Info.isValidAudio
static public function isValidAudio($filename) { if (!file_exists($filename)) throw new Exception('File '.$filename.' is not present!'); $raw = file_get_contents($filename, false, null, 0, 3); return ($raw == self::TAG2_SYNC || (self::FRAME_SYNC == (unpack('n*', $raw)[1] & self::FRAME_SYNC))); }
php
static public function isValidAudio($filename) { if (!file_exists($filename)) throw new Exception('File '.$filename.' is not present!'); $raw = file_get_contents($filename, false, null, 0, 3); return ($raw == self::TAG2_SYNC || (self::FRAME_SYNC == (unpack('n*', $raw)[1] & self::FRAME_SYNC))); }
[ "static", "public", "function", "isValidAudio", "(", "$", "filename", ")", "{", "if", "(", "!", "file_exists", "(", "$", "filename", ")", ")", "throw", "new", "Exception", "(", "'File '", ".", "$", "filename", ".", "' is not present!'", ")", ";", "$", "r...
Simple function that checks mpeg-audio correctness of given file. Actually it checks that first 3 bytes of file is a id3v2 tag mark or that first 11 bits of file is a frame header sync mark. To perform full test create an instance of Mp3Info with given file. @param string $filename File to be tested. @return boolean True if file is looks correct, False otherwise. @throws \Exception
[ "Simple", "function", "that", "checks", "mpeg", "-", "audio", "correctness", "of", "given", "file", ".", "Actually", "it", "checks", "that", "first", "3", "bytes", "of", "file", "is", "a", "id3v2", "tag", "mark", "or", "that", "first", "11", "bits", "of"...
491bee5706683193b8965122755bd12c47f90560
https://github.com/wapmorgan/Mp3Info/blob/491bee5706683193b8965122755bd12c47f90560/src/Mp3Info.php#L656-L661
40,824
mosbth/cimage
CAsciiArt.php
CAsciiArt.setOptions
public function setOptions($options = array()) { $default = array( "characterSet" => 'two', "scale" => 14, "luminanceStrategy" => 3, "customCharacterSet" => null, ); $default = array_merge($default, $options); if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; return $this; }
php
public function setOptions($options = array()) { $default = array( "characterSet" => 'two', "scale" => 14, "luminanceStrategy" => 3, "customCharacterSet" => null, ); $default = array_merge($default, $options); if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; return $this; }
[ "public", "function", "setOptions", "(", "$", "options", "=", "array", "(", ")", ")", "{", "$", "default", "=", "array", "(", "\"characterSet\"", "=>", "'two'", ",", "\"scale\"", "=>", "14", ",", "\"luminanceStrategy\"", "=>", "3", ",", "\"customCharacterSet...
Set options for processing, defaults are available. @param array $options to use as default settings. @return $this
[ "Set", "options", "for", "processing", "defaults", "are", "available", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L80-L101
40,825
mosbth/cimage
CAsciiArt.php
CAsciiArt.createFromFile
public function createFromFile($filename) { $img = imagecreatefromstring(file_get_contents($filename)); list($width, $height) = getimagesize($filename); $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); $toY = min($y + $this->scale, $height - 1); $luminance = $this->luminanceAreaAverage($img, $x, $y, $toX, $toY); $ascii .= $this->luminance2character($luminance); } $ascii .= PHP_EOL; } return $ascii; }
php
public function createFromFile($filename) { $img = imagecreatefromstring(file_get_contents($filename)); list($width, $height) = getimagesize($filename); $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); $toY = min($y + $this->scale, $height - 1); $luminance = $this->luminanceAreaAverage($img, $x, $y, $toX, $toY); $ascii .= $this->luminance2character($luminance); } $ascii .= PHP_EOL; } return $ascii; }
[ "public", "function", "createFromFile", "(", "$", "filename", ")", "{", "$", "img", "=", "imagecreatefromstring", "(", "file_get_contents", "(", "$", "filename", ")", ")", ";", "list", "(", "$", "width", ",", "$", "height", ")", "=", "getimagesize", "(", ...
Create an Ascii image from an image file. @param string $filename of the image to use. @return string $ascii with the ASCII image.
[ "Create", "an", "Ascii", "image", "from", "an", "image", "file", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L112-L132
40,826
mosbth/cimage
CAsciiArt.php
CAsciiArt.luminanceAreaAverage
public function luminanceAreaAverage($img, $x1, $y1, $x2, $y2) { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); $red = (($rgb >> 16) & 0xFF); $green = (($rgb >> 8) & 0xFF); $blue = ($rgb & 0xFF); $luminance += $this->getLuminance($red, $green, $blue); } } return $luminance / $numPixels; }
php
public function luminanceAreaAverage($img, $x1, $y1, $x2, $y2) { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); $red = (($rgb >> 16) & 0xFF); $green = (($rgb >> 8) & 0xFF); $blue = ($rgb & 0xFF); $luminance += $this->getLuminance($red, $green, $blue); } } return $luminance / $numPixels; }
[ "public", "function", "luminanceAreaAverage", "(", "$", "img", ",", "$", "x1", ",", "$", "y1", ",", "$", "x2", ",", "$", "y2", ")", "{", "$", "numPixels", "=", "(", "$", "x2", "-", "$", "x1", "+", "1", ")", "*", "(", "$", "y2", "-", "$", "y...
Get the luminance from a region of an image using average color value. @param string $img the image. @param integer $x1 the area to get pixels from. @param integer $y1 the area to get pixels from. @param integer $x2 the area to get pixels from. @param integer $y2 the area to get pixels from. @return integer $luminance with a value between 0 and 100.
[ "Get", "the", "luminance", "from", "a", "region", "of", "an", "image", "using", "average", "color", "value", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L147-L163
40,827
mosbth/cimage
CAsciiArt.php
CAsciiArt.getLuminance
public function getLuminance($red, $green, $blue) { switch ($this->luminanceStrategy) { case 1: $luminance = ($red * 0.2126 + $green * 0.7152 + $blue * 0.0722) / 255; break; case 2: $luminance = ($red * 0.299 + $green * 0.587 + $blue * 0.114) / 255; break; case 3: $luminance = sqrt(0.299 * pow($red, 2) + 0.587 * pow($green, 2) + 0.114 * pow($blue, 2)) / 255; break; case 0: default: $luminance = ($red + $green + $blue) / (255 * 3); } return $luminance; }
php
public function getLuminance($red, $green, $blue) { switch ($this->luminanceStrategy) { case 1: $luminance = ($red * 0.2126 + $green * 0.7152 + $blue * 0.0722) / 255; break; case 2: $luminance = ($red * 0.299 + $green * 0.587 + $blue * 0.114) / 255; break; case 3: $luminance = sqrt(0.299 * pow($red, 2) + 0.587 * pow($green, 2) + 0.114 * pow($blue, 2)) / 255; break; case 0: default: $luminance = ($red + $green + $blue) / (255 * 3); } return $luminance; }
[ "public", "function", "getLuminance", "(", "$", "red", ",", "$", "green", ",", "$", "blue", ")", "{", "switch", "(", "$", "this", "->", "luminanceStrategy", ")", "{", "case", "1", ":", "$", "luminance", "=", "(", "$", "red", "*", "0.2126", "+", "$"...
Calculate luminance value with different strategies. @param integer $red The color red. @param integer $green The color green. @param integer $blue The color blue. @return float $luminance with a value between 0 and 1.
[ "Calculate", "luminance", "value", "with", "different", "strategies", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L176-L194
40,828
mosbth/cimage
CAsciiArt.php
CAsciiArt.luminance2character
public function luminance2character($luminance) { $position = (int) round($luminance * ($this->charCount - 1)); $char = $this->characters[$position]; return $char; }
php
public function luminance2character($luminance) { $position = (int) round($luminance * ($this->charCount - 1)); $char = $this->characters[$position]; return $char; }
[ "public", "function", "luminance2character", "(", "$", "luminance", ")", "{", "$", "position", "=", "(", "int", ")", "round", "(", "$", "luminance", "*", "(", "$", "this", "->", "charCount", "-", "1", ")", ")", ";", "$", "char", "=", "$", "this", "...
Translate the luminance value to a character. @param string $position a value between 0-100 representing the luminance. @return string with the ascii character.
[ "Translate", "the", "luminance", "value", "to", "a", "character", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CAsciiArt.php#L206-L211
40,829
mosbth/cimage
CImage.php
CImage.injectDependency
public function injectDependency($property, $object) { if (!property_exists($this, $property)) { $this->raiseError("Injecting unknown property."); } $this->$property = $object; return $this; }
php
public function injectDependency($property, $object) { if (!property_exists($this, $property)) { $this->raiseError("Injecting unknown property."); } $this->$property = $object; return $this; }
[ "public", "function", "injectDependency", "(", "$", "property", ",", "$", "object", ")", "{", "if", "(", "!", "property_exists", "(", "$", "this", ",", "$", "property", ")", ")", "{", "$", "this", "->", "raiseError", "(", "\"Injecting unknown property.\"", ...
Inject object and use it, must be available as member. @param string $property to set as object. @param object $object to set to property. @return $this
[ "Inject", "object", "and", "use", "it", "must", "be", "available", "as", "member", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L478-L485
40,830
mosbth/cimage
CImage.php
CImage.setRemoteDownload
public function setRemoteDownload($allow, $cache, $pattern = null) { $this->allowRemote = $allow; $this->remoteCache = $cache; $this->remotePattern = is_null($pattern) ? $this->remotePattern : $pattern; $this->log( "Set remote download to: " . ($this->allowRemote ? "true" : "false") . " using pattern " . $this->remotePattern ); return $this; }
php
public function setRemoteDownload($allow, $cache, $pattern = null) { $this->allowRemote = $allow; $this->remoteCache = $cache; $this->remotePattern = is_null($pattern) ? $this->remotePattern : $pattern; $this->log( "Set remote download to: " . ($this->allowRemote ? "true" : "false") . " using pattern " . $this->remotePattern ); return $this; }
[ "public", "function", "setRemoteDownload", "(", "$", "allow", ",", "$", "cache", ",", "$", "pattern", "=", "null", ")", "{", "$", "this", "->", "allowRemote", "=", "$", "allow", ";", "$", "this", "->", "remoteCache", "=", "$", "cache", ";", "$", "thi...
Allow or disallow remote image download. @param boolean $allow true or false to enable and disable. @param string $cache path to cache dir. @param string $pattern to use to detect if its a remote file. @return $this
[ "Allow", "or", "disallow", "remote", "image", "download", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L567-L581
40,831
mosbth/cimage
CImage.php
CImage.isRemoteSource
public function isRemoteSource($src) { $remote = preg_match($this->remotePattern, $src); $this->log("Detected remote image: " . ($remote ? "true" : "false")); return !!$remote; }
php
public function isRemoteSource($src) { $remote = preg_match($this->remotePattern, $src); $this->log("Detected remote image: " . ($remote ? "true" : "false")); return !!$remote; }
[ "public", "function", "isRemoteSource", "(", "$", "src", ")", "{", "$", "remote", "=", "preg_match", "(", "$", "this", "->", "remotePattern", ",", "$", "src", ")", ";", "$", "this", "->", "log", "(", "\"Detected remote image: \"", ".", "(", "$", "remote"...
Check if the image resource is a remote file or not. @param string $src check if src is remote. @return boolean true if $src is a remote file, else false.
[ "Check", "if", "the", "image", "resource", "is", "a", "remote", "file", "or", "not", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L592-L597
40,832
mosbth/cimage
CImage.php
CImage.setRemoteHostWhitelist
public function setRemoteHostWhitelist($whitelist = null) { $this->remoteHostWhitelist = $whitelist; $this->log( "Setting remote host whitelist to: " . (is_null($whitelist) ? "null" : print_r($whitelist, 1)) ); return $this; }
php
public function setRemoteHostWhitelist($whitelist = null) { $this->remoteHostWhitelist = $whitelist; $this->log( "Setting remote host whitelist to: " . (is_null($whitelist) ? "null" : print_r($whitelist, 1)) ); return $this; }
[ "public", "function", "setRemoteHostWhitelist", "(", "$", "whitelist", "=", "null", ")", "{", "$", "this", "->", "remoteHostWhitelist", "=", "$", "whitelist", ";", "$", "this", "->", "log", "(", "\"Setting remote host whitelist to: \"", ".", "(", "is_null", "(",...
Set whitelist for valid hostnames from where remote source can be downloaded. @param array $whitelist with regexp hostnames to allow download from. @return $this
[ "Set", "whitelist", "for", "valid", "hostnames", "from", "where", "remote", "source", "can", "be", "downloaded", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L609-L617
40,833
mosbth/cimage
CImage.php
CImage.isRemoteSourceOnWhitelist
public function isRemoteSourceOnWhitelist($src) { if (is_null($this->remoteHostWhitelist)) { $this->log("Remote host on whitelist not configured - allowing."); return true; } $whitelist = new CWhitelist(); $hostname = parse_url($src, PHP_URL_HOST); $allow = $whitelist->check($hostname, $this->remoteHostWhitelist); $this->log( "Remote host is on whitelist: " . ($allow ? "true" : "false") ); return $allow; }
php
public function isRemoteSourceOnWhitelist($src) { if (is_null($this->remoteHostWhitelist)) { $this->log("Remote host on whitelist not configured - allowing."); return true; } $whitelist = new CWhitelist(); $hostname = parse_url($src, PHP_URL_HOST); $allow = $whitelist->check($hostname, $this->remoteHostWhitelist); $this->log( "Remote host is on whitelist: " . ($allow ? "true" : "false") ); return $allow; }
[ "public", "function", "isRemoteSourceOnWhitelist", "(", "$", "src", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "remoteHostWhitelist", ")", ")", "{", "$", "this", "->", "log", "(", "\"Remote host on whitelist not configured - allowing.\"", ")", ";", ...
Check if the hostname for the remote image, is on a whitelist, if the whitelist is defined. @param string $src the remote source. @return boolean true if hostname on $src is in the whitelist, else false.
[ "Check", "if", "the", "hostname", "for", "the", "remote", "image", "is", "on", "a", "whitelist", "if", "the", "whitelist", "is", "defined", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L629-L645
40,834
mosbth/cimage
CImage.php
CImage.checkFileExtension
private function checkFileExtension($extension) { $valid = array('jpg', 'jpeg', 'png', 'gif', 'webp'); in_array(strtolower($extension), $valid) or $this->raiseError('Not a valid file extension.'); return $this; }
php
private function checkFileExtension($extension) { $valid = array('jpg', 'jpeg', 'png', 'gif', 'webp'); in_array(strtolower($extension), $valid) or $this->raiseError('Not a valid file extension.'); return $this; }
[ "private", "function", "checkFileExtension", "(", "$", "extension", ")", "{", "$", "valid", "=", "array", "(", "'jpg'", ",", "'jpeg'", ",", "'png'", ",", "'gif'", ",", "'webp'", ")", ";", "in_array", "(", "strtolower", "(", "$", "extension", ")", ",", ...
Check if file extension is valid as a file extension. @param string $extension of image file. @return $this
[ "Check", "if", "file", "extension", "is", "valid", "as", "a", "file", "extension", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L656-L664
40,835
mosbth/cimage
CImage.php
CImage.normalizeFileExtension
private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); if ($extension == 'jpeg') { $extension = 'jpg'; } return $extension; }
php
private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); if ($extension == 'jpeg') { $extension = 'jpg'; } return $extension; }
[ "private", "function", "normalizeFileExtension", "(", "$", "extension", "=", "null", ")", "{", "$", "extension", "=", "strtolower", "(", "$", "extension", "?", "$", "extension", ":", "$", "this", "->", "extension", ")", ";", "if", "(", "$", "extension", ...
Normalize the file extension. @param string $extension of image file or skip to use internal. @return string $extension as a normalized file extension.
[ "Normalize", "the", "file", "extension", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L675-L684
40,836
mosbth/cimage
CImage.php
CImage.downloadRemoteSource
public function downloadRemoteSource($src) { if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } $remote = new CRemoteImage(); if (!is_writable($this->remoteCache)) { $this->log("The remote cache is not writable."); } $remote->setCache($this->remoteCache); $remote->useCache($this->useCache); $src = $remote->download($src); $this->log("Remote HTTP status: " . $remote->getStatus()); $this->log("Remote item is in local cache: $src"); $this->log("Remote details on cache:" . print_r($remote->getDetails(), true)); return $src; }
php
public function downloadRemoteSource($src) { if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } $remote = new CRemoteImage(); if (!is_writable($this->remoteCache)) { $this->log("The remote cache is not writable."); } $remote->setCache($this->remoteCache); $remote->useCache($this->useCache); $src = $remote->download($src); $this->log("Remote HTTP status: " . $remote->getStatus()); $this->log("Remote item is in local cache: $src"); $this->log("Remote details on cache:" . print_r($remote->getDetails(), true)); return $src; }
[ "public", "function", "downloadRemoteSource", "(", "$", "src", ")", "{", "if", "(", "!", "$", "this", "->", "isRemoteSourceOnWhitelist", "(", "$", "src", ")", ")", "{", "throw", "new", "Exception", "(", "\"Hostname is not on whitelist for remote sources.\"", ")", ...
Download a remote image and return path to its local copy. @param string $src remote path to image. @return string as path to downloaded remote source.
[ "Download", "a", "remote", "image", "and", "return", "path", "to", "its", "local", "copy", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L695-L716
40,837
mosbth/cimage
CImage.php
CImage.setSource
public function setSource($src, $dir = null) { if (!isset($src)) { $this->imageSrc = null; $this->pathToImage = null; return $this; } if ($this->allowRemote && $this->isRemoteSource($src)) { $src = $this->downloadRemoteSource($src); $dir = null; } if (!isset($dir)) { $dir = dirname($src); $src = basename($src); } $this->imageSrc = ltrim($src, '/'); $imageFolder = rtrim($dir, '/'); $this->pathToImage = $imageFolder . '/' . $this->imageSrc; return $this; }
php
public function setSource($src, $dir = null) { if (!isset($src)) { $this->imageSrc = null; $this->pathToImage = null; return $this; } if ($this->allowRemote && $this->isRemoteSource($src)) { $src = $this->downloadRemoteSource($src); $dir = null; } if (!isset($dir)) { $dir = dirname($src); $src = basename($src); } $this->imageSrc = ltrim($src, '/'); $imageFolder = rtrim($dir, '/'); $this->pathToImage = $imageFolder . '/' . $this->imageSrc; return $this; }
[ "public", "function", "setSource", "(", "$", "src", ",", "$", "dir", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "src", ")", ")", "{", "$", "this", "->", "imageSrc", "=", "null", ";", "$", "this", "->", "pathToImage", "=", "null", ...
Set source file to use as image source. @param string $src of image. @param string $dir as optional base directory where images are. @return $this
[ "Set", "source", "file", "to", "use", "as", "image", "source", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L728-L751
40,838
mosbth/cimage
CImage.php
CImage.mapFilter
private function mapFilter($name) { $map = array( 'negate' => array('id'=>0, 'argc'=>0, 'type'=>IMG_FILTER_NEGATE), 'grayscale' => array('id'=>1, 'argc'=>0, 'type'=>IMG_FILTER_GRAYSCALE), 'brightness' => array('id'=>2, 'argc'=>1, 'type'=>IMG_FILTER_BRIGHTNESS), 'contrast' => array('id'=>3, 'argc'=>1, 'type'=>IMG_FILTER_CONTRAST), 'colorize' => array('id'=>4, 'argc'=>4, 'type'=>IMG_FILTER_COLORIZE), 'edgedetect' => array('id'=>5, 'argc'=>0, 'type'=>IMG_FILTER_EDGEDETECT), 'emboss' => array('id'=>6, 'argc'=>0, 'type'=>IMG_FILTER_EMBOSS), 'gaussian_blur' => array('id'=>7, 'argc'=>0, 'type'=>IMG_FILTER_GAUSSIAN_BLUR), 'selective_blur' => array('id'=>8, 'argc'=>0, 'type'=>IMG_FILTER_SELECTIVE_BLUR), 'mean_removal' => array('id'=>9, 'argc'=>0, 'type'=>IMG_FILTER_MEAN_REMOVAL), 'smooth' => array('id'=>10, 'argc'=>1, 'type'=>IMG_FILTER_SMOOTH), 'pixelate' => array('id'=>11, 'argc'=>2, 'type'=>IMG_FILTER_PIXELATE), ); if (isset($map[$name])) { return $map[$name]; } else { throw new Exception('No such filter.'); } }
php
private function mapFilter($name) { $map = array( 'negate' => array('id'=>0, 'argc'=>0, 'type'=>IMG_FILTER_NEGATE), 'grayscale' => array('id'=>1, 'argc'=>0, 'type'=>IMG_FILTER_GRAYSCALE), 'brightness' => array('id'=>2, 'argc'=>1, 'type'=>IMG_FILTER_BRIGHTNESS), 'contrast' => array('id'=>3, 'argc'=>1, 'type'=>IMG_FILTER_CONTRAST), 'colorize' => array('id'=>4, 'argc'=>4, 'type'=>IMG_FILTER_COLORIZE), 'edgedetect' => array('id'=>5, 'argc'=>0, 'type'=>IMG_FILTER_EDGEDETECT), 'emboss' => array('id'=>6, 'argc'=>0, 'type'=>IMG_FILTER_EMBOSS), 'gaussian_blur' => array('id'=>7, 'argc'=>0, 'type'=>IMG_FILTER_GAUSSIAN_BLUR), 'selective_blur' => array('id'=>8, 'argc'=>0, 'type'=>IMG_FILTER_SELECTIVE_BLUR), 'mean_removal' => array('id'=>9, 'argc'=>0, 'type'=>IMG_FILTER_MEAN_REMOVAL), 'smooth' => array('id'=>10, 'argc'=>1, 'type'=>IMG_FILTER_SMOOTH), 'pixelate' => array('id'=>11, 'argc'=>2, 'type'=>IMG_FILTER_PIXELATE), ); if (isset($map[$name])) { return $map[$name]; } else { throw new Exception('No such filter.'); } }
[ "private", "function", "mapFilter", "(", "$", "name", ")", "{", "$", "map", "=", "array", "(", "'negate'", "=>", "array", "(", "'id'", "=>", "0", ",", "'argc'", "=>", "0", ",", "'type'", "=>", "IMG_FILTER_NEGATE", ")", ",", "'grayscale'", "=>", "array"...
Map filter name to PHP filter and id. @param string $name the name of the filter. @return array with filter settings @throws Exception
[ "Map", "filter", "name", "to", "PHP", "filter", "and", "id", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L921-L943
40,839
mosbth/cimage
CImage.php
CImage.loadImageDetails
public function loadImageDetails($file = null) { $file = $file ? $file : $this->pathToImage; is_readable($file) or $this->raiseError('Image file does not exist.'); $info = list($this->width, $this->height, $this->fileType) = getimagesize($file); if (empty($info)) { // To support webp $this->fileType = false; if (function_exists("exif_imagetype")) { $this->fileType = exif_imagetype($file); if ($this->fileType === false) { if (function_exists("imagecreatefromwebp")) { $webp = imagecreatefromwebp($file); if ($webp !== false) { $this->width = imagesx($webp); $this->height = imagesy($webp); $this->fileType = IMG_WEBP; } } } } } if (!$this->fileType) { throw new Exception("Loading image details, the file doesn't seem to be a valid image."); } if ($this->verbose) { $this->log("Loading image details for: {$file}"); $this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType})."); $this->log(" Image filesize: " . filesize($file) . " bytes."); $this->log(" Image mimetype: " . $this->getMimeType()); } return $this; }
php
public function loadImageDetails($file = null) { $file = $file ? $file : $this->pathToImage; is_readable($file) or $this->raiseError('Image file does not exist.'); $info = list($this->width, $this->height, $this->fileType) = getimagesize($file); if (empty($info)) { // To support webp $this->fileType = false; if (function_exists("exif_imagetype")) { $this->fileType = exif_imagetype($file); if ($this->fileType === false) { if (function_exists("imagecreatefromwebp")) { $webp = imagecreatefromwebp($file); if ($webp !== false) { $this->width = imagesx($webp); $this->height = imagesy($webp); $this->fileType = IMG_WEBP; } } } } } if (!$this->fileType) { throw new Exception("Loading image details, the file doesn't seem to be a valid image."); } if ($this->verbose) { $this->log("Loading image details for: {$file}"); $this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType})."); $this->log(" Image filesize: " . filesize($file) . " bytes."); $this->log(" Image mimetype: " . $this->getMimeType()); } return $this; }
[ "public", "function", "loadImageDetails", "(", "$", "file", "=", "null", ")", "{", "$", "file", "=", "$", "file", "?", "$", "file", ":", "$", "this", "->", "pathToImage", ";", "is_readable", "(", "$", "file", ")", "or", "$", "this", "->", "raiseError...
Load image details from original image file. @param string $file the file to load or null to use $this->pathToImage. @return $this @throws Exception
[ "Load", "image", "details", "from", "original", "image", "file", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L955-L993
40,840
mosbth/cimage
CImage.php
CImage.reCalculateDimensions
public function reCalculateDimensions() { $this->log("Re-calculate image dimensions, newWidth x newHeigh was: " . $this->newWidth . " x " . $this->newHeight); $this->newWidth = $this->newWidthOrig; $this->newHeight = $this->newHeightOrig; $this->crop = $this->cropOrig; $this->initDimensions() ->calculateNewWidthAndHeight(); return $this; }
php
public function reCalculateDimensions() { $this->log("Re-calculate image dimensions, newWidth x newHeigh was: " . $this->newWidth . " x " . $this->newHeight); $this->newWidth = $this->newWidthOrig; $this->newHeight = $this->newHeightOrig; $this->crop = $this->cropOrig; $this->initDimensions() ->calculateNewWidthAndHeight(); return $this; }
[ "public", "function", "reCalculateDimensions", "(", ")", "{", "$", "this", "->", "log", "(", "\"Re-calculate image dimensions, newWidth x newHeigh was: \"", ".", "$", "this", "->", "newWidth", ".", "\" x \"", ".", "$", "this", "->", "newHeight", ")", ";", "$", "...
Re-calculate image dimensions when original image dimension has changed. @return $this
[ "Re", "-", "calculate", "image", "dimensions", "when", "original", "image", "dimension", "has", "changed", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1245-L1257
40,841
mosbth/cimage
CImage.php
CImage.setSaveAsExtension
public function setSaveAsExtension($saveAs = null) { if (isset($saveAs)) { $saveAs = strtolower($saveAs); $this->checkFileExtension($saveAs); $this->saveAs = $saveAs; $this->extension = $saveAs; } $this->log("Prepare to save image as: " . $this->extension); return $this; }
php
public function setSaveAsExtension($saveAs = null) { if (isset($saveAs)) { $saveAs = strtolower($saveAs); $this->checkFileExtension($saveAs); $this->saveAs = $saveAs; $this->extension = $saveAs; } $this->log("Prepare to save image as: " . $this->extension); return $this; }
[ "public", "function", "setSaveAsExtension", "(", "$", "saveAs", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "saveAs", ")", ")", "{", "$", "saveAs", "=", "strtolower", "(", "$", "saveAs", ")", ";", "$", "this", "->", "checkFileExtension", "(", ...
Set extension for filename to save as. @param string $saveas extension to save image as @return $this
[ "Set", "extension", "for", "filename", "to", "save", "as", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1268-L1280
40,842
mosbth/cimage
CImage.php
CImage.setJpegQuality
public function setJpegQuality($quality = null) { if ($quality) { $this->useQuality = true; } $this->quality = isset($quality) ? $quality : self::JPEG_QUALITY_DEFAULT; (is_numeric($this->quality) and $this->quality > 0 and $this->quality <= 100) or $this->raiseError('Quality not in range.'); $this->log("Setting JPEG quality to {$this->quality}."); return $this; }
php
public function setJpegQuality($quality = null) { if ($quality) { $this->useQuality = true; } $this->quality = isset($quality) ? $quality : self::JPEG_QUALITY_DEFAULT; (is_numeric($this->quality) and $this->quality > 0 and $this->quality <= 100) or $this->raiseError('Quality not in range.'); $this->log("Setting JPEG quality to {$this->quality}."); return $this; }
[ "public", "function", "setJpegQuality", "(", "$", "quality", "=", "null", ")", "{", "if", "(", "$", "quality", ")", "{", "$", "this", "->", "useQuality", "=", "true", ";", "}", "$", "this", "->", "quality", "=", "isset", "(", "$", "quality", ")", "...
Set JPEG quality to use when saving image @param int $quality as the quality to set. @return $this
[ "Set", "JPEG", "quality", "to", "use", "when", "saving", "image" ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1291-L1307
40,843
mosbth/cimage
CImage.php
CImage.setPngCompression
public function setPngCompression($compress = null) { if ($compress) { $this->useCompress = true; } $this->compress = isset($compress) ? $compress : self::PNG_COMPRESSION_DEFAULT; (is_numeric($this->compress) and $this->compress >= -1 and $this->compress <= 9) or $this->raiseError('Quality not in range.'); $this->log("Setting PNG compression level to {$this->compress}."); return $this; }
php
public function setPngCompression($compress = null) { if ($compress) { $this->useCompress = true; } $this->compress = isset($compress) ? $compress : self::PNG_COMPRESSION_DEFAULT; (is_numeric($this->compress) and $this->compress >= -1 and $this->compress <= 9) or $this->raiseError('Quality not in range.'); $this->log("Setting PNG compression level to {$this->compress}."); return $this; }
[ "public", "function", "setPngCompression", "(", "$", "compress", "=", "null", ")", "{", "if", "(", "$", "compress", ")", "{", "$", "this", "->", "useCompress", "=", "true", ";", "}", "$", "this", "->", "compress", "=", "isset", "(", "$", "compress", ...
Set PNG compressen algorithm to use when saving image @param int $compress as the algorithm to use. @return $this
[ "Set", "PNG", "compressen", "algorithm", "to", "use", "when", "saving", "image" ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1318-L1334
40,844
mosbth/cimage
CImage.php
CImage.useOriginalIfPossible
public function useOriginalIfPossible($useOrig = true) { if ($useOrig && ($this->newWidth == $this->width) && ($this->newHeight == $this->height) && !$this->area && !$this->crop && !$this->cropToFit && !$this->fillToFit && !$this->filters && !$this->sharpen && !$this->emboss && !$this->blur && !$this->convolve && !$this->palette && !$this->useQuality && !$this->useCompress && !$this->saveAs && !$this->rotateBefore && !$this->rotateAfter && !$this->autoRotate && !$this->bgColor && ($this->upscale === self::UPSCALE_DEFAULT) && !$this->lossy ) { $this->log("Using original image."); $this->output($this->pathToImage); } return $this; }
php
public function useOriginalIfPossible($useOrig = true) { if ($useOrig && ($this->newWidth == $this->width) && ($this->newHeight == $this->height) && !$this->area && !$this->crop && !$this->cropToFit && !$this->fillToFit && !$this->filters && !$this->sharpen && !$this->emboss && !$this->blur && !$this->convolve && !$this->palette && !$this->useQuality && !$this->useCompress && !$this->saveAs && !$this->rotateBefore && !$this->rotateAfter && !$this->autoRotate && !$this->bgColor && ($this->upscale === self::UPSCALE_DEFAULT) && !$this->lossy ) { $this->log("Using original image."); $this->output($this->pathToImage); } return $this; }
[ "public", "function", "useOriginalIfPossible", "(", "$", "useOrig", "=", "true", ")", "{", "if", "(", "$", "useOrig", "&&", "(", "$", "this", "->", "newWidth", "==", "$", "this", "->", "width", ")", "&&", "(", "$", "this", "->", "newHeight", "==", "$...
Use original image if possible, check options which affects image processing. @param boolean $useOrig default is to use original if possible, else set to false. @return $this
[ "Use", "original", "image", "if", "possible", "check", "options", "which", "affects", "image", "processing", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1345-L1375
40,845
mosbth/cimage
CImage.php
CImage.useCacheIfPossible
public function useCacheIfPossible($useCache = true) { if ($useCache && is_readable($this->cacheFileName)) { $fileTime = filemtime($this->pathToImage); $cacheTime = filemtime($this->cacheFileName); if ($fileTime <= $cacheTime) { if ($this->useCache) { if ($this->verbose) { $this->log("Use cached file."); $this->log("Cached image filesize: " . filesize($this->cacheFileName) . " bytes."); } $this->output($this->cacheFileName, $this->outputFormat); } else { $this->log("Cache is valid but ignoring it by intention."); } } else { $this->log("Original file is modified, ignoring cache."); } } else { $this->log("Cachefile does not exists or ignoring it."); } return $this; }
php
public function useCacheIfPossible($useCache = true) { if ($useCache && is_readable($this->cacheFileName)) { $fileTime = filemtime($this->pathToImage); $cacheTime = filemtime($this->cacheFileName); if ($fileTime <= $cacheTime) { if ($this->useCache) { if ($this->verbose) { $this->log("Use cached file."); $this->log("Cached image filesize: " . filesize($this->cacheFileName) . " bytes."); } $this->output($this->cacheFileName, $this->outputFormat); } else { $this->log("Cache is valid but ignoring it by intention."); } } else { $this->log("Original file is modified, ignoring cache."); } } else { $this->log("Cachefile does not exists or ignoring it."); } return $this; }
[ "public", "function", "useCacheIfPossible", "(", "$", "useCache", "=", "true", ")", "{", "if", "(", "$", "useCache", "&&", "is_readable", "(", "$", "this", "->", "cacheFileName", ")", ")", "{", "$", "fileTime", "=", "filemtime", "(", "$", "this", "->", ...
Use cached version of image, if possible. @param boolean $useCache is default true, set to false to avoid using cached object. @return $this
[ "Use", "cached", "version", "of", "image", "if", "possible", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1483-L1507
40,846
mosbth/cimage
CImage.php
CImage.load
public function load($src = null, $dir = null) { if (isset($src)) { $this->setSource($src, $dir); } $this->loadImageDetails(); if ($this->fileType === IMG_WEBP) { $this->image = imagecreatefromwebp($this->pathToImage); } else { $imageAsString = file_get_contents($this->pathToImage); $this->image = imagecreatefromstring($imageAsString); } if ($this->image === false) { throw new Exception("Could not load image."); } /* Removed v0.7.7 if (image_type_to_mime_type($this->fileType) == 'image/png') { $type = $this->getPngType(); $hasFewColors = imagecolorstotal($this->image); if ($type == self::PNG_RGB_PALETTE || ($hasFewColors > 0 && $hasFewColors <= 256)) { if ($this->verbose) { $this->log("Handle this image as a palette image."); } $this->palette = true; } } */ if ($this->verbose) { $this->log("### Image successfully loaded from file."); $this->log(" imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false')); $this->log(" imagecolorstotal() : " . imagecolorstotal($this->image)); $this->log(" Number of colors in image = " . $this->colorsTotal($this->image)); $index = imagecolortransparent($this->image); $this->log(" Detected transparent color = " . ($index >= 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index"); } return $this; }
php
public function load($src = null, $dir = null) { if (isset($src)) { $this->setSource($src, $dir); } $this->loadImageDetails(); if ($this->fileType === IMG_WEBP) { $this->image = imagecreatefromwebp($this->pathToImage); } else { $imageAsString = file_get_contents($this->pathToImage); $this->image = imagecreatefromstring($imageAsString); } if ($this->image === false) { throw new Exception("Could not load image."); } /* Removed v0.7.7 if (image_type_to_mime_type($this->fileType) == 'image/png') { $type = $this->getPngType(); $hasFewColors = imagecolorstotal($this->image); if ($type == self::PNG_RGB_PALETTE || ($hasFewColors > 0 && $hasFewColors <= 256)) { if ($this->verbose) { $this->log("Handle this image as a palette image."); } $this->palette = true; } } */ if ($this->verbose) { $this->log("### Image successfully loaded from file."); $this->log(" imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false')); $this->log(" imagecolorstotal() : " . imagecolorstotal($this->image)); $this->log(" Number of colors in image = " . $this->colorsTotal($this->image)); $index = imagecolortransparent($this->image); $this->log(" Detected transparent color = " . ($index >= 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index"); } return $this; }
[ "public", "function", "load", "(", "$", "src", "=", "null", ",", "$", "dir", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "src", ")", ")", "{", "$", "this", "->", "setSource", "(", "$", "src", ",", "$", "dir", ")", ";", "}", "$", "t...
Load image from disk. Try to load image without verbose error message, if fail, load again and display error messages. @param string $src of image. @param string $dir as base directory where images are. @return $this
[ "Load", "image", "from", "disk", ".", "Try", "to", "load", "image", "without", "verbose", "error", "message", "if", "fail", "load", "again", "and", "display", "error", "messages", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1521-L1563
40,847
mosbth/cimage
CImage.php
CImage.getPngType
public function getPngType($filename = null) { $filename = $filename ? $filename : $this->pathToImage; $pngType = ord(file_get_contents($filename, false, null, 25, 1)); if ($this->verbose) { $this->log("Checking png type of: " . $filename); $this->log($this->getPngTypeAsString($pngType)); } return $pngType; }
php
public function getPngType($filename = null) { $filename = $filename ? $filename : $this->pathToImage; $pngType = ord(file_get_contents($filename, false, null, 25, 1)); if ($this->verbose) { $this->log("Checking png type of: " . $filename); $this->log($this->getPngTypeAsString($pngType)); } return $pngType; }
[ "public", "function", "getPngType", "(", "$", "filename", "=", "null", ")", "{", "$", "filename", "=", "$", "filename", "?", "$", "filename", ":", "$", "this", "->", "pathToImage", ";", "$", "pngType", "=", "ord", "(", "file_get_contents", "(", "$", "f...
Get the type of PNG image. @param string $filename to use instead of default. @return int as the type of the png-image
[ "Get", "the", "type", "of", "PNG", "image", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1575-L1587
40,848
mosbth/cimage
CImage.php
CImage.getPngTypeAsString
private function getPngTypeAsString($pngType = null, $filename = null) { if ($filename || !$pngType) { $pngType = $this->getPngType($filename); } $index = imagecolortransparent($this->image); $transparent = null; if ($index != -1) { $transparent = " (transparent)"; } switch ($pngType) { case self::PNG_GREYSCALE: $text = "PNG is type 0, Greyscale$transparent"; break; case self::PNG_RGB: $text = "PNG is type 2, RGB$transparent"; break; case self::PNG_RGB_PALETTE: $text = "PNG is type 3, RGB with palette$transparent"; break; case self::PNG_GREYSCALE_ALPHA: $text = "PNG is type 4, Greyscale with alpha channel"; break; case self::PNG_RGB_ALPHA: $text = "PNG is type 6, RGB with alpha channel (PNG 32-bit)"; break; default: $text = "PNG is UNKNOWN type, is it really a PNG image?"; } return $text; }
php
private function getPngTypeAsString($pngType = null, $filename = null) { if ($filename || !$pngType) { $pngType = $this->getPngType($filename); } $index = imagecolortransparent($this->image); $transparent = null; if ($index != -1) { $transparent = " (transparent)"; } switch ($pngType) { case self::PNG_GREYSCALE: $text = "PNG is type 0, Greyscale$transparent"; break; case self::PNG_RGB: $text = "PNG is type 2, RGB$transparent"; break; case self::PNG_RGB_PALETTE: $text = "PNG is type 3, RGB with palette$transparent"; break; case self::PNG_GREYSCALE_ALPHA: $text = "PNG is type 4, Greyscale with alpha channel"; break; case self::PNG_RGB_ALPHA: $text = "PNG is type 6, RGB with alpha channel (PNG 32-bit)"; break; default: $text = "PNG is UNKNOWN type, is it really a PNG image?"; } return $text; }
[ "private", "function", "getPngTypeAsString", "(", "$", "pngType", "=", "null", ",", "$", "filename", "=", "null", ")", "{", "if", "(", "$", "filename", "||", "!", "$", "pngType", ")", "{", "$", "pngType", "=", "$", "this", "->", "getPngType", "(", "$...
Get the type of PNG image as a verbose string. @param integer $type to use, default is to check the type. @param string $filename to use instead of default. @return int as the type of the png-image
[ "Get", "the", "type", "of", "PNG", "image", "as", "a", "verbose", "string", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1600-L1639
40,849
mosbth/cimage
CImage.php
CImage.colorsTotal
private function colorsTotal($im) { if (imageistruecolor($im)) { $this->log("Colors as true color."); $h = imagesy($im); $w = imagesx($im); $c = array(); for ($x=0; $x < $w; $x++) { for ($y=0; $y < $h; $y++) { @$c['c'.imagecolorat($im, $x, $y)]++; } } return count($c); } else { $this->log("Colors as palette."); return imagecolorstotal($im); } }
php
private function colorsTotal($im) { if (imageistruecolor($im)) { $this->log("Colors as true color."); $h = imagesy($im); $w = imagesx($im); $c = array(); for ($x=0; $x < $w; $x++) { for ($y=0; $y < $h; $y++) { @$c['c'.imagecolorat($im, $x, $y)]++; } } return count($c); } else { $this->log("Colors as palette."); return imagecolorstotal($im); } }
[ "private", "function", "colorsTotal", "(", "$", "im", ")", "{", "if", "(", "imageistruecolor", "(", "$", "im", ")", ")", "{", "$", "this", "->", "log", "(", "\"Colors as true color.\"", ")", ";", "$", "h", "=", "imagesy", "(", "$", "im", ")", ";", ...
Calculate number of colors in an image. @param resource $im the image. @return int
[ "Calculate", "number", "of", "colors", "in", "an", "image", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1651-L1668
40,850
mosbth/cimage
CImage.php
CImage.imageCopyResampled
public function imageCopyResampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { if($this->copyStrategy == self::RESIZE) { $this->log("Copy by resize"); imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } else { $this->log("Copy by resample"); imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } }
php
public function imageCopyResampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { if($this->copyStrategy == self::RESIZE) { $this->log("Copy by resize"); imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } else { $this->log("Copy by resample"); imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } }
[ "public", "function", "imageCopyResampled", "(", "$", "dst_image", ",", "$", "src_image", ",", "$", "dst_x", ",", "$", "dst_y", ",", "$", "src_x", ",", "$", "src_y", ",", "$", "dst_w", ",", "$", "dst_h", ",", "$", "src_w", ",", "$", "src_h", ")", "...
Resize and or crop the image. @return void
[ "Resize", "and", "or", "crop", "the", "image", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L1732-L1741
40,851
mosbth/cimage
CImage.php
CImage.rotate
public function rotate($angle, $bgColor) { $this->log("Rotate image " . $angle . " degrees with filler color."); $color = $this->getBackgroundColor(); $this->image = imagerotate($this->image, $angle, $color); $this->width = imagesx($this->image); $this->height = imagesy($this->image); $this->log("New image dimension width x height: " . $this->width . " x " . $this->height); return $this; }
php
public function rotate($angle, $bgColor) { $this->log("Rotate image " . $angle . " degrees with filler color."); $color = $this->getBackgroundColor(); $this->image = imagerotate($this->image, $angle, $color); $this->width = imagesx($this->image); $this->height = imagesy($this->image); $this->log("New image dimension width x height: " . $this->width . " x " . $this->height); return $this; }
[ "public", "function", "rotate", "(", "$", "angle", ",", "$", "bgColor", ")", "{", "$", "this", "->", "log", "(", "\"Rotate image \"", ".", "$", "angle", ".", "\" degrees with filler color.\"", ")", ";", "$", "color", "=", "$", "this", "->", "getBackgroundC...
Rotate image using angle. @param float $angle to rotate image. @param int $anglebgColor to fill image with if needed. @return $this
[ "Rotate", "image", "using", "angle", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2014-L2027
40,852
mosbth/cimage
CImage.php
CImage.rotateExif
public function rotateExif() { if (!in_array($this->fileType, array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM))) { $this->log("Autorotate ignored, EXIF not supported by this filetype."); return $this; } $exif = exif_read_data($this->pathToImage); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: $this->log("Autorotate 180."); $this->rotate(180, $this->bgColor); break; case 6: $this->log("Autorotate -90."); $this->rotate(-90, $this->bgColor); break; case 8: $this->log("Autorotate 90."); $this->rotate(90, $this->bgColor); break; default: $this->log("Autorotate ignored, unknown value as orientation."); } } else { $this->log("Autorotate ignored, no orientation in EXIF."); } return $this; }
php
public function rotateExif() { if (!in_array($this->fileType, array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM))) { $this->log("Autorotate ignored, EXIF not supported by this filetype."); return $this; } $exif = exif_read_data($this->pathToImage); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: $this->log("Autorotate 180."); $this->rotate(180, $this->bgColor); break; case 6: $this->log("Autorotate -90."); $this->rotate(-90, $this->bgColor); break; case 8: $this->log("Autorotate 90."); $this->rotate(90, $this->bgColor); break; default: $this->log("Autorotate ignored, unknown value as orientation."); } } else { $this->log("Autorotate ignored, no orientation in EXIF."); } return $this; }
[ "public", "function", "rotateExif", "(", ")", "{", "if", "(", "!", "in_array", "(", "$", "this", "->", "fileType", ",", "array", "(", "IMAGETYPE_JPEG", ",", "IMAGETYPE_TIFF_II", ",", "IMAGETYPE_TIFF_MM", ")", ")", ")", "{", "$", "this", "->", "log", "(",...
Rotate image using information in EXIF. @return $this
[ "Rotate", "image", "using", "information", "in", "EXIF", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2036-L2070
40,853
mosbth/cimage
CImage.php
CImage.setDefaultBackgroundColor
public function setDefaultBackgroundColor($color) { $this->log("Setting default background color to '$color'."); if (!(strlen($color) == 6 || strlen($color) == 8)) { throw new Exception( "Background color needs a hex value of 6 or 8 digits. 000000-FFFFFF or 00000000-FFFFFF7F. Current value was: '$color'." ); } $red = hexdec(substr($color, 0, 2)); $green = hexdec(substr($color, 2, 2)); $blue = hexdec(substr($color, 4, 2)); $alpha = (strlen($color) == 8) ? hexdec(substr($color, 6, 2)) : null; if (($red < 0 || $red > 255) || ($green < 0 || $green > 255) || ($blue < 0 || $blue > 255) || ($alpha < 0 || $alpha > 127) ) { throw new Exception( "Background color out of range. Red, green blue should be 00-FF and alpha should be 00-7F. Current value was: '$color'." ); } $this->bgColor = strtolower($color); $this->bgColorDefault = array( 'red' => $red, 'green' => $green, 'blue' => $blue, 'alpha' => $alpha ); return $this; }
php
public function setDefaultBackgroundColor($color) { $this->log("Setting default background color to '$color'."); if (!(strlen($color) == 6 || strlen($color) == 8)) { throw new Exception( "Background color needs a hex value of 6 or 8 digits. 000000-FFFFFF or 00000000-FFFFFF7F. Current value was: '$color'." ); } $red = hexdec(substr($color, 0, 2)); $green = hexdec(substr($color, 2, 2)); $blue = hexdec(substr($color, 4, 2)); $alpha = (strlen($color) == 8) ? hexdec(substr($color, 6, 2)) : null; if (($red < 0 || $red > 255) || ($green < 0 || $green > 255) || ($blue < 0 || $blue > 255) || ($alpha < 0 || $alpha > 127) ) { throw new Exception( "Background color out of range. Red, green blue should be 00-FF and alpha should be 00-7F. Current value was: '$color'." ); } $this->bgColor = strtolower($color); $this->bgColorDefault = array( 'red' => $red, 'green' => $green, 'blue' => $blue, 'alpha' => $alpha ); return $this; }
[ "public", "function", "setDefaultBackgroundColor", "(", "$", "color", ")", "{", "$", "this", "->", "log", "(", "\"Setting default background color to '$color'.\"", ")", ";", "if", "(", "!", "(", "strlen", "(", "$", "color", ")", "==", "6", "||", "strlen", "(...
Set default background color between 000000-FFFFFF or if using alpha 00000000-FFFFFF7F. @param string $color as hex value. @return $this
[ "Set", "default", "background", "color", "between", "000000", "-", "FFFFFF", "or", "if", "using", "alpha", "00000000", "-", "FFFFFF7F", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2235-L2276
40,854
mosbth/cimage
CImage.php
CImage.getBackgroundColor
private function getBackgroundColor($img = null) { $img = isset($img) ? $img : $this->image; if ($this->bgColorDefault) { $red = $this->bgColorDefault['red']; $green = $this->bgColorDefault['green']; $blue = $this->bgColorDefault['blue']; $alpha = $this->bgColorDefault['alpha']; if ($alpha) { $color = imagecolorallocatealpha($img, $red, $green, $blue, $alpha); } else { $color = imagecolorallocate($img, $red, $green, $blue); } return $color; } else { return 0; } }
php
private function getBackgroundColor($img = null) { $img = isset($img) ? $img : $this->image; if ($this->bgColorDefault) { $red = $this->bgColorDefault['red']; $green = $this->bgColorDefault['green']; $blue = $this->bgColorDefault['blue']; $alpha = $this->bgColorDefault['alpha']; if ($alpha) { $color = imagecolorallocatealpha($img, $red, $green, $blue, $alpha); } else { $color = imagecolorallocate($img, $red, $green, $blue); } return $color; } else { return 0; } }
[ "private", "function", "getBackgroundColor", "(", "$", "img", "=", "null", ")", "{", "$", "img", "=", "isset", "(", "$", "img", ")", "?", "$", "img", ":", "$", "this", "->", "image", ";", "if", "(", "$", "this", "->", "bgColorDefault", ")", "{", ...
Get the background color. @param resource $img the image to work with or null if using $this->image. @return color value or null if no background color is set.
[ "Get", "the", "background", "color", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2287-L2309
40,855
mosbth/cimage
CImage.php
CImage.createImageKeepTransparency
private function createImageKeepTransparency($width, $height) { $this->log("Creating a new working image width={$width}px, height={$height}px."); $img = imagecreatetruecolor($width, $height); imagealphablending($img, false); imagesavealpha($img, true); $index = $this->image ? imagecolortransparent($this->image) : -1; if ($index != -1) { imagealphablending($img, true); $transparent = imagecolorsforindex($this->image, $index); $color = imagecolorallocatealpha($img, $transparent['red'], $transparent['green'], $transparent['blue'], $transparent['alpha']); imagefill($img, 0, 0, $color); $index = imagecolortransparent($img, $color); $this->Log("Detected transparent color = " . implode(", ", $transparent) . " at index = $index"); } elseif ($this->bgColorDefault) { $color = $this->getBackgroundColor($img); imagefill($img, 0, 0, $color); $this->Log("Filling image with background color."); } return $img; }
php
private function createImageKeepTransparency($width, $height) { $this->log("Creating a new working image width={$width}px, height={$height}px."); $img = imagecreatetruecolor($width, $height); imagealphablending($img, false); imagesavealpha($img, true); $index = $this->image ? imagecolortransparent($this->image) : -1; if ($index != -1) { imagealphablending($img, true); $transparent = imagecolorsforindex($this->image, $index); $color = imagecolorallocatealpha($img, $transparent['red'], $transparent['green'], $transparent['blue'], $transparent['alpha']); imagefill($img, 0, 0, $color); $index = imagecolortransparent($img, $color); $this->Log("Detected transparent color = " . implode(", ", $transparent) . " at index = $index"); } elseif ($this->bgColorDefault) { $color = $this->getBackgroundColor($img); imagefill($img, 0, 0, $color); $this->Log("Filling image with background color."); } return $img; }
[ "private", "function", "createImageKeepTransparency", "(", "$", "width", ",", "$", "height", ")", "{", "$", "this", "->", "log", "(", "\"Creating a new working image width={$width}px, height={$height}px.\"", ")", ";", "$", "img", "=", "imagecreatetruecolor", "(", "$",...
Create a image and keep transparency for png and gifs. @param int $width of the new image. @param int $height of the new image. @return image resource.
[ "Create", "a", "image", "and", "keep", "transparency", "for", "png", "and", "gifs", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2321-L2349
40,856
mosbth/cimage
CImage.php
CImage.setPostProcessingOptions
public function setPostProcessingOptions($options) { if (isset($options['jpeg_optimize']) && $options['jpeg_optimize']) { $this->jpegOptimizeCmd = $options['jpeg_optimize_cmd']; } else { $this->jpegOptimizeCmd = null; } if (array_key_exists("png_lossy", $options) && $options['png_lossy'] !== false) { $this->pngLossy = $options['png_lossy']; $this->pngLossyCmd = $options['png_lossy_cmd']; } else { $this->pngLossyCmd = null; } if (isset($options['png_filter']) && $options['png_filter']) { $this->pngFilterCmd = $options['png_filter_cmd']; } else { $this->pngFilterCmd = null; } if (isset($options['png_deflate']) && $options['png_deflate']) { $this->pngDeflateCmd = $options['png_deflate_cmd']; } else { $this->pngDeflateCmd = null; } return $this; }
php
public function setPostProcessingOptions($options) { if (isset($options['jpeg_optimize']) && $options['jpeg_optimize']) { $this->jpegOptimizeCmd = $options['jpeg_optimize_cmd']; } else { $this->jpegOptimizeCmd = null; } if (array_key_exists("png_lossy", $options) && $options['png_lossy'] !== false) { $this->pngLossy = $options['png_lossy']; $this->pngLossyCmd = $options['png_lossy_cmd']; } else { $this->pngLossyCmd = null; } if (isset($options['png_filter']) && $options['png_filter']) { $this->pngFilterCmd = $options['png_filter_cmd']; } else { $this->pngFilterCmd = null; } if (isset($options['png_deflate']) && $options['png_deflate']) { $this->pngDeflateCmd = $options['png_deflate_cmd']; } else { $this->pngDeflateCmd = null; } return $this; }
[ "public", "function", "setPostProcessingOptions", "(", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'jpeg_optimize'", "]", ")", "&&", "$", "options", "[", "'jpeg_optimize'", "]", ")", "{", "$", "this", "->", "jpegOptimizeCmd", "...
Set optimizing and post-processing options. @param array $options with config for postprocessing with external tools. @return $this
[ "Set", "optimizing", "and", "post", "-", "processing", "options", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2360-L2389
40,857
mosbth/cimage
CImage.php
CImage.linkToCacheFile
public function linkToCacheFile($alias) { if ($alias === null) { $this->log("Ignore creating alias."); return $this; } if (is_readable($alias)) { unlink($alias); } $res = link($this->cacheFileName, $alias); if ($res) { $this->log("Created an alias as: $alias"); } else { $this->log("Failed to create the alias: $alias"); } return $this; }
php
public function linkToCacheFile($alias) { if ($alias === null) { $this->log("Ignore creating alias."); return $this; } if (is_readable($alias)) { unlink($alias); } $res = link($this->cacheFileName, $alias); if ($res) { $this->log("Created an alias as: $alias"); } else { $this->log("Failed to create the alias: $alias"); } return $this; }
[ "public", "function", "linkToCacheFile", "(", "$", "alias", ")", "{", "if", "(", "$", "alias", "===", "null", ")", "{", "$", "this", "->", "log", "(", "\"Ignore creating alias.\"", ")", ";", "return", "$", "this", ";", "}", "if", "(", "is_readable", "(...
Create a hard link, as an alias, to the cached file. @param string $alias where to store the link, filename without extension. @return $this
[ "Create", "a", "hard", "link", "as", "an", "alias", "to", "the", "cached", "file", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2615-L2635
40,858
mosbth/cimage
CImage.php
CImage.json
public function json($file = null) { $file = $file ? $file : $this->cacheFileName; $details = array(); clearstatcache(); $details['src'] = $this->imageSrc; $lastModified = filemtime($this->pathToImage); $details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified); $details['cache'] = basename($this->cacheFileName); $lastModified = filemtime($this->cacheFileName); $details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified); $this->load($file); $details['filename'] = basename($file); $details['mimeType'] = $this->getMimeType($this->fileType); $details['width'] = $this->width; $details['height'] = $this->height; $details['aspectRatio'] = round($this->width / $this->height, 3); $details['size'] = filesize($file); $details['colors'] = $this->colorsTotal($this->image); $details['includedFiles'] = count(get_included_files()); $details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ; $details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB"; $details['memoryLimit'] = ini_get('memory_limit'); if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { $details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s"; } if ($details['mimeType'] == 'image/png') { $details['pngType'] = $this->getPngTypeAsString(null, $file); } $options = null; if (defined("JSON_PRETTY_PRINT") && defined("JSON_UNESCAPED_SLASHES")) { $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES; } return json_encode($details, $options); }
php
public function json($file = null) { $file = $file ? $file : $this->cacheFileName; $details = array(); clearstatcache(); $details['src'] = $this->imageSrc; $lastModified = filemtime($this->pathToImage); $details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified); $details['cache'] = basename($this->cacheFileName); $lastModified = filemtime($this->cacheFileName); $details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified); $this->load($file); $details['filename'] = basename($file); $details['mimeType'] = $this->getMimeType($this->fileType); $details['width'] = $this->width; $details['height'] = $this->height; $details['aspectRatio'] = round($this->width / $this->height, 3); $details['size'] = filesize($file); $details['colors'] = $this->colorsTotal($this->image); $details['includedFiles'] = count(get_included_files()); $details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ; $details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB"; $details['memoryLimit'] = ini_get('memory_limit'); if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { $details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s"; } if ($details['mimeType'] == 'image/png') { $details['pngType'] = $this->getPngTypeAsString(null, $file); } $options = null; if (defined("JSON_PRETTY_PRINT") && defined("JSON_UNESCAPED_SLASHES")) { $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES; } return json_encode($details, $options); }
[ "public", "function", "json", "(", "$", "file", "=", "null", ")", "{", "$", "file", "=", "$", "file", "?", "$", "file", ":", "$", "this", "->", "cacheFileName", ";", "$", "details", "=", "array", "(", ")", ";", "clearstatcache", "(", ")", ";", "$...
Create a JSON object from the image details. @param string $file the file to output. @return string json-encoded representation of the image.
[ "Create", "a", "JSON", "object", "from", "the", "image", "details", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2767-L2811
40,859
mosbth/cimage
CImage.php
CImage.ascii
public function ascii($file = null) { $file = $file ? $file : $this->cacheFileName; $asciiArt = new CAsciiArt(); $asciiArt->setOptions($this->asciiOptions); return $asciiArt->createFromFile($file); }
php
public function ascii($file = null) { $file = $file ? $file : $this->cacheFileName; $asciiArt = new CAsciiArt(); $asciiArt->setOptions($this->asciiOptions); return $asciiArt->createFromFile($file); }
[ "public", "function", "ascii", "(", "$", "file", "=", "null", ")", "{", "$", "file", "=", "$", "file", "?", "$", "file", ":", "$", "this", "->", "cacheFileName", ";", "$", "asciiArt", "=", "new", "CAsciiArt", "(", ")", ";", "$", "asciiArt", "->", ...
Create an ASCII version from the image details. @param string $file the file to output. @return string ASCII representation of the image.
[ "Create", "an", "ASCII", "version", "from", "the", "image", "details", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2836-L2843
40,860
mosbth/cimage
CImage.php
CImage.verboseOutput
private function verboseOutput() { $log = null; $this->log("### Summary of verbose log"); $this->log("As JSON: \n" . $this->json()); $this->log("Memory peak: " . round(memory_get_peak_usage() /1024/1024) . "M"); $this->log("Memory limit: " . ini_get('memory_limit')); $included = get_included_files(); $this->log("Included files: " . count($included)); foreach ($this->log as $val) { if (is_array($val)) { foreach ($val as $val1) { $log .= htmlentities($val1) . '<br/>'; } } else { $log .= htmlentities($val) . '<br/>'; } } if (!is_null($this->verboseFileName)) { file_put_contents( $this->verboseFileName, str_replace("<br/>", "\n", $log) ); } else { echo <<<EOD <h1>CImage Verbose Output</h1> <pre>{$log}</pre> EOD; } }
php
private function verboseOutput() { $log = null; $this->log("### Summary of verbose log"); $this->log("As JSON: \n" . $this->json()); $this->log("Memory peak: " . round(memory_get_peak_usage() /1024/1024) . "M"); $this->log("Memory limit: " . ini_get('memory_limit')); $included = get_included_files(); $this->log("Included files: " . count($included)); foreach ($this->log as $val) { if (is_array($val)) { foreach ($val as $val1) { $log .= htmlentities($val1) . '<br/>'; } } else { $log .= htmlentities($val) . '<br/>'; } } if (!is_null($this->verboseFileName)) { file_put_contents( $this->verboseFileName, str_replace("<br/>", "\n", $log) ); } else { echo <<<EOD <h1>CImage Verbose Output</h1> <pre>{$log}</pre> EOD; } }
[ "private", "function", "verboseOutput", "(", ")", "{", "$", "log", "=", "null", ";", "$", "this", "->", "log", "(", "\"### Summary of verbose log\"", ")", ";", "$", "this", "->", "log", "(", "\"As JSON: \\n\"", ".", "$", "this", "->", "json", "(", ")", ...
Do verbose output and print out the log and the actual images. @return void
[ "Do", "verbose", "output", "and", "print", "out", "the", "log", "and", "the", "actual", "images", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CImage.php#L2885-L2917
40,861
mosbth/cimage
CRemoteImage.php
CRemoteImage.setHeaderFields
public function setHeaderFields() { $cimageVersion = "CImage"; if (defined("CIMAGE_USER_AGENT")) { $cimageVersion = CIMAGE_USER_AGENT; } $this->http->setHeader("User-Agent", "$cimageVersion (PHP/". phpversion() . " cURL)"); $this->http->setHeader("Accept", "image/jpeg,image/png,image/gif"); if ($this->useCache) { $this->http->setHeader("Cache-Control", "max-age=0"); } else { $this->http->setHeader("Cache-Control", "no-cache"); $this->http->setHeader("Pragma", "no-cache"); } }
php
public function setHeaderFields() { $cimageVersion = "CImage"; if (defined("CIMAGE_USER_AGENT")) { $cimageVersion = CIMAGE_USER_AGENT; } $this->http->setHeader("User-Agent", "$cimageVersion (PHP/". phpversion() . " cURL)"); $this->http->setHeader("Accept", "image/jpeg,image/png,image/gif"); if ($this->useCache) { $this->http->setHeader("Cache-Control", "max-age=0"); } else { $this->http->setHeader("Cache-Control", "no-cache"); $this->http->setHeader("Pragma", "no-cache"); } }
[ "public", "function", "setHeaderFields", "(", ")", "{", "$", "cimageVersion", "=", "\"CImage\"", ";", "if", "(", "defined", "(", "\"CIMAGE_USER_AGENT\"", ")", ")", "{", "$", "cimageVersion", "=", "CIMAGE_USER_AGENT", ";", "}", "$", "this", "->", "http", "->"...
Set header fields. @return $this
[ "Set", "header", "fields", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CRemoteImage.php#L148-L164
40,862
mosbth/cimage
CRemoteImage.php
CRemoteImage.save
public function save() { $this->cache = array(); $date = $this->http->getDate(time()); $maxAge = $this->http->getMaxAge($this->defaultMaxAge); $lastModified = $this->http->getLastModified(); $type = $this->http->getContentType(); $this->cache['Date'] = gmdate("D, d M Y H:i:s T", $date); $this->cache['Max-Age'] = $maxAge; $this->cache['Content-Type'] = $type; $this->cache['Url'] = $this->url; if ($lastModified) { $this->cache['Last-Modified'] = gmdate("D, d M Y H:i:s T", $lastModified); } // Save only if body is a valid image $body = $this->http->getBody(); $img = imagecreatefromstring($body); if ($img !== false) { file_put_contents($this->fileName, $body); file_put_contents($this->fileJson, json_encode($this->cache)); return $this->fileName; } return false; }
php
public function save() { $this->cache = array(); $date = $this->http->getDate(time()); $maxAge = $this->http->getMaxAge($this->defaultMaxAge); $lastModified = $this->http->getLastModified(); $type = $this->http->getContentType(); $this->cache['Date'] = gmdate("D, d M Y H:i:s T", $date); $this->cache['Max-Age'] = $maxAge; $this->cache['Content-Type'] = $type; $this->cache['Url'] = $this->url; if ($lastModified) { $this->cache['Last-Modified'] = gmdate("D, d M Y H:i:s T", $lastModified); } // Save only if body is a valid image $body = $this->http->getBody(); $img = imagecreatefromstring($body); if ($img !== false) { file_put_contents($this->fileName, $body); file_put_contents($this->fileJson, json_encode($this->cache)); return $this->fileName; } return false; }
[ "public", "function", "save", "(", ")", "{", "$", "this", "->", "cache", "=", "array", "(", ")", ";", "$", "date", "=", "$", "this", "->", "http", "->", "getDate", "(", "time", "(", ")", ")", ";", "$", "maxAge", "=", "$", "this", "->", "http", ...
Save downloaded resource to cache. @return string as path to saved file or false if not saved.
[ "Save", "downloaded", "resource", "to", "cache", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CRemoteImage.php#L173-L201
40,863
mosbth/cimage
CRemoteImage.php
CRemoteImage.updateCacheDetails
public function updateCacheDetails() { $date = $this->http->getDate(time()); $maxAge = $this->http->getMaxAge($this->defaultMaxAge); $lastModified = $this->http->getLastModified(); $this->cache['Date'] = gmdate("D, d M Y H:i:s T", $date); $this->cache['Max-Age'] = $maxAge; if ($lastModified) { $this->cache['Last-Modified'] = gmdate("D, d M Y H:i:s T", $lastModified); } file_put_contents($this->fileJson, json_encode($this->cache)); return $this->fileName; }
php
public function updateCacheDetails() { $date = $this->http->getDate(time()); $maxAge = $this->http->getMaxAge($this->defaultMaxAge); $lastModified = $this->http->getLastModified(); $this->cache['Date'] = gmdate("D, d M Y H:i:s T", $date); $this->cache['Max-Age'] = $maxAge; if ($lastModified) { $this->cache['Last-Modified'] = gmdate("D, d M Y H:i:s T", $lastModified); } file_put_contents($this->fileJson, json_encode($this->cache)); return $this->fileName; }
[ "public", "function", "updateCacheDetails", "(", ")", "{", "$", "date", "=", "$", "this", "->", "http", "->", "getDate", "(", "time", "(", ")", ")", ";", "$", "maxAge", "=", "$", "this", "->", "http", "->", "getMaxAge", "(", "$", "this", "->", "def...
Got a 304 and updates cache with new age. @return string as path to cached file.
[ "Got", "a", "304", "and", "updates", "cache", "with", "new", "age", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CRemoteImage.php#L210-L225
40,864
mosbth/cimage
CRemoteImage.php
CRemoteImage.loadCacheDetails
public function loadCacheDetails() { $cacheFile = md5($this->url); $this->fileName = $this->saveFolder . $cacheFile; $this->fileJson = $this->fileName . ".json"; if (is_readable($this->fileJson)) { $this->cache = json_decode(file_get_contents($this->fileJson), true); } }
php
public function loadCacheDetails() { $cacheFile = md5($this->url); $this->fileName = $this->saveFolder . $cacheFile; $this->fileJson = $this->fileName . ".json"; if (is_readable($this->fileJson)) { $this->cache = json_decode(file_get_contents($this->fileJson), true); } }
[ "public", "function", "loadCacheDetails", "(", ")", "{", "$", "cacheFile", "=", "md5", "(", "$", "this", "->", "url", ")", ";", "$", "this", "->", "fileName", "=", "$", "this", "->", "saveFolder", ".", "$", "cacheFile", ";", "$", "this", "->", "fileJ...
Get the path to the cached image file if the cache is valid. @return $this
[ "Get", "the", "path", "to", "the", "cached", "image", "file", "if", "the", "cache", "is", "valid", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CRemoteImage.php#L278-L286
40,865
mosbth/cimage
CWhitelist.php
CWhitelist.check
public function check($item, $whitelist = null) { if ($whitelist !== null) { $this->set($whitelist); } if (empty($item) or empty($this->whitelist)) { return false; } foreach ($this->whitelist as $regexp) { if (preg_match("#$regexp#", $item)) { return true; } } return false; }
php
public function check($item, $whitelist = null) { if ($whitelist !== null) { $this->set($whitelist); } if (empty($item) or empty($this->whitelist)) { return false; } foreach ($this->whitelist as $regexp) { if (preg_match("#$regexp#", $item)) { return true; } } return false; }
[ "public", "function", "check", "(", "$", "item", ",", "$", "whitelist", "=", "null", ")", "{", "if", "(", "$", "whitelist", "!==", "null", ")", "{", "$", "this", "->", "set", "(", "$", "whitelist", ")", ";", "}", "if", "(", "empty", "(", "$", "...
Check if item exists in the whitelist. @param string $item string to check. @param array $whitelist optional with all valid options, default is null. @return boolean true if item is in whitelist, else false.
[ "Check", "if", "item", "exists", "in", "the", "whitelist", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CWhitelist.php#L44-L61
40,866
mosbth/cimage
CFastTrackCache.php
CFastTrackCache.setFilename
public function setFilename($clear) { $query = $_GET; // Remove parts from querystring that should not be part of filename foreach ($clear as $value) { unset($query[$value]); } arsort($query); $queryAsString = http_build_query($query); $this->filename = md5($queryAsString); if (CIMAGE_DEBUG) { $this->container["query-string"] = $queryAsString; } return $this->filename; }
php
public function setFilename($clear) { $query = $_GET; // Remove parts from querystring that should not be part of filename foreach ($clear as $value) { unset($query[$value]); } arsort($query); $queryAsString = http_build_query($query); $this->filename = md5($queryAsString); if (CIMAGE_DEBUG) { $this->container["query-string"] = $queryAsString; } return $this->filename; }
[ "public", "function", "setFilename", "(", "$", "clear", ")", "{", "$", "query", "=", "$", "_GET", ";", "// Remove parts from querystring that should not be part of filename", "foreach", "(", "$", "clear", "as", "$", "value", ")", "{", "unset", "(", "$", "query",...
Set the filename to store in cache, use the querystring to create that filename. @param array $clear items to clear in $_GET when creating the filename. @return string as filename created.
[ "Set", "the", "filename", "to", "store", "in", "cache", "use", "the", "querystring", "to", "create", "that", "filename", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CFastTrackCache.php#L81-L100
40,867
mosbth/cimage
CHttpGet.php
CHttpGet.parseHeader
public function parseHeader() { //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n")); $rawHeaders = rtrim($this->response['headerRaw'], "\r\n"); # Handle multiple responses e.g. with redirections (proxies too) $headerGroups = explode("\r\n\r\n", $rawHeaders); # We're only interested in the last one $header = explode("\r\n", end($headerGroups)); $output = array(); if ('HTTP' === substr($header[0], 0, 4)) { list($output['version'], $output['status']) = explode(' ', $header[0]); unset($header[0]); } foreach ($header as $entry) { $pos = strpos($entry, ':'); $output[trim(substr($entry, 0, $pos))] = trim(substr($entry, $pos + 1)); } $this->response['header'] = $output; return $this; }
php
public function parseHeader() { //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n")); $rawHeaders = rtrim($this->response['headerRaw'], "\r\n"); # Handle multiple responses e.g. with redirections (proxies too) $headerGroups = explode("\r\n\r\n", $rawHeaders); # We're only interested in the last one $header = explode("\r\n", end($headerGroups)); $output = array(); if ('HTTP' === substr($header[0], 0, 4)) { list($output['version'], $output['status']) = explode(' ', $header[0]); unset($header[0]); } foreach ($header as $entry) { $pos = strpos($entry, ':'); $output[trim(substr($entry, 0, $pos))] = trim(substr($entry, $pos + 1)); } $this->response['header'] = $output; return $this; }
[ "public", "function", "parseHeader", "(", ")", "{", "//$header = explode(\"\\r\\n\", rtrim($this->response['headerRaw'], \"\\r\\n\"));", "$", "rawHeaders", "=", "rtrim", "(", "$", "this", "->", "response", "[", "'headerRaw'", "]", ",", "\"\\r\\n\"", ")", ";", "# Handle ...
Set header fields for the request. @param string $field @param string $value @return $this
[ "Set", "header", "fields", "for", "the", "request", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CHttpGet.php#L102-L126
40,868
mosbth/cimage
CHttpGet.php
CHttpGet.getMaxAge
public function getMaxAge($default = false) { $cacheControl = isset($this->response['header']['Cache-Control']) ? $this->response['header']['Cache-Control'] : null; $maxAge = null; if ($cacheControl) { // max-age=2592000 $part = explode('=', $cacheControl); $maxAge = ($part[0] == "max-age") ? (int) $part[1] : null; } if ($maxAge) { return $maxAge; } $expire = isset($this->response['header']['Expires']) ? strtotime($this->response['header']['Expires']) : null; return $expire ? $expire : $default; }
php
public function getMaxAge($default = false) { $cacheControl = isset($this->response['header']['Cache-Control']) ? $this->response['header']['Cache-Control'] : null; $maxAge = null; if ($cacheControl) { // max-age=2592000 $part = explode('=', $cacheControl); $maxAge = ($part[0] == "max-age") ? (int) $part[1] : null; } if ($maxAge) { return $maxAge; } $expire = isset($this->response['header']['Expires']) ? strtotime($this->response['header']['Expires']) : null; return $expire ? $expire : $default; }
[ "public", "function", "getMaxAge", "(", "$", "default", "=", "false", ")", "{", "$", "cacheControl", "=", "isset", "(", "$", "this", "->", "response", "[", "'header'", "]", "[", "'Cache-Control'", "]", ")", "?", "$", "this", "->", "response", "[", "'he...
Get max age of cachable item. @param mixed $default as default value if date is missing in response header. @return int as timestamp or false if not available.
[ "Get", "max", "age", "of", "cachable", "item", "." ]
8fec09b195e79cbb8ad2ed3f997dd106132922a3
https://github.com/mosbth/cimage/blob/8fec09b195e79cbb8ad2ed3f997dd106132922a3/CHttpGet.php#L253-L277
40,869
yajra/pdo-via-oci8
src/Pdo/Oci8.php
Oci8.checkSequence
public function checkSequence($name) { try { $stmt = $this->query( "SELECT count(*) FROM ALL_SEQUENCES WHERE SEQUENCE_NAME=UPPER('{$name}') AND SEQUENCE_OWNER=UPPER(USER)", PDO::FETCH_COLUMN ); return $stmt->fetch(); } catch (\Exception $e) { return false; } }
php
public function checkSequence($name) { try { $stmt = $this->query( "SELECT count(*) FROM ALL_SEQUENCES WHERE SEQUENCE_NAME=UPPER('{$name}') AND SEQUENCE_OWNER=UPPER(USER)", PDO::FETCH_COLUMN ); return $stmt->fetch(); } catch (\Exception $e) { return false; } }
[ "public", "function", "checkSequence", "(", "$", "name", ")", "{", "try", "{", "$", "stmt", "=", "$", "this", "->", "query", "(", "\"SELECT count(*) FROM ALL_SEQUENCES WHERE SEQUENCE_NAME=UPPER('{$name}') AND SEQUENCE_OWNER=UPPER(USER)\"", ",", "PDO", "::", "FETCH_COLUMN"...
Special non PDO function to check if sequence exists. @param string $name @return bool
[ "Special", "non", "PDO", "function", "to", "check", "if", "sequence", "exists", "." ]
35ca9a2dbbaed0432f91f1b15507cadab614ed02
https://github.com/yajra/pdo-via-oci8/blob/35ca9a2dbbaed0432f91f1b15507cadab614ed02/src/Pdo/Oci8.php#L412-L424
40,870
yajra/pdo-via-oci8
src/Pdo/Oci8.php
Oci8.isNamedParameterable
private function isNamedParameterable($statement) { return ! preg_match('/^alter+ +table/', strtolower(trim($statement))) and ! preg_match('/^create+ +table/', strtolower(trim($statement))); }
php
private function isNamedParameterable($statement) { return ! preg_match('/^alter+ +table/', strtolower(trim($statement))) and ! preg_match('/^create+ +table/', strtolower(trim($statement))); }
[ "private", "function", "isNamedParameterable", "(", "$", "statement", ")", "{", "return", "!", "preg_match", "(", "'/^alter+ +table/'", ",", "strtolower", "(", "trim", "(", "$", "statement", ")", ")", ")", "and", "!", "preg_match", "(", "'/^create+ +table/'", ...
Check if statement can use pseudo named parameter. @param string $statement @return bool
[ "Check", "if", "statement", "can", "use", "pseudo", "named", "parameter", "." ]
35ca9a2dbbaed0432f91f1b15507cadab614ed02
https://github.com/yajra/pdo-via-oci8/blob/35ca9a2dbbaed0432f91f1b15507cadab614ed02/src/Pdo/Oci8.php#L432-L436
40,871
yajra/pdo-via-oci8
src/Pdo/Oci8.php
Oci8._getCharset
private function _getCharset($charset=null) { if (! $charset) { return; } $expr = '/^(charset=)(\w+)$/'; $tokens = array_filter( $charset, function ($token) use ($expr) { return preg_match($expr, $token, $matches); } ); if (count($tokens) > 0) { preg_match($expr, array_shift($tokens), $matches); $_charset = $matches[2]; } else { $_charset = null; } return $_charset; }
php
private function _getCharset($charset=null) { if (! $charset) { return; } $expr = '/^(charset=)(\w+)$/'; $tokens = array_filter( $charset, function ($token) use ($expr) { return preg_match($expr, $token, $matches); } ); if (count($tokens) > 0) { preg_match($expr, array_shift($tokens), $matches); $_charset = $matches[2]; } else { $_charset = null; } return $_charset; }
[ "private", "function", "_getCharset", "(", "$", "charset", "=", "null", ")", "{", "if", "(", "!", "$", "charset", ")", "{", "return", ";", "}", "$", "expr", "=", "'/^(charset=)(\\w+)$/'", ";", "$", "tokens", "=", "array_filter", "(", "$", "charset", ",...
Find the charset. @param string $charset charset @return charset
[ "Find", "the", "charset", "." ]
35ca9a2dbbaed0432f91f1b15507cadab614ed02
https://github.com/yajra/pdo-via-oci8/blob/35ca9a2dbbaed0432f91f1b15507cadab614ed02/src/Pdo/Oci8.php#L471-L491
40,872
yajra/pdo-via-oci8
src/Pdo/Oci8.php
Oci8.configureCharset
private function configureCharset(array $options) { $charset = 'AL32UTF8'; // Get the character set from the options. if (array_key_exists('charset', $options)) { $charset = $options['charset']; } // Convert UTF8 charset to AL32UTF8 $charset = strtolower($charset) == 'utf8' ? 'AL32UTF8' : $charset; return $charset; }
php
private function configureCharset(array $options) { $charset = 'AL32UTF8'; // Get the character set from the options. if (array_key_exists('charset', $options)) { $charset = $options['charset']; } // Convert UTF8 charset to AL32UTF8 $charset = strtolower($charset) == 'utf8' ? 'AL32UTF8' : $charset; return $charset; }
[ "private", "function", "configureCharset", "(", "array", "$", "options", ")", "{", "$", "charset", "=", "'AL32UTF8'", ";", "// Get the character set from the options.", "if", "(", "array_key_exists", "(", "'charset'", ",", "$", "options", ")", ")", "{", "$", "ch...
Configure proper charset. @param array $options @return string
[ "Configure", "proper", "charset", "." ]
35ca9a2dbbaed0432f91f1b15507cadab614ed02
https://github.com/yajra/pdo-via-oci8/blob/35ca9a2dbbaed0432f91f1b15507cadab614ed02/src/Pdo/Oci8.php#L499-L510
40,873
yajra/pdo-via-oci8
src/Pdo/Oci8/Statement.php
Statement.bindArray
public function bindArray($parameter, &$variable, $maxTableLength, $maxItemLength = -1, $type = SQLT_CHR) { $this->bindings[] = $variable; return oci_bind_array_by_name($this->sth, $parameter, $variable, $maxTableLength, $maxItemLength, $type); }
php
public function bindArray($parameter, &$variable, $maxTableLength, $maxItemLength = -1, $type = SQLT_CHR) { $this->bindings[] = $variable; return oci_bind_array_by_name($this->sth, $parameter, $variable, $maxTableLength, $maxItemLength, $type); }
[ "public", "function", "bindArray", "(", "$", "parameter", ",", "&", "$", "variable", ",", "$", "maxTableLength", ",", "$", "maxItemLength", "=", "-", "1", ",", "$", "type", "=", "SQLT_CHR", ")", "{", "$", "this", "->", "bindings", "[", "]", "=", "$",...
Special non-PDO function that binds an array parameter to the specified variable name. @see http://php.net/manual/en/function.oci-bind-array-by-name.php @param string $parameter The Oracle placeholder. @param array $variable An array. @param int $maxTableLength Sets the maximum length both for incoming and result arrays. @param int $maxItemLength Sets maximum length for array items. If not specified or equals to -1, oci_bind_array_by_name() will find the longest element in the incoming array and will use it as the maximum length. @param int $type Explicit data type for the parameter using the @return bool TRUE on success or FALSE on failure.
[ "Special", "non", "-", "PDO", "function", "that", "binds", "an", "array", "parameter", "to", "the", "specified", "variable", "name", "." ]
35ca9a2dbbaed0432f91f1b15507cadab614ed02
https://github.com/yajra/pdo-via-oci8/blob/35ca9a2dbbaed0432f91f1b15507cadab614ed02/src/Pdo/Oci8/Statement.php#L507-L512
40,874
yajra/pdo-via-oci8
src/Pdo/Oci8/Statement.php
Statement.errorInfo
public function errorInfo() { $e = oci_error($this->sth); if (is_array($e)) { return [ 'HY000', $e['code'], $e['message'], ]; } return ['00000', null, null]; }
php
public function errorInfo() { $e = oci_error($this->sth); if (is_array($e)) { return [ 'HY000', $e['code'], $e['message'], ]; } return ['00000', null, null]; }
[ "public", "function", "errorInfo", "(", ")", "{", "$", "e", "=", "oci_error", "(", "$", "this", "->", "sth", ")", ";", "if", "(", "is_array", "(", "$", "e", ")", ")", "{", "return", "[", "'HY000'", ",", "$", "e", "[", "'code'", "]", ",", "$", ...
Fetch extended error information associated with the last operation on the resource handle. @return array Array of error information about the last operation performed
[ "Fetch", "extended", "error", "information", "associated", "with", "the", "last", "operation", "on", "the", "resource", "handle", "." ]
35ca9a2dbbaed0432f91f1b15507cadab614ed02
https://github.com/yajra/pdo-via-oci8/blob/35ca9a2dbbaed0432f91f1b15507cadab614ed02/src/Pdo/Oci8/Statement.php#L653-L666
40,875
adesigns/calendar-bundle
Controller/CalendarController.php
CalendarController.loadCalendarAction
public function loadCalendarAction(Request $request) { $startDatetime = new \DateTime(); $startDatetime->setTimestamp($request->get('start')); $endDatetime = new \DateTime(); $endDatetime->setTimestamp($request->get('end')); $events = $this->container->get('event_dispatcher')->dispatch(CalendarEvent::CONFIGURE, new CalendarEvent($startDatetime, $endDatetime, $request))->getEvents(); $response = new \Symfony\Component\HttpFoundation\Response(); $response->headers->set('Content-Type', 'application/json'); $return_events = array(); foreach($events as $event) { $return_events[] = $event->toArray(); } $response->setContent(json_encode($return_events)); return $response; }
php
public function loadCalendarAction(Request $request) { $startDatetime = new \DateTime(); $startDatetime->setTimestamp($request->get('start')); $endDatetime = new \DateTime(); $endDatetime->setTimestamp($request->get('end')); $events = $this->container->get('event_dispatcher')->dispatch(CalendarEvent::CONFIGURE, new CalendarEvent($startDatetime, $endDatetime, $request))->getEvents(); $response = new \Symfony\Component\HttpFoundation\Response(); $response->headers->set('Content-Type', 'application/json'); $return_events = array(); foreach($events as $event) { $return_events[] = $event->toArray(); } $response->setContent(json_encode($return_events)); return $response; }
[ "public", "function", "loadCalendarAction", "(", "Request", "$", "request", ")", "{", "$", "startDatetime", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "startDatetime", "->", "setTimestamp", "(", "$", "request", "->", "get", "(", "'start'", ")", ")",...
Dispatch a CalendarEvent and return a JSON Response of any events returned. @param Request $request @return Response
[ "Dispatch", "a", "CalendarEvent", "and", "return", "a", "JSON", "Response", "of", "any", "events", "returned", "." ]
056861b042f4c70c7d929c3ad62d891fe4eb0e36
https://github.com/adesigns/calendar-bundle/blob/056861b042f4c70c7d929c3ad62d891fe4eb0e36/Controller/CalendarController.php#L18-L40
40,876
adesigns/calendar-bundle
Event/CalendarEvent.php
CalendarEvent.addEvent
public function addEvent(EventEntity $event) { if (!$this->events->contains($event)) { $this->events[] = $event; } return $this; }
php
public function addEvent(EventEntity $event) { if (!$this->events->contains($event)) { $this->events[] = $event; } return $this; }
[ "public", "function", "addEvent", "(", "EventEntity", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "events", "->", "contains", "(", "$", "event", ")", ")", "{", "$", "this", "->", "events", "[", "]", "=", "$", "event", ";", "}", "re...
If the event isn't already in the list, add it @param EventEntity $event @return CalendarEvent $this
[ "If", "the", "event", "isn", "t", "already", "in", "the", "list", "add", "it" ]
056861b042f4c70c7d929c3ad62d891fe4eb0e36
https://github.com/adesigns/calendar-bundle/blob/056861b042f4c70c7d929c3ad62d891fe4eb0e36/Event/CalendarEvent.php#L52-L59
40,877
adesigns/calendar-bundle
Entity/EventEntity.php
EventEntity.toArray
public function toArray() { $event = array(); if ($this->id !== null) { $event['id'] = $this->id; } $event['title'] = $this->title; $event['start'] = $this->startDatetime->format("Y-m-d\TH:i:sP"); if ($this->url !== null) { $event['url'] = $this->url; } if ($this->bgColor !== null) { $event['backgroundColor'] = $this->bgColor; $event['borderColor'] = $this->bgColor; } if ($this->fgColor !== null) { $event['textColor'] = $this->fgColor; } if ($this->cssClass !== null) { $event['className'] = $this->cssClass; } if ($this->endDatetime !== null) { $event['end'] = $this->endDatetime->format("Y-m-d\TH:i:sP"); } $event['allDay'] = $this->allDay; foreach ($this->otherFields as $field => $value) { $event[$field] = $value; } return $event; }
php
public function toArray() { $event = array(); if ($this->id !== null) { $event['id'] = $this->id; } $event['title'] = $this->title; $event['start'] = $this->startDatetime->format("Y-m-d\TH:i:sP"); if ($this->url !== null) { $event['url'] = $this->url; } if ($this->bgColor !== null) { $event['backgroundColor'] = $this->bgColor; $event['borderColor'] = $this->bgColor; } if ($this->fgColor !== null) { $event['textColor'] = $this->fgColor; } if ($this->cssClass !== null) { $event['className'] = $this->cssClass; } if ($this->endDatetime !== null) { $event['end'] = $this->endDatetime->format("Y-m-d\TH:i:sP"); } $event['allDay'] = $this->allDay; foreach ($this->otherFields as $field => $value) { $event[$field] = $value; } return $event; }
[ "public", "function", "toArray", "(", ")", "{", "$", "event", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "id", "!==", "null", ")", "{", "$", "event", "[", "'id'", "]", "=", "$", "this", "->", "id", ";", "}", "$", "event", "[",...
Convert calendar event details to an array @return array $event
[ "Convert", "calendar", "event", "details", "to", "an", "array" ]
056861b042f4c70c7d929c3ad62d891fe4eb0e36
https://github.com/adesigns/calendar-bundle/blob/056861b042f4c70c7d929c3ad62d891fe4eb0e36/Entity/EventEntity.php#L80-L119
40,878
mac-cain13/notificato
src/Wrep/Notificato/Apns/Message.php
Message.getJson
public function getJson() { // Get message and aps array to create JSON from $message = array(); $aps = array(); // If we have a payload replace the message object by the payload if (null !== $this->payload) { $message = $this->payload; } // Add the alert if any if (null !== $this->alert) { $aps['alert'] = $this->alert; } // Add the badge if any if (null !== $this->badge) { $aps['badge'] = $this->badge; } // Add the sound if any if (null !== $this->sound) { $aps['sound'] = $this->sound; } // Add category identifier if any if (null !== $this->category) { $aps['category'] = $this->category; } // Add the content-available flag if set if (true == $this->contentAvailable) { $aps['content-available'] = 1; } // Check if APS data is set if (count($aps) > 0) { $message['aps'] = $aps; } // Encode as JSON object $json = json_encode($message); if (false == $json) { throw new \RuntimeException('Failed to convert APNS\Message to JSON, are all strings UTF-8?', json_last_error()); } return $json; }
php
public function getJson() { // Get message and aps array to create JSON from $message = array(); $aps = array(); // If we have a payload replace the message object by the payload if (null !== $this->payload) { $message = $this->payload; } // Add the alert if any if (null !== $this->alert) { $aps['alert'] = $this->alert; } // Add the badge if any if (null !== $this->badge) { $aps['badge'] = $this->badge; } // Add the sound if any if (null !== $this->sound) { $aps['sound'] = $this->sound; } // Add category identifier if any if (null !== $this->category) { $aps['category'] = $this->category; } // Add the content-available flag if set if (true == $this->contentAvailable) { $aps['content-available'] = 1; } // Check if APS data is set if (count($aps) > 0) { $message['aps'] = $aps; } // Encode as JSON object $json = json_encode($message); if (false == $json) { throw new \RuntimeException('Failed to convert APNS\Message to JSON, are all strings UTF-8?', json_last_error()); } return $json; }
[ "public", "function", "getJson", "(", ")", "{", "// Get message and aps array to create JSON from", "$", "message", "=", "array", "(", ")", ";", "$", "aps", "=", "array", "(", ")", ";", "// If we have a payload replace the message object by the payload", "if", "(", "n...
Get the JSON payload that should be send to the APNS @return string @throws \RuntimeException When unable to create JSON, for example because of non-UTF-8 characters
[ "Get", "the", "JSON", "payload", "that", "should", "be", "send", "to", "the", "APNS" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Message.php#L177-L225
40,879
mac-cain13/notificato
src/Wrep/Notificato/Apns/Message.php
Message.setDeviceToken
private function setDeviceToken($deviceToken) { // Check if a devicetoken is given if (null == $deviceToken) { throw new \InvalidArgumentException('No device token given.'); } // Check if the devicetoken is a valid hexadecimal string if (!ctype_xdigit($deviceToken)) { throw new \InvalidArgumentException('Invalid device token given, no hexadecimal: ' . $deviceToken); } // Check if the length of the devicetoken is correct if (64 != strlen($deviceToken)) { throw new \InvalidArgumentException('Invalid device token given, incorrect length: ' . $deviceToken . ' (' . strlen($deviceToken) . ')'); } // Set the devicetoken $this->deviceToken = $deviceToken; }
php
private function setDeviceToken($deviceToken) { // Check if a devicetoken is given if (null == $deviceToken) { throw new \InvalidArgumentException('No device token given.'); } // Check if the devicetoken is a valid hexadecimal string if (!ctype_xdigit($deviceToken)) { throw new \InvalidArgumentException('Invalid device token given, no hexadecimal: ' . $deviceToken); } // Check if the length of the devicetoken is correct if (64 != strlen($deviceToken)) { throw new \InvalidArgumentException('Invalid device token given, incorrect length: ' . $deviceToken . ' (' . strlen($deviceToken) . ')'); } // Set the devicetoken $this->deviceToken = $deviceToken; }
[ "private", "function", "setDeviceToken", "(", "$", "deviceToken", ")", "{", "// Check if a devicetoken is given", "if", "(", "null", "==", "$", "deviceToken", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'No device token given.'", ")", ";", "}",...
Set the receiver of the message @param string Receiver of this message @throws \InvalidArgumentException On invalid or missing arguments
[ "Set", "the", "receiver", "of", "the", "message" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Message.php#L285-L304
40,880
mac-cain13/notificato
src/Wrep/Notificato/Apns/Message.php
Message.setBadge
private function setBadge($badge) { // Validate the badge int if ((int)$badge < 0) { throw new \InvalidArgumentException('Badge must be 0 or higher.'); } // Cast to int or set to null $this->badge = (null === $badge) ? null : (int)$badge; }
php
private function setBadge($badge) { // Validate the badge int if ((int)$badge < 0) { throw new \InvalidArgumentException('Badge must be 0 or higher.'); } // Cast to int or set to null $this->badge = (null === $badge) ? null : (int)$badge; }
[ "private", "function", "setBadge", "(", "$", "badge", ")", "{", "// Validate the badge int", "if", "(", "(", "int", ")", "$", "badge", "<", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Badge must be 0 or higher.'", ")", ";", "}", "...
Set the badge to display on the App icon @param int|null The badge number to display, zero to remove badge @throws \InvalidArgumentException On invalid or missing arguments
[ "Set", "the", "badge", "to", "display", "on", "the", "App", "icon" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Message.php#L351-L360
40,881
mac-cain13/notificato
src/Wrep/Notificato/Apns/Message.php
Message.setPayload
private function setPayload($payload) { if ( (is_string($payload) && empty($payload)) || (is_array($payload) && count($payload) == 0) ) { // Empty strings or arrays are not allowed throw new \InvalidArgumentException('Invalid payload for message. Payload was empty, but not null)'); } else if (is_array($payload) || null === $payload) { if ( isset($payload['aps']) ) { // Reserved key is used throw new \InvalidArgumentException('Invalid payload for message. Custom payload may not contain the reserved "aps" key.'); } else { // This is okay, set as payload $this->payload = $payload; } } else { // Try to decode JSON string payload $payload = json_decode($payload, true); // Check if decoding the payload worked if (null === $payload) { throw new \InvalidArgumentException('Invalid payload for message. Payload was invalid JSON.'); } // Set as payload $this->payload = $payload; } }
php
private function setPayload($payload) { if ( (is_string($payload) && empty($payload)) || (is_array($payload) && count($payload) == 0) ) { // Empty strings or arrays are not allowed throw new \InvalidArgumentException('Invalid payload for message. Payload was empty, but not null)'); } else if (is_array($payload) || null === $payload) { if ( isset($payload['aps']) ) { // Reserved key is used throw new \InvalidArgumentException('Invalid payload for message. Custom payload may not contain the reserved "aps" key.'); } else { // This is okay, set as payload $this->payload = $payload; } } else { // Try to decode JSON string payload $payload = json_decode($payload, true); // Check if decoding the payload worked if (null === $payload) { throw new \InvalidArgumentException('Invalid payload for message. Payload was invalid JSON.'); } // Set as payload $this->payload = $payload; } }
[ "private", "function", "setPayload", "(", "$", "payload", ")", "{", "if", "(", "(", "is_string", "(", "$", "payload", ")", "&&", "empty", "(", "$", "payload", ")", ")", "||", "(", "is_array", "(", "$", "payload", ")", "&&", "count", "(", "$", "payl...
Set custom payload to go with the message @param array|json|null The payload to send as array or JSON string @throws \InvalidArgumentException On invalid or missing arguments
[ "Set", "custom", "payload", "to", "go", "with", "the", "message" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Message.php#L368-L401
40,882
mac-cain13/notificato
src/Wrep/Notificato/Apns/SslSocket.php
SslSocket.disconnect
protected function disconnect() { $this->logger->debug('Disconnecting Apns\SslSocket from the APNS service with certificate "' . $this->getCertificate()->getDescription() . '"'); // Check if there is a socket to disconnect if (is_resource($this->connection)) { // Disconnect and unset the connection variable fclose($this->connection); } $this->connection = null; }
php
protected function disconnect() { $this->logger->debug('Disconnecting Apns\SslSocket from the APNS service with certificate "' . $this->getCertificate()->getDescription() . '"'); // Check if there is a socket to disconnect if (is_resource($this->connection)) { // Disconnect and unset the connection variable fclose($this->connection); } $this->connection = null; }
[ "protected", "function", "disconnect", "(", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "'Disconnecting Apns\\SslSocket from the APNS service with certificate \"'", ".", "$", "this", "->", "getCertificate", "(", ")", "->", "getDescription", "(", ")", ...
Disconnect from the endpoint
[ "Disconnect", "from", "the", "endpoint" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/SslSocket.php#L120-L132
40,883
mac-cain13/notificato
src/Wrep/Notificato/Apns/Gateway.php
Gateway.queue
public function queue(Message $message) { // Bump the message ID $this->lastMessageId++; // Put the message in an envelope $envelope = new MessageEnvelope($this->lastMessageId, $message); // Save the message so we can update it later on $this->storeMessageEnvelope($envelope); // Queue and return the envelope $this->logger->debug('Queuing Apns\Message #' . $this->lastMessageId . ' to device "' . $message->getDeviceToken() . '" on Apns\Gateway with certificate "' . $this->getCertificate()->getDescription() . '"'); $this->sendQueue->enqueue($envelope); return $envelope; }
php
public function queue(Message $message) { // Bump the message ID $this->lastMessageId++; // Put the message in an envelope $envelope = new MessageEnvelope($this->lastMessageId, $message); // Save the message so we can update it later on $this->storeMessageEnvelope($envelope); // Queue and return the envelope $this->logger->debug('Queuing Apns\Message #' . $this->lastMessageId . ' to device "' . $message->getDeviceToken() . '" on Apns\Gateway with certificate "' . $this->getCertificate()->getDescription() . '"'); $this->sendQueue->enqueue($envelope); return $envelope; }
[ "public", "function", "queue", "(", "Message", "$", "message", ")", "{", "// Bump the message ID", "$", "this", "->", "lastMessageId", "++", ";", "// Put the message in an envelope", "$", "envelope", "=", "new", "MessageEnvelope", "(", "$", "this", "->", "lastMess...
Queue a message for sending @param Message The message object to queue for sending @return MessageEnvelope
[ "Queue", "a", "message", "for", "sending" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Gateway.php#L48-L64
40,884
mac-cain13/notificato
src/Wrep/Notificato/Apns/Gateway.php
Gateway.retrieveMessageEnvelope
protected function retrieveMessageEnvelope($identifier) { $envelope = null; // Fetch the requested anvelope if we have any if ( isset($this->messageEnvelopeStore[self::MESSAGE_ENVELOPE_STORE_PREFIX . $identifier]) ) { $envelope = $this->messageEnvelopeStore[self::MESSAGE_ENVELOPE_STORE_PREFIX . $identifier]; } return $envelope; }
php
protected function retrieveMessageEnvelope($identifier) { $envelope = null; // Fetch the requested anvelope if we have any if ( isset($this->messageEnvelopeStore[self::MESSAGE_ENVELOPE_STORE_PREFIX . $identifier]) ) { $envelope = $this->messageEnvelopeStore[self::MESSAGE_ENVELOPE_STORE_PREFIX . $identifier]; } return $envelope; }
[ "protected", "function", "retrieveMessageEnvelope", "(", "$", "identifier", ")", "{", "$", "envelope", "=", "null", ";", "// Fetch the requested anvelope if we have any", "if", "(", "isset", "(", "$", "this", "->", "messageEnvelopeStore", "[", "self", "::", "MESSAGE...
Retrieve a stored envelope @return MessageEnvelope|null
[ "Retrieve", "a", "stored", "envelope" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Gateway.php#L242-L252
40,885
mac-cain13/notificato
src/Wrep/Notificato/Notificato.php
Notificato.createCertificate
public function createCertificate($pemFile, $passphrase = null, $validate = true, $endpointEnv = null) { return $this->certificateFactory->createCertificate($pemFile, $passphrase, $validate, $endpointEnv); }
php
public function createCertificate($pemFile, $passphrase = null, $validate = true, $endpointEnv = null) { return $this->certificateFactory->createCertificate($pemFile, $passphrase, $validate, $endpointEnv); }
[ "public", "function", "createCertificate", "(", "$", "pemFile", ",", "$", "passphrase", "=", "null", ",", "$", "validate", "=", "true", ",", "$", "endpointEnv", "=", "null", ")", "{", "return", "$", "this", "->", "certificateFactory", "->", "createCertificat...
Create an APNS Certificate @param string Path to the PEM certificate file @param string|null Passphrase to use with the PEM file @param boolean Set to false to skip the validation of the certificate, default true @param string|null APNS environment this certificate is valid for, by default autodetects during validation @return Apns\Certificate
[ "Create", "an", "APNS", "Certificate" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Notificato.php#L46-L49
40,886
mac-cain13/notificato
src/Wrep/Notificato/Notificato.php
Notificato.messageBuilder
public function messageBuilder() { $builder = Apns\Message::builder(); if ($this->certificateFactory->getDefaultCertificate() != null) { $builder->setCertificate( $this->certificateFactory->getDefaultCertificate() ); } return $builder; }
php
public function messageBuilder() { $builder = Apns\Message::builder(); if ($this->certificateFactory->getDefaultCertificate() != null) { $builder->setCertificate( $this->certificateFactory->getDefaultCertificate() ); } return $builder; }
[ "public", "function", "messageBuilder", "(", ")", "{", "$", "builder", "=", "Apns", "\\", "Message", "::", "builder", "(", ")", ";", "if", "(", "$", "this", "->", "certificateFactory", "->", "getDefaultCertificate", "(", ")", "!=", "null", ")", "{", "$",...
Create a Message builder @return Apns\MessageBuilder
[ "Create", "a", "Message", "builder" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Notificato.php#L56-L65
40,887
mac-cain13/notificato
src/Wrep/Notificato/Apns/CertificateFactory.php
CertificateFactory.createCertificate
public function createCertificate($pemFile, $passphrase = null, $validate = true, $endpointEnv = null) { return new Certificate($pemFile, $passphrase, $validate, $endpointEnv); }
php
public function createCertificate($pemFile, $passphrase = null, $validate = true, $endpointEnv = null) { return new Certificate($pemFile, $passphrase, $validate, $endpointEnv); }
[ "public", "function", "createCertificate", "(", "$", "pemFile", ",", "$", "passphrase", "=", "null", ",", "$", "validate", "=", "true", ",", "$", "endpointEnv", "=", "null", ")", "{", "return", "new", "Certificate", "(", "$", "pemFile", ",", "$", "passph...
Create a Certificate @param string Path to the PEM certificate file @param string|null Passphrase to use with the PEM file @param boolean Set to false to skip the validation of the certificate, default true @param string|null APNS environment this certificate is valid for, by default autodetects during validation @return Certificate
[ "Create", "a", "Certificate" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/CertificateFactory.php#L56-L59
40,888
mac-cain13/notificato
src/Wrep/Notificato/Apns/MessageEnvelope.php
MessageEnvelope.setStatus
public function setStatus($status, $envelope = null) { // Check if we're not in a final state yet if ($this->status > 0) { throw new \RuntimeException('Cannot change status from final state ' . $this->status . ' to state ' . $status . '.'); } // Check if this is a valid state if ( !in_array($status, array_keys(self::$statusDescriptionMapping)) ) { throw new \InvalidArgumentException('Status ' . $status . ' is not a valid status.'); } // Check if the retry envelope is not this envelope if ($this === $envelope) { throw new \InvalidArgumentException('Retry envelope cannot be set to this envelope.'); } // Save it! $this->status = $status; $this->retryEnvelope = $envelope; }
php
public function setStatus($status, $envelope = null) { // Check if we're not in a final state yet if ($this->status > 0) { throw new \RuntimeException('Cannot change status from final state ' . $this->status . ' to state ' . $status . '.'); } // Check if this is a valid state if ( !in_array($status, array_keys(self::$statusDescriptionMapping)) ) { throw new \InvalidArgumentException('Status ' . $status . ' is not a valid status.'); } // Check if the retry envelope is not this envelope if ($this === $envelope) { throw new \InvalidArgumentException('Retry envelope cannot be set to this envelope.'); } // Save it! $this->status = $status; $this->retryEnvelope = $envelope; }
[ "public", "function", "setStatus", "(", "$", "status", ",", "$", "envelope", "=", "null", ")", "{", "// Check if we're not in a final state yet", "if", "(", "$", "this", "->", "status", ">", "0", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Can...
Set the status of this message envelope only possible if there is no final state set yet. @param int One of the keys in self::$statusDescriptionMapping @param MessageEnvelope|null Envelope for the retry of this MessageEnvelope
[ "Set", "the", "status", "of", "this", "message", "envelope", "only", "possible", "if", "there", "is", "no", "final", "state", "set", "yet", "." ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/MessageEnvelope.php#L127-L147
40,889
mac-cain13/notificato
src/Wrep/Notificato/Apns/MessageEnvelope.php
MessageEnvelope.getFinalStatus
public function getFinalStatus() { $currentEnvelope = $this; while ( null != $currentEnvelope->getRetryEnvelope() ) { $currentEnvelope = $currentEnvelope->getRetryEnvelope(); } return $currentEnvelope->getStatus(); }
php
public function getFinalStatus() { $currentEnvelope = $this; while ( null != $currentEnvelope->getRetryEnvelope() ) { $currentEnvelope = $currentEnvelope->getRetryEnvelope(); } return $currentEnvelope->getStatus(); }
[ "public", "function", "getFinalStatus", "(", ")", "{", "$", "currentEnvelope", "=", "$", "this", ";", "while", "(", "null", "!=", "$", "currentEnvelope", "->", "getRetryEnvelope", "(", ")", ")", "{", "$", "currentEnvelope", "=", "$", "currentEnvelope", "->",...
Get the final status after all retries. Use this method to know how the message ended up after all retries. @return int
[ "Get", "the", "final", "status", "after", "all", "retries", ".", "Use", "this", "method", "to", "know", "how", "the", "message", "ended", "up", "after", "all", "retries", "." ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/MessageEnvelope.php#L175-L183
40,890
mac-cain13/notificato
src/Wrep/Notificato/Apns/MessageEnvelope.php
MessageEnvelope.getBinaryMessage
public function getBinaryMessage() { $jsonMessage = $this->getMessage()->getJson(); $jsonMessageLength = strlen($jsonMessage); $binaryMessage = pack('CNNnH*', self::BINARY_COMMAND, $this->getIdentifier(), $this->getMessage()->getExpiresAt(), self::BINARY_DEVICETOKEN_SIZE, $this->getMessage()->getDeviceToken()) . pack('n', $jsonMessageLength); return $binaryMessage . $jsonMessage; }
php
public function getBinaryMessage() { $jsonMessage = $this->getMessage()->getJson(); $jsonMessageLength = strlen($jsonMessage); $binaryMessage = pack('CNNnH*', self::BINARY_COMMAND, $this->getIdentifier(), $this->getMessage()->getExpiresAt(), self::BINARY_DEVICETOKEN_SIZE, $this->getMessage()->getDeviceToken()) . pack('n', $jsonMessageLength); return $binaryMessage . $jsonMessage; }
[ "public", "function", "getBinaryMessage", "(", ")", "{", "$", "jsonMessage", "=", "$", "this", "->", "getMessage", "(", ")", "->", "getJson", "(", ")", ";", "$", "jsonMessageLength", "=", "strlen", "(", "$", "jsonMessage", ")", ";", "$", "binaryMessage", ...
Get the message that this envelope contains in binary APNS compatible format @return string
[ "Get", "the", "message", "that", "this", "envelope", "contains", "in", "binary", "APNS", "compatible", "format" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/MessageEnvelope.php#L201-L208
40,891
mac-cain13/notificato
src/Wrep/Notificato/Apns/Feedback/FeedbackFactory.php
FeedbackFactory.createFeedback
public function createFeedback(Certificate $certificate = null) { // Check if a certificate is given, if not use the default certificate if (null == $certificate && $this->getCertificateFactory() != null) { $certificate = $this->getCertificateFactory()->getDefaultCertificate(); } // Check if there is a certificate to use after falling back on the default certificate if (null == $certificate) { throw new \RuntimeException('No certificate given for the creation of the feedback service and no default certificate available.'); } return new Feedback($certificate); }
php
public function createFeedback(Certificate $certificate = null) { // Check if a certificate is given, if not use the default certificate if (null == $certificate && $this->getCertificateFactory() != null) { $certificate = $this->getCertificateFactory()->getDefaultCertificate(); } // Check if there is a certificate to use after falling back on the default certificate if (null == $certificate) { throw new \RuntimeException('No certificate given for the creation of the feedback service and no default certificate available.'); } return new Feedback($certificate); }
[ "public", "function", "createFeedback", "(", "Certificate", "$", "certificate", "=", "null", ")", "{", "// Check if a certificate is given, if not use the default certificate", "if", "(", "null", "==", "$", "certificate", "&&", "$", "this", "->", "getCertificateFactory", ...
Create a Feedback object @param Certificate|null The certificate to use or null to use the default certificate from the given certificate factory @return Feedback
[ "Create", "a", "Feedback", "object" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Feedback/FeedbackFactory.php#L48-L61
40,892
mac-cain13/notificato
src/Wrep/Notificato/Apns/Sender.php
Sender.queue
public function queue(Message $message) { // Get the gateway for the certificate $gateway = $this->getGatewayForCertificate( $message->getCertificate() ); // Queue the message return $gateway->queue($message); }
php
public function queue(Message $message) { // Get the gateway for the certificate $gateway = $this->getGatewayForCertificate( $message->getCertificate() ); // Queue the message return $gateway->queue($message); }
[ "public", "function", "queue", "(", "Message", "$", "message", ")", "{", "// Get the gateway for the certificate", "$", "gateway", "=", "$", "this", "->", "getGatewayForCertificate", "(", "$", "message", "->", "getCertificate", "(", ")", ")", ";", "// Queue the me...
Queue a message on the correct APNS gateway connection @param Message The message to queue @param int The times Notificato should retry to deliver the message on failure (deprecated and ignored) @return MessageEnvelope
[ "Queue", "a", "message", "on", "the", "correct", "APNS", "gateway", "connection" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Sender.php#L84-L91
40,893
mac-cain13/notificato
src/Wrep/Notificato/Apns/Sender.php
Sender.getQueueLength
public function getQueueLength() { $queueLength = 0; foreach ($this->gatewayPool as $gateway) { $queueLength += $gateway->getQueueLength(); } return $queueLength; }
php
public function getQueueLength() { $queueLength = 0; foreach ($this->gatewayPool as $gateway) { $queueLength += $gateway->getQueueLength(); } return $queueLength; }
[ "public", "function", "getQueueLength", "(", ")", "{", "$", "queueLength", "=", "0", ";", "foreach", "(", "$", "this", "->", "gatewayPool", "as", "$", "gateway", ")", "{", "$", "queueLength", "+=", "$", "gateway", "->", "getQueueLength", "(", ")", ";", ...
Count of all queued messages @return int
[ "Count", "of", "all", "queued", "messages" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Sender.php#L98-L108
40,894
mac-cain13/notificato
src/Wrep/Notificato/Apns/Certificate.php
Certificate.getDescription
public function getDescription() { $description = $this->description; if (null == $description) { $description = $this->getFingerprint(); } return $description; }
php
public function getDescription() { $description = $this->description; if (null == $description) { $description = $this->getFingerprint(); } return $description; }
[ "public", "function", "getDescription", "(", ")", "{", "$", "description", "=", "$", "this", "->", "description", ";", "if", "(", "null", "==", "$", "description", ")", "{", "$", "description", "=", "$", "this", "->", "getFingerprint", "(", ")", ";", "...
An as humanreadable as possible description of the certificate to identify the certificate @return string
[ "An", "as", "humanreadable", "as", "possible", "description", "of", "the", "certificate", "to", "identify", "the", "certificate" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Certificate.php#L238-L247
40,895
mac-cain13/notificato
src/Wrep/Notificato/Apns/Certificate.php
Certificate.getEndpoint
public function getEndpoint($endpointType) { // Check if the endpoint type is valid if (self::ENDPOINT_TYPE_GATEWAY !== $endpointType && self::ENDPOINT_TYPE_FEEDBACK !== $endpointType ) { throw new \InvalidArgumentException($endpointType . ' is not a valid endpoint type.'); } return self::$endpoints[$this->endpointEnv][$endpointType]; }
php
public function getEndpoint($endpointType) { // Check if the endpoint type is valid if (self::ENDPOINT_TYPE_GATEWAY !== $endpointType && self::ENDPOINT_TYPE_FEEDBACK !== $endpointType ) { throw new \InvalidArgumentException($endpointType . ' is not a valid endpoint type.'); } return self::$endpoints[$this->endpointEnv][$endpointType]; }
[ "public", "function", "getEndpoint", "(", "$", "endpointType", ")", "{", "// Check if the endpoint type is valid", "if", "(", "self", "::", "ENDPOINT_TYPE_GATEWAY", "!==", "$", "endpointType", "&&", "self", "::", "ENDPOINT_TYPE_FEEDBACK", "!==", "$", "endpointType", "...
Get the endpoint this certificate is valid for @param string The type of endpoint you want @return string @throws \InvalidArgumentException
[ "Get", "the", "endpoint", "this", "certificate", "is", "valid", "for" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Certificate.php#L279-L287
40,896
mac-cain13/notificato
src/Wrep/Notificato/Apns/Certificate.php
Certificate.getFingerprint
public function getFingerprint() { // Calculate fingerprint if unknown if (null == $this->fingerprint) { $this->fingerprint = sha1( $this->endpointEnv . sha1_file($this->getPemFile()) ); } return $this->fingerprint; }
php
public function getFingerprint() { // Calculate fingerprint if unknown if (null == $this->fingerprint) { $this->fingerprint = sha1( $this->endpointEnv . sha1_file($this->getPemFile()) ); } return $this->fingerprint; }
[ "public", "function", "getFingerprint", "(", ")", "{", "// Calculate fingerprint if unknown", "if", "(", "null", "==", "$", "this", "->", "fingerprint", ")", "{", "$", "this", "->", "fingerprint", "=", "sha1", "(", "$", "this", "->", "endpointEnv", ".", "sha...
Get a unique hash of the certificate this can be used to check if two Apns\Certificate objects are the same @return string
[ "Get", "a", "unique", "hash", "of", "the", "certificate", "this", "can", "be", "used", "to", "check", "if", "two", "Apns", "\\", "Certificate", "objects", "are", "the", "same" ]
a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915
https://github.com/mac-cain13/notificato/blob/a4b3c3edda1ffeb4ba154fad31dbda4a5a5cf915/src/Wrep/Notificato/Apns/Certificate.php#L295-L303
40,897
potievdev/slim-rbac
src/migrations/20171210103530_create_permission.php
CreatePermission.change
public function change() { $permissionTable = $this->table('permission', ['signed' => false]); $permissionTable->addColumn('name', 'string', ['limit' => 100]) ->addColumn('status', 'boolean', ['default' => 1]) ->addColumn('created_at', 'datetime') ->addColumn('updated_at', 'datetime', ['null' => true]) ->addIndex('name', ['name' => 'idx_role_name' ,'unique' => true]) ->create(); }
php
public function change() { $permissionTable = $this->table('permission', ['signed' => false]); $permissionTable->addColumn('name', 'string', ['limit' => 100]) ->addColumn('status', 'boolean', ['default' => 1]) ->addColumn('created_at', 'datetime') ->addColumn('updated_at', 'datetime', ['null' => true]) ->addIndex('name', ['name' => 'idx_role_name' ,'unique' => true]) ->create(); }
[ "public", "function", "change", "(", ")", "{", "$", "permissionTable", "=", "$", "this", "->", "table", "(", "'permission'", ",", "[", "'signed'", "=>", "false", "]", ")", ";", "$", "permissionTable", "->", "addColumn", "(", "'name'", ",", "'string'", ",...
Create permission table in database. Field 'name' is unique index.
[ "Create", "permission", "table", "in", "database", ".", "Field", "name", "is", "unique", "index", "." ]
1c79649b7cc651d878c3dcfed73c7c858fd54345
https://github.com/potievdev/slim-rbac/blob/1c79649b7cc651d878c3dcfed73c7c858fd54345/src/migrations/20171210103530_create_permission.php#L14-L24
40,898
potievdev/slim-rbac
src/Models/Repository/RoleHierarchyRepository.php
RoleHierarchyRepository.getChildIds
private function getChildIds($parentIds) { $qb = $this->createQueryBuilder('roleHierarchy'); $qb->select('roleHierarchy.childRoleId') ->where($qb->expr()->in( 'roleHierarchy.parentRoleId', $parentIds)) ->indexBy('roleHierarchy', 'roleHierarchy.childRoleId'); $childRoleIds = $qb->getQuery()->getArrayResult(); return array_keys($childRoleIds); }
php
private function getChildIds($parentIds) { $qb = $this->createQueryBuilder('roleHierarchy'); $qb->select('roleHierarchy.childRoleId') ->where($qb->expr()->in( 'roleHierarchy.parentRoleId', $parentIds)) ->indexBy('roleHierarchy', 'roleHierarchy.childRoleId'); $childRoleIds = $qb->getQuery()->getArrayResult(); return array_keys($childRoleIds); }
[ "private", "function", "getChildIds", "(", "$", "parentIds", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'roleHierarchy'", ")", ";", "$", "qb", "->", "select", "(", "'roleHierarchy.childRoleId'", ")", "->", "where", "(", "$", "...
Returns array of child role ids for given parent role ids @param integer[] $parentIds @return integer[] @throws \Doctrine\ORM\Query\QueryException
[ "Returns", "array", "of", "child", "role", "ids", "for", "given", "parent", "role", "ids" ]
1c79649b7cc651d878c3dcfed73c7c858fd54345
https://github.com/potievdev/slim-rbac/blob/1c79649b7cc651d878c3dcfed73c7c858fd54345/src/Models/Repository/RoleHierarchyRepository.php#L22-L33
40,899
potievdev/slim-rbac
src/Models/Repository/RoleHierarchyRepository.php
RoleHierarchyRepository.getAllChildRoleIds
private function getAllChildRoleIds($parentIds) { $allChildIds = []; while (count($parentIds) > 0) { $parentIds = $this->getChildIds($parentIds); $allChildIds = ArrayHelper::merge($allChildIds, $parentIds); }; return $allChildIds; }
php
private function getAllChildRoleIds($parentIds) { $allChildIds = []; while (count($parentIds) > 0) { $parentIds = $this->getChildIds($parentIds); $allChildIds = ArrayHelper::merge($allChildIds, $parentIds); }; return $allChildIds; }
[ "private", "function", "getAllChildRoleIds", "(", "$", "parentIds", ")", "{", "$", "allChildIds", "=", "[", "]", ";", "while", "(", "count", "(", "$", "parentIds", ")", ">", "0", ")", "{", "$", "parentIds", "=", "$", "this", "->", "getChildIds", "(", ...
Returns all child role ids for given parent role ids @param integer[] $parentIds @return integer[] @throws \Doctrine\ORM\Query\QueryException
[ "Returns", "all", "child", "role", "ids", "for", "given", "parent", "role", "ids" ]
1c79649b7cc651d878c3dcfed73c7c858fd54345
https://github.com/potievdev/slim-rbac/blob/1c79649b7cc651d878c3dcfed73c7c858fd54345/src/Models/Repository/RoleHierarchyRepository.php#L69-L79