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
41,100
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readByte
public function readByte(Stream $stream) { $char = $stream->read(1); $byte = ord($char); return $byte; }
php
public function readByte(Stream $stream) { $char = $stream->read(1); $byte = ord($char); return $byte; }
[ "public", "function", "readByte", "(", "Stream", "$", "stream", ")", "{", "$", "char", "=", "$", "stream", "->", "read", "(", "1", ")", ";", "$", "byte", "=", "ord", "(", "$", "char", ")", ";", "return", "$", "byte", ";", "}" ]
Reads a byte. @param \Protobuf\Stream $stream @return integer
[ "Reads", "a", "byte", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L54-L60
41,101
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readVarint
public function readVarint(Stream $stream) { // Optimize common case (single byte varints) $byte = $this->readByte($stream); if ($byte < 0x80) { return $byte; } $length = $stream->getSize(); $offset = $stream->tell(); $result = $byte & 0x7f; $shift = 7; // fastpath 32bit varints (5bytes) by unrolling the loop if ($length - $offset >= 4) { // 2 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 7; if ($byte < 0x80) { return $result; } // 3 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 14; if ($byte < 0x80) { return $result; } // 4 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 21; if ($byte < 0x80) { return $result; } // 5 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 28; if ($byte < 0x80) { return $result; } $shift = 35; } // If we're just at the end of the buffer or handling a 64bit varint do { $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << $shift; $shift += 7; } while ($byte > 0x7f); return $result; }
php
public function readVarint(Stream $stream) { // Optimize common case (single byte varints) $byte = $this->readByte($stream); if ($byte < 0x80) { return $byte; } $length = $stream->getSize(); $offset = $stream->tell(); $result = $byte & 0x7f; $shift = 7; // fastpath 32bit varints (5bytes) by unrolling the loop if ($length - $offset >= 4) { // 2 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 7; if ($byte < 0x80) { return $result; } // 3 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 14; if ($byte < 0x80) { return $result; } // 4 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 21; if ($byte < 0x80) { return $result; } // 5 $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << 28; if ($byte < 0x80) { return $result; } $shift = 35; } // If we're just at the end of the buffer or handling a 64bit varint do { $byte = $this->readByte($stream); $result |= ($byte & 0x7f) << $shift; $shift += 7; } while ($byte > 0x7f); return $result; }
[ "public", "function", "readVarint", "(", "Stream", "$", "stream", ")", "{", "// Optimize common case (single byte varints)", "$", "byte", "=", "$", "this", "->", "readByte", "(", "$", "stream", ")", ";", "if", "(", "$", "byte", "<", "0x80", ")", "{", "retu...
Decode a varint. @param \Protobuf\Stream $stream @return integer
[ "Decode", "a", "varint", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L69-L128
41,102
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readZigzag
public function readZigzag(Stream $stream) { $number = $this->readVarint($stream); $zigzag = ($number >> 1) ^ (-($number & 1)); return $zigzag; }
php
public function readZigzag(Stream $stream) { $number = $this->readVarint($stream); $zigzag = ($number >> 1) ^ (-($number & 1)); return $zigzag; }
[ "public", "function", "readZigzag", "(", "Stream", "$", "stream", ")", "{", "$", "number", "=", "$", "this", "->", "readVarint", "(", "$", "stream", ")", ";", "$", "zigzag", "=", "(", "$", "number", ">>", "1", ")", "^", "(", "-", "(", "$", "numbe...
Decodes a zigzag integer of the given bits. @param \Protobuf\Stream $stream @return integer
[ "Decodes", "a", "zigzag", "integer", "of", "the", "given", "bits", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L137-L143
41,103
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readSFixed32
public function readSFixed32(Stream $stream) { $bytes = $stream->read(4); if ($this->isBigEndian) { $bytes = strrev($bytes); } list(, $result) = unpack('l', $bytes); return $result; }
php
public function readSFixed32(Stream $stream) { $bytes = $stream->read(4); if ($this->isBigEndian) { $bytes = strrev($bytes); } list(, $result) = unpack('l', $bytes); return $result; }
[ "public", "function", "readSFixed32", "(", "Stream", "$", "stream", ")", "{", "$", "bytes", "=", "$", "stream", "->", "read", "(", "4", ")", ";", "if", "(", "$", "this", "->", "isBigEndian", ")", "{", "$", "bytes", "=", "strrev", "(", "$", "bytes",...
Decode a fixed 32bit integer with sign. @param \Protobuf\Stream $stream @return integer
[ "Decode", "a", "fixed", "32bit", "integer", "with", "sign", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L152-L163
41,104
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readFixed32
public function readFixed32(Stream $stream) { $bytes = $stream->read(4); if (PHP_INT_SIZE < 8) { list(, $lo, $hi) = unpack('v*', $bytes); return $hi << 16 | $lo; } list(, $result) = unpack('V*', $bytes); return $result; }
php
public function readFixed32(Stream $stream) { $bytes = $stream->read(4); if (PHP_INT_SIZE < 8) { list(, $lo, $hi) = unpack('v*', $bytes); return $hi << 16 | $lo; } list(, $result) = unpack('V*', $bytes); return $result; }
[ "public", "function", "readFixed32", "(", "Stream", "$", "stream", ")", "{", "$", "bytes", "=", "$", "stream", "->", "read", "(", "4", ")", ";", "if", "(", "PHP_INT_SIZE", "<", "8", ")", "{", "list", "(", ",", "$", "lo", ",", "$", "hi", ")", "=...
Decode a fixed 32bit integer without sign. @param \Protobuf\Stream $stream @return integer
[ "Decode", "a", "fixed", "32bit", "integer", "without", "sign", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L172-L185
41,105
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readSFixed64
public function readSFixed64(Stream $stream) { $bytes = $stream->read(8); list(, $lo0, $lo1, $hi0, $hi1) = unpack('v*', $bytes); return ($hi1 << 16 | $hi0) << 32 | ($lo1 << 16 | $lo0); }
php
public function readSFixed64(Stream $stream) { $bytes = $stream->read(8); list(, $lo0, $lo1, $hi0, $hi1) = unpack('v*', $bytes); return ($hi1 << 16 | $hi0) << 32 | ($lo1 << 16 | $lo0); }
[ "public", "function", "readSFixed64", "(", "Stream", "$", "stream", ")", "{", "$", "bytes", "=", "$", "stream", "->", "read", "(", "8", ")", ";", "list", "(", ",", "$", "lo0", ",", "$", "lo1", ",", "$", "hi0", ",", "$", "hi1", ")", "=", "unpack...
Decode a fixed 64bit integer with sign. @param \Protobuf\Stream $stream @return integer
[ "Decode", "a", "fixed", "64bit", "integer", "with", "sign", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L194-L201
41,106
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readString
public function readString(Stream $stream) { $length = $this->readVarint($stream); $string = $stream->read($length); return $string; }
php
public function readString(Stream $stream) { $length = $this->readVarint($stream); $string = $stream->read($length); return $string; }
[ "public", "function", "readString", "(", "Stream", "$", "stream", ")", "{", "$", "length", "=", "$", "this", "->", "readVarint", "(", "$", "stream", ")", ";", "$", "string", "=", "$", "stream", "->", "read", "(", "$", "length", ")", ";", "return", ...
Decode a string. @param \Protobuf\Stream $stream @return string
[ "Decode", "a", "string", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L274-L280
41,107
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readByteStream
public function readByteStream(Stream $stream) { $length = $this->readVarint($stream); $value = $stream->readStream($length); return $value; }
php
public function readByteStream(Stream $stream) { $length = $this->readVarint($stream); $value = $stream->readStream($length); return $value; }
[ "public", "function", "readByteStream", "(", "Stream", "$", "stream", ")", "{", "$", "length", "=", "$", "this", "->", "readVarint", "(", "$", "stream", ")", ";", "$", "value", "=", "$", "stream", "->", "readStream", "(", "$", "length", ")", ";", "re...
Decode a stream of bytes. @param \Protobuf\Stream $stream @return \Protobuf\Stream
[ "Decode", "a", "stream", "of", "bytes", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L289-L295
41,108
protobuf-php/protobuf
src/Binary/StreamReader.php
StreamReader.readUnknown
public function readUnknown(Stream $stream, $wire) { if ($wire === WireFormat::WIRE_VARINT) { return $this->readVarint($stream); } if ($wire === WireFormat::WIRE_LENGTH) { return $this->readString($stream); } if ($wire === WireFormat::WIRE_FIXED32) { return $this->readFixed32($stream); } if ($wire === WireFormat::WIRE_FIXED64) { return $this->readFixed64($stream); } if ($wire === WireFormat::WIRE_GROUP_START || $wire === WireFormat::WIRE_GROUP_END) { throw new RuntimeException('Groups are deprecated in Protocol Buffers and unsupported.'); } throw new RuntimeException("Unsupported wire type '$wire' while reading unknown field."); }
php
public function readUnknown(Stream $stream, $wire) { if ($wire === WireFormat::WIRE_VARINT) { return $this->readVarint($stream); } if ($wire === WireFormat::WIRE_LENGTH) { return $this->readString($stream); } if ($wire === WireFormat::WIRE_FIXED32) { return $this->readFixed32($stream); } if ($wire === WireFormat::WIRE_FIXED64) { return $this->readFixed64($stream); } if ($wire === WireFormat::WIRE_GROUP_START || $wire === WireFormat::WIRE_GROUP_END) { throw new RuntimeException('Groups are deprecated in Protocol Buffers and unsupported.'); } throw new RuntimeException("Unsupported wire type '$wire' while reading unknown field."); }
[ "public", "function", "readUnknown", "(", "Stream", "$", "stream", ",", "$", "wire", ")", "{", "if", "(", "$", "wire", "===", "WireFormat", "::", "WIRE_VARINT", ")", "{", "return", "$", "this", "->", "readVarint", "(", "$", "stream", ")", ";", "}", "...
Read unknown scalar value. @param \Protobuf\Stream $stream @param integer $wire @return scalar
[ "Read", "unknown", "scalar", "value", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamReader.php#L305-L328
41,109
protobuf-php/protobuf
src/Binary/Platform/PlatformFactory.php
PlatformFactory.getNegativeEncoder
public function getNegativeEncoder() { if ($this->negativeEncoder !== null) { return $this->negativeEncoder; } if ($this->isExtensionLoaded('gmp')) { return $this->negativeEncoder = new GmpNegativeEncoder(); } if ($this->isExtensionLoaded('bcmath') && ! $this->is32Bit()) { return $this->negativeEncoder = new BcNegativeEncoder(); } return $this->negativeEncoder = new InvalidNegativeEncoder(); }
php
public function getNegativeEncoder() { if ($this->negativeEncoder !== null) { return $this->negativeEncoder; } if ($this->isExtensionLoaded('gmp')) { return $this->negativeEncoder = new GmpNegativeEncoder(); } if ($this->isExtensionLoaded('bcmath') && ! $this->is32Bit()) { return $this->negativeEncoder = new BcNegativeEncoder(); } return $this->negativeEncoder = new InvalidNegativeEncoder(); }
[ "public", "function", "getNegativeEncoder", "(", ")", "{", "if", "(", "$", "this", "->", "negativeEncoder", "!==", "null", ")", "{", "return", "$", "this", "->", "negativeEncoder", ";", "}", "if", "(", "$", "this", "->", "isExtensionLoaded", "(", "'gmp'", ...
Return a NegativeEncoder. @return \Protobuf\Binary\Platform\NegativeEncoder
[ "Return", "a", "NegativeEncoder", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/Platform/PlatformFactory.php#L24-L39
41,110
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeBytes
public function writeBytes(Stream $stream, $bytes, $length = null) { if ($length === null) { $length = mb_strlen($bytes, '8bit'); } $stream->write($bytes, $length); }
php
public function writeBytes(Stream $stream, $bytes, $length = null) { if ($length === null) { $length = mb_strlen($bytes, '8bit'); } $stream->write($bytes, $length); }
[ "public", "function", "writeBytes", "(", "Stream", "$", "stream", ",", "$", "bytes", ",", "$", "length", "=", "null", ")", "{", "if", "(", "$", "length", "===", "null", ")", "{", "$", "length", "=", "mb_strlen", "(", "$", "bytes", ",", "'8bit'", ")...
Store the given bytes in the stream. @param \Protobuf\Stream $stream @param string $bytes @param int $length
[ "Store", "the", "given", "bytes", "in", "the", "stream", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L53-L60
41,111
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeVarint
public function writeVarint(Stream $stream, $value) { // Small values do not need to be encoded if ($value >= 0 && $value < 0x80) { $this->writeByte($stream, $value); return; } $values = null; // Build an array of bytes with the encoded values if ($value > 0) { $values = []; while ($value > 0) { $values[] = 0x80 | ($value & 0x7f); $value = $value >> 7; } } if ($values === null) { $values = $this->negativeEncoder->encodeVarint($value); } // Remove the MSB flag from the last byte $values[count($values) - 1] &= 0x7f; // Convert the byte sized ints to actual bytes in a string $values = array_merge(['C*'], $values); $bytes = call_user_func_array('pack', $values); $this->writeBytes($stream, $bytes); }
php
public function writeVarint(Stream $stream, $value) { // Small values do not need to be encoded if ($value >= 0 && $value < 0x80) { $this->writeByte($stream, $value); return; } $values = null; // Build an array of bytes with the encoded values if ($value > 0) { $values = []; while ($value > 0) { $values[] = 0x80 | ($value & 0x7f); $value = $value >> 7; } } if ($values === null) { $values = $this->negativeEncoder->encodeVarint($value); } // Remove the MSB flag from the last byte $values[count($values) - 1] &= 0x7f; // Convert the byte sized ints to actual bytes in a string $values = array_merge(['C*'], $values); $bytes = call_user_func_array('pack', $values); $this->writeBytes($stream, $bytes); }
[ "public", "function", "writeVarint", "(", "Stream", "$", "stream", ",", "$", "value", ")", "{", "// Small values do not need to be encoded", "if", "(", "$", "value", ">=", "0", "&&", "$", "value", "<", "0x80", ")", "{", "$", "this", "->", "writeByte", "(",...
Store an integer encoded as varint. @param \Protobuf\Stream $stream @param integer $value
[ "Store", "an", "integer", "encoded", "as", "varint", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L79-L112
41,112
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeZigzag
public function writeZigzag(Stream $stream, $value, $base = 32) { if ($base == 32) { $this->writeZigzag32($stream, $value); return; } $this->writeZigzag64($stream, $value); }
php
public function writeZigzag(Stream $stream, $value, $base = 32) { if ($base == 32) { $this->writeZigzag32($stream, $value); return; } $this->writeZigzag64($stream, $value); }
[ "public", "function", "writeZigzag", "(", "Stream", "$", "stream", ",", "$", "value", ",", "$", "base", "=", "32", ")", "{", "if", "(", "$", "base", "==", "32", ")", "{", "$", "this", "->", "writeZigzag32", "(", "$", "stream", ",", "$", "value", ...
Encodes an integer with zigzag. @param \Protobuf\Stream $stream @param integer $value @param integer $base
[ "Encodes", "an", "integer", "with", "zigzag", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L121-L130
41,113
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeSFixed64
public function writeSFixed64(Stream $stream, $value) { if ($value >= 0) { $this->writeFixed64($stream, $value); return; } $bytes = $this->negativeEncoder->encodeSFixed64($value); $this->writeBytes($stream, $bytes); }
php
public function writeSFixed64(Stream $stream, $value) { if ($value >= 0) { $this->writeFixed64($stream, $value); return; } $bytes = $this->negativeEncoder->encodeSFixed64($value); $this->writeBytes($stream, $bytes); }
[ "public", "function", "writeSFixed64", "(", "Stream", "$", "stream", ",", "$", "value", ")", "{", "if", "(", "$", "value", ">=", "0", ")", "{", "$", "this", "->", "writeFixed64", "(", "$", "stream", ",", "$", "value", ")", ";", "return", ";", "}", ...
Encode an integer as a fixed of 64bits with sign. @param \Protobuf\Stream $stream @param integer $value
[ "Encode", "an", "integer", "as", "a", "fixed", "of", "64bits", "with", "sign", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L188-L199
41,114
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeFixed64
public function writeFixed64(Stream $stream, $value) { $bytes = pack('V*', $value & 0xffffffff, $value / (0xffffffff + 1)); $this->writeBytes($stream, $bytes, 8); }
php
public function writeFixed64(Stream $stream, $value) { $bytes = pack('V*', $value & 0xffffffff, $value / (0xffffffff + 1)); $this->writeBytes($stream, $bytes, 8); }
[ "public", "function", "writeFixed64", "(", "Stream", "$", "stream", ",", "$", "value", ")", "{", "$", "bytes", "=", "pack", "(", "'V*'", ",", "$", "value", "&", "0xffffffff", ",", "$", "value", "/", "(", "0xffffffff", "+", "1", ")", ")", ";", "$", ...
Encode an integer as a fixed of 64bits without sign. @param \Protobuf\Stream $stream @param integer $value
[ "Encode", "an", "integer", "as", "a", "fixed", "of", "64bits", "without", "sign", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L207-L212
41,115
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeDouble
public function writeDouble(Stream $stream, $value) { $bytes = pack('d*', $value); if ($this->isBigEndian) { $bytes = strrev($bytes); } $this->writeBytes($stream, $bytes, 8); }
php
public function writeDouble(Stream $stream, $value) { $bytes = pack('d*', $value); if ($this->isBigEndian) { $bytes = strrev($bytes); } $this->writeBytes($stream, $bytes, 8); }
[ "public", "function", "writeDouble", "(", "Stream", "$", "stream", ",", "$", "value", ")", "{", "$", "bytes", "=", "pack", "(", "'d*'", ",", "$", "value", ")", ";", "if", "(", "$", "this", "->", "isBigEndian", ")", "{", "$", "bytes", "=", "strrev",...
Encode a number as a 64bit double. @param \Protobuf\Stream $stream @param float $value
[ "Encode", "a", "number", "as", "a", "64bit", "double", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L237-L246
41,116
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeString
public function writeString(Stream $stream, $value) { $this->writeVarint($stream, mb_strlen($value, '8bit')); $this->writeBytes($stream, $value); }
php
public function writeString(Stream $stream, $value) { $this->writeVarint($stream, mb_strlen($value, '8bit')); $this->writeBytes($stream, $value); }
[ "public", "function", "writeString", "(", "Stream", "$", "stream", ",", "$", "value", ")", "{", "$", "this", "->", "writeVarint", "(", "$", "stream", ",", "mb_strlen", "(", "$", "value", ",", "'8bit'", ")", ")", ";", "$", "this", "->", "writeBytes", ...
Encode a string. @param \Protobuf\Stream $stream @param string $value
[ "Encode", "a", "string", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L265-L269
41,117
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeByteStream
public function writeByteStream(Stream $stream, Stream $value) { $length = $value->getSize(); $value->seek(0); $this->writeVarint($stream, $length); $stream->writeStream($value, $length); }
php
public function writeByteStream(Stream $stream, Stream $value) { $length = $value->getSize(); $value->seek(0); $this->writeVarint($stream, $length); $stream->writeStream($value, $length); }
[ "public", "function", "writeByteStream", "(", "Stream", "$", "stream", ",", "Stream", "$", "value", ")", "{", "$", "length", "=", "$", "value", "->", "getSize", "(", ")", ";", "$", "value", "->", "seek", "(", "0", ")", ";", "$", "this", "->", "writ...
Encode a stream of bytes. @param \Protobuf\Stream $stream @param \Protobuf\Stream $value
[ "Encode", "a", "stream", "of", "bytes", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L277-L284
41,118
protobuf-php/protobuf
src/Binary/StreamWriter.php
StreamWriter.writeStream
public function writeStream(Stream $stream, Stream $value, $length = null) { if ($length === null) { $length = $value->getSize(); } $stream->writeStream($value, $length); }
php
public function writeStream(Stream $stream, Stream $value, $length = null) { if ($length === null) { $length = $value->getSize(); } $stream->writeStream($value, $length); }
[ "public", "function", "writeStream", "(", "Stream", "$", "stream", ",", "Stream", "$", "value", ",", "$", "length", "=", "null", ")", "{", "if", "(", "$", "length", "===", "null", ")", "{", "$", "length", "=", "$", "value", "->", "getSize", "(", ")...
Write the given stream. @param \Protobuf\Stream $stream @param \Protobuf\Stream $value @param int $length
[ "Write", "the", "given", "stream", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/StreamWriter.php#L293-L300
41,119
protobuf-php/protobuf
src/Binary/SizeCalculator.php
SizeCalculator.computeVarintSize
public function computeVarintSize($value) { if (($value & (0xffffffff << 7)) === 0) { return 1; } if (($value & (0xffffffff << 14)) === 0) { return 2; } if (($value & (0xffffffff << 21)) === 0) { return 3; } if (($value & (0xffffffff << 28)) === 0) { return 4; } if (($value & (0xffffffff << 35)) === 0) { return 5; } if (($value & (0xffffffff << 42)) === 0) { return 6; } if (($value & (0xffffffff << 49)) === 0) { return 7; } if (($value & (0xffffffff << 56)) === 0) { return 8; } if (($value & (0xffffffff << 63)) === 0) { return 9; } return 10; }
php
public function computeVarintSize($value) { if (($value & (0xffffffff << 7)) === 0) { return 1; } if (($value & (0xffffffff << 14)) === 0) { return 2; } if (($value & (0xffffffff << 21)) === 0) { return 3; } if (($value & (0xffffffff << 28)) === 0) { return 4; } if (($value & (0xffffffff << 35)) === 0) { return 5; } if (($value & (0xffffffff << 42)) === 0) { return 6; } if (($value & (0xffffffff << 49)) === 0) { return 7; } if (($value & (0xffffffff << 56)) === 0) { return 8; } if (($value & (0xffffffff << 63)) === 0) { return 9; } return 10; }
[ "public", "function", "computeVarintSize", "(", "$", "value", ")", "{", "if", "(", "(", "$", "value", "&", "(", "0xffffffff", "<<", "7", ")", ")", "===", "0", ")", "{", "return", "1", ";", "}", "if", "(", "(", "$", "value", "&", "(", "0xffffffff"...
Compute the number of bytes that would be needed to encode a varint. @param integer $value @return integer
[ "Compute", "the", "number", "of", "bytes", "that", "would", "be", "needed", "to", "encode", "a", "varint", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/SizeCalculator.php#L41-L80
41,120
protobuf-php/protobuf
src/Binary/SizeCalculator.php
SizeCalculator.computeZigzag32Size
public function computeZigzag32Size($value) { $varint = ($value << 1) ^ ($value >> 32 - 1); $size = $this->computeVarintSize($varint); return $size; }
php
public function computeZigzag32Size($value) { $varint = ($value << 1) ^ ($value >> 32 - 1); $size = $this->computeVarintSize($varint); return $size; }
[ "public", "function", "computeZigzag32Size", "(", "$", "value", ")", "{", "$", "varint", "=", "(", "$", "value", "<<", "1", ")", "^", "(", "$", "value", ">>", "32", "-", "1", ")", ";", "$", "size", "=", "$", "this", "->", "computeVarintSize", "(", ...
Compute the number of bytes that would be needed to encode a zigzag 32. @param integer $value @return integer
[ "Compute", "the", "number", "of", "bytes", "that", "would", "be", "needed", "to", "encode", "a", "zigzag", "32", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/SizeCalculator.php#L89-L95
41,121
protobuf-php/protobuf
src/Binary/SizeCalculator.php
SizeCalculator.computeZigzag64Size
public function computeZigzag64Size($value) { $varint = ($value << 1) ^ ($value >> 64 - 1); $size = $this->computeVarintSize($varint); return $size; }
php
public function computeZigzag64Size($value) { $varint = ($value << 1) ^ ($value >> 64 - 1); $size = $this->computeVarintSize($varint); return $size; }
[ "public", "function", "computeZigzag64Size", "(", "$", "value", ")", "{", "$", "varint", "=", "(", "$", "value", "<<", "1", ")", "^", "(", "$", "value", ">>", "64", "-", "1", ")", ";", "$", "size", "=", "$", "this", "->", "computeVarintSize", "(", ...
Compute the number of bytes that would be needed to encode a zigzag 64. @param integer $value @return integer
[ "Compute", "the", "number", "of", "bytes", "that", "would", "be", "needed", "to", "encode", "a", "zigzag", "64", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/SizeCalculator.php#L104-L110
41,122
protobuf-php/protobuf
src/Binary/SizeCalculator.php
SizeCalculator.computeStringSize
public function computeStringSize($value) { $length = mb_strlen($value, '8bit'); $size = $length + $this->computeVarintSize($length); return $size; }
php
public function computeStringSize($value) { $length = mb_strlen($value, '8bit'); $size = $length + $this->computeVarintSize($length); return $size; }
[ "public", "function", "computeStringSize", "(", "$", "value", ")", "{", "$", "length", "=", "mb_strlen", "(", "$", "value", ",", "'8bit'", ")", ";", "$", "size", "=", "$", "length", "+", "$", "this", "->", "computeVarintSize", "(", "$", "length", ")", ...
Compute the number of bytes that would be needed to encode a string. @param integer $value @return integer
[ "Compute", "the", "number", "of", "bytes", "that", "would", "be", "needed", "to", "encode", "a", "string", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/SizeCalculator.php#L119-L125
41,123
protobuf-php/protobuf
src/Binary/SizeCalculator.php
SizeCalculator.computeByteStreamSize
public function computeByteStreamSize(Stream $value) { $length = $value->getSize(); $size = $length + $this->computeVarintSize($length); return $size; }
php
public function computeByteStreamSize(Stream $value) { $length = $value->getSize(); $size = $length + $this->computeVarintSize($length); return $size; }
[ "public", "function", "computeByteStreamSize", "(", "Stream", "$", "value", ")", "{", "$", "length", "=", "$", "value", "->", "getSize", "(", ")", ";", "$", "size", "=", "$", "length", "+", "$", "this", "->", "computeVarintSize", "(", "$", "length", ")...
Compute the number of bytes that would be needed to encode a stream of bytes. @param \Protobuf\Stream $value @return integer
[ "Compute", "the", "number", "of", "bytes", "that", "would", "be", "needed", "to", "encode", "a", "stream", "of", "bytes", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Binary/SizeCalculator.php#L134-L140
41,124
protobuf-php/protobuf
src/ScalarCollection.php
ScalarCollection.add
public function add($value) { if ( ! is_scalar($value)) { throw new InvalidArgumentException(sprintf( 'Argument 1 passed to %s must be a scalar value, %s given', __METHOD__, is_object($value) ? get_class($value) : gettype($value) )); } parent::offsetSet(null, $value); }
php
public function add($value) { if ( ! is_scalar($value)) { throw new InvalidArgumentException(sprintf( 'Argument 1 passed to %s must be a scalar value, %s given', __METHOD__, is_object($value) ? get_class($value) : gettype($value) )); } parent::offsetSet(null, $value); }
[ "public", "function", "add", "(", "$", "value", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Argument 1 passed to %s must be a scalar value, %s given'", ",", "__METHOD__...
Adds a value to this collection @param scalar $value
[ "Adds", "a", "value", "to", "this", "collection" ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/ScalarCollection.php#L28-L39
41,125
protobuf-php/protobuf
src/Stream.php
Stream.read
public function read($length) { if ($length < 1) { return ''; } $buffer = fread($this->stream, $length); if ($buffer === false) { throw new RuntimeException('Failed to read ' . $length . ' bytes'); } return $buffer; }
php
public function read($length) { if ($length < 1) { return ''; } $buffer = fread($this->stream, $length); if ($buffer === false) { throw new RuntimeException('Failed to read ' . $length . ' bytes'); } return $buffer; }
[ "public", "function", "read", "(", "$", "length", ")", "{", "if", "(", "$", "length", "<", "1", ")", "{", "return", "''", ";", "}", "$", "buffer", "=", "fread", "(", "$", "this", "->", "stream", ",", "$", "length", ")", ";", "if", "(", "$", "...
Read data from the stream @param int $length @return string
[ "Read", "data", "from", "the", "stream" ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Stream.php#L153-L166
41,126
protobuf-php/protobuf
src/Stream.php
Stream.wrap
public static function wrap($resource = '', $size = null) { if ($resource instanceof Stream) { return $resource; } $type = gettype($resource); if ($type == 'string') { return self::fromString($resource, $size); } if ($type == 'resource') { return new self($resource, $size); } throw new InvalidArgumentException('Invalid resource type: ' . $type); }
php
public static function wrap($resource = '', $size = null) { if ($resource instanceof Stream) { return $resource; } $type = gettype($resource); if ($type == 'string') { return self::fromString($resource, $size); } if ($type == 'resource') { return new self($resource, $size); } throw new InvalidArgumentException('Invalid resource type: ' . $type); }
[ "public", "static", "function", "wrap", "(", "$", "resource", "=", "''", ",", "$", "size", "=", "null", ")", "{", "if", "(", "$", "resource", "instanceof", "Stream", ")", "{", "return", "$", "resource", ";", "}", "$", "type", "=", "gettype", "(", "...
Wrap the input resource in a stream object. @param \Protobuf\Stream|resource|string $resource @param integer $size @return \Protobuf\Stream @throws \InvalidArgumentException if the $resource arg is not valid.
[ "Wrap", "the", "input", "resource", "in", "a", "stream", "object", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Stream.php#L256-L273
41,127
protobuf-php/protobuf
src/Configuration.php
Configuration.getStreamReader
public function getStreamReader() { if ($this->streamReader !== null) { return $this->streamReader; } return $this->streamReader = new StreamReader($this); }
php
public function getStreamReader() { if ($this->streamReader !== null) { return $this->streamReader; } return $this->streamReader = new StreamReader($this); }
[ "public", "function", "getStreamReader", "(", ")", "{", "if", "(", "$", "this", "->", "streamReader", "!==", "null", ")", "{", "return", "$", "this", "->", "streamReader", ";", "}", "return", "$", "this", "->", "streamReader", "=", "new", "StreamReader", ...
Return a StreamReader @return \Protobuf\Binary\StreamReader
[ "Return", "a", "StreamReader" ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Configuration.php#L91-L98
41,128
protobuf-php/protobuf
src/Configuration.php
Configuration.getStreamWriter
public function getStreamWriter() { if ($this->streamWriter !== null) { return $this->streamWriter; } return $this->streamWriter = new StreamWriter($this); }
php
public function getStreamWriter() { if ($this->streamWriter !== null) { return $this->streamWriter; } return $this->streamWriter = new StreamWriter($this); }
[ "public", "function", "getStreamWriter", "(", ")", "{", "if", "(", "$", "this", "->", "streamWriter", "!==", "null", ")", "{", "return", "$", "this", "->", "streamWriter", ";", "}", "return", "$", "this", "->", "streamWriter", "=", "new", "StreamWriter", ...
Return a StreamWriter @return \Protobuf\Binary\StreamWriter
[ "Return", "a", "StreamWriter" ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Configuration.php#L105-L112
41,129
protobuf-php/protobuf
src/Configuration.php
Configuration.getSizeCalculator
public function getSizeCalculator() { if ($this->sizeCalculator !== null) { return $this->sizeCalculator; } return $this->sizeCalculator = new SizeCalculator($this); }
php
public function getSizeCalculator() { if ($this->sizeCalculator !== null) { return $this->sizeCalculator; } return $this->sizeCalculator = new SizeCalculator($this); }
[ "public", "function", "getSizeCalculator", "(", ")", "{", "if", "(", "$", "this", "->", "sizeCalculator", "!==", "null", ")", "{", "return", "$", "this", "->", "sizeCalculator", ";", "}", "return", "$", "this", "->", "sizeCalculator", "=", "new", "SizeCalc...
Return a SizeCalculator @return \Protobuf\Binary\SizeCalculator
[ "Return", "a", "SizeCalculator" ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Configuration.php#L119-L126
41,130
protobuf-php/protobuf
src/Configuration.php
Configuration.createWriteContext
public function createWriteContext() { $stream = Stream::create(); $writer = $this->getStreamWriter(); $sizeContext = $this->createComputeSizeContext(); $context = new WriteContext($stream, $writer, $sizeContext); return $context; }
php
public function createWriteContext() { $stream = Stream::create(); $writer = $this->getStreamWriter(); $sizeContext = $this->createComputeSizeContext(); $context = new WriteContext($stream, $writer, $sizeContext); return $context; }
[ "public", "function", "createWriteContext", "(", ")", "{", "$", "stream", "=", "Stream", "::", "create", "(", ")", ";", "$", "writer", "=", "$", "this", "->", "getStreamWriter", "(", ")", ";", "$", "sizeContext", "=", "$", "this", "->", "createComputeSiz...
Create a write context. @return \Protobuf\WriteContext
[ "Create", "a", "write", "context", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Configuration.php#L156-L164
41,131
protobuf-php/protobuf
src/Configuration.php
Configuration.createReadContext
public function createReadContext($stream) { $reader = $this->getStreamReader(); $registry = $this->extensionRegistry; $context = new ReadContext($stream, $reader, $registry); return $context; }
php
public function createReadContext($stream) { $reader = $this->getStreamReader(); $registry = $this->extensionRegistry; $context = new ReadContext($stream, $reader, $registry); return $context; }
[ "public", "function", "createReadContext", "(", "$", "stream", ")", "{", "$", "reader", "=", "$", "this", "->", "getStreamReader", "(", ")", ";", "$", "registry", "=", "$", "this", "->", "extensionRegistry", ";", "$", "context", "=", "new", "ReadContext", ...
Create a read context. @param \Protobuf\Stream|resource|string $stream @return \Protobuf\ReadContext
[ "Create", "a", "read", "context", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Configuration.php#L173-L180
41,132
protobuf-php/protobuf
src/Extension/ExtensionRegistry.php
ExtensionRegistry.add
public function add(ExtensionField $extension) { $extendee = trim($extension->getExtendee(), '\\'); $number = $extension->getTag(); if ( ! isset($this->extensions[$extendee])) { $this->extensions[$extendee] = []; } $this->extensions[$extendee][$number] = $extension; }
php
public function add(ExtensionField $extension) { $extendee = trim($extension->getExtendee(), '\\'); $number = $extension->getTag(); if ( ! isset($this->extensions[$extendee])) { $this->extensions[$extendee] = []; } $this->extensions[$extendee][$number] = $extension; }
[ "public", "function", "add", "(", "ExtensionField", "$", "extension", ")", "{", "$", "extendee", "=", "trim", "(", "$", "extension", "->", "getExtendee", "(", ")", ",", "'\\\\'", ")", ";", "$", "number", "=", "$", "extension", "->", "getTag", "(", ")",...
Adds an element to the registry. @param \Protobuf\Extension\ExtensionField $extension
[ "Adds", "an", "element", "to", "the", "registry", "." ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Extension/ExtensionRegistry.php#L30-L40
41,133
protobuf-php/protobuf
src/Extension/ExtensionRegistry.php
ExtensionRegistry.findByNumber
public function findByNumber($className, $number) { $extendee = trim($className, '\\'); if ( ! isset($this->extensions[$extendee][$number])) { return null; } return $this->extensions[$extendee][$number]; }
php
public function findByNumber($className, $number) { $extendee = trim($className, '\\'); if ( ! isset($this->extensions[$extendee][$number])) { return null; } return $this->extensions[$extendee][$number]; }
[ "public", "function", "findByNumber", "(", "$", "className", ",", "$", "number", ")", "{", "$", "extendee", "=", "trim", "(", "$", "className", ",", "'\\\\'", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "extensions", "[", "$", "extende...
Find an extension by containing field number @param string $className @param integer $number @return \Protobuf\Extension\ExtensionField|null
[ "Find", "an", "extension", "by", "containing", "field", "number" ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/Extension/ExtensionRegistry.php#L50-L59
41,134
protobuf-php/protobuf
src/WireFormat.php
WireFormat.assertWireType
public static function assertWireType($wire, $type) { $expected = WireFormat::getWireType($type, $wire); if ($wire !== $expected) { throw new RuntimeException(sprintf( "Expected wire type %s but got %s for type %s.", $expected, $wire, $type )); } }
php
public static function assertWireType($wire, $type) { $expected = WireFormat::getWireType($type, $wire); if ($wire !== $expected) { throw new RuntimeException(sprintf( "Expected wire type %s but got %s for type %s.", $expected, $wire, $type )); } }
[ "public", "static", "function", "assertWireType", "(", "$", "wire", ",", "$", "type", ")", "{", "$", "expected", "=", "WireFormat", "::", "getWireType", "(", "$", "type", ",", "$", "wire", ")", ";", "if", "(", "$", "wire", "!==", "$", "expected", ")"...
Assert the wire type match @param integer $wire @param integer $type
[ "Assert", "the", "wire", "type", "match" ]
c0da95f75ea418b39b02ff4528ca9926cc246a8c
https://github.com/protobuf-php/protobuf/blob/c0da95f75ea418b39b02ff4528ca9926cc246a8c/src/WireFormat.php#L72-L84
41,135
antonioribeiro/google2fa-qrcode
src/Google2FA.php
Google2FA.getQRCodeInline
public function getQRCodeInline($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { return $this->getBaconQRCodeVersion() === 1 ? $this->getQRCodeInlineV1($company, $holder, $secret, $size, $encoding) : $this->getQRCodeInlineV2($company, $holder, $secret, $size, $encoding); }
php
public function getQRCodeInline($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { return $this->getBaconQRCodeVersion() === 1 ? $this->getQRCodeInlineV1($company, $holder, $secret, $size, $encoding) : $this->getQRCodeInlineV2($company, $holder, $secret, $size, $encoding); }
[ "public", "function", "getQRCodeInline", "(", "$", "company", ",", "$", "holder", ",", "$", "secret", ",", "$", "size", "=", "200", ",", "$", "encoding", "=", "'utf-8'", ")", "{", "return", "$", "this", "->", "getBaconQRCodeVersion", "(", ")", "===", "...
Generates a QR code data url to display inline. @param string $company @param string $holder @param string $secret @param int $size @param string $encoding Default to UTF-8 @return string
[ "Generates", "a", "QR", "code", "data", "url", "to", "display", "inline", "." ]
0e60e5a70eb4d2e8a19afa5af813bdf1158e5094
https://github.com/antonioribeiro/google2fa-qrcode/blob/0e60e5a70eb4d2e8a19afa5af813bdf1158e5094/src/Google2FA.php#L56-L61
41,136
antonioribeiro/google2fa-qrcode
src/Google2FA.php
Google2FA.getQRCodeInlineV1
public function getQRCodeInlineV1($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { $url = $this->getQRCodeUrl($company, $holder, $secret); $renderer = $this->imageBackEnd; $renderer->setWidth($size); $renderer->setHeight($size); $bacon = new BaconQrCodeWriter($renderer); $data = $bacon->writeString($url, $encoding); if ($this->imageBackEnd instanceof Png) { return 'data:image/png;base64,'.base64_encode($data); } return $data; }
php
public function getQRCodeInlineV1($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { $url = $this->getQRCodeUrl($company, $holder, $secret); $renderer = $this->imageBackEnd; $renderer->setWidth($size); $renderer->setHeight($size); $bacon = new BaconQrCodeWriter($renderer); $data = $bacon->writeString($url, $encoding); if ($this->imageBackEnd instanceof Png) { return 'data:image/png;base64,'.base64_encode($data); } return $data; }
[ "public", "function", "getQRCodeInlineV1", "(", "$", "company", ",", "$", "holder", ",", "$", "secret", ",", "$", "size", "=", "200", ",", "$", "encoding", "=", "'utf-8'", ")", "{", "$", "url", "=", "$", "this", "->", "getQRCodeUrl", "(", "$", "compa...
Generates a QR code data url to display inline for Bacon QRCode v1 @param string $company @param string $holder @param string $secret @param int $size @param string $encoding Default to UTF-8 @return string
[ "Generates", "a", "QR", "code", "data", "url", "to", "display", "inline", "for", "Bacon", "QRCode", "v1" ]
0e60e5a70eb4d2e8a19afa5af813bdf1158e5094
https://github.com/antonioribeiro/google2fa-qrcode/blob/0e60e5a70eb4d2e8a19afa5af813bdf1158e5094/src/Google2FA.php#L74-L89
41,137
antonioribeiro/google2fa-qrcode
src/Google2FA.php
Google2FA.getQRCodeInlineV2
public function getQRCodeInlineV2($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { $renderer = new ImageRenderer( (new RendererStyle($size))->withSize($size), $this->imageBackEnd ); $bacon = new Writer($renderer); $data = $bacon->writeString( $this->getQRCodeUrl($company, $holder, $secret), $encoding ); if ($this->imageBackEnd instanceof ImagickImageBackEnd) { return 'data:image/png;base64,'.base64_encode($data); } return $data; }
php
public function getQRCodeInlineV2($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { $renderer = new ImageRenderer( (new RendererStyle($size))->withSize($size), $this->imageBackEnd ); $bacon = new Writer($renderer); $data = $bacon->writeString( $this->getQRCodeUrl($company, $holder, $secret), $encoding ); if ($this->imageBackEnd instanceof ImagickImageBackEnd) { return 'data:image/png;base64,'.base64_encode($data); } return $data; }
[ "public", "function", "getQRCodeInlineV2", "(", "$", "company", ",", "$", "holder", ",", "$", "secret", ",", "$", "size", "=", "200", ",", "$", "encoding", "=", "'utf-8'", ")", "{", "$", "renderer", "=", "new", "ImageRenderer", "(", "(", "new", "Render...
Generates a QR code data url to display inline for Bacon QRCode v2 @param string $company @param string $holder @param string $secret @param int $size @param string $encoding Default to UTF-8 @return string
[ "Generates", "a", "QR", "code", "data", "url", "to", "display", "inline", "for", "Bacon", "QRCode", "v2" ]
0e60e5a70eb4d2e8a19afa5af813bdf1158e5094
https://github.com/antonioribeiro/google2fa-qrcode/blob/0e60e5a70eb4d2e8a19afa5af813bdf1158e5094/src/Google2FA.php#L102-L121
41,138
RusticiSoftware/TinCanPHP
src/AsVersionTrait.php
AsVersionTrait.asVersion
public function asVersion($version) { $result = array(); foreach (get_object_vars($this) as $property => $value) { // // skip properties that start with an underscore to allow // storing information that isn't included in statement // structure etc. (see Attachment.content for example) // if (strpos($property, '_') === 0) { continue; } if ($value instanceof VersionableInterface) { $value = $value->asVersion($version); } elseif (is_array($value) && !empty($value)) { $tmp_value = array(); foreach ($value as $element) { if ($element instanceof VersionableInterface) { array_push($tmp_value, $element->asVersion($version)); } else { array_push($tmp_value, $element); } } $value = $tmp_value; } if (isset($value) && (!is_array($value) || !empty($value))) { $result[$property] = $value; } } if (method_exists($this, '_asVersion')) { $this->_asVersion($result, $version); } return $result; }
php
public function asVersion($version) { $result = array(); foreach (get_object_vars($this) as $property => $value) { // // skip properties that start with an underscore to allow // storing information that isn't included in statement // structure etc. (see Attachment.content for example) // if (strpos($property, '_') === 0) { continue; } if ($value instanceof VersionableInterface) { $value = $value->asVersion($version); } elseif (is_array($value) && !empty($value)) { $tmp_value = array(); foreach ($value as $element) { if ($element instanceof VersionableInterface) { array_push($tmp_value, $element->asVersion($version)); } else { array_push($tmp_value, $element); } } $value = $tmp_value; } if (isset($value) && (!is_array($value) || !empty($value))) { $result[$property] = $value; } } if (method_exists($this, '_asVersion')) { $this->_asVersion($result, $version); } return $result; }
[ "public", "function", "asVersion", "(", "$", "version", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "get_object_vars", "(", "$", "this", ")", "as", "$", "property", "=>", "$", "value", ")", "{", "//", "// skip properties that st...
Collects defined object properties for a given version into an array @param mixed $version @return array
[ "Collects", "defined", "object", "properties", "for", "a", "given", "version", "into", "an", "array" ]
9758b3ec08653f7a49c8ab14ebd1f01557d89b78
https://github.com/RusticiSoftware/TinCanPHP/blob/9758b3ec08653f7a49c8ab14ebd1f01557d89b78/src/AsVersionTrait.php#L33-L72
41,139
RusticiSoftware/TinCanPHP
src/SignatureComparisonTrait.php
SignatureComparisonTrait.compareWithSignature
public function compareWithSignature($fromSig) { $skip = property_exists($this, 'signatureSkipProperties') ? self::$signatureSkipProperties : array(); foreach (get_object_vars($this) as $property => $value) { // // skip properties that start with an underscore to allow // storing information that isn't included in statement // structure etc. (see Attachment.content for example) // // also allow a class to specify a list of additional // properties that should not be included in verification // if (strpos($property, '_') === 0 || $property === 'objectType' || in_array($property, $skip)) { continue; } $result = self::doMatch($value, $fromSig->$property, $property); if (! $result['success']) { return $result; } } return array( 'success' => true, 'reason' => null ); }
php
public function compareWithSignature($fromSig) { $skip = property_exists($this, 'signatureSkipProperties') ? self::$signatureSkipProperties : array(); foreach (get_object_vars($this) as $property => $value) { // // skip properties that start with an underscore to allow // storing information that isn't included in statement // structure etc. (see Attachment.content for example) // // also allow a class to specify a list of additional // properties that should not be included in verification // if (strpos($property, '_') === 0 || $property === 'objectType' || in_array($property, $skip)) { continue; } $result = self::doMatch($value, $fromSig->$property, $property); if (! $result['success']) { return $result; } } return array( 'success' => true, 'reason' => null ); }
[ "public", "function", "compareWithSignature", "(", "$", "fromSig", ")", "{", "$", "skip", "=", "property_exists", "(", "$", "this", ",", "'signatureSkipProperties'", ")", "?", "self", "::", "$", "signatureSkipProperties", ":", "array", "(", ")", ";", "foreach"...
Compares the instance with a provided instance for determining whether an object received in a signature is a meaningful match @param mixed $fromSig @return array
[ "Compares", "the", "instance", "with", "a", "provided", "instance", "for", "determining", "whether", "an", "object", "received", "in", "a", "signature", "is", "a", "meaningful", "match" ]
9758b3ec08653f7a49c8ab14ebd1f01557d89b78
https://github.com/RusticiSoftware/TinCanPHP/blob/9758b3ec08653f7a49c8ab14ebd1f01557d89b78/src/SignatureComparisonTrait.php#L32-L58
41,140
davidyell/CakePHP3-Proffer
src/Lib/ImageTransform.php
ImageTransform.processThumbnails
public function processThumbnails(array $config) { $thumbnailPaths = []; if (!isset($config['thumbnailSizes'])) { return $thumbnailPaths; } foreach ($config['thumbnailSizes'] as $prefix => $thumbnailConfig) { $method = 'gd'; if (!empty($config['thumbnailMethod'])) { $method = $config['thumbnailMethod']; } $this->ImageManager = new ImageManager(['driver' => $method]); $thumbnailPaths[] = $this->makeThumbnail($prefix, $thumbnailConfig); } return $thumbnailPaths; }
php
public function processThumbnails(array $config) { $thumbnailPaths = []; if (!isset($config['thumbnailSizes'])) { return $thumbnailPaths; } foreach ($config['thumbnailSizes'] as $prefix => $thumbnailConfig) { $method = 'gd'; if (!empty($config['thumbnailMethod'])) { $method = $config['thumbnailMethod']; } $this->ImageManager = new ImageManager(['driver' => $method]); $thumbnailPaths[] = $this->makeThumbnail($prefix, $thumbnailConfig); } return $thumbnailPaths; }
[ "public", "function", "processThumbnails", "(", "array", "$", "config", ")", "{", "$", "thumbnailPaths", "=", "[", "]", ";", "if", "(", "!", "isset", "(", "$", "config", "[", "'thumbnailSizes'", "]", ")", ")", "{", "return", "$", "thumbnailPaths", ";", ...
Take an upload fields configuration and create all the thumbnails @param array $config The upload fields configuration @return array
[ "Take", "an", "upload", "fields", "configuration", "and", "create", "all", "the", "thumbnails" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ImageTransform.php#L51-L70
41,141
davidyell/CakePHP3-Proffer
src/Lib/ImageTransform.php
ImageTransform.makeThumbnail
public function makeThumbnail($prefix, array $config) { $defaultConfig = [ 'jpeg_quality' => 100 ]; $config = array_merge($defaultConfig, $config); $width = !empty($config['w']) ? $config['w'] : null; $height = !empty($config['h']) ? $config['h'] : null; $image = $this->ImageManager->make($this->Path->fullPath()); if (!empty($config['orientate'])) { $image = $this->orientate($image); } if (!empty($config['crop'])) { $image = $this->thumbnailCrop($image, $width, $height); } elseif (!empty($config['fit'])) { $image = $this->thumbnailFit($image, $width, $height); } elseif (!empty($config['custom'])) { $image = $this->thumbnailCustom($image, $config['custom'], $config['params']); } else { $image = $this->thumbnailResize($image, $width, $height); } unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params'], $config['orientate']); $image->save($this->Path->fullPath($prefix), $config['jpeg_quality']); return $this->Path->fullPath($prefix); }
php
public function makeThumbnail($prefix, array $config) { $defaultConfig = [ 'jpeg_quality' => 100 ]; $config = array_merge($defaultConfig, $config); $width = !empty($config['w']) ? $config['w'] : null; $height = !empty($config['h']) ? $config['h'] : null; $image = $this->ImageManager->make($this->Path->fullPath()); if (!empty($config['orientate'])) { $image = $this->orientate($image); } if (!empty($config['crop'])) { $image = $this->thumbnailCrop($image, $width, $height); } elseif (!empty($config['fit'])) { $image = $this->thumbnailFit($image, $width, $height); } elseif (!empty($config['custom'])) { $image = $this->thumbnailCustom($image, $config['custom'], $config['params']); } else { $image = $this->thumbnailResize($image, $width, $height); } unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params'], $config['orientate']); $image->save($this->Path->fullPath($prefix), $config['jpeg_quality']); return $this->Path->fullPath($prefix); }
[ "public", "function", "makeThumbnail", "(", "$", "prefix", ",", "array", "$", "config", ")", "{", "$", "defaultConfig", "=", "[", "'jpeg_quality'", "=>", "100", "]", ";", "$", "config", "=", "array_merge", "(", "$", "defaultConfig", ",", "$", "config", "...
Generate and save the thumbnail @param string $prefix The thumbnail prefix @param array $config Array of thumbnail config @return string
[ "Generate", "and", "save", "the", "thumbnail" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ImageTransform.php#L79-L110
41,142
davidyell/CakePHP3-Proffer
src/Lib/ImageTransform.php
ImageTransform.thumbnailResize
protected function thumbnailResize(Image $image, $width, $height) { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); }
php
protected function thumbnailResize(Image $image, $width, $height) { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); }
[ "protected", "function", "thumbnailResize", "(", "Image", "$", "image", ",", "$", "width", ",", "$", "height", ")", "{", "return", "$", "image", "->", "resize", "(", "$", "width", ",", "$", "height", ",", "function", "(", "$", "constraint", ")", "{", ...
Resize current image @see http://image.intervention.io/api/resize @param \Intervention\Image\Image $image Image instance @param int $width Desired width in pixels @param int $height Desired height in pixels @return \Intervention\Image\Image
[ "Resize", "current", "image" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ImageTransform.php#L155-L160
41,143
davidyell/CakePHP3-Proffer
src/Model/Validation/ProfferRules.php
ProfferRules.dimensions
public static function dimensions($value, array $dimensions) { $fileDimensions = getimagesize($value['tmp_name']); if ($fileDimensions === false) { return false; } $sourceWidth = $fileDimensions[0]; $sourceHeight = $fileDimensions[1]; foreach ($dimensions as $rule => $sizes) { if ($rule === 'min') { if (isset($sizes['w']) && $sourceWidth < $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight < $sizes['h']) { return false; } } elseif ($rule === 'max') { if (isset($sizes['w']) && $sourceWidth > $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight > $sizes['h']) { return false; } } } return true; }
php
public static function dimensions($value, array $dimensions) { $fileDimensions = getimagesize($value['tmp_name']); if ($fileDimensions === false) { return false; } $sourceWidth = $fileDimensions[0]; $sourceHeight = $fileDimensions[1]; foreach ($dimensions as $rule => $sizes) { if ($rule === 'min') { if (isset($sizes['w']) && $sourceWidth < $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight < $sizes['h']) { return false; } } elseif ($rule === 'max') { if (isset($sizes['w']) && $sourceWidth > $sizes['w']) { return false; } if (isset($sizes['h']) && $sourceHeight > $sizes['h']) { return false; } } } return true; }
[ "public", "static", "function", "dimensions", "(", "$", "value", ",", "array", "$", "dimensions", ")", "{", "$", "fileDimensions", "=", "getimagesize", "(", "$", "value", "[", "'tmp_name'", "]", ")", ";", "if", "(", "$", "fileDimensions", "===", "false", ...
Validate the dimensions of an image. If the file isn't an image then validation will fail @param array $value An array of the name and value of the field @param array $dimensions Array of rule dimensions for example ['dimensions', [ 'min' => ['w' => 100, 'h' => 100], 'max' => ['w' => 500, 'h' => 500] ]] would validate a minimum size of 100x100 pixels and a maximum of 500x500 pixels @return bool
[ "Validate", "the", "dimensions", "of", "an", "image", ".", "If", "the", "file", "isn", "t", "an", "image", "then", "validation", "will", "fail" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Validation/ProfferRules.php#L27-L57
41,144
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.getOptionParser
public function getOptionParser() { $parser = parent::getOptionParser(); $parser->addSubcommand('generate', [ 'help' => __('Regenerate thumbnails for a specific table.'), 'parser' => [ 'description' => [__('Use this command to regenerate the thumbnails for a specific table.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'path-class' => [ 'short' => 'p', 'help' => __('Fully name spaced custom path class, you must use double backslash.') ], 'image-class' => [ 'short' => 'i', 'help' => __('Fully name spaced custom image transform class, you must use double backslash.') ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before generate.'), ], ] ] ]); $parser->addSubcommand('cleanup', [ 'help' => __('Clean up old images on the file system which are not linked in the database.'), 'parser' => [ 'description' => [__('This command will delete images which are not part of the model configuration.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'dry-run' => [ 'short' => 'd', 'help' => __('Do a dry run and don\'t delete any files.'), 'boolean' => true ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before cleanup.'), ], ] ], ]); return $parser; }
php
public function getOptionParser() { $parser = parent::getOptionParser(); $parser->addSubcommand('generate', [ 'help' => __('Regenerate thumbnails for a specific table.'), 'parser' => [ 'description' => [__('Use this command to regenerate the thumbnails for a specific table.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'path-class' => [ 'short' => 'p', 'help' => __('Fully name spaced custom path class, you must use double backslash.') ], 'image-class' => [ 'short' => 'i', 'help' => __('Fully name spaced custom image transform class, you must use double backslash.') ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before generate.'), ], ] ] ]); $parser->addSubcommand('cleanup', [ 'help' => __('Clean up old images on the file system which are not linked in the database.'), 'parser' => [ 'description' => [__('This command will delete images which are not part of the model configuration.')], 'arguments' => [ 'table' => ['help' => __('The table to regenerate thumbs for'), 'required' => true] ], 'options' => [ 'dry-run' => [ 'short' => 'd', 'help' => __('Do a dry run and don\'t delete any files.'), 'boolean' => true ], 'remove-behaviors' => [ 'help' => __('The behaviors to remove before cleanup.'), ], ] ], ]); return $parser; }
[ "public", "function", "getOptionParser", "(", ")", "{", "$", "parser", "=", "parent", "::", "getOptionParser", "(", ")", ";", "$", "parser", "->", "addSubcommand", "(", "'generate'", ",", "[", "'help'", "=>", "__", "(", "'Regenerate thumbnails for a specific tab...
Return the help options and validate arguments @return \Cake\Console\ConsoleOptionParser
[ "Return", "the", "help", "options", "and", "validate", "arguments" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L27-L73
41,145
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.main
public function main() { $this->out('Welcome to the Proffer shell.'); $this->out('This shell can be used to regenerate thumbnails and cleanup unlinked images.'); $this->hr(); $this->out($this->OptionParser->help()); }
php
public function main() { $this->out('Welcome to the Proffer shell.'); $this->out('This shell can be used to regenerate thumbnails and cleanup unlinked images.'); $this->hr(); $this->out($this->OptionParser->help()); }
[ "public", "function", "main", "(", ")", "{", "$", "this", "->", "out", "(", "'Welcome to the Proffer shell.'", ")", ";", "$", "this", "->", "out", "(", "'This shell can be used to regenerate thumbnails and cleanup unlinked images.'", ")", ";", "$", "this", "->", "hr...
Introduction to the shell @return void
[ "Introduction", "to", "the", "shell" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L80-L86
41,146
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.generate
public function generate($table) { $this->checkTable($table); $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { $records = $this->{$this->Table->alias()}->find() ->select([$this->Table->primaryKey(), $field, $settings['dir']]) ->where([ "$field IS NOT NULL", "$field != ''" ]); foreach ($records as $item) { if ($this->param('verbose')) { $this->out( __('Processing ' . $this->Table->alias() . ' ' . $item->get($this->Table->primaryKey())) ); } if (!empty($this->param('path-class'))) { $class = (string)$this->param('path-class'); $path = new $class($this->Table, $item, $field, $settings); } else { $path = new ProfferPath($this->Table, $item, $field, $settings); } if (!empty($this->param('image-class'))) { $class = (string)$this->param('image-class'); $transform = new $class($this->Table, $path); } else { $transform = new ImageTransform($this->Table, $path); } $transform->processThumbnails($settings); if ($this->param('verbose')) { $this->out(__('Thumbnails regenerated for ' . $path->fullPath())); } else { $this->out(__('Thumbnails regenerated for ' . $this->Table->alias() . ' ' . $item->get($field))); } } } $this->out($this->nl(0)); $this->out(__('<info>Completed</info>')); }
php
public function generate($table) { $this->checkTable($table); $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { $records = $this->{$this->Table->alias()}->find() ->select([$this->Table->primaryKey(), $field, $settings['dir']]) ->where([ "$field IS NOT NULL", "$field != ''" ]); foreach ($records as $item) { if ($this->param('verbose')) { $this->out( __('Processing ' . $this->Table->alias() . ' ' . $item->get($this->Table->primaryKey())) ); } if (!empty($this->param('path-class'))) { $class = (string)$this->param('path-class'); $path = new $class($this->Table, $item, $field, $settings); } else { $path = new ProfferPath($this->Table, $item, $field, $settings); } if (!empty($this->param('image-class'))) { $class = (string)$this->param('image-class'); $transform = new $class($this->Table, $path); } else { $transform = new ImageTransform($this->Table, $path); } $transform->processThumbnails($settings); if ($this->param('verbose')) { $this->out(__('Thumbnails regenerated for ' . $path->fullPath())); } else { $this->out(__('Thumbnails regenerated for ' . $this->Table->alias() . ' ' . $item->get($field))); } } } $this->out($this->nl(0)); $this->out(__('<info>Completed</info>')); }
[ "public", "function", "generate", "(", "$", "table", ")", "{", "$", "this", "->", "checkTable", "(", "$", "table", ")", ";", "$", "config", "=", "$", "this", "->", "Table", "->", "behaviors", "(", ")", "->", "Proffer", "->", "config", "(", ")", ";"...
Load a table, get it's config and then regenerate the thumbnails for that tables upload fields. @param string $table The name of the table @return void
[ "Load", "a", "table", "get", "it", "s", "config", "and", "then", "regenerate", "the", "thumbnails", "for", "that", "tables", "upload", "fields", "." ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L94-L141
41,147
davidyell/CakePHP3-Proffer
src/Shell/ProfferShell.php
ProfferShell.checkTable
protected function checkTable($table) { try { $this->Table = $this->loadModel($table); } catch (Exception $e) { $this->out(__('<error>' . $e->getMessage() . '</error>')); $this->_stop(); } if (get_class($this->Table) === 'AppModel') { $this->out(__('<error>The table could not be found, instance of AppModel loaded.</error>')); $this->_stop(); } if (!$this->Table->hasBehavior('Proffer')) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the Proffer behavior attached.</error>" ); $this->out($out); $this->_stop(); } $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { if (!$this->Table->hasField($field)) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured upload field in it's schema.</error>" ); $this->out($out); $this->_stop(); } if (!$this->Table->hasField($settings['dir'])) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured dir field in it's schema.</error>" ); $this->out($out); $this->_stop(); } } if ($this->param('remove-behaviors')) { $removeBehaviors = explode(',', (string)$this->param('remove-behaviors')); foreach ($removeBehaviors as $removeBehavior) { $this->Table->removeBehavior($removeBehavior); } } }
php
protected function checkTable($table) { try { $this->Table = $this->loadModel($table); } catch (Exception $e) { $this->out(__('<error>' . $e->getMessage() . '</error>')); $this->_stop(); } if (get_class($this->Table) === 'AppModel') { $this->out(__('<error>The table could not be found, instance of AppModel loaded.</error>')); $this->_stop(); } if (!$this->Table->hasBehavior('Proffer')) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the Proffer behavior attached.</error>" ); $this->out($out); $this->_stop(); } $config = $this->Table->behaviors()->Proffer->config(); foreach ($config as $field => $settings) { if (!$this->Table->hasField($field)) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured upload field in it's schema.</error>" ); $this->out($out); $this->_stop(); } if (!$this->Table->hasField($settings['dir'])) { $out = __( "<error>The table '" . $this->Table->alias() . "' does not have the configured dir field in it's schema.</error>" ); $this->out($out); $this->_stop(); } } if ($this->param('remove-behaviors')) { $removeBehaviors = explode(',', (string)$this->param('remove-behaviors')); foreach ($removeBehaviors as $removeBehavior) { $this->Table->removeBehavior($removeBehavior); } } }
[ "protected", "function", "checkTable", "(", "$", "table", ")", "{", "try", "{", "$", "this", "->", "Table", "=", "$", "this", "->", "loadModel", "(", "$", "table", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "...
Do some checks on the table which has been passed to make sure that it has what we need @param string $table The table @return void
[ "Do", "some", "checks", "on", "the", "table", "which", "has", "been", "passed", "to", "make", "sure", "that", "it", "has", "what", "we", "need" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Shell/ProfferShell.php#L264-L313
41,148
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.setFilename
public function setFilename($filename) { if (is_array($filename) && isset($filename['name'])) { $this->filename = $filename['name']; } else { $this->filename = $filename; } }
php
public function setFilename($filename) { if (is_array($filename) && isset($filename['name'])) { $this->filename = $filename['name']; } else { $this->filename = $filename; } }
[ "public", "function", "setFilename", "(", "$", "filename", ")", "{", "if", "(", "is_array", "(", "$", "filename", ")", "&&", "isset", "(", "$", "filename", "[", "'name'", "]", ")", ")", "{", "$", "this", "->", "filename", "=", "$", "filename", "[", ...
Set the filename or pull it from the upload array @param string|array $filename The name of the actual file including it's extension @return void
[ "Set", "the", "filename", "or", "pull", "it", "from", "the", "upload", "array" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L158-L165
41,149
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.setPrefixes
public function setPrefixes(array $thumbnailSizes) { foreach ($thumbnailSizes as $prefix => $dimensions) { array_push($this->prefixes, $prefix); } }
php
public function setPrefixes(array $thumbnailSizes) { foreach ($thumbnailSizes as $prefix => $dimensions) { array_push($this->prefixes, $prefix); } }
[ "public", "function", "setPrefixes", "(", "array", "$", "thumbnailSizes", ")", "{", "foreach", "(", "$", "thumbnailSizes", "as", "$", "prefix", "=>", "$", "dimensions", ")", "{", "array_push", "(", "$", "this", "->", "prefixes", ",", "$", "prefix", ")", ...
Take the configured thumbnail sizes and store the prefixes @param array $thumbnailSizes The 'thumbnailSizes' dimension of the behaviour configuration array @return void
[ "Take", "the", "configured", "thumbnail", "sizes", "and", "store", "the", "prefixes" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L183-L188
41,150
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.fullPath
public function fullPath($prefix = null) { if ($prefix) { return $this->getFolder() . $prefix . '_' . $this->getFilename(); } return $this->getFolder() . $this->getFilename(); }
php
public function fullPath($prefix = null) { if ($prefix) { return $this->getFolder() . $prefix . '_' . $this->getFilename(); } return $this->getFolder() . $this->getFilename(); }
[ "public", "function", "fullPath", "(", "$", "prefix", "=", "null", ")", "{", "if", "(", "$", "prefix", ")", "{", "return", "$", "this", "->", "getFolder", "(", ")", ".", "$", "prefix", ".", "'_'", ".", "$", "this", "->", "getFilename", "(", ")", ...
Return the complete absolute path to an upload. If it's an image with thumbnails you can pass the prefix to get the path to the prefixed thumbnail file. @param string $prefix Thumbnail prefix @return string
[ "Return", "the", "complete", "absolute", "path", "to", "an", "upload", ".", "If", "it", "s", "an", "image", "with", "thumbnails", "you", "can", "pass", "the", "prefix", "to", "get", "the", "path", "to", "the", "prefixed", "thumbnail", "file", "." ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L212-L219
41,151
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.getFolder
public function getFolder() { $table = $this->getTable(); $table = (!empty($table)) ? $table . DS : null; $seed = $this->getSeed(); $seed = (!empty($seed)) ? $seed . DS : null; return $this->getRoot() . DS . $table . $this->getField() . DS . $seed; }
php
public function getFolder() { $table = $this->getTable(); $table = (!empty($table)) ? $table . DS : null; $seed = $this->getSeed(); $seed = (!empty($seed)) ? $seed . DS : null; return $this->getRoot() . DS . $table . $this->getField() . DS . $seed; }
[ "public", "function", "getFolder", "(", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "table", "=", "(", "!", "empty", "(", "$", "table", ")", ")", "?", "$", "table", ".", "DS", ":", "null", ";", "$", "seed", ...
Return the absolute path to the containing parent folder where all the files will be uploaded @return string
[ "Return", "the", "absolute", "path", "to", "the", "containing", "parent", "folder", "where", "all", "the", "files", "will", "be", "uploaded" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L226-L235
41,152
davidyell/CakePHP3-Proffer
src/Lib/ProfferPath.php
ProfferPath.deleteFiles
public function deleteFiles($folder, $rmdir = false) { array_map('unlink', glob($folder . DS . '*')); if ($rmdir) { rmdir($folder); } }
php
public function deleteFiles($folder, $rmdir = false) { array_map('unlink', glob($folder . DS . '*')); if ($rmdir) { rmdir($folder); } }
[ "public", "function", "deleteFiles", "(", "$", "folder", ",", "$", "rmdir", "=", "false", ")", "{", "array_map", "(", "'unlink'", ",", "glob", "(", "$", "folder", ".", "DS", ".", "'*'", ")", ")", ";", "if", "(", "$", "rmdir", ")", "{", "rmdir", "...
Clear out a folder and optionally delete it @param string $folder Absolute path to the folder @param bool $rmdir If you want to remove the folder as well @return void
[ "Clear", "out", "a", "folder", "and", "optionally", "delete", "it" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Lib/ProfferPath.php#L258-L264
41,153
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.process
protected function process($field, array $settings, EntityInterface $entity, ProfferPathInterface $path = null) { $path = $this->createPath($entity, $field, $settings, $path); if (is_array($entity->get($field)) && count(array_filter(array_keys($entity->get($field)), 'is_string')) > 0) { $uploadList = [$entity->get($field)]; } else { $uploadList = [ [ 'name' => $entity->get('name'), 'type' => $entity->get('type'), 'tmp_name' => $entity->get('tmp_name'), 'error' => $entity->get('error'), 'size' => $entity->get('size'), ] ]; } foreach ($uploadList as $upload) { if ($this->moveUploadedFile($upload['tmp_name'], $path->fullPath())) { $entity->set($field, $path->getFilename()); $entity->set($settings['dir'], $path->getSeed()); $this->createThumbnails($entity, $settings, $path); } else { throw new CannotUploadFileException("File `{$upload['name']}` could not be copied."); } } unset($path); }
php
protected function process($field, array $settings, EntityInterface $entity, ProfferPathInterface $path = null) { $path = $this->createPath($entity, $field, $settings, $path); if (is_array($entity->get($field)) && count(array_filter(array_keys($entity->get($field)), 'is_string')) > 0) { $uploadList = [$entity->get($field)]; } else { $uploadList = [ [ 'name' => $entity->get('name'), 'type' => $entity->get('type'), 'tmp_name' => $entity->get('tmp_name'), 'error' => $entity->get('error'), 'size' => $entity->get('size'), ] ]; } foreach ($uploadList as $upload) { if ($this->moveUploadedFile($upload['tmp_name'], $path->fullPath())) { $entity->set($field, $path->getFilename()); $entity->set($settings['dir'], $path->getSeed()); $this->createThumbnails($entity, $settings, $path); } else { throw new CannotUploadFileException("File `{$upload['name']}` could not be copied."); } } unset($path); }
[ "protected", "function", "process", "(", "$", "field", ",", "array", "$", "settings", ",", "EntityInterface", "$", "entity", ",", "ProfferPathInterface", "$", "path", "=", "null", ")", "{", "$", "path", "=", "$", "this", "->", "createPath", "(", "$", "en...
Process any uploaded files, generate paths, move the files and kick off thumbnail generation if it's an image @param string $field The upload field name @param array $settings Array of upload settings for the field @param \Cake\Datasource\EntityInterface $entity The current entity to process @param \Proffer\Lib\ProfferPathInterface|null $path Inject an instance of ProfferPath @throws \Exception If the file cannot be renamed / moved to the correct path @return void
[ "Process", "any", "uploaded", "files", "generate", "paths", "move", "the", "files", "and", "kick", "off", "thumbnail", "generation", "if", "it", "s", "an", "image" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L116-L146
41,154
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.createPath
protected function createPath(EntityInterface $entity, $field, array $settings, ProfferPathInterface $path = null) { if (!empty($settings['pathClass'])) { $path = new $settings['pathClass']($this->_table, $entity, $field, $settings); if (!$path instanceof ProfferPathInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ProfferPathInterface."); } } elseif (!isset($path)) { $path = new ProfferPath($this->_table, $entity, $field, $settings); } $event = new Event('Proffer.afterPath', $entity, ['path' => $path]); $this->_table->getEventManager()->dispatch($event); if (!empty($event->result)) { $path = $event->result; } $path->createPathFolder(); return $path; }
php
protected function createPath(EntityInterface $entity, $field, array $settings, ProfferPathInterface $path = null) { if (!empty($settings['pathClass'])) { $path = new $settings['pathClass']($this->_table, $entity, $field, $settings); if (!$path instanceof ProfferPathInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ProfferPathInterface."); } } elseif (!isset($path)) { $path = new ProfferPath($this->_table, $entity, $field, $settings); } $event = new Event('Proffer.afterPath', $entity, ['path' => $path]); $this->_table->getEventManager()->dispatch($event); if (!empty($event->result)) { $path = $event->result; } $path->createPathFolder(); return $path; }
[ "protected", "function", "createPath", "(", "EntityInterface", "$", "entity", ",", "$", "field", ",", "array", "$", "settings", ",", "ProfferPathInterface", "$", "path", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "settings", "[", "'pathClass...
Load a path class instance and create the path for the uploads to be moved into @param \Cake\Datasource\EntityInterface $entity Instance of the entity @param string $field The upload field name @param array $settings Array of upload settings for the field @param \Proffer\Lib\ProfferPathInterface|null $path Inject an instance of ProfferPath @throws \App\Exception\InvalidClassException If the custom class doesn't implement the interface @return \Proffer\Lib\ProfferPathInterface
[ "Load", "a", "path", "class", "instance", "and", "create", "the", "path", "for", "the", "uploads", "to", "be", "moved", "into" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L160-L180
41,155
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.createThumbnails
protected function createThumbnails(EntityInterface $entity, array $settings, ProfferPathInterface $path) { if (getimagesize($path->fullPath()) !== false && isset($settings['thumbnailSizes'])) { $imagePaths = [$path->fullPath()]; if (!empty($settings['transformClass'])) { $imageTransform = new $settings['transformClass']($this->_table, $path); if (!$imageTransform instanceof ImageTransformInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ImageTransformInterface."); } } else { $imageTransform = new ImageTransform($this->_table, $path); } $thumbnailPaths = $imageTransform->processThumbnails($settings); $imagePaths = array_merge($imagePaths, $thumbnailPaths); $eventData = ['path' => $path, 'images' => $imagePaths]; $event = new Event('Proffer.afterCreateImage', $entity, $eventData); $this->_table->getEventManager()->dispatch($event); } }
php
protected function createThumbnails(EntityInterface $entity, array $settings, ProfferPathInterface $path) { if (getimagesize($path->fullPath()) !== false && isset($settings['thumbnailSizes'])) { $imagePaths = [$path->fullPath()]; if (!empty($settings['transformClass'])) { $imageTransform = new $settings['transformClass']($this->_table, $path); if (!$imageTransform instanceof ImageTransformInterface) { throw new InvalidClassException("Class {$settings['pathClass']} does not implement the ImageTransformInterface."); } } else { $imageTransform = new ImageTransform($this->_table, $path); } $thumbnailPaths = $imageTransform->processThumbnails($settings); $imagePaths = array_merge($imagePaths, $thumbnailPaths); $eventData = ['path' => $path, 'images' => $imagePaths]; $event = new Event('Proffer.afterCreateImage', $entity, $eventData); $this->_table->getEventManager()->dispatch($event); } }
[ "protected", "function", "createThumbnails", "(", "EntityInterface", "$", "entity", ",", "array", "$", "settings", ",", "ProfferPathInterface", "$", "path", ")", "{", "if", "(", "getimagesize", "(", "$", "path", "->", "fullPath", "(", ")", ")", "!==", "false...
Create a new image transform instance, and create any configured thumbnails; if the upload is an image and there are thumbnails configured. @param \Cake\Datasource\EntityInterface $entity Instance of the entity @param array $settings Array of upload field settings @param \Proffer\Lib\ProfferPathInterface $path Instance of the path class @throws \App\Exception\InvalidClassException If the transform class doesn't implement the interface @return void
[ "Create", "a", "new", "image", "transform", "instance", "and", "create", "any", "configured", "thumbnails", ";", "if", "the", "upload", "is", "an", "image", "and", "there", "are", "thumbnails", "configured", "." ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L194-L215
41,156
davidyell/CakePHP3-Proffer
src/Model/Behavior/ProfferBehavior.php
ProfferBehavior.moveUploadedFile
protected function moveUploadedFile($file, $destination) { if (is_uploaded_file($file)) { return move_uploaded_file($file, $destination); } return rename($file, $destination); }
php
protected function moveUploadedFile($file, $destination) { if (is_uploaded_file($file)) { return move_uploaded_file($file, $destination); } return rename($file, $destination); }
[ "protected", "function", "moveUploadedFile", "(", "$", "file", ",", "$", "destination", ")", "{", "if", "(", "is_uploaded_file", "(", "$", "file", ")", ")", "{", "return", "move_uploaded_file", "(", "$", "file", ",", "$", "destination", ")", ";", "}", "r...
Wrapper method for move_uploaded_file to facilitate testing and 'uploading' of local files This will check if the file has been uploaded or not before picking the correct method to move the file @param string $file Path to the uploaded file @param string $destination The destination file name @return bool
[ "Wrapper", "method", "for", "move_uploaded_file", "to", "facilitate", "testing", "and", "uploading", "of", "local", "files" ]
b4a841e0c2dcd99454989a77b4395e4029c04a03
https://github.com/davidyell/CakePHP3-Proffer/blob/b4a841e0c2dcd99454989a77b4395e4029c04a03/src/Model/Behavior/ProfferBehavior.php#L262-L269
41,157
imbo/behat-api-extension
src/Context/Initializer/ApiClientAwareInitializer.php
ApiClientAwareInitializer.initializeContext
public function initializeContext(Context $context) { if ($context instanceof ApiClientAwareContext) { // Fetch base URI from the Guzzle client configuration, if it exists $baseUri = !empty($this->guzzleConfig['base_uri']) ? $this->guzzleConfig['base_uri'] : null; if ($baseUri && !$this->validateConnection($baseUri)) { throw new RuntimeException(sprintf('Can\'t connect to base_uri: "%s".', $baseUri)); } $context->setClient(new Client($this->guzzleConfig)); } }
php
public function initializeContext(Context $context) { if ($context instanceof ApiClientAwareContext) { // Fetch base URI from the Guzzle client configuration, if it exists $baseUri = !empty($this->guzzleConfig['base_uri']) ? $this->guzzleConfig['base_uri'] : null; if ($baseUri && !$this->validateConnection($baseUri)) { throw new RuntimeException(sprintf('Can\'t connect to base_uri: "%s".', $baseUri)); } $context->setClient(new Client($this->guzzleConfig)); } }
[ "public", "function", "initializeContext", "(", "Context", "$", "context", ")", "{", "if", "(", "$", "context", "instanceof", "ApiClientAwareContext", ")", "{", "// Fetch base URI from the Guzzle client configuration, if it exists", "$", "baseUri", "=", "!", "empty", "(...
Initialize the context Inject the Guzzle client if the context implements the ApiClientAwareContext interface @param Context $context
[ "Initialize", "the", "context" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/Initializer/ApiClientAwareInitializer.php#L39-L50
41,158
imbo/behat-api-extension
src/Context/Initializer/ApiClientAwareInitializer.php
ApiClientAwareInitializer.validateConnection
private function validateConnection($baseUri) { $parts = parse_url($baseUri); $host = $parts['host']; $port = isset($parts['port']) ? $parts['port'] : ($parts['scheme'] === 'https' ? 443 : 80); set_error_handler(function () { return true; }); $resource = fsockopen($host, $port); restore_error_handler(); if ($resource === false) { // Can't connect return false; } // Connection successful, close connection fclose($resource); return true; }
php
private function validateConnection($baseUri) { $parts = parse_url($baseUri); $host = $parts['host']; $port = isset($parts['port']) ? $parts['port'] : ($parts['scheme'] === 'https' ? 443 : 80); set_error_handler(function () { return true; }); $resource = fsockopen($host, $port); restore_error_handler(); if ($resource === false) { // Can't connect return false; } // Connection successful, close connection fclose($resource); return true; }
[ "private", "function", "validateConnection", "(", "$", "baseUri", ")", "{", "$", "parts", "=", "parse_url", "(", "$", "baseUri", ")", ";", "$", "host", "=", "$", "parts", "[", "'host'", "]", ";", "$", "port", "=", "isset", "(", "$", "parts", "[", "...
Validate a connection to the base URI @param string $baseUri @return boolean
[ "Validate", "a", "connection", "to", "the", "base", "URI" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/Initializer/ApiClientAwareInitializer.php#L58-L79
41,159
imbo/behat-api-extension
src/ArrayContainsComparator.php
ArrayContainsComparator.addFunction
public function addFunction($name, $callback) { if (!is_callable($callback)) { throw new InvalidArgumentException(sprintf( 'Callback provided for function "%s" is not callable.', $name )); } $this->functions[$name] = $callback; return $this; }
php
public function addFunction($name, $callback) { if (!is_callable($callback)) { throw new InvalidArgumentException(sprintf( 'Callback provided for function "%s" is not callable.', $name )); } $this->functions[$name] = $callback; return $this; }
[ "public", "function", "addFunction", "(", "$", "name", ",", "$", "callback", ")", "{", "if", "(", "!", "is_callable", "(", "$", "callback", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Callback provided for function \"%s\" is...
Add a custom matcher function If an existing function exists with the same name it will be replaced @param string $name The name of the function, for instance "length" @param callable $callback The piece of callback code @throws InvalidArgumentException Throws an exception if the callback is not callable @return self
[ "Add", "a", "custom", "matcher", "function" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/ArrayContainsComparator.php#L34-L45
41,160
imbo/behat-api-extension
src/ArrayContainsComparator.php
ArrayContainsComparator.getMatcherFunction
public function getMatcherFunction($name) { if (!isset($this->functions[$name])) { throw new InvalidArgumentException(sprintf( 'No matcher function registered for "%s".', $name )); } return $this->functions[$name]; }
php
public function getMatcherFunction($name) { if (!isset($this->functions[$name])) { throw new InvalidArgumentException(sprintf( 'No matcher function registered for "%s".', $name )); } return $this->functions[$name]; }
[ "public", "function", "getMatcherFunction", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "functions", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'No matcher functi...
Get a matcher function by name @param string $name The name of the matcher function @return mixed
[ "Get", "a", "matcher", "function", "by", "name" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/ArrayContainsComparator.php#L53-L62
41,161
imbo/behat-api-extension
src/ArrayContainsComparator.php
ArrayContainsComparator.compareValues
protected function compareValues($needleValue, $haystackValue) { $match = []; // List of available function names $functions = array_map(function($value) { return preg_quote($value, '/'); }, array_keys($this->functions)); // Dynamic pattern, based on the keys in the functions list $pattern = sprintf( '/^@(?<function>%s)\((?<params>.*?)\)$/', implode('|', $functions) ); if (is_string($needleValue) && $functions && preg_match($pattern, $needleValue, $match)) { // Custom function matching $function = $match['function']; $params = $match['params']; try { $this->functions[$function]($haystackValue, $params); return true; } catch (Exception $e) { throw new ArrayContainsComparatorException( sprintf( 'Function "%s" failed with error message: "%s".', $function, $e->getMessage() ), 0, $e, $needleValue, $haystackValue ); } } // Regular value matching return $needleValue === $haystackValue; }
php
protected function compareValues($needleValue, $haystackValue) { $match = []; // List of available function names $functions = array_map(function($value) { return preg_quote($value, '/'); }, array_keys($this->functions)); // Dynamic pattern, based on the keys in the functions list $pattern = sprintf( '/^@(?<function>%s)\((?<params>.*?)\)$/', implode('|', $functions) ); if (is_string($needleValue) && $functions && preg_match($pattern, $needleValue, $match)) { // Custom function matching $function = $match['function']; $params = $match['params']; try { $this->functions[$function]($haystackValue, $params); return true; } catch (Exception $e) { throw new ArrayContainsComparatorException( sprintf( 'Function "%s" failed with error message: "%s".', $function, $e->getMessage() ), 0, $e, $needleValue, $haystackValue ); } } // Regular value matching return $needleValue === $haystackValue; }
[ "protected", "function", "compareValues", "(", "$", "needleValue", ",", "$", "haystackValue", ")", "{", "$", "match", "=", "[", "]", ";", "// List of available function names", "$", "functions", "=", "array_map", "(", "function", "(", "$", "value", ")", "{", ...
Compare a value from a needle with a value from the haystack Based on the value of the needle, this method will perform a regular value comparison, or a custom function match. @param mixed $needleValue @param mixed $haystackValue @throws ArrayContainsComparatorException @return boolean
[ "Compare", "a", "value", "from", "a", "needle", "with", "a", "value", "from", "the", "haystack" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/ArrayContainsComparator.php#L174-L210
41,162
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.addMultipartFileToRequest
public function addMultipartFileToRequest($path, $partName) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } // Create the multipart entry in the request options if it does not already exist if (!isset($this->requestOptions['multipart'])) { $this->requestOptions['multipart'] = []; } // Add an entry to the multipart array $this->requestOptions['multipart'][] = [ 'name' => $partName, 'contents' => fopen($path, 'r'), 'filename' => basename($path), ]; return $this; }
php
public function addMultipartFileToRequest($path, $partName) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } // Create the multipart entry in the request options if it does not already exist if (!isset($this->requestOptions['multipart'])) { $this->requestOptions['multipart'] = []; } // Add an entry to the multipart array $this->requestOptions['multipart'][] = [ 'name' => $partName, 'contents' => fopen($path, 'r'), 'filename' => basename($path), ]; return $this; }
[ "public", "function", "addMultipartFileToRequest", "(", "$", "path", ",", "$", "partName", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'File does not exist: \"%s\"'",...
Attach a file to the request @param string $path Path to the image to add to the request @param string $partName Multipart entry name @throws InvalidArgumentException If the $path does not point to a file, an exception is thrown @return self @Given I attach :path to the request as :partName
[ "Attach", "a", "file", "to", "the", "request" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L107-L125
41,163
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestHeader
public function setRequestHeader($header, $value) { $this->request = $this->request->withHeader($header, $value); return $this; }
php
public function setRequestHeader($header, $value) { $this->request = $this->request->withHeader($header, $value); return $this; }
[ "public", "function", "setRequestHeader", "(", "$", "header", ",", "$", "value", ")", "{", "$", "this", "->", "request", "=", "$", "this", "->", "request", "->", "withHeader", "(", "$", "header", ",", "$", "value", ")", ";", "return", "$", "this", ";...
Set a HTTP request header If the header already exists it will be overwritten @param string $header The header name @param string $value The header value @return self @Given the :header request header is :value
[ "Set", "a", "HTTP", "request", "header" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L153-L157
41,164
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestFormParams
public function setRequestFormParams(TableNode $table) { if (!isset($this->requestOptions['form_params'])) { $this->requestOptions['form_params'] = []; } foreach ($table as $row) { $name = $row['name']; $value = $row['value']; if (isset($this->requestOptions['form_params'][$name]) && !is_array($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name] = [$this->requestOptions['form_params'][$name]]; } if (isset($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name][] = $value; } else { $this->requestOptions['form_params'][$name] = $value; } } return $this; }
php
public function setRequestFormParams(TableNode $table) { if (!isset($this->requestOptions['form_params'])) { $this->requestOptions['form_params'] = []; } foreach ($table as $row) { $name = $row['name']; $value = $row['value']; if (isset($this->requestOptions['form_params'][$name]) && !is_array($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name] = [$this->requestOptions['form_params'][$name]]; } if (isset($this->requestOptions['form_params'][$name])) { $this->requestOptions['form_params'][$name][] = $value; } else { $this->requestOptions['form_params'][$name] = $value; } } return $this; }
[ "public", "function", "setRequestFormParams", "(", "TableNode", "$", "table", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "requestOptions", "[", "'form_params'", "]", ")", ")", "{", "$", "this", "->", "requestOptions", "[", "'form_params'", ...
Set form parameters @param TableNode $table Table with name / value pairs @return self @Given the following form parameters are set:
[ "Set", "form", "parameters" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L184-L205
41,165
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestBody
public function setRequestBody($string) { if (!empty($this->requestOptions['multipart']) || !empty($this->requestOptions['form_params'])) { throw new InvalidArgumentException( 'It\'s not allowed to set a request body when using multipart/form-data or form parameters.' ); } $this->request = $this->request->withBody(Psr7\stream_for($string)); return $this; }
php
public function setRequestBody($string) { if (!empty($this->requestOptions['multipart']) || !empty($this->requestOptions['form_params'])) { throw new InvalidArgumentException( 'It\'s not allowed to set a request body when using multipart/form-data or form parameters.' ); } $this->request = $this->request->withBody(Psr7\stream_for($string)); return $this; }
[ "public", "function", "setRequestBody", "(", "$", "string", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "requestOptions", "[", "'multipart'", "]", ")", "||", "!", "empty", "(", "$", "this", "->", "requestOptions", "[", "'form_params'", "]"...
Set the request body to a string @param resource|string|PyStringNode $string The content to set as the request body @throws InvalidArgumentException If form_params or multipart is used in the request options an exception will be thrown as these can't be combined. @return self @Given the request body is:
[ "Set", "the", "request", "body", "to", "a", "string" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L217-L227
41,166
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestBodyToFileResource
public function setRequestBodyToFileResource($path) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } if (!is_readable($path)) { throw new InvalidArgumentException(sprintf('File is not readable: "%s"', $path)); } // Set the Content-Type request header and the request body return $this ->setRequestHeader('Content-Type', mime_content_type($path)) ->setRequestBody(fopen($path, 'r')); }
php
public function setRequestBodyToFileResource($path) { if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('File does not exist: "%s"', $path)); } if (!is_readable($path)) { throw new InvalidArgumentException(sprintf('File is not readable: "%s"', $path)); } // Set the Content-Type request header and the request body return $this ->setRequestHeader('Content-Type', mime_content_type($path)) ->setRequestBody(fopen($path, 'r')); }
[ "public", "function", "setRequestBodyToFileResource", "(", "$", "path", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'File does not exist: \"%s\"'", ",", "$", "path", ...
Set the request body to a read-only resource pointing to a file This step will open a read-only resource to $path and attach it to the request body. If the file does not exist or is not readable the method will end up throwing an exception. The method will also set the Content-Type request header. mime_content_type() is used to get the mime type of the file. @param string $path Path to a file @throws InvalidArgumentException @return self @Given the request body contains :path
[ "Set", "the", "request", "body", "to", "a", "read", "-", "only", "resource", "pointing", "to", "a", "file" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L243-L256
41,167
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.addJwtToken
public function addJwtToken($name, $secret, PyStringNode $payload) { $jwtMatcher = $this->arrayContainsComparator->getMatcherFunction('jwt'); if (!($jwtMatcher instanceof JwtMatcher)) { throw new RuntimeException(sprintf( 'Matcher registered for the @jwt() matcher function must be an instance of %s', JwtMatcher::class )); } $jwtMatcher->addToken($name, $this->jsonDecode((string) $payload), $secret); return $this; }
php
public function addJwtToken($name, $secret, PyStringNode $payload) { $jwtMatcher = $this->arrayContainsComparator->getMatcherFunction('jwt'); if (!($jwtMatcher instanceof JwtMatcher)) { throw new RuntimeException(sprintf( 'Matcher registered for the @jwt() matcher function must be an instance of %s', JwtMatcher::class )); } $jwtMatcher->addToken($name, $this->jsonDecode((string) $payload), $secret); return $this; }
[ "public", "function", "addJwtToken", "(", "$", "name", ",", "$", "secret", ",", "PyStringNode", "$", "payload", ")", "{", "$", "jwtMatcher", "=", "$", "this", "->", "arrayContainsComparator", "->", "getMatcherFunction", "(", "'jwt'", ")", ";", "if", "(", "...
Add a JWT token to the matcher @param string $name String identifying the token @param string $secret The secret used to sign the token @param PyStringNode $payload The payload for the JWT @throws RuntimeException @return self @Given the response body contains a JWT identified by :name, signed with :secret:
[ "Add", "a", "JWT", "token", "to", "the", "matcher" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L269-L282
41,168
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.requestPath
public function requestPath($path, $method = null) { $this->setRequestPath($path); if (null === $method) { $this->setRequestMethod('GET', false); } else { $this->setRequestMethod($method); } return $this->sendRequest(); }
php
public function requestPath($path, $method = null) { $this->setRequestPath($path); if (null === $method) { $this->setRequestMethod('GET', false); } else { $this->setRequestMethod($method); } return $this->sendRequest(); }
[ "public", "function", "requestPath", "(", "$", "path", ",", "$", "method", "=", "null", ")", "{", "$", "this", "->", "setRequestPath", "(", "$", "path", ")", ";", "if", "(", "null", "===", "$", "method", ")", "{", "$", "this", "->", "setRequestMethod...
Request a path @param string $path The path to request @param string $method The HTTP method to use @return self @When I request :path @When I request :path using HTTP :method
[ "Request", "a", "path" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L294-L304
41,169
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseCodeIs
public function assertResponseCodeIs($code) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getStatusCode(), $expected = $this->validateResponseCode($code), sprintf('Expected response code %d, got %d.', $expected, $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseCodeIs($code) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getStatusCode(), $expected = $this->validateResponseCode($code), sprintf('Expected response code %d, got %d.', $expected, $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseCodeIs", "(", "$", "code", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "getStatusCode", "(", ")",...
Assert the HTTP response code @param int $code The HTTP response code @throws AssertionFailedException @return void @Then the response code is :code
[ "Assert", "the", "HTTP", "response", "code" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L315-L327
41,170
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseCodeIsNot
public function assertResponseCodeIsNot($code) { $this->requireResponse(); try { Assertion::notSame( $actual = $this->response->getStatusCode(), $this->validateResponseCode($code), sprintf('Did not expect response code %d.', $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseCodeIsNot($code) { $this->requireResponse(); try { Assertion::notSame( $actual = $this->response->getStatusCode(), $this->validateResponseCode($code), sprintf('Did not expect response code %d.', $actual) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseCodeIsNot", "(", "$", "code", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "notSame", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "getStatusCode", "(", ...
Assert the HTTP response code is not a specific code @param int $code The HTTP response code @throws AssertionFailedException @return void @Then the response code is not :code
[ "Assert", "the", "HTTP", "response", "code", "is", "not", "a", "specific", "code" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L338-L350
41,171
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseReasonPhraseIs
public function assertResponseReasonPhraseIs($phrase) { $this->requireResponse(); try { Assertion::same($phrase, $actual = $this->response->getReasonPhrase(), sprintf( 'Expected response reason phrase "%s", got "%s".', $phrase, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseReasonPhraseIs($phrase) { $this->requireResponse(); try { Assertion::same($phrase, $actual = $this->response->getReasonPhrase(), sprintf( 'Expected response reason phrase "%s", got "%s".', $phrase, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseReasonPhraseIs", "(", "$", "phrase", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "$", "phrase", ",", "$", "actual", "=", "$", "this", "->", "response", "-...
Assert that the HTTP response reason phrase equals a given value @param string $phrase Expected HTTP response reason phrase @throws AssertionFailedException @return void @Then the response reason phrase is :phrase
[ "Assert", "that", "the", "HTTP", "response", "reason", "phrase", "equals", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L361-L373
41,172
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseReasonPhraseIsNot
public function assertResponseReasonPhraseIsNot($phrase) { $this->requireResponse(); try { Assertion::notSame($phrase, $this->response->getReasonPhrase(), sprintf( 'Did not expect response reason phrase "%s".', $phrase )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseReasonPhraseIsNot($phrase) { $this->requireResponse(); try { Assertion::notSame($phrase, $this->response->getReasonPhrase(), sprintf( 'Did not expect response reason phrase "%s".', $phrase )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseReasonPhraseIsNot", "(", "$", "phrase", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "notSame", "(", "$", "phrase", ",", "$", "this", "->", "response", "->", "getReasonPhra...
Assert that the HTTP response reason phrase does not equal a given value @param string $phrase Reason phrase that the HTTP response should not equal @throws AssertionFailedException @return void @Then the response reason phrase is not :phrase
[ "Assert", "that", "the", "HTTP", "response", "reason", "phrase", "does", "not", "equal", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L384-L395
41,173
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseReasonPhraseMatches
public function assertResponseReasonPhraseMatches($pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getReasonPhrase(), $pattern, sprintf( 'Expected the response reason phrase to match the regular expression "%s", got "%s".', $pattern, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseReasonPhraseMatches($pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getReasonPhrase(), $pattern, sprintf( 'Expected the response reason phrase to match the regular expression "%s", got "%s".', $pattern, $actual )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseReasonPhraseMatches", "(", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "regex", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "getReasonPhr...
Assert that the HTTP response reason phrase matches a regular expression @param string $pattern Regular expression pattern @throws AssertionFailedException @return void @Then the response reason phrase matches :expression
[ "Assert", "that", "the", "HTTP", "response", "reason", "phrase", "matches", "a", "regular", "expression" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L406-L421
41,174
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseStatusLineIs
public function assertResponseStatusLineIs($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::same($line, $actualStatusLine, sprintf( 'Expected response status line "%s", got "%s".', $line, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseStatusLineIs($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::same($line, $actualStatusLine, sprintf( 'Expected response status line "%s", got "%s".', $line, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseStatusLineIs", "(", "$", "line", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "$", "actualStatusLine", "=", "sprintf", "(", "'%d %s'", ",", "$", "this", "->", "response", "->", "getStatusCode...
Assert that the HTTP response status line equals a given value @param string $line Expected HTTP response status line @throws AssertionFailedException @return void @Then the response status line is :line
[ "Assert", "that", "the", "HTTP", "response", "status", "line", "equals", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L432-L450
41,175
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseStatusLineIsNot
public function assertResponseStatusLineIsNot($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::notSame($line, $actualStatusLine, sprintf( 'Did not expect response status line "%s".', $line )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseStatusLineIsNot($line) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::notSame($line, $actualStatusLine, sprintf( 'Did not expect response status line "%s".', $line )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseStatusLineIsNot", "(", "$", "line", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "$", "actualStatusLine", "=", "sprintf", "(", "'%d %s'", ",", "$", "this", "->", "response", "->", "getStatusC...
Assert that the HTTP response status line does not equal a given value @param string $line Value that the HTTP response status line must not equal @throws AssertionFailedException @return void @Then the response status line is not :line
[ "Assert", "that", "the", "HTTP", "response", "status", "line", "does", "not", "equal", "a", "given", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L461-L478
41,176
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseStatusLineMatches
public function assertResponseStatusLineMatches($pattern) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::regex( $actualStatusLine, $pattern, sprintf( 'Expected the response status line to match the regular expression "%s", got "%s".', $pattern, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseStatusLineMatches($pattern) { $this->requireResponse(); try { $actualStatusLine = sprintf( '%d %s', $this->response->getStatusCode(), $this->response->getReasonPhrase() ); Assertion::regex( $actualStatusLine, $pattern, sprintf( 'Expected the response status line to match the regular expression "%s", got "%s".', $pattern, $actualStatusLine )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseStatusLineMatches", "(", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "$", "actualStatusLine", "=", "sprintf", "(", "'%d %s'", ",", "$", "this", "->", "response", "->", "getSt...
Assert that the HTTP response status line matches a regular expression @param string $pattern Regular expression pattern @throws AssertionFailedException @return void @Then the response status line matches :expression
[ "Assert", "that", "the", "HTTP", "response", "status", "line", "matches", "a", "regular", "expression" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L489-L510
41,177
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseIs
public function assertResponseIs($group) { $this->requireResponse(); $range = $this->getResponseCodeGroupRange($group); try { Assertion::range($code = $this->response->getStatusCode(), $range['min'], $range['max']); } catch (AssertionFailure $e) { throw new AssertionFailedException(sprintf( 'Expected response group "%s", got "%s" (response code: %d).', $group, $this->getResponseGroup($code), $code )); } }
php
public function assertResponseIs($group) { $this->requireResponse(); $range = $this->getResponseCodeGroupRange($group); try { Assertion::range($code = $this->response->getStatusCode(), $range['min'], $range['max']); } catch (AssertionFailure $e) { throw new AssertionFailedException(sprintf( 'Expected response group "%s", got "%s" (response code: %d).', $group, $this->getResponseGroup($code), $code )); } }
[ "public", "function", "assertResponseIs", "(", "$", "group", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "range", "=", "$", "this", "->", "getResponseCodeGroupRange", "(", "$", "group", ")", ";", "try", "{", "Assertion", "::", "ra...
Checks if the HTTP response code is in a group Allowed groups are: - informational - success - redirection - client error - server error @param string $group Name of the group that the response code should be in @throws AssertionFailedException @return void @Then the response is :group
[ "Checks", "if", "the", "HTTP", "response", "code", "is", "in", "a", "group" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L529-L543
41,178
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderExists
public function assertResponseHeaderExists($header) { $this->requireResponse(); try { Assertion::true( $this->response->hasHeader($header), sprintf('The "%s" response header does not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderExists($header) { $this->requireResponse(); try { Assertion::true( $this->response->hasHeader($header), sprintf('The "%s" response header does not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderExists", "(", "$", "header", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "true", "(", "$", "this", "->", "response", "->", "hasHeader", "(", "$", "header", ")", ...
Assert that a response header exists @param string $header Then name of the header @throws AssertionFailedException @return void @Then the :header response header exists
[ "Assert", "that", "a", "response", "header", "exists" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L586-L597
41,179
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderDoesNotExist
public function assertResponseHeaderDoesNotExist($header) { $this->requireResponse(); try { Assertion::false( $this->response->hasHeader($header), sprintf('The "%s" response header should not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderDoesNotExist($header) { $this->requireResponse(); try { Assertion::false( $this->response->hasHeader($header), sprintf('The "%s" response header should not exist.', $header) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderDoesNotExist", "(", "$", "header", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "false", "(", "$", "this", "->", "response", "->", "hasHeader", "(", "$", "header", ...
Assert that a response header does not exist @param string $header Then name of the header @throws AssertionFailedException @return void @Then the :header response header does not exist
[ "Assert", "that", "a", "response", "header", "does", "not", "exist" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L608-L619
41,180
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderIs
public function assertResponseHeaderIs($header, $value) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getHeaderLine($header), $value, sprintf( 'Expected the "%s" response header to be "%s", got "%s".', $header, $value, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderIs($header, $value) { $this->requireResponse(); try { Assertion::same( $actual = $this->response->getHeaderLine($header), $value, sprintf( 'Expected the "%s" response header to be "%s", got "%s".', $header, $value, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderIs", "(", "$", "header", ",", "$", "value", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "$", "actual", "=", "$", "this", "->", "response", "->", "...
Compare a response header value against a string @param string $header The name of the header @param string $value The value to compare with @throws AssertionFailedException @return void @Then the :header response header is :value
[ "Compare", "a", "response", "header", "value", "against", "a", "string" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L631-L648
41,181
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderIsNot
public function assertResponseHeaderIsNot($header, $value) { $this->requireResponse(); try { Assertion::notSame( $this->response->getHeaderLine($header), $value, sprintf( 'Did not expect the "%s" response header to be "%s".', $header, $value ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderIsNot($header, $value) { $this->requireResponse(); try { Assertion::notSame( $this->response->getHeaderLine($header), $value, sprintf( 'Did not expect the "%s" response header to be "%s".', $header, $value ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderIsNot", "(", "$", "header", ",", "$", "value", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "notSame", "(", "$", "this", "->", "response", "->", "getHeaderLine", "(...
Assert that a response header is not a value @param string $header The name of the header @param string $value The value to compare with @throws AssertionFailedException @return void @Then the :header response header is not :value
[ "Assert", "that", "a", "response", "header", "is", "not", "a", "value" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L660-L676
41,182
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseHeaderMatches
public function assertResponseHeaderMatches($header, $pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getHeaderLine($header), $pattern, sprintf( 'Expected the "%s" response header to match the regular expression "%s", got "%s".', $header, $pattern, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseHeaderMatches($header, $pattern) { $this->requireResponse(); try { Assertion::regex( $actual = $this->response->getHeaderLine($header), $pattern, sprintf( 'Expected the "%s" response header to match the regular expression "%s", got "%s".', $header, $pattern, $actual ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseHeaderMatches", "(", "$", "header", ",", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "regex", "(", "$", "actual", "=", "$", "this", "->", "response", "...
Match a response header value against a regular expression pattern @param string $header The name of the header @param string $pattern The regular expression pattern @throws AssertionFailedException @return void @Then the :header response header matches :pattern
[ "Match", "a", "response", "header", "value", "against", "a", "regular", "expression", "pattern" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L688-L705
41,183
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIsAnEmptyJsonObject
public function assertResponseBodyIsAnEmptyJsonObject() { $this->requireResponse(); $body = $this->getResponseBody(); try { Assertion::isInstanceOf($body, 'stdClass', 'Expected response body to be a JSON object.'); Assertion::same('{}', $encoded = json_encode($body, JSON_PRETTY_PRINT), sprintf( 'Expected response body to be an empty JSON object, got "%s".', $encoded )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIsAnEmptyJsonObject() { $this->requireResponse(); $body = $this->getResponseBody(); try { Assertion::isInstanceOf($body, 'stdClass', 'Expected response body to be a JSON object.'); Assertion::same('{}', $encoded = json_encode($body, JSON_PRETTY_PRINT), sprintf( 'Expected response body to be an empty JSON object, got "%s".', $encoded )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIsAnEmptyJsonObject", "(", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "body", "=", "$", "this", "->", "getResponseBody", "(", ")", ";", "try", "{", "Assertion", "::", "isInstanceOf", "(", "$",...
Assert that the response body contains an empty JSON object @throws AssertionFailedException @return void @Then the response body is an empty JSON object
[ "Assert", "that", "the", "response", "body", "contains", "an", "empty", "JSON", "object" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L715-L728
41,184
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIsAnEmptyJsonArray
public function assertResponseBodyIsAnEmptyJsonArray() { $this->requireResponse(); try { Assertion::same( [], $body = $this->getResponseBodyArray(), sprintf('Expected response body to be an empty JSON array, got "%s".', json_encode($body, JSON_PRETTY_PRINT)) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIsAnEmptyJsonArray() { $this->requireResponse(); try { Assertion::same( [], $body = $this->getResponseBodyArray(), sprintf('Expected response body to be an empty JSON array, got "%s".', json_encode($body, JSON_PRETTY_PRINT)) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIsAnEmptyJsonArray", "(", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "try", "{", "Assertion", "::", "same", "(", "[", "]", ",", "$", "body", "=", "$", "this", "->", "getResponseBodyArray", "(", "...
Assert that the response body contains an empty JSON array @throws AssertionFailedException @return void @Then the response body is an empty JSON array
[ "Assert", "that", "the", "response", "body", "contains", "an", "empty", "JSON", "array" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L738-L750
41,185
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyJsonArrayLength
public function assertResponseBodyJsonArrayLength($length) { $this->requireResponse(); $length = (int) $length; try { Assertion::count( $body = $this->getResponseBodyArray(), $length, sprintf( 'Expected response body to be a JSON array with %d entr%s, got %d: "%s".', $length, $length === 1 ? 'y' : 'ies', count($body), json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyJsonArrayLength($length) { $this->requireResponse(); $length = (int) $length; try { Assertion::count( $body = $this->getResponseBodyArray(), $length, sprintf( 'Expected response body to be a JSON array with %d entr%s, got %d: "%s".', $length, $length === 1 ? 'y' : 'ies', count($body), json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyJsonArrayLength", "(", "$", "length", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "length", "=", "(", "int", ")", "$", "length", ";", "try", "{", "Assertion", "::", "count", "(", "$", "body...
Assert that the response body contains an array with a specific length @param int $length The length of the array @throws AssertionFailedException @return void @Then the response body is a JSON array of length :length
[ "Assert", "that", "the", "response", "body", "contains", "an", "array", "with", "a", "specific", "length" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L761-L780
41,186
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyJsonArrayMinLength
public function assertResponseBodyJsonArrayMinLength($length) { $this->requireResponse(); $length = (int) $length; $body = $this->getResponseBodyArray(); try { Assertion::min( $bodyLength = count($body), $length, sprintf( 'Expected response body to be a JSON array with at least %d entr%s, got %d: "%s".', $length, (int) $length === 1 ? 'y' : 'ies', $bodyLength, json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyJsonArrayMinLength($length) { $this->requireResponse(); $length = (int) $length; $body = $this->getResponseBodyArray(); try { Assertion::min( $bodyLength = count($body), $length, sprintf( 'Expected response body to be a JSON array with at least %d entr%s, got %d: "%s".', $length, (int) $length === 1 ? 'y' : 'ies', $bodyLength, json_encode($body, JSON_PRETTY_PRINT) ) ); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyJsonArrayMinLength", "(", "$", "length", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "length", "=", "(", "int", ")", "$", "length", ";", "$", "body", "=", "$", "this", "->", "getResponseBodyA...
Assert that the response body contains an array with a length of at least a given length @param int $length The length to use in the assertion @throws AssertionFailedException @return void @Then the response body is a JSON array with a length of at least :length
[ "Assert", "that", "the", "response", "body", "contains", "an", "array", "with", "a", "length", "of", "at", "least", "a", "given", "length" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L791-L812
41,187
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIs
public function assertResponseBodyIs(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::same($body = (string) $this->response->getBody(), $content, sprintf( 'Expected response body "%s", got "%s".', $content, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIs(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::same($body = (string) $this->response->getBody(), $content, sprintf( 'Expected response body "%s", got "%s".', $content, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIs", "(", "PyStringNode", "$", "content", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "content", "=", "(", "string", ")", "$", "content", ";", "try", "{", "Assertion", "::", "same", "(", "$...
Assert that the response body matches some content @param PyStringNode $content The content to match the response body against @throws AssertionFailedException @return void @Then the response body is:
[ "Assert", "that", "the", "response", "body", "matches", "some", "content" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L856-L869
41,188
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyIsNot
public function assertResponseBodyIsNot(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::notSame((string) $this->response->getBody(), $content, sprintf( 'Did not expect response body to be "%s".', $content )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyIsNot(PyStringNode $content) { $this->requireResponse(); $content = (string) $content; try { Assertion::notSame((string) $this->response->getBody(), $content, sprintf( 'Did not expect response body to be "%s".', $content )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyIsNot", "(", "PyStringNode", "$", "content", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "content", "=", "(", "string", ")", "$", "content", ";", "try", "{", "Assertion", "::", "notSame", "("...
Assert that the response body does not match some content @param PyStringNode $content The content that the response body should not match @throws AssertionFailedException @return void @Then the response body is not:
[ "Assert", "that", "the", "response", "body", "does", "not", "match", "some", "content" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L880-L892
41,189
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.assertResponseBodyMatches
public function assertResponseBodyMatches(PyStringNode $pattern) { $this->requireResponse(); $pattern = (string) $pattern; try { Assertion::regex($body = (string) $this->response->getBody(), $pattern, sprintf( 'Expected response body to match regular expression "%s", got "%s".', $pattern, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
php
public function assertResponseBodyMatches(PyStringNode $pattern) { $this->requireResponse(); $pattern = (string) $pattern; try { Assertion::regex($body = (string) $this->response->getBody(), $pattern, sprintf( 'Expected response body to match regular expression "%s", got "%s".', $pattern, $body )); } catch (AssertionFailure $e) { throw new AssertionFailedException($e->getMessage()); } }
[ "public", "function", "assertResponseBodyMatches", "(", "PyStringNode", "$", "pattern", ")", "{", "$", "this", "->", "requireResponse", "(", ")", ";", "$", "pattern", "=", "(", "string", ")", "$", "pattern", ";", "try", "{", "Assertion", "::", "regex", "("...
Assert that the response body matches some content using a regular expression @param PyStringNode $pattern The regular expression pattern to use for the match @throws AssertionFailedException @return void @Then the response body matches:
[ "Assert", "that", "the", "response", "body", "matches", "some", "content", "using", "a", "regular", "expression" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L903-L916
41,190
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.sendRequest
protected function sendRequest() { if (!empty($this->requestOptions['form_params']) && !$this->forceHttpMethod) { $this->setRequestMethod('POST'); } if (!empty($this->requestOptions['multipart']) && !empty($this->requestOptions['form_params'])) { // We have both multipart and form_params set in the request options. Take all // form_params and add them to the multipart part of the option array as it's not // allowed to have both. foreach ($this->requestOptions['form_params'] as $name => $contents) { if (is_array($contents)) { // The contents is an array, so use array notation for the part name and store // all values under this name $name .= '[]'; foreach ($contents as $content) { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $content, ]; } } else { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $contents ]; } } // Remove form_params from the options, otherwise Guzzle will throw an exception unset($this->requestOptions['form_params']); } try { $this->response = $this->client->send( $this->request, $this->requestOptions ); } catch (RequestException $e) { $this->response = $e->getResponse(); if (!$this->response) { throw $e; } } return $this; }
php
protected function sendRequest() { if (!empty($this->requestOptions['form_params']) && !$this->forceHttpMethod) { $this->setRequestMethod('POST'); } if (!empty($this->requestOptions['multipart']) && !empty($this->requestOptions['form_params'])) { // We have both multipart and form_params set in the request options. Take all // form_params and add them to the multipart part of the option array as it's not // allowed to have both. foreach ($this->requestOptions['form_params'] as $name => $contents) { if (is_array($contents)) { // The contents is an array, so use array notation for the part name and store // all values under this name $name .= '[]'; foreach ($contents as $content) { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $content, ]; } } else { $this->requestOptions['multipart'][] = [ 'name' => $name, 'contents' => $contents ]; } } // Remove form_params from the options, otherwise Guzzle will throw an exception unset($this->requestOptions['form_params']); } try { $this->response = $this->client->send( $this->request, $this->requestOptions ); } catch (RequestException $e) { $this->response = $e->getResponse(); if (!$this->response) { throw $e; } } return $this; }
[ "protected", "function", "sendRequest", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "requestOptions", "[", "'form_params'", "]", ")", "&&", "!", "$", "this", "->", "forceHttpMethod", ")", "{", "$", "this", "->", "setRequestMethod", "(...
Send the current request and set the response instance @throws RequestException @return self
[ "Send", "the", "current", "request", "and", "set", "the", "response", "instance" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L952-L999
41,191
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.getResponseCodeGroupRange
protected function getResponseCodeGroupRange($group) { switch ($group) { case 'informational': $min = 100; $max = 199; break; case 'success': $min = 200; $max = 299; break; case 'redirection': $min = 300; $max = 399; break; case 'client error': $min = 400; $max = 499; break; case 'server error': $min = 500; $max = 599; break; default: throw new InvalidArgumentException(sprintf('Invalid response code group: %s', $group)); } return [ 'min' => $min, 'max' => $max, ]; }
php
protected function getResponseCodeGroupRange($group) { switch ($group) { case 'informational': $min = 100; $max = 199; break; case 'success': $min = 200; $max = 299; break; case 'redirection': $min = 300; $max = 399; break; case 'client error': $min = 400; $max = 499; break; case 'server error': $min = 500; $max = 599; break; default: throw new InvalidArgumentException(sprintf('Invalid response code group: %s', $group)); } return [ 'min' => $min, 'max' => $max, ]; }
[ "protected", "function", "getResponseCodeGroupRange", "(", "$", "group", ")", "{", "switch", "(", "$", "group", ")", "{", "case", "'informational'", ":", "$", "min", "=", "100", ";", "$", "max", "=", "199", ";", "break", ";", "case", "'success'", ":", ...
Get the min and max values for a response body group @param string $group The name of the group @throws InvalidArgumentException @return array An array with two keys, min and max, which represents the min and max values for $group
[ "Get", "the", "min", "and", "max", "values", "for", "a", "response", "body", "group" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1020-L1050
41,192
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.validateResponseCode
protected function validateResponseCode($code) { $code = (int) $code; try { Assertion::range($code, 100, 599, sprintf('Response code must be between 100 and 599, got %d.', $code)); } catch (AssertionFailure $e) { throw new InvalidArgumentException($e->getMessage()); } return $code; }
php
protected function validateResponseCode($code) { $code = (int) $code; try { Assertion::range($code, 100, 599, sprintf('Response code must be between 100 and 599, got %d.', $code)); } catch (AssertionFailure $e) { throw new InvalidArgumentException($e->getMessage()); } return $code; }
[ "protected", "function", "validateResponseCode", "(", "$", "code", ")", "{", "$", "code", "=", "(", "int", ")", "$", "code", ";", "try", "{", "Assertion", "::", "range", "(", "$", "code", ",", "100", ",", "599", ",", "sprintf", "(", "'Response code mus...
Validate a response code @param int $code @throws InvalidArgumentException @return int
[ "Validate", "a", "response", "code" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1081-L1091
41,193
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestPath
protected function setRequestPath($path) { // Resolve the path with the base_uri set in the client $uri = Psr7\Uri::resolve($this->client->getConfig('base_uri'), Psr7\uri_for($path)); $this->request = $this->request->withUri($uri); return $this; }
php
protected function setRequestPath($path) { // Resolve the path with the base_uri set in the client $uri = Psr7\Uri::resolve($this->client->getConfig('base_uri'), Psr7\uri_for($path)); $this->request = $this->request->withUri($uri); return $this; }
[ "protected", "function", "setRequestPath", "(", "$", "path", ")", "{", "// Resolve the path with the base_uri set in the client", "$", "uri", "=", "Psr7", "\\", "Uri", "::", "resolve", "(", "$", "this", "->", "client", "->", "getConfig", "(", "'base_uri'", ")", ...
Update the path of the request @param string $path The path to request @return self
[ "Update", "the", "path", "of", "the", "request" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1099-L1105
41,194
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.setRequestMethod
protected function setRequestMethod($method, $force = true) { $this->request = $this->request->withMethod($method); $this->forceHttpMethod = $force; return $this; }
php
protected function setRequestMethod($method, $force = true) { $this->request = $this->request->withMethod($method); $this->forceHttpMethod = $force; return $this; }
[ "protected", "function", "setRequestMethod", "(", "$", "method", ",", "$", "force", "=", "true", ")", "{", "$", "this", "->", "request", "=", "$", "this", "->", "request", "->", "withMethod", "(", "$", "method", ")", ";", "$", "this", "->", "forceHttpM...
Update the HTTP method of the request @param string $method The HTTP method @param boolean $force Force the HTTP method. If set to false the method set CAN be overridden (this occurs for instance when adding form parameters to the request, and not specifying HTTP POST for the request) @return self
[ "Update", "the", "HTTP", "method", "of", "the", "request" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1116-L1121
41,195
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.getResponseBody
protected function getResponseBody() { $body = json_decode((string) $this->response->getBody()); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException('The response body does not contain valid JSON data.'); } else if (!is_array($body) && !($body instanceof stdClass)) { throw new InvalidArgumentException('The response body does not contain a valid JSON array / object.'); } return $body; }
php
protected function getResponseBody() { $body = json_decode((string) $this->response->getBody()); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException('The response body does not contain valid JSON data.'); } else if (!is_array($body) && !($body instanceof stdClass)) { throw new InvalidArgumentException('The response body does not contain a valid JSON array / object.'); } return $body; }
[ "protected", "function", "getResponseBody", "(", ")", "{", "$", "body", "=", "json_decode", "(", "(", "string", ")", "$", "this", "->", "response", "->", "getBody", "(", ")", ")", ";", "if", "(", "json_last_error", "(", ")", "!==", "JSON_ERROR_NONE", ")"...
Get the JSON-encoded array or stdClass from the response body @throws InvalidArgumentException @return array|stdClass
[ "Get", "the", "JSON", "-", "encoded", "array", "or", "stdClass", "from", "the", "response", "body" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1129-L1139
41,196
imbo/behat-api-extension
src/Context/ApiContext.php
ApiContext.jsonDecode
protected function jsonDecode($value, $errorMessage = null) { $decoded = json_decode($value, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException( $errorMessage ?: 'The supplied parameter is not a valid JSON object.' ); } return $decoded; }
php
protected function jsonDecode($value, $errorMessage = null) { $decoded = json_decode($value, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidArgumentException( $errorMessage ?: 'The supplied parameter is not a valid JSON object.' ); } return $decoded; }
[ "protected", "function", "jsonDecode", "(", "$", "value", ",", "$", "errorMessage", "=", "null", ")", "{", "$", "decoded", "=", "json_decode", "(", "$", "value", ",", "true", ")", ";", "if", "(", "json_last_error", "(", ")", "!==", "JSON_ERROR_NONE", ")"...
Convert some variable to a JSON-array @param string $value The value to decode @param string $errorMessage Optional error message @throws InvalidArgumentException @return array
[ "Convert", "some", "variable", "to", "a", "JSON", "-", "array" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/src/Context/ApiContext.php#L1163-L1173
41,197
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.prepareScenario
public function prepareScenario(BeforeScenarioScope $scope) { $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-api-extension' . DIRECTORY_SEPARATOR . microtime(true); mkdir($dir . '/features/bootstrap', 0777, true); // Locate the php binary if (($bin = (new PhpExecutableFinder())->find()) === false) { throw new RuntimeException('Unable to find the PHP executable.'); } $this->workingDir = $dir; $this->phpBin = $bin; $this->process = new Process(null); }
php
public function prepareScenario(BeforeScenarioScope $scope) { $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-api-extension' . DIRECTORY_SEPARATOR . microtime(true); mkdir($dir . '/features/bootstrap', 0777, true); // Locate the php binary if (($bin = (new PhpExecutableFinder())->find()) === false) { throw new RuntimeException('Unable to find the PHP executable.'); } $this->workingDir = $dir; $this->phpBin = $bin; $this->process = new Process(null); }
[ "public", "function", "prepareScenario", "(", "BeforeScenarioScope", "$", "scope", ")", "{", "$", "dir", "=", "sys_get_temp_dir", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "'behat-api-extension'", ".", "DIRECTORY_SEPARATOR", ".", "microtime", "(", "true", ")", ";...
Prepare a scenario @param BeforeScenarioScope $scope @throws RuntimeException @BeforeScenario
[ "Prepare", "a", "scenario" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L64-L76
41,198
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.createFile
public function createFile($filename, PyStringNode $content, $readable = true) { $filename = rtrim($this->workingDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($filename, DIRECTORY_SEPARATOR); $path = dirname($filename); $content = str_replace("'''", '"""', (string) $content); if (!is_dir($path)) { mkdir($path, 0777, true); } file_put_contents($filename, $content); if (!$readable) { chmod($filename, 0000); } }
php
public function createFile($filename, PyStringNode $content, $readable = true) { $filename = rtrim($this->workingDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($filename, DIRECTORY_SEPARATOR); $path = dirname($filename); $content = str_replace("'''", '"""', (string) $content); if (!is_dir($path)) { mkdir($path, 0777, true); } file_put_contents($filename, $content); if (!$readable) { chmod($filename, 0000); } }
[ "public", "function", "createFile", "(", "$", "filename", ",", "PyStringNode", "$", "content", ",", "$", "readable", "=", "true", ")", "{", "$", "filename", "=", "rtrim", "(", "$", "this", "->", "workingDir", ",", "DIRECTORY_SEPARATOR", ")", ".", "DIRECTOR...
Creates a file with specified name and content in the current working dir @param string $filename Name of the file relative to the working dir @param PyStringNode $content Content of the file @param boolean $readable Whether or not the created file is readable @Given a file named :filename with:
[ "Creates", "a", "file", "with", "specified", "name", "and", "content", "in", "the", "current", "working", "dir" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L87-L101
41,199
imbo/behat-api-extension
features/bootstrap/FeatureContext.php
FeatureContext.assertCommandResultWithOutput
public function assertCommandResultWithOutput($result, PyStringNode $output) { $this->assertCommandResult($result); $this->assertCommandOutputMatches($output); }
php
public function assertCommandResultWithOutput($result, PyStringNode $output) { $this->assertCommandResult($result); $this->assertCommandOutputMatches($output); }
[ "public", "function", "assertCommandResultWithOutput", "(", "$", "result", ",", "PyStringNode", "$", "output", ")", "{", "$", "this", "->", "assertCommandResult", "(", "$", "result", ")", ";", "$", "this", "->", "assertCommandOutputMatches", "(", "$", "output", ...
Checks whether the command failed or passed, with output @param string $result @param PyStringNode $output @Then /^it should (fail|pass) with:$/
[ "Checks", "whether", "the", "command", "failed", "or", "passed", "with", "output" ]
f1607cc88fd352a73a87ebf69214b5e2e505fb34
https://github.com/imbo/behat-api-extension/blob/f1607cc88fd352a73a87ebf69214b5e2e505fb34/features/bootstrap/FeatureContext.php#L146-L149