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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
SwooleDistributed/SwooleDistributed
|
src/Server/Components/Blade/Blade.php
|
Blade.render
|
public function render($view, $data = [], $mergeData = [])
{
return $this->container['view']->make($view, $data, $mergeData)->render();
}
|
php
|
public function render($view, $data = [], $mergeData = [])
{
return $this->container['view']->make($view, $data, $mergeData)->render();
}
|
[
"public",
"function",
"render",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"mergeData",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"[",
"'view'",
"]",
"->",
"make",
"(",
"$",
"view",
",",
"$",
"data",
",",
"$",
"mergeData",
")",
"->",
"render",
"(",
")",
";",
"}"
] |
Render shortcut.
@param string $view
@param array $data
@param array $mergeData
@return string
|
[
"Render",
"shortcut",
"."
] |
bca3c1fde5a3160747b7e2234bb3851a19bc2e94
|
https://github.com/SwooleDistributed/SwooleDistributed/blob/bca3c1fde5a3160747b7e2234bb3851a19bc2e94/src/Server/Components/Blade/Blade.php#L89-L92
|
train
|
ramsey/uuid
|
src/Generator/PeclUuidTimeGenerator.php
|
PeclUuidTimeGenerator.generate
|
public function generate($node = null, $clockSeq = null)
{
$uuid = uuid_create(UUID_TYPE_TIME);
return uuid_parse($uuid);
}
|
php
|
public function generate($node = null, $clockSeq = null)
{
$uuid = uuid_create(UUID_TYPE_TIME);
return uuid_parse($uuid);
}
|
[
"public",
"function",
"generate",
"(",
"$",
"node",
"=",
"null",
",",
"$",
"clockSeq",
"=",
"null",
")",
"{",
"$",
"uuid",
"=",
"uuid_create",
"(",
"UUID_TYPE_TIME",
")",
";",
"return",
"uuid_parse",
"(",
"$",
"uuid",
")",
";",
"}"
] |
Generate a version 1 UUID using the PECL UUID extension
@param int|string $node Not used in this context
@param int $clockSeq Not used in this context
@return string A binary string
|
[
"Generate",
"a",
"version",
"1",
"UUID",
"using",
"the",
"PECL",
"UUID",
"extension"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Generator/PeclUuidTimeGenerator.php#L32-L37
|
train
|
ramsey/uuid
|
src/Builder/DegradedUuidBuilder.php
|
DegradedUuidBuilder.build
|
public function build(CodecInterface $codec, array $fields)
{
return new DegradedUuid($fields, $this->numberConverter, $codec, $this->timeConverter);
}
|
php
|
public function build(CodecInterface $codec, array $fields)
{
return new DegradedUuid($fields, $this->numberConverter, $codec, $this->timeConverter);
}
|
[
"public",
"function",
"build",
"(",
"CodecInterface",
"$",
"codec",
",",
"array",
"$",
"fields",
")",
"{",
"return",
"new",
"DegradedUuid",
"(",
"$",
"fields",
",",
"$",
"this",
"->",
"numberConverter",
",",
"$",
"codec",
",",
"$",
"this",
"->",
"timeConverter",
")",
";",
"}"
] |
Builds a DegradedUuid
@param CodecInterface $codec The codec to use for building this DegradedUuid
@param array $fields An array of fields from which to construct the DegradedUuid;
see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure.
@return DegradedUuid
|
[
"Builds",
"a",
"DegradedUuid"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Builder/DegradedUuidBuilder.php#L59-L62
|
train
|
ramsey/uuid
|
src/BinaryUtils.php
|
BinaryUtils.applyVersion
|
public static function applyVersion($timeHi, $version)
{
$timeHi = hexdec($timeHi) & 0x0fff;
$timeHi &= ~(0xf000);
$timeHi |= $version << 12;
return $timeHi;
}
|
php
|
public static function applyVersion($timeHi, $version)
{
$timeHi = hexdec($timeHi) & 0x0fff;
$timeHi &= ~(0xf000);
$timeHi |= $version << 12;
return $timeHi;
}
|
[
"public",
"static",
"function",
"applyVersion",
"(",
"$",
"timeHi",
",",
"$",
"version",
")",
"{",
"$",
"timeHi",
"=",
"hexdec",
"(",
"$",
"timeHi",
")",
"&",
"0x0fff",
";",
"$",
"timeHi",
"&=",
"~",
"(",
"0xf000",
")",
";",
"$",
"timeHi",
"|=",
"$",
"version",
"<<",
"12",
";",
"return",
"$",
"timeHi",
";",
"}"
] |
Applies the RFC 4122 version number to the `time_hi_and_version` field
@param string $timeHi
@param integer $version
@return int The high field of the timestamp multiplexed with the version number
@link http://tools.ietf.org/html/rfc4122#section-4.1.3
|
[
"Applies",
"the",
"RFC",
"4122",
"version",
"number",
"to",
"the",
"time_hi_and_version",
"field"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/BinaryUtils.php#L35-L42
|
train
|
ramsey/uuid
|
src/Codec/TimestampFirstCombCodec.php
|
TimestampFirstCombCodec.encode
|
public function encode(UuidInterface $uuid)
{
$sixPieceComponents = array_values($uuid->getFieldsHex());
$this->swapTimestampAndRandomBits($sixPieceComponents);
return vsprintf(
'%08s-%04s-%04s-%02s%02s-%012s',
$sixPieceComponents
);
}
|
php
|
public function encode(UuidInterface $uuid)
{
$sixPieceComponents = array_values($uuid->getFieldsHex());
$this->swapTimestampAndRandomBits($sixPieceComponents);
return vsprintf(
'%08s-%04s-%04s-%02s%02s-%012s',
$sixPieceComponents
);
}
|
[
"public",
"function",
"encode",
"(",
"UuidInterface",
"$",
"uuid",
")",
"{",
"$",
"sixPieceComponents",
"=",
"array_values",
"(",
"$",
"uuid",
"->",
"getFieldsHex",
"(",
")",
")",
";",
"$",
"this",
"->",
"swapTimestampAndRandomBits",
"(",
"$",
"sixPieceComponents",
")",
";",
"return",
"vsprintf",
"(",
"'%08s-%04s-%04s-%02s%02s-%012s'",
",",
"$",
"sixPieceComponents",
")",
";",
"}"
] |
Encodes a UuidInterface as a string representation of a timestamp first COMB UUID
@param UuidInterface $uuid
@return string Hexadecimal string representation of a GUID
|
[
"Encodes",
"a",
"UuidInterface",
"as",
"a",
"string",
"representation",
"of",
"a",
"timestamp",
"first",
"COMB",
"UUID"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/TimestampFirstCombCodec.php#L31-L41
|
train
|
ramsey/uuid
|
src/Codec/TimestampFirstCombCodec.php
|
TimestampFirstCombCodec.encodeBinary
|
public function encodeBinary(UuidInterface $uuid)
{
$stringEncoding = $this->encode($uuid);
return hex2bin(str_replace('-', '', $stringEncoding));
}
|
php
|
public function encodeBinary(UuidInterface $uuid)
{
$stringEncoding = $this->encode($uuid);
return hex2bin(str_replace('-', '', $stringEncoding));
}
|
[
"public",
"function",
"encodeBinary",
"(",
"UuidInterface",
"$",
"uuid",
")",
"{",
"$",
"stringEncoding",
"=",
"$",
"this",
"->",
"encode",
"(",
"$",
"uuid",
")",
";",
"return",
"hex2bin",
"(",
"str_replace",
"(",
"'-'",
",",
"''",
",",
"$",
"stringEncoding",
")",
")",
";",
"}"
] |
Encodes a UuidInterface as a binary representation of timestamp first COMB UUID
@param UuidInterface $uuid
@return string Binary string representation of timestamp first COMB UUID
|
[
"Encodes",
"a",
"UuidInterface",
"as",
"a",
"binary",
"representation",
"of",
"timestamp",
"first",
"COMB",
"UUID"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/TimestampFirstCombCodec.php#L50-L55
|
train
|
ramsey/uuid
|
src/Codec/TimestampFirstCombCodec.php
|
TimestampFirstCombCodec.decode
|
public function decode($encodedUuid)
{
$fivePieceComponents = $this->extractComponents($encodedUuid);
$this->swapTimestampAndRandomBits($fivePieceComponents);
return $this->getBuilder()->build($this, $this->getFields($fivePieceComponents));
}
|
php
|
public function decode($encodedUuid)
{
$fivePieceComponents = $this->extractComponents($encodedUuid);
$this->swapTimestampAndRandomBits($fivePieceComponents);
return $this->getBuilder()->build($this, $this->getFields($fivePieceComponents));
}
|
[
"public",
"function",
"decode",
"(",
"$",
"encodedUuid",
")",
"{",
"$",
"fivePieceComponents",
"=",
"$",
"this",
"->",
"extractComponents",
"(",
"$",
"encodedUuid",
")",
";",
"$",
"this",
"->",
"swapTimestampAndRandomBits",
"(",
"$",
"fivePieceComponents",
")",
";",
"return",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"build",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getFields",
"(",
"$",
"fivePieceComponents",
")",
")",
";",
"}"
] |
Decodes a string representation of timestamp first COMB UUID into a UuidInterface object instance
@param string $encodedUuid
@return UuidInterface
@throws \Ramsey\Uuid\Exception\InvalidUuidStringException
|
[
"Decodes",
"a",
"string",
"representation",
"of",
"timestamp",
"first",
"COMB",
"UUID",
"into",
"a",
"UuidInterface",
"object",
"instance"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/TimestampFirstCombCodec.php#L65-L72
|
train
|
ramsey/uuid
|
src/Codec/TimestampFirstCombCodec.php
|
TimestampFirstCombCodec.swapTimestampAndRandomBits
|
protected function swapTimestampAndRandomBits(array &$components)
{
$last48Bits = $components[4];
if (count($components) == 6) {
$last48Bits = $components[5];
$components[5] = $components[0] . $components[1];
} else {
$components[4] = $components[0] . $components[1];
}
$components[0] = substr($last48Bits, 0, 8);
$components[1] = substr($last48Bits, 8, 4);
}
|
php
|
protected function swapTimestampAndRandomBits(array &$components)
{
$last48Bits = $components[4];
if (count($components) == 6) {
$last48Bits = $components[5];
$components[5] = $components[0] . $components[1];
} else {
$components[4] = $components[0] . $components[1];
}
$components[0] = substr($last48Bits, 0, 8);
$components[1] = substr($last48Bits, 8, 4);
}
|
[
"protected",
"function",
"swapTimestampAndRandomBits",
"(",
"array",
"&",
"$",
"components",
")",
"{",
"$",
"last48Bits",
"=",
"$",
"components",
"[",
"4",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"components",
")",
"==",
"6",
")",
"{",
"$",
"last48Bits",
"=",
"$",
"components",
"[",
"5",
"]",
";",
"$",
"components",
"[",
"5",
"]",
"=",
"$",
"components",
"[",
"0",
"]",
".",
"$",
"components",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"components",
"[",
"4",
"]",
"=",
"$",
"components",
"[",
"0",
"]",
".",
"$",
"components",
"[",
"1",
"]",
";",
"}",
"$",
"components",
"[",
"0",
"]",
"=",
"substr",
"(",
"$",
"last48Bits",
",",
"0",
",",
"8",
")",
";",
"$",
"components",
"[",
"1",
"]",
"=",
"substr",
"(",
"$",
"last48Bits",
",",
"8",
",",
"4",
")",
";",
"}"
] |
Swaps the first 48 bits with the last 48 bits
@param array $components An array of UUID components (the UUID exploded on its dashes)
@return void
|
[
"Swaps",
"the",
"first",
"48",
"bits",
"with",
"the",
"last",
"48",
"bits"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/TimestampFirstCombCodec.php#L94-L106
|
train
|
ramsey/uuid
|
src/Generator/DefaultTimeGenerator.php
|
DefaultTimeGenerator.generate
|
public function generate($node = null, $clockSeq = null)
{
$node = $this->getValidNode($node);
if ($clockSeq === null) {
// Not using "stable storage"; see RFC 4122, Section 4.2.1.1
$clockSeq = random_int(0, 0x3fff);
}
// Create a 60-bit time value as a count of 100-nanosecond intervals
// since 00:00:00.00, 15 October 1582
$timeOfDay = $this->timeProvider->currentTime();
$uuidTime = $this->timeConverter->calculateTime((string) $timeOfDay['sec'], (string) $timeOfDay['usec']);
$timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1);
$clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8);
$hex = vsprintf(
'%08s%04s%04s%02s%02s%012s',
[
$uuidTime['low'],
$uuidTime['mid'],
sprintf('%04x', $timeHi),
sprintf('%02x', $clockSeqHi),
sprintf('%02x', $clockSeq & 0xff),
$node,
]
);
return hex2bin($hex);
}
|
php
|
public function generate($node = null, $clockSeq = null)
{
$node = $this->getValidNode($node);
if ($clockSeq === null) {
// Not using "stable storage"; see RFC 4122, Section 4.2.1.1
$clockSeq = random_int(0, 0x3fff);
}
// Create a 60-bit time value as a count of 100-nanosecond intervals
// since 00:00:00.00, 15 October 1582
$timeOfDay = $this->timeProvider->currentTime();
$uuidTime = $this->timeConverter->calculateTime((string) $timeOfDay['sec'], (string) $timeOfDay['usec']);
$timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1);
$clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8);
$hex = vsprintf(
'%08s%04s%04s%02s%02s%012s',
[
$uuidTime['low'],
$uuidTime['mid'],
sprintf('%04x', $timeHi),
sprintf('%02x', $clockSeqHi),
sprintf('%02x', $clockSeq & 0xff),
$node,
]
);
return hex2bin($hex);
}
|
[
"public",
"function",
"generate",
"(",
"$",
"node",
"=",
"null",
",",
"$",
"clockSeq",
"=",
"null",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"getValidNode",
"(",
"$",
"node",
")",
";",
"if",
"(",
"$",
"clockSeq",
"===",
"null",
")",
"{",
"// Not using \"stable storage\"; see RFC 4122, Section 4.2.1.1",
"$",
"clockSeq",
"=",
"random_int",
"(",
"0",
",",
"0x3fff",
")",
";",
"}",
"// Create a 60-bit time value as a count of 100-nanosecond intervals",
"// since 00:00:00.00, 15 October 1582",
"$",
"timeOfDay",
"=",
"$",
"this",
"->",
"timeProvider",
"->",
"currentTime",
"(",
")",
";",
"$",
"uuidTime",
"=",
"$",
"this",
"->",
"timeConverter",
"->",
"calculateTime",
"(",
"(",
"string",
")",
"$",
"timeOfDay",
"[",
"'sec'",
"]",
",",
"(",
"string",
")",
"$",
"timeOfDay",
"[",
"'usec'",
"]",
")",
";",
"$",
"timeHi",
"=",
"BinaryUtils",
"::",
"applyVersion",
"(",
"$",
"uuidTime",
"[",
"'hi'",
"]",
",",
"1",
")",
";",
"$",
"clockSeqHi",
"=",
"BinaryUtils",
"::",
"applyVariant",
"(",
"$",
"clockSeq",
">>",
"8",
")",
";",
"$",
"hex",
"=",
"vsprintf",
"(",
"'%08s%04s%04s%02s%02s%012s'",
",",
"[",
"$",
"uuidTime",
"[",
"'low'",
"]",
",",
"$",
"uuidTime",
"[",
"'mid'",
"]",
",",
"sprintf",
"(",
"'%04x'",
",",
"$",
"timeHi",
")",
",",
"sprintf",
"(",
"'%02x'",
",",
"$",
"clockSeqHi",
")",
",",
"sprintf",
"(",
"'%02x'",
",",
"$",
"clockSeq",
"&",
"0xff",
")",
",",
"$",
"node",
",",
"]",
")",
";",
"return",
"hex2bin",
"(",
"$",
"hex",
")",
";",
"}"
] |
Generate a version 1 UUID from a host ID, sequence number, and the current time
If $node is not given, we will attempt to obtain the local hardware
address. If $clockSeq is given, it is used as the sequence number;
otherwise a random 14-bit sequence number is chosen.
@param int|string $node A 48-bit number representing the hardware address
This number may be represented as an integer or a hexadecimal string.
@param int $clockSeq A 14-bit number used to help avoid duplicates that
could arise when the clock is set backwards in time or if the node ID
changes.
@return string A binary string
@throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and
`Moontoast\Math\BigNumber` is not present
@throws \InvalidArgumentException
@throws \Exception if it was not possible to gather sufficient entropy
|
[
"Generate",
"a",
"version",
"1",
"UUID",
"from",
"a",
"host",
"ID",
"sequence",
"number",
"and",
"the",
"current",
"time"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Generator/DefaultTimeGenerator.php#L80-L110
|
train
|
ramsey/uuid
|
src/UuidFactory.php
|
UuidFactory.uuidFromNsAndName
|
protected function uuidFromNsAndName($ns, $name, $version, $hashFunction)
{
if (!($ns instanceof UuidInterface)) {
$ns = $this->codec->decode($ns);
}
$hash = call_user_func($hashFunction, ($ns->getBytes() . $name));
return $this->uuidFromHashedName($hash, $version);
}
|
php
|
protected function uuidFromNsAndName($ns, $name, $version, $hashFunction)
{
if (!($ns instanceof UuidInterface)) {
$ns = $this->codec->decode($ns);
}
$hash = call_user_func($hashFunction, ($ns->getBytes() . $name));
return $this->uuidFromHashedName($hash, $version);
}
|
[
"protected",
"function",
"uuidFromNsAndName",
"(",
"$",
"ns",
",",
"$",
"name",
",",
"$",
"version",
",",
"$",
"hashFunction",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"ns",
"instanceof",
"UuidInterface",
")",
")",
"{",
"$",
"ns",
"=",
"$",
"this",
"->",
"codec",
"->",
"decode",
"(",
"$",
"ns",
")",
";",
"}",
"$",
"hash",
"=",
"call_user_func",
"(",
"$",
"hashFunction",
",",
"(",
"$",
"ns",
"->",
"getBytes",
"(",
")",
".",
"$",
"name",
")",
")",
";",
"return",
"$",
"this",
"->",
"uuidFromHashedName",
"(",
"$",
"hash",
",",
"$",
"version",
")",
";",
"}"
] |
Returns a version 3 or 5 namespaced `Uuid`
@param string|UuidInterface $ns The UUID namespace to use
@param string $name The string to hash together with the namespace
@param int $version The version of UUID to create (3 or 5)
@param string $hashFunction The hash function to use when hashing together
the namespace and name
@return UuidInterface
@throws \Ramsey\Uuid\Exception\InvalidUuidStringException
|
[
"Returns",
"a",
"version",
"3",
"or",
"5",
"namespaced",
"Uuid"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/UuidFactory.php#L302-L311
|
train
|
ramsey/uuid
|
src/Codec/StringCodec.php
|
StringCodec.decode
|
public function decode($encodedUuid)
{
$components = $this->extractComponents($encodedUuid);
$fields = $this->getFields($components);
return $this->builder->build($this, $fields);
}
|
php
|
public function decode($encodedUuid)
{
$components = $this->extractComponents($encodedUuid);
$fields = $this->getFields($components);
return $this->builder->build($this, $fields);
}
|
[
"public",
"function",
"decode",
"(",
"$",
"encodedUuid",
")",
"{",
"$",
"components",
"=",
"$",
"this",
"->",
"extractComponents",
"(",
"$",
"encodedUuid",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
"$",
"components",
")",
";",
"return",
"$",
"this",
"->",
"builder",
"->",
"build",
"(",
"$",
"this",
",",
"$",
"fields",
")",
";",
"}"
] |
Decodes a string representation of a UUID into a UuidInterface object instance
@param string $encodedUuid
@return UuidInterface
@throws \Ramsey\Uuid\Exception\InvalidUuidStringException
|
[
"Decodes",
"a",
"string",
"representation",
"of",
"a",
"UUID",
"into",
"a",
"UuidInterface",
"object",
"instance"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/StringCodec.php#L79-L85
|
train
|
ramsey/uuid
|
src/Codec/StringCodec.php
|
StringCodec.decodeBytes
|
public function decodeBytes($bytes)
{
if (strlen($bytes) !== 16) {
throw new InvalidArgumentException('$bytes string should contain 16 characters.');
}
$hexUuid = unpack('H*', $bytes);
return $this->decode($hexUuid[1]);
}
|
php
|
public function decodeBytes($bytes)
{
if (strlen($bytes) !== 16) {
throw new InvalidArgumentException('$bytes string should contain 16 characters.');
}
$hexUuid = unpack('H*', $bytes);
return $this->decode($hexUuid[1]);
}
|
[
"public",
"function",
"decodeBytes",
"(",
"$",
"bytes",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"bytes",
")",
"!==",
"16",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$bytes string should contain 16 characters.'",
")",
";",
"}",
"$",
"hexUuid",
"=",
"unpack",
"(",
"'H*'",
",",
"$",
"bytes",
")",
";",
"return",
"$",
"this",
"->",
"decode",
"(",
"$",
"hexUuid",
"[",
"1",
"]",
")",
";",
"}"
] |
Decodes a binary representation of a UUID into a UuidInterface object instance
@param string $bytes
@return UuidInterface
@throws \InvalidArgumentException if string has not 16 characters
|
[
"Decodes",
"a",
"binary",
"representation",
"of",
"a",
"UUID",
"into",
"a",
"UuidInterface",
"object",
"instance"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/StringCodec.php#L94-L103
|
train
|
ramsey/uuid
|
src/Codec/StringCodec.php
|
StringCodec.getFields
|
protected function getFields(array $components)
{
return [
'time_low' => str_pad($components[0], 8, '0', STR_PAD_LEFT),
'time_mid' => str_pad($components[1], 4, '0', STR_PAD_LEFT),
'time_hi_and_version' => str_pad($components[2], 4, '0', STR_PAD_LEFT),
'clock_seq_hi_and_reserved' => str_pad(substr($components[3], 0, 2), 2, '0', STR_PAD_LEFT),
'clock_seq_low' => str_pad(substr($components[3], 2), 2, '0', STR_PAD_LEFT),
'node' => str_pad($components[4], 12, '0', STR_PAD_LEFT)
];
}
|
php
|
protected function getFields(array $components)
{
return [
'time_low' => str_pad($components[0], 8, '0', STR_PAD_LEFT),
'time_mid' => str_pad($components[1], 4, '0', STR_PAD_LEFT),
'time_hi_and_version' => str_pad($components[2], 4, '0', STR_PAD_LEFT),
'clock_seq_hi_and_reserved' => str_pad(substr($components[3], 0, 2), 2, '0', STR_PAD_LEFT),
'clock_seq_low' => str_pad(substr($components[3], 2), 2, '0', STR_PAD_LEFT),
'node' => str_pad($components[4], 12, '0', STR_PAD_LEFT)
];
}
|
[
"protected",
"function",
"getFields",
"(",
"array",
"$",
"components",
")",
"{",
"return",
"[",
"'time_low'",
"=>",
"str_pad",
"(",
"$",
"components",
"[",
"0",
"]",
",",
"8",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
",",
"'time_mid'",
"=>",
"str_pad",
"(",
"$",
"components",
"[",
"1",
"]",
",",
"4",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
",",
"'time_hi_and_version'",
"=>",
"str_pad",
"(",
"$",
"components",
"[",
"2",
"]",
",",
"4",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
",",
"'clock_seq_hi_and_reserved'",
"=>",
"str_pad",
"(",
"substr",
"(",
"$",
"components",
"[",
"3",
"]",
",",
"0",
",",
"2",
")",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
",",
"'clock_seq_low'",
"=>",
"str_pad",
"(",
"substr",
"(",
"$",
"components",
"[",
"3",
"]",
",",
"2",
")",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
",",
"'node'",
"=>",
"str_pad",
"(",
"$",
"components",
"[",
"4",
"]",
",",
"12",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
"]",
";",
"}"
] |
Returns the fields that make up this UUID
@see \Ramsey\Uuid\UuidInterface::getFieldsHex()
@param array $components
@return array
|
[
"Returns",
"the",
"fields",
"that",
"make",
"up",
"this",
"UUID"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/StringCodec.php#L159-L169
|
train
|
ramsey/uuid
|
src/Codec/GuidStringCodec.php
|
GuidStringCodec.encode
|
public function encode(UuidInterface $uuid)
{
$components = array_values($uuid->getFieldsHex());
// Swap byte-order on the first three fields
$this->swapFields($components);
return vsprintf(
'%08s-%04s-%04s-%02s%02s-%012s',
$components
);
}
|
php
|
public function encode(UuidInterface $uuid)
{
$components = array_values($uuid->getFieldsHex());
// Swap byte-order on the first three fields
$this->swapFields($components);
return vsprintf(
'%08s-%04s-%04s-%02s%02s-%012s',
$components
);
}
|
[
"public",
"function",
"encode",
"(",
"UuidInterface",
"$",
"uuid",
")",
"{",
"$",
"components",
"=",
"array_values",
"(",
"$",
"uuid",
"->",
"getFieldsHex",
"(",
")",
")",
";",
"// Swap byte-order on the first three fields",
"$",
"this",
"->",
"swapFields",
"(",
"$",
"components",
")",
";",
"return",
"vsprintf",
"(",
"'%08s-%04s-%04s-%02s%02s-%012s'",
",",
"$",
"components",
")",
";",
"}"
] |
Encodes a UuidInterface as a string representation of a GUID
@param UuidInterface $uuid
@return string Hexadecimal string representation of a GUID
|
[
"Encodes",
"a",
"UuidInterface",
"as",
"a",
"string",
"representation",
"of",
"a",
"GUID"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/GuidStringCodec.php#L32-L43
|
train
|
ramsey/uuid
|
src/Codec/GuidStringCodec.php
|
GuidStringCodec.encodeBinary
|
public function encodeBinary(UuidInterface $uuid)
{
$components = array_values($uuid->getFieldsHex());
return hex2bin(implode('', $components));
}
|
php
|
public function encodeBinary(UuidInterface $uuid)
{
$components = array_values($uuid->getFieldsHex());
return hex2bin(implode('', $components));
}
|
[
"public",
"function",
"encodeBinary",
"(",
"UuidInterface",
"$",
"uuid",
")",
"{",
"$",
"components",
"=",
"array_values",
"(",
"$",
"uuid",
"->",
"getFieldsHex",
"(",
")",
")",
";",
"return",
"hex2bin",
"(",
"implode",
"(",
"''",
",",
"$",
"components",
")",
")",
";",
"}"
] |
Encodes a UuidInterface as a binary representation of a GUID
@param UuidInterface $uuid
@return string Binary string representation of a GUID
|
[
"Encodes",
"a",
"UuidInterface",
"as",
"a",
"binary",
"representation",
"of",
"a",
"GUID"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/GuidStringCodec.php#L51-L56
|
train
|
ramsey/uuid
|
src/Codec/GuidStringCodec.php
|
GuidStringCodec.decode
|
public function decode($encodedUuid)
{
$components = $this->extractComponents($encodedUuid);
$this->swapFields($components);
return $this->getBuilder()->build($this, $this->getFields($components));
}
|
php
|
public function decode($encodedUuid)
{
$components = $this->extractComponents($encodedUuid);
$this->swapFields($components);
return $this->getBuilder()->build($this, $this->getFields($components));
}
|
[
"public",
"function",
"decode",
"(",
"$",
"encodedUuid",
")",
"{",
"$",
"components",
"=",
"$",
"this",
"->",
"extractComponents",
"(",
"$",
"encodedUuid",
")",
";",
"$",
"this",
"->",
"swapFields",
"(",
"$",
"components",
")",
";",
"return",
"$",
"this",
"->",
"getBuilder",
"(",
")",
"->",
"build",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getFields",
"(",
"$",
"components",
")",
")",
";",
"}"
] |
Decodes a string representation of a GUID into a UuidInterface object instance
@param string $encodedUuid
@return UuidInterface
@throws \Ramsey\Uuid\Exception\InvalidUuidStringException
|
[
"Decodes",
"a",
"string",
"representation",
"of",
"a",
"GUID",
"into",
"a",
"UuidInterface",
"object",
"instance"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/GuidStringCodec.php#L65-L72
|
train
|
ramsey/uuid
|
src/Codec/GuidStringCodec.php
|
GuidStringCodec.swapFields
|
protected function swapFields(array &$components)
{
$hex = unpack('H*', pack('L', hexdec($components[0])));
$components[0] = $hex[1];
$hex = unpack('H*', pack('S', hexdec($components[1])));
$components[1] = $hex[1];
$hex = unpack('H*', pack('S', hexdec($components[2])));
$components[2] = $hex[1];
}
|
php
|
protected function swapFields(array &$components)
{
$hex = unpack('H*', pack('L', hexdec($components[0])));
$components[0] = $hex[1];
$hex = unpack('H*', pack('S', hexdec($components[1])));
$components[1] = $hex[1];
$hex = unpack('H*', pack('S', hexdec($components[2])));
$components[2] = $hex[1];
}
|
[
"protected",
"function",
"swapFields",
"(",
"array",
"&",
"$",
"components",
")",
"{",
"$",
"hex",
"=",
"unpack",
"(",
"'H*'",
",",
"pack",
"(",
"'L'",
",",
"hexdec",
"(",
"$",
"components",
"[",
"0",
"]",
")",
")",
")",
";",
"$",
"components",
"[",
"0",
"]",
"=",
"$",
"hex",
"[",
"1",
"]",
";",
"$",
"hex",
"=",
"unpack",
"(",
"'H*'",
",",
"pack",
"(",
"'S'",
",",
"hexdec",
"(",
"$",
"components",
"[",
"1",
"]",
")",
")",
")",
";",
"$",
"components",
"[",
"1",
"]",
"=",
"$",
"hex",
"[",
"1",
"]",
";",
"$",
"hex",
"=",
"unpack",
"(",
"'H*'",
",",
"pack",
"(",
"'S'",
",",
"hexdec",
"(",
"$",
"components",
"[",
"2",
"]",
")",
")",
")",
";",
"$",
"components",
"[",
"2",
"]",
"=",
"$",
"hex",
"[",
"1",
"]",
";",
"}"
] |
Swaps fields to support GUID byte order
@param array $components An array of UUID components (the UUID exploded on its dashes)
@return void
|
[
"Swaps",
"fields",
"to",
"support",
"GUID",
"byte",
"order"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/GuidStringCodec.php#L93-L101
|
train
|
ramsey/uuid
|
src/Provider/Node/FallbackNodeProvider.php
|
FallbackNodeProvider.getNode
|
public function getNode()
{
foreach ($this->nodeProviders as $provider) {
if ($node = $provider->getNode()) {
return $node;
}
}
return null;
}
|
php
|
public function getNode()
{
foreach ($this->nodeProviders as $provider) {
if ($node = $provider->getNode()) {
return $node;
}
}
return null;
}
|
[
"public",
"function",
"getNode",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"nodeProviders",
"as",
"$",
"provider",
")",
"{",
"if",
"(",
"$",
"node",
"=",
"$",
"provider",
"->",
"getNode",
"(",
")",
")",
"{",
"return",
"$",
"node",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the system node ID by iterating over an array of node providers
and returning the first non-empty value found
@return string|null System node ID as a hexadecimal string
@throws \Exception
|
[
"Returns",
"the",
"system",
"node",
"ID",
"by",
"iterating",
"over",
"an",
"array",
"of",
"node",
"providers",
"and",
"returning",
"the",
"first",
"non",
"-",
"empty",
"value",
"found"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Provider/Node/FallbackNodeProvider.php#L48-L57
|
train
|
ramsey/uuid
|
src/Codec/OrderedTimeCodec.php
|
OrderedTimeCodec.encodeBinary
|
public function encodeBinary(UuidInterface $uuid)
{
$fields = $uuid->getFieldsHex();
$optimized = [
$fields['time_hi_and_version'],
$fields['time_mid'],
$fields['time_low'],
$fields['clock_seq_hi_and_reserved'],
$fields['clock_seq_low'],
$fields['node'],
];
return hex2bin(implode('', $optimized));
}
|
php
|
public function encodeBinary(UuidInterface $uuid)
{
$fields = $uuid->getFieldsHex();
$optimized = [
$fields['time_hi_and_version'],
$fields['time_mid'],
$fields['time_low'],
$fields['clock_seq_hi_and_reserved'],
$fields['clock_seq_low'],
$fields['node'],
];
return hex2bin(implode('', $optimized));
}
|
[
"public",
"function",
"encodeBinary",
"(",
"UuidInterface",
"$",
"uuid",
")",
"{",
"$",
"fields",
"=",
"$",
"uuid",
"->",
"getFieldsHex",
"(",
")",
";",
"$",
"optimized",
"=",
"[",
"$",
"fields",
"[",
"'time_hi_and_version'",
"]",
",",
"$",
"fields",
"[",
"'time_mid'",
"]",
",",
"$",
"fields",
"[",
"'time_low'",
"]",
",",
"$",
"fields",
"[",
"'clock_seq_hi_and_reserved'",
"]",
",",
"$",
"fields",
"[",
"'clock_seq_low'",
"]",
",",
"$",
"fields",
"[",
"'node'",
"]",
",",
"]",
";",
"return",
"hex2bin",
"(",
"implode",
"(",
"''",
",",
"$",
"optimized",
")",
")",
";",
"}"
] |
Encodes a UuidInterface as an optimized binary representation of a UUID
@param UuidInterface $uuid
@return string Binary string representation of a UUID
|
[
"Encodes",
"a",
"UuidInterface",
"as",
"an",
"optimized",
"binary",
"representation",
"of",
"a",
"UUID"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/OrderedTimeCodec.php#L32-L46
|
train
|
ramsey/uuid
|
src/Codec/OrderedTimeCodec.php
|
OrderedTimeCodec.decodeBytes
|
public function decodeBytes($bytes)
{
if (strlen($bytes) !== 16) {
throw new InvalidArgumentException('$bytes string should contain 16 characters.');
}
$hex = unpack('H*', $bytes)[1];
// Rearrange the fields to their original order
$hex = substr($hex, 8, 4) . substr($hex, 12, 4) . substr($hex, 4, 4) . substr($hex, 0, 4) . substr($hex, 16);
return $this->decode($hex);
}
|
php
|
public function decodeBytes($bytes)
{
if (strlen($bytes) !== 16) {
throw new InvalidArgumentException('$bytes string should contain 16 characters.');
}
$hex = unpack('H*', $bytes)[1];
// Rearrange the fields to their original order
$hex = substr($hex, 8, 4) . substr($hex, 12, 4) . substr($hex, 4, 4) . substr($hex, 0, 4) . substr($hex, 16);
return $this->decode($hex);
}
|
[
"public",
"function",
"decodeBytes",
"(",
"$",
"bytes",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"bytes",
")",
"!==",
"16",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$bytes string should contain 16 characters.'",
")",
";",
"}",
"$",
"hex",
"=",
"unpack",
"(",
"'H*'",
",",
"$",
"bytes",
")",
"[",
"1",
"]",
";",
"// Rearrange the fields to their original order",
"$",
"hex",
"=",
"substr",
"(",
"$",
"hex",
",",
"8",
",",
"4",
")",
".",
"substr",
"(",
"$",
"hex",
",",
"12",
",",
"4",
")",
".",
"substr",
"(",
"$",
"hex",
",",
"4",
",",
"4",
")",
".",
"substr",
"(",
"$",
"hex",
",",
"0",
",",
"4",
")",
".",
"substr",
"(",
"$",
"hex",
",",
"16",
")",
";",
"return",
"$",
"this",
"->",
"decode",
"(",
"$",
"hex",
")",
";",
"}"
] |
Decodes an optimized binary representation of a UUID into a UuidInterface object instance
@param string $bytes
@return UuidInterface
@throws \InvalidArgumentException if string has not 16 characters
|
[
"Decodes",
"an",
"optimized",
"binary",
"representation",
"of",
"a",
"UUID",
"into",
"a",
"UuidInterface",
"object",
"instance"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Codec/OrderedTimeCodec.php#L55-L67
|
train
|
ramsey/uuid
|
src/Builder/DefaultUuidBuilder.php
|
DefaultUuidBuilder.build
|
public function build(CodecInterface $codec, array $fields)
{
return new Uuid($fields, $this->numberConverter, $codec, $this->timeConverter);
}
|
php
|
public function build(CodecInterface $codec, array $fields)
{
return new Uuid($fields, $this->numberConverter, $codec, $this->timeConverter);
}
|
[
"public",
"function",
"build",
"(",
"CodecInterface",
"$",
"codec",
",",
"array",
"$",
"fields",
")",
"{",
"return",
"new",
"Uuid",
"(",
"$",
"fields",
",",
"$",
"this",
"->",
"numberConverter",
",",
"$",
"codec",
",",
"$",
"this",
"->",
"timeConverter",
")",
";",
"}"
] |
Builds a Uuid
@param CodecInterface $codec The codec to use for building this Uuid
@param array $fields An array of fields from which to construct the Uuid;
see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure.
@return Uuid
|
[
"Builds",
"a",
"Uuid"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Builder/DefaultUuidBuilder.php#L60-L63
|
train
|
ramsey/uuid
|
src/Generator/CombGenerator.php
|
CombGenerator.generate
|
public function generate($length)
{
if ($length < self::TIMESTAMP_BYTES || $length < 0) {
throw new \InvalidArgumentException('Length must be a positive integer.');
}
$hash = '';
if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) {
$hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES);
}
$lsbTime = str_pad($this->converter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT);
return hex2bin(str_pad(bin2hex($hash), $length - self::TIMESTAMP_BYTES, '0') . $lsbTime);
}
|
php
|
public function generate($length)
{
if ($length < self::TIMESTAMP_BYTES || $length < 0) {
throw new \InvalidArgumentException('Length must be a positive integer.');
}
$hash = '';
if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) {
$hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES);
}
$lsbTime = str_pad($this->converter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT);
return hex2bin(str_pad(bin2hex($hash), $length - self::TIMESTAMP_BYTES, '0') . $lsbTime);
}
|
[
"public",
"function",
"generate",
"(",
"$",
"length",
")",
"{",
"if",
"(",
"$",
"length",
"<",
"self",
"::",
"TIMESTAMP_BYTES",
"||",
"$",
"length",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Length must be a positive integer.'",
")",
";",
"}",
"$",
"hash",
"=",
"''",
";",
"if",
"(",
"self",
"::",
"TIMESTAMP_BYTES",
">",
"0",
"&&",
"$",
"length",
">",
"self",
"::",
"TIMESTAMP_BYTES",
")",
"{",
"$",
"hash",
"=",
"$",
"this",
"->",
"randomGenerator",
"->",
"generate",
"(",
"$",
"length",
"-",
"self",
"::",
"TIMESTAMP_BYTES",
")",
";",
"}",
"$",
"lsbTime",
"=",
"str_pad",
"(",
"$",
"this",
"->",
"converter",
"->",
"toHex",
"(",
"$",
"this",
"->",
"timestamp",
"(",
")",
")",
",",
"self",
"::",
"TIMESTAMP_BYTES",
"*",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"return",
"hex2bin",
"(",
"str_pad",
"(",
"bin2hex",
"(",
"$",
"hash",
")",
",",
"$",
"length",
"-",
"self",
"::",
"TIMESTAMP_BYTES",
",",
"'0'",
")",
".",
"$",
"lsbTime",
")",
";",
"}"
] |
Generates a string of binary data of the specified length
@param integer $length The number of bytes of random binary data to generate
@return string A binary string
@throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
@throws \InvalidArgumentException if length is not a positive integer
@throws \Exception
|
[
"Generates",
"a",
"string",
"of",
"binary",
"data",
"of",
"the",
"specified",
"length"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Generator/CombGenerator.php#L60-L75
|
train
|
ramsey/uuid
|
src/Converter/Number/BigNumberConverter.php
|
BigNumberConverter.toHex
|
public function toHex($integer)
{
if (!$integer instanceof BigNumber) {
$integer = new BigNumber($integer);
}
return BigNumber::convertFromBase10($integer, 16);
}
|
php
|
public function toHex($integer)
{
if (!$integer instanceof BigNumber) {
$integer = new BigNumber($integer);
}
return BigNumber::convertFromBase10($integer, 16);
}
|
[
"public",
"function",
"toHex",
"(",
"$",
"integer",
")",
"{",
"if",
"(",
"!",
"$",
"integer",
"instanceof",
"BigNumber",
")",
"{",
"$",
"integer",
"=",
"new",
"BigNumber",
"(",
"$",
"integer",
")",
";",
"}",
"return",
"BigNumber",
"::",
"convertFromBase10",
"(",
"$",
"integer",
",",
"16",
")",
";",
"}"
] |
Converts an integer or `Moontoast\Math\BigNumber` integer representation
into a hexadecimal string representation
@param int|string|BigNumber $integer An integer or `Moontoast\Math\BigNumber`
@return string Hexadecimal string
|
[
"Converts",
"an",
"integer",
"or",
"Moontoast",
"\\",
"Math",
"\\",
"BigNumber",
"integer",
"representation",
"into",
"a",
"hexadecimal",
"string",
"representation"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Converter/Number/BigNumberConverter.php#L46-L53
|
train
|
ramsey/uuid
|
src/Uuid.php
|
Uuid.unserialize
|
public function unserialize($serialized)
{
/** @var \Ramsey\Uuid\Uuid $uuid */
$uuid = self::fromString($serialized);
$this->codec = $uuid->codec;
$this->numberConverter = $uuid->getNumberConverter();
$this->fields = $uuid->fields;
}
|
php
|
public function unserialize($serialized)
{
/** @var \Ramsey\Uuid\Uuid $uuid */
$uuid = self::fromString($serialized);
$this->codec = $uuid->codec;
$this->numberConverter = $uuid->getNumberConverter();
$this->fields = $uuid->fields;
}
|
[
"public",
"function",
"unserialize",
"(",
"$",
"serialized",
")",
"{",
"/** @var \\Ramsey\\Uuid\\Uuid $uuid */",
"$",
"uuid",
"=",
"self",
"::",
"fromString",
"(",
"$",
"serialized",
")",
";",
"$",
"this",
"->",
"codec",
"=",
"$",
"uuid",
"->",
"codec",
";",
"$",
"this",
"->",
"numberConverter",
"=",
"$",
"uuid",
"->",
"getNumberConverter",
"(",
")",
";",
"$",
"this",
"->",
"fields",
"=",
"$",
"uuid",
"->",
"fields",
";",
"}"
] |
Re-constructs the object from its serialized form.
@param string $serialized
@link http://php.net/manual/en/class.serializable.php
@throws \Ramsey\Uuid\Exception\InvalidUuidStringException
|
[
"Re",
"-",
"constructs",
"the",
"object",
"from",
"its",
"serialized",
"form",
"."
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Uuid.php#L240-L247
|
train
|
ramsey/uuid
|
src/Provider/Node/SystemNodeProvider.php
|
SystemNodeProvider.getIfconfig
|
protected function getIfconfig()
{
if (strpos(strtolower(ini_get('disable_functions')), 'passthru') !== false) {
return '';
}
ob_start();
switch (strtoupper(substr(php_uname('a'), 0, 3))) {
case 'WIN':
passthru('ipconfig /all 2>&1');
break;
case 'DAR':
passthru('ifconfig 2>&1');
break;
case 'FRE':
passthru('netstat -i -f link 2>&1');
break;
case 'LIN':
default:
passthru('netstat -ie 2>&1');
break;
}
return ob_get_clean();
}
|
php
|
protected function getIfconfig()
{
if (strpos(strtolower(ini_get('disable_functions')), 'passthru') !== false) {
return '';
}
ob_start();
switch (strtoupper(substr(php_uname('a'), 0, 3))) {
case 'WIN':
passthru('ipconfig /all 2>&1');
break;
case 'DAR':
passthru('ifconfig 2>&1');
break;
case 'FRE':
passthru('netstat -i -f link 2>&1');
break;
case 'LIN':
default:
passthru('netstat -ie 2>&1');
break;
}
return ob_get_clean();
}
|
[
"protected",
"function",
"getIfconfig",
"(",
")",
"{",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"ini_get",
"(",
"'disable_functions'",
")",
")",
",",
"'passthru'",
")",
"!==",
"false",
")",
"{",
"return",
"''",
";",
"}",
"ob_start",
"(",
")",
";",
"switch",
"(",
"strtoupper",
"(",
"substr",
"(",
"php_uname",
"(",
"'a'",
")",
",",
"0",
",",
"3",
")",
")",
")",
"{",
"case",
"'WIN'",
":",
"passthru",
"(",
"'ipconfig /all 2>&1'",
")",
";",
"break",
";",
"case",
"'DAR'",
":",
"passthru",
"(",
"'ifconfig 2>&1'",
")",
";",
"break",
";",
"case",
"'FRE'",
":",
"passthru",
"(",
"'netstat -i -f link 2>&1'",
")",
";",
"break",
";",
"case",
"'LIN'",
":",
"default",
":",
"passthru",
"(",
"'netstat -ie 2>&1'",
")",
";",
"break",
";",
"}",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] |
Returns the network interface configuration for the system
@codeCoverageIgnore
@return string
|
[
"Returns",
"the",
"network",
"interface",
"configuration",
"for",
"the",
"system"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Provider/Node/SystemNodeProvider.php#L63-L87
|
train
|
ramsey/uuid
|
src/Provider/Node/SystemNodeProvider.php
|
SystemNodeProvider.getSysfs
|
protected function getSysfs()
{
$mac = false;
if (strtoupper(php_uname('s')) === 'LINUX') {
$addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT);
if (empty($addressPaths)) {
return false;
}
array_walk($addressPaths, function ($addressPath) use (&$macs) {
$macs[] = file_get_contents($addressPath);
});
$macs = array_map('trim', $macs);
// remove invalid entries
$macs = array_filter($macs, function ($mac) {
return
// localhost adapter
$mac !== '00:00:00:00:00:00' &&
// must match mac adress
preg_match('/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i', $mac);
});
$mac = reset($macs);
}
return $mac;
}
|
php
|
protected function getSysfs()
{
$mac = false;
if (strtoupper(php_uname('s')) === 'LINUX') {
$addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT);
if (empty($addressPaths)) {
return false;
}
array_walk($addressPaths, function ($addressPath) use (&$macs) {
$macs[] = file_get_contents($addressPath);
});
$macs = array_map('trim', $macs);
// remove invalid entries
$macs = array_filter($macs, function ($mac) {
return
// localhost adapter
$mac !== '00:00:00:00:00:00' &&
// must match mac adress
preg_match('/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i', $mac);
});
$mac = reset($macs);
}
return $mac;
}
|
[
"protected",
"function",
"getSysfs",
"(",
")",
"{",
"$",
"mac",
"=",
"false",
";",
"if",
"(",
"strtoupper",
"(",
"php_uname",
"(",
"'s'",
")",
")",
"===",
"'LINUX'",
")",
"{",
"$",
"addressPaths",
"=",
"glob",
"(",
"'/sys/class/net/*/address'",
",",
"GLOB_NOSORT",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"addressPaths",
")",
")",
"{",
"return",
"false",
";",
"}",
"array_walk",
"(",
"$",
"addressPaths",
",",
"function",
"(",
"$",
"addressPath",
")",
"use",
"(",
"&",
"$",
"macs",
")",
"{",
"$",
"macs",
"[",
"]",
"=",
"file_get_contents",
"(",
"$",
"addressPath",
")",
";",
"}",
")",
";",
"$",
"macs",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"macs",
")",
";",
"// remove invalid entries",
"$",
"macs",
"=",
"array_filter",
"(",
"$",
"macs",
",",
"function",
"(",
"$",
"mac",
")",
"{",
"return",
"// localhost adapter",
"$",
"mac",
"!==",
"'00:00:00:00:00:00'",
"&&",
"// must match mac adress",
"preg_match",
"(",
"'/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i'",
",",
"$",
"mac",
")",
";",
"}",
")",
";",
"$",
"mac",
"=",
"reset",
"(",
"$",
"macs",
")",
";",
"}",
"return",
"$",
"mac",
";",
"}"
] |
Returns mac address from the first system interface via the sysfs interface
@return string|bool
|
[
"Returns",
"mac",
"address",
"from",
"the",
"first",
"system",
"interface",
"via",
"the",
"sysfs",
"interface"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Provider/Node/SystemNodeProvider.php#L94-L124
|
train
|
ramsey/uuid
|
src/FeatureSet.php
|
FeatureSet.buildCodec
|
protected function buildCodec($useGuids = false)
{
if ($useGuids) {
return new GuidStringCodec($this->builder);
}
return new StringCodec($this->builder);
}
|
php
|
protected function buildCodec($useGuids = false)
{
if ($useGuids) {
return new GuidStringCodec($this->builder);
}
return new StringCodec($this->builder);
}
|
[
"protected",
"function",
"buildCodec",
"(",
"$",
"useGuids",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"useGuids",
")",
"{",
"return",
"new",
"GuidStringCodec",
"(",
"$",
"this",
"->",
"builder",
")",
";",
"}",
"return",
"new",
"StringCodec",
"(",
"$",
"this",
"->",
"builder",
")",
";",
"}"
] |
Determines which UUID coder-decoder to use and returns the configured
codec for this environment
@param bool $useGuids Whether to build UUIDs using the `GuidStringCodec`
@return CodecInterface
|
[
"Determines",
"which",
"UUID",
"coder",
"-",
"decoder",
"to",
"use",
"and",
"returns",
"the",
"configured",
"codec",
"for",
"this",
"environment"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/FeatureSet.php#L254-L261
|
train
|
ramsey/uuid
|
src/FeatureSet.php
|
FeatureSet.buildTimeGenerator
|
protected function buildTimeGenerator(TimeProviderInterface $timeProvider)
{
if ($this->enablePecl) {
return new PeclUuidTimeGenerator();
}
return (new TimeGeneratorFactory(
$this->nodeProvider,
$this->timeConverter,
$timeProvider
))->getGenerator();
}
|
php
|
protected function buildTimeGenerator(TimeProviderInterface $timeProvider)
{
if ($this->enablePecl) {
return new PeclUuidTimeGenerator();
}
return (new TimeGeneratorFactory(
$this->nodeProvider,
$this->timeConverter,
$timeProvider
))->getGenerator();
}
|
[
"protected",
"function",
"buildTimeGenerator",
"(",
"TimeProviderInterface",
"$",
"timeProvider",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enablePecl",
")",
"{",
"return",
"new",
"PeclUuidTimeGenerator",
"(",
")",
";",
"}",
"return",
"(",
"new",
"TimeGeneratorFactory",
"(",
"$",
"this",
"->",
"nodeProvider",
",",
"$",
"this",
"->",
"timeConverter",
",",
"$",
"timeProvider",
")",
")",
"->",
"getGenerator",
"(",
")",
";",
"}"
] |
Determines which time-based UUID generator to use and returns the configured
time-based UUID generator for this environment
@param TimeProviderInterface $timeProvider
@return TimeGeneratorInterface
|
[
"Determines",
"which",
"time",
"-",
"based",
"UUID",
"generator",
"to",
"use",
"and",
"returns",
"the",
"configured",
"time",
"-",
"based",
"UUID",
"generator",
"for",
"this",
"environment"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/FeatureSet.php#L316-L327
|
train
|
ramsey/uuid
|
src/FeatureSet.php
|
FeatureSet.buildTimeConverter
|
protected function buildTimeConverter()
{
if ($this->is64BitSystem()) {
return new PhpTimeConverter();
} elseif ($this->hasGmp()) {
return new GmpTimeConverter();
} elseif ($this->hasBigNumber()) {
return new BigNumberTimeConverter();
}
return new DegradedTimeConverter();
}
|
php
|
protected function buildTimeConverter()
{
if ($this->is64BitSystem()) {
return new PhpTimeConverter();
} elseif ($this->hasGmp()) {
return new GmpTimeConverter();
} elseif ($this->hasBigNumber()) {
return new BigNumberTimeConverter();
}
return new DegradedTimeConverter();
}
|
[
"protected",
"function",
"buildTimeConverter",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is64BitSystem",
"(",
")",
")",
"{",
"return",
"new",
"PhpTimeConverter",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"hasGmp",
"(",
")",
")",
"{",
"return",
"new",
"GmpTimeConverter",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"hasBigNumber",
"(",
")",
")",
"{",
"return",
"new",
"BigNumberTimeConverter",
"(",
")",
";",
"}",
"return",
"new",
"DegradedTimeConverter",
"(",
")",
";",
"}"
] |
Determines which time converter to use and returns the configured
time converter for this environment
@return \Ramsey\Uuid\Converter\TimeConverterInterface
|
[
"Determines",
"which",
"time",
"converter",
"to",
"use",
"and",
"returns",
"the",
"configured",
"time",
"converter",
"for",
"this",
"environment"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/FeatureSet.php#L335-L346
|
train
|
ramsey/uuid
|
src/FeatureSet.php
|
FeatureSet.buildUuidBuilder
|
protected function buildUuidBuilder()
{
if ($this->is64BitSystem()) {
return new DefaultUuidBuilder($this->numberConverter, $this->timeConverter);
}
return new DegradedUuidBuilder($this->numberConverter, $this->timeConverter);
}
|
php
|
protected function buildUuidBuilder()
{
if ($this->is64BitSystem()) {
return new DefaultUuidBuilder($this->numberConverter, $this->timeConverter);
}
return new DegradedUuidBuilder($this->numberConverter, $this->timeConverter);
}
|
[
"protected",
"function",
"buildUuidBuilder",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is64BitSystem",
"(",
")",
")",
"{",
"return",
"new",
"DefaultUuidBuilder",
"(",
"$",
"this",
"->",
"numberConverter",
",",
"$",
"this",
"->",
"timeConverter",
")",
";",
"}",
"return",
"new",
"DegradedUuidBuilder",
"(",
"$",
"this",
"->",
"numberConverter",
",",
"$",
"this",
"->",
"timeConverter",
")",
";",
"}"
] |
Determines which UUID builder to use and returns the configured UUID
builder for this environment
@return UuidBuilderInterface
|
[
"Determines",
"which",
"UUID",
"builder",
"to",
"use",
"and",
"returns",
"the",
"configured",
"UUID",
"builder",
"for",
"this",
"environment"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/FeatureSet.php#L354-L361
|
train
|
ramsey/uuid
|
src/Validator/Validator.php
|
Validator.validate
|
public function validate($uuid)
{
$uuid = str_replace(['urn:', 'uuid:', '{', '}'], '', $uuid);
if ($uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/D', $uuid)) {
return true;
}
return false;
}
|
php
|
public function validate($uuid)
{
$uuid = str_replace(['urn:', 'uuid:', '{', '}'], '', $uuid);
if ($uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/D', $uuid)) {
return true;
}
return false;
}
|
[
"public",
"function",
"validate",
"(",
"$",
"uuid",
")",
"{",
"$",
"uuid",
"=",
"str_replace",
"(",
"[",
"'urn:'",
",",
"'uuid:'",
",",
"'{'",
",",
"'}'",
"]",
",",
"''",
",",
"$",
"uuid",
")",
";",
"if",
"(",
"$",
"uuid",
"===",
"Uuid",
"::",
"NIL",
"||",
"preg_match",
"(",
"'/'",
".",
"self",
"::",
"VALID_PATTERN",
".",
"'/D'",
",",
"$",
"uuid",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Validate that a string represents a UUID
@param string $uuid
@return bool Returns TRUE if the string was validated as a valid UUID or FALSE on failure
|
[
"Validate",
"that",
"a",
"string",
"represents",
"a",
"UUID"
] |
f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7
|
https://github.com/ramsey/uuid/blob/f30bc1af81b1fdf5dec5ae085eb3ac2c59c32fe7/src/Validator/Validator.php#L36-L45
|
train
|
pinguo/php-msf
|
src/Pools/Miner.php
|
Miner.columnQuote
|
public function columnQuote($column)
{
if (empty($column)) {
return null;
}
preg_match('/^(?:(?<table>\w+)\.)?(?<column>\w+)$/iu', $column, $match);
if (isset($match['table'], $match['column'])) {
$table = $this->tableQuote($match['table']);
$match['column'] = str_replace('`', '', $match['column']);
$column = $this->escapes ? "`{$match['column']}`" : "{$match['column']}";
return $table ? $table . '.' . $column : $column;
}
return $column;
}
|
php
|
public function columnQuote($column)
{
if (empty($column)) {
return null;
}
preg_match('/^(?:(?<table>\w+)\.)?(?<column>\w+)$/iu', $column, $match);
if (isset($match['table'], $match['column'])) {
$table = $this->tableQuote($match['table']);
$match['column'] = str_replace('`', '', $match['column']);
$column = $this->escapes ? "`{$match['column']}`" : "{$match['column']}";
return $table ? $table . '.' . $column : $column;
}
return $column;
}
|
[
"public",
"function",
"columnQuote",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"column",
")",
")",
"{",
"return",
"null",
";",
"}",
"preg_match",
"(",
"'/^(?:(?<table>\\w+)\\.)?(?<column>\\w+)$/iu'",
",",
"$",
"column",
",",
"$",
"match",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'table'",
"]",
",",
"$",
"match",
"[",
"'column'",
"]",
")",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"tableQuote",
"(",
"$",
"match",
"[",
"'table'",
"]",
")",
";",
"$",
"match",
"[",
"'column'",
"]",
"=",
"str_replace",
"(",
"'`'",
",",
"''",
",",
"$",
"match",
"[",
"'column'",
"]",
")",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"escapes",
"?",
"\"`{$match['column']}`\"",
":",
"\"{$match['column']}\"",
";",
"return",
"$",
"table",
"?",
"$",
"table",
".",
"'.'",
".",
"$",
"column",
":",
"$",
"column",
";",
"}",
"return",
"$",
"column",
";",
"}"
] |
Quotes a column name for use in a query.
@param string $column
The column name.
@return string
|
[
"Quotes",
"a",
"column",
"name",
"for",
"use",
"in",
"a",
"query",
"."
] |
2a193c53da996c260e8aace9affa12fc2b9c08a6
|
https://github.com/pinguo/php-msf/blob/2a193c53da996c260e8aace9affa12fc2b9c08a6/src/Pools/Miner.php#L393-L406
|
train
|
pinguo/php-msf
|
src/Pools/Miner.php
|
Miner.set
|
public function set($column, $value = null, $quote = null)
{
if (is_array($column)) {
foreach ($column as $columnName => $columnValue) {
$this->set($columnName, $columnValue, $quote);
}
} else {
$this->set[] = array(
'column' => $this->columnQuote($column),
'value' => $value,
'quote' => $quote
);
}
return $this;
}
|
php
|
public function set($column, $value = null, $quote = null)
{
if (is_array($column)) {
foreach ($column as $columnName => $columnValue) {
$this->set($columnName, $columnValue, $quote);
}
} else {
$this->set[] = array(
'column' => $this->columnQuote($column),
'value' => $value,
'quote' => $quote
);
}
return $this;
}
|
[
"public",
"function",
"set",
"(",
"$",
"column",
",",
"$",
"value",
"=",
"null",
",",
"$",
"quote",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"foreach",
"(",
"$",
"column",
"as",
"$",
"columnName",
"=>",
"$",
"columnValue",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"columnName",
",",
"$",
"columnValue",
",",
"$",
"quote",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"set",
"[",
"]",
"=",
"array",
"(",
"'column'",
"=>",
"$",
"this",
"->",
"columnQuote",
"(",
"$",
"column",
")",
",",
"'value'",
"=>",
"$",
"value",
",",
"'quote'",
"=>",
"$",
"quote",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add one or more column values to INSERT, UPDATE, or REPLACE.
@param string|array $column
column name or array of columns => values
@param mixed|null $value
optional value for single column
@param bool|null $quote
optional auto-escape value, default to global
@return Miner
|
[
"Add",
"one",
"or",
"more",
"column",
"values",
"to",
"INSERT",
"UPDATE",
"or",
"REPLACE",
"."
] |
2a193c53da996c260e8aace9affa12fc2b9c08a6
|
https://github.com/pinguo/php-msf/blob/2a193c53da996c260e8aace9affa12fc2b9c08a6/src/Pools/Miner.php#L468-L483
|
train
|
pinguo/php-msf
|
src/Pools/Miner.php
|
Miner.criteria
|
private function criteria(array &$criteria, $column, $value, $operator = self::EQUALS, $connector = self::LOGICAL_AND, $quote = null)
{
$criteria[] = array(
'column' => $this->columnQuote($column),
'value' => $value,
'operator' => $operator,
'connector' => $connector,
'quote' => $quote
);
return $this;
}
|
php
|
private function criteria(array &$criteria, $column, $value, $operator = self::EQUALS, $connector = self::LOGICAL_AND, $quote = null)
{
$criteria[] = array(
'column' => $this->columnQuote($column),
'value' => $value,
'operator' => $operator,
'connector' => $connector,
'quote' => $quote
);
return $this;
}
|
[
"private",
"function",
"criteria",
"(",
"array",
"&",
"$",
"criteria",
",",
"$",
"column",
",",
"$",
"value",
",",
"$",
"operator",
"=",
"self",
"::",
"EQUALS",
",",
"$",
"connector",
"=",
"self",
"::",
"LOGICAL_AND",
",",
"$",
"quote",
"=",
"null",
")",
"{",
"$",
"criteria",
"[",
"]",
"=",
"array",
"(",
"'column'",
"=>",
"$",
"this",
"->",
"columnQuote",
"(",
"$",
"column",
")",
",",
"'value'",
"=>",
"$",
"value",
",",
"'operator'",
"=>",
"$",
"operator",
",",
"'connector'",
"=>",
"$",
"connector",
",",
"'quote'",
"=>",
"$",
"quote",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a condition to the specified WHERE or HAVING criteria.
@param array $criteria
WHERE or HAVING criteria
@param string $column
column name
@param mixed $value
value
@param string $operator
optional comparison operator, default =
@param string $connector
optional logical connector, default AND
@param bool|null $quote
optional auto-escape value, default to global
@return Miner
|
[
"Add",
"a",
"condition",
"to",
"the",
"specified",
"WHERE",
"or",
"HAVING",
"criteria",
"."
] |
2a193c53da996c260e8aace9affa12fc2b9c08a6
|
https://github.com/pinguo/php-msf/blob/2a193c53da996c260e8aace9affa12fc2b9c08a6/src/Pools/Miner.php#L652-L663
|
train
|
pinguo/php-msf
|
src/Pools/Miner.php
|
Miner.orHaving
|
public function orHaving($column, $value, $operator = self::EQUALS, $quote = null)
{
return $this->orCriteria($this->having, $column, $value, $operator, self::LOGICAL_OR, $quote);
}
|
php
|
public function orHaving($column, $value, $operator = self::EQUALS, $quote = null)
{
return $this->orCriteria($this->having, $column, $value, $operator, self::LOGICAL_OR, $quote);
}
|
[
"public",
"function",
"orHaving",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"operator",
"=",
"self",
"::",
"EQUALS",
",",
"$",
"quote",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"orCriteria",
"(",
"$",
"this",
"->",
"having",
",",
"$",
"column",
",",
"$",
"value",
",",
"$",
"operator",
",",
"self",
"::",
"LOGICAL_OR",
",",
"$",
"quote",
")",
";",
"}"
] |
Add an OR HAVING condition.
@param string $column
colum name
@param mixed $value
value
@param string $operator
optional comparison operator, default =
@param bool|null $quote
optional auto-escape value, default to global
@return Miner
|
[
"Add",
"an",
"OR",
"HAVING",
"condition",
"."
] |
2a193c53da996c260e8aace9affa12fc2b9c08a6
|
https://github.com/pinguo/php-msf/blob/2a193c53da996c260e8aace9affa12fc2b9c08a6/src/Pools/Miner.php#L900-L903
|
train
|
pinguo/php-msf
|
src/Pools/Miner.php
|
Miner.getJoinString
|
public function getJoinString()
{
$statement = "";
foreach ($this->join as $i => $join) {
$statement .= " " . $join['type'] . " " . $join['table'];
if ($join['alias']) {
$statement .= " AS " . $join['alias'];
}
// Add ON criteria if specified.
if ($join['criteria']) {
$statement .= " ON ";
foreach ($join['criteria'] as $x => $criterion) {
// Logically join each criterion with AND.
if ($x != 0) {
$statement .= " " . self::LOGICAL_AND . " ";
}
// If the criterion does not include an equals sign, assume a
// column name and join against the same column from the previous
// table.
if (strpos($criterion, '=') === false) {
$statement .= $this->getJoinCriteriaUsingPreviousTable($i, $join['table'], $criterion);
} else {
$statement .= $criterion;
}
}
}
}
$statement = trim($statement);
return $statement;
}
|
php
|
public function getJoinString()
{
$statement = "";
foreach ($this->join as $i => $join) {
$statement .= " " . $join['type'] . " " . $join['table'];
if ($join['alias']) {
$statement .= " AS " . $join['alias'];
}
// Add ON criteria if specified.
if ($join['criteria']) {
$statement .= " ON ";
foreach ($join['criteria'] as $x => $criterion) {
// Logically join each criterion with AND.
if ($x != 0) {
$statement .= " " . self::LOGICAL_AND . " ";
}
// If the criterion does not include an equals sign, assume a
// column name and join against the same column from the previous
// table.
if (strpos($criterion, '=') === false) {
$statement .= $this->getJoinCriteriaUsingPreviousTable($i, $join['table'], $criterion);
} else {
$statement .= $criterion;
}
}
}
}
$statement = trim($statement);
return $statement;
}
|
[
"public",
"function",
"getJoinString",
"(",
")",
"{",
"$",
"statement",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"join",
"as",
"$",
"i",
"=>",
"$",
"join",
")",
"{",
"$",
"statement",
".=",
"\" \"",
".",
"$",
"join",
"[",
"'type'",
"]",
".",
"\" \"",
".",
"$",
"join",
"[",
"'table'",
"]",
";",
"if",
"(",
"$",
"join",
"[",
"'alias'",
"]",
")",
"{",
"$",
"statement",
".=",
"\" AS \"",
".",
"$",
"join",
"[",
"'alias'",
"]",
";",
"}",
"// Add ON criteria if specified.",
"if",
"(",
"$",
"join",
"[",
"'criteria'",
"]",
")",
"{",
"$",
"statement",
".=",
"\" ON \"",
";",
"foreach",
"(",
"$",
"join",
"[",
"'criteria'",
"]",
"as",
"$",
"x",
"=>",
"$",
"criterion",
")",
"{",
"// Logically join each criterion with AND.",
"if",
"(",
"$",
"x",
"!=",
"0",
")",
"{",
"$",
"statement",
".=",
"\" \"",
".",
"self",
"::",
"LOGICAL_AND",
".",
"\" \"",
";",
"}",
"// If the criterion does not include an equals sign, assume a",
"// column name and join against the same column from the previous",
"// table.",
"if",
"(",
"strpos",
"(",
"$",
"criterion",
",",
"'='",
")",
"===",
"false",
")",
"{",
"$",
"statement",
".=",
"$",
"this",
"->",
"getJoinCriteriaUsingPreviousTable",
"(",
"$",
"i",
",",
"$",
"join",
"[",
"'table'",
"]",
",",
"$",
"criterion",
")",
";",
"}",
"else",
"{",
"$",
"statement",
".=",
"$",
"criterion",
";",
"}",
"}",
"}",
"}",
"$",
"statement",
"=",
"trim",
"(",
"$",
"statement",
")",
";",
"return",
"$",
"statement",
";",
"}"
] |
Get the JOIN portion of the statement as a string.
@return string JOIN portion of the statement
|
[
"Get",
"the",
"JOIN",
"portion",
"of",
"the",
"statement",
"as",
"a",
"string",
"."
] |
2a193c53da996c260e8aace9affa12fc2b9c08a6
|
https://github.com/pinguo/php-msf/blob/2a193c53da996c260e8aace9affa12fc2b9c08a6/src/Pools/Miner.php#L1268-L1304
|
train
|
pinguo/php-msf
|
src/Pools/Miner.php
|
Miner.mergeInto
|
public function mergeInto(Miner $Miner, $overrideLimit = true)
{
if ($this->isSelect()) {
$this->mergeSelectInto($Miner);
$this->mergeFromInto($Miner);
$this->mergeJoinInto($Miner);
$this->mergeWhereInto($Miner);
$this->mergeGroupByInto($Miner);
$this->mergeHavingInto($Miner);
$this->mergeOrderByInto($Miner);
if ($overrideLimit) {
$this->mergeLimitInto($Miner);
}
} elseif ($this->isInsert()) {
$this->mergeInsertInto($Miner);
$this->mergeSetInto($Miner);
} elseif ($this->isReplace()) {
$this->mergeReplaceInto($Miner);
$this->mergeSetInto($Miner);
} elseif ($this->isUpdate()) {
$this->mergeUpdateInto($Miner);
$this->mergeJoinInto($Miner);
$this->mergeSetInto($Miner);
$this->mergeWhereInto($Miner);
// ORDER BY and LIMIT are only applicable when updating a single table.
if (! $this->join) {
$this->mergeOrderByInto($Miner);
if ($overrideLimit) {
$this->mergeLimitInto($Miner);
}
}
} elseif ($this->isDelete()) {
$this->mergeDeleteInto($Miner);
$this->mergeFromInto($Miner);
$this->mergeJoinInto($Miner);
$this->mergeWhereInto($Miner);
// ORDER BY and LIMIT are only applicable when deleting from a single
// table.
if ($this->isDeleteTableFrom()) {
$this->mergeOrderByInto($Miner);
if ($overrideLimit) {
$this->mergeLimitInto($Miner);
}
}
}
return $Miner;
}
|
php
|
public function mergeInto(Miner $Miner, $overrideLimit = true)
{
if ($this->isSelect()) {
$this->mergeSelectInto($Miner);
$this->mergeFromInto($Miner);
$this->mergeJoinInto($Miner);
$this->mergeWhereInto($Miner);
$this->mergeGroupByInto($Miner);
$this->mergeHavingInto($Miner);
$this->mergeOrderByInto($Miner);
if ($overrideLimit) {
$this->mergeLimitInto($Miner);
}
} elseif ($this->isInsert()) {
$this->mergeInsertInto($Miner);
$this->mergeSetInto($Miner);
} elseif ($this->isReplace()) {
$this->mergeReplaceInto($Miner);
$this->mergeSetInto($Miner);
} elseif ($this->isUpdate()) {
$this->mergeUpdateInto($Miner);
$this->mergeJoinInto($Miner);
$this->mergeSetInto($Miner);
$this->mergeWhereInto($Miner);
// ORDER BY and LIMIT are only applicable when updating a single table.
if (! $this->join) {
$this->mergeOrderByInto($Miner);
if ($overrideLimit) {
$this->mergeLimitInto($Miner);
}
}
} elseif ($this->isDelete()) {
$this->mergeDeleteInto($Miner);
$this->mergeFromInto($Miner);
$this->mergeJoinInto($Miner);
$this->mergeWhereInto($Miner);
// ORDER BY and LIMIT are only applicable when deleting from a single
// table.
if ($this->isDeleteTableFrom()) {
$this->mergeOrderByInto($Miner);
if ($overrideLimit) {
$this->mergeLimitInto($Miner);
}
}
}
return $Miner;
}
|
[
"public",
"function",
"mergeInto",
"(",
"Miner",
"$",
"Miner",
",",
"$",
"overrideLimit",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSelect",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mergeSelectInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeFromInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeJoinInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeWhereInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeGroupByInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeHavingInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeOrderByInto",
"(",
"$",
"Miner",
")",
";",
"if",
"(",
"$",
"overrideLimit",
")",
"{",
"$",
"this",
"->",
"mergeLimitInto",
"(",
"$",
"Miner",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isInsert",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mergeInsertInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeSetInto",
"(",
"$",
"Miner",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isReplace",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mergeReplaceInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeSetInto",
"(",
"$",
"Miner",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isUpdate",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mergeUpdateInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeJoinInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeSetInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeWhereInto",
"(",
"$",
"Miner",
")",
";",
"// ORDER BY and LIMIT are only applicable when updating a single table.",
"if",
"(",
"!",
"$",
"this",
"->",
"join",
")",
"{",
"$",
"this",
"->",
"mergeOrderByInto",
"(",
"$",
"Miner",
")",
";",
"if",
"(",
"$",
"overrideLimit",
")",
"{",
"$",
"this",
"->",
"mergeLimitInto",
"(",
"$",
"Miner",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isDelete",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mergeDeleteInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeFromInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeJoinInto",
"(",
"$",
"Miner",
")",
";",
"$",
"this",
"->",
"mergeWhereInto",
"(",
"$",
"Miner",
")",
";",
"// ORDER BY and LIMIT are only applicable when deleting from a single",
"// table.",
"if",
"(",
"$",
"this",
"->",
"isDeleteTableFrom",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mergeOrderByInto",
"(",
"$",
"Miner",
")",
";",
"if",
"(",
"$",
"overrideLimit",
")",
"{",
"$",
"this",
"->",
"mergeLimitInto",
"(",
"$",
"Miner",
")",
";",
"}",
"}",
"}",
"return",
"$",
"Miner",
";",
"}"
] |
Merge this Miner into the given Miner.
@param Miner $Miner
to merge into
@param bool $overrideLimit
optional override limit, default true
@return Miner
|
[
"Merge",
"this",
"Miner",
"into",
"the",
"given",
"Miner",
"."
] |
2a193c53da996c260e8aace9affa12fc2b9c08a6
|
https://github.com/pinguo/php-msf/blob/2a193c53da996c260e8aace9affa12fc2b9c08a6/src/Pools/Miner.php#L2135-L2187
|
train
|
DarkaOnLine/L5-Swagger
|
src/Generator.php
|
Generator.prepareDirectory
|
protected function prepareDirectory()
{
if (File::exists($this->docDir) && ! is_writable($this->docDir)) {
throw new L5SwaggerException('Documentation storage directory is not writable');
}
// delete all existing documentation
if (File::exists($this->docDir)) {
File::deleteDirectory($this->docDir);
}
File::makeDirectory($this->docDir);
return $this;
}
|
php
|
protected function prepareDirectory()
{
if (File::exists($this->docDir) && ! is_writable($this->docDir)) {
throw new L5SwaggerException('Documentation storage directory is not writable');
}
// delete all existing documentation
if (File::exists($this->docDir)) {
File::deleteDirectory($this->docDir);
}
File::makeDirectory($this->docDir);
return $this;
}
|
[
"protected",
"function",
"prepareDirectory",
"(",
")",
"{",
"if",
"(",
"File",
"::",
"exists",
"(",
"$",
"this",
"->",
"docDir",
")",
"&&",
"!",
"is_writable",
"(",
"$",
"this",
"->",
"docDir",
")",
")",
"{",
"throw",
"new",
"L5SwaggerException",
"(",
"'Documentation storage directory is not writable'",
")",
";",
"}",
"// delete all existing documentation",
"if",
"(",
"File",
"::",
"exists",
"(",
"$",
"this",
"->",
"docDir",
")",
")",
"{",
"File",
"::",
"deleteDirectory",
"(",
"$",
"this",
"->",
"docDir",
")",
";",
"}",
"File",
"::",
"makeDirectory",
"(",
"$",
"this",
"->",
"docDir",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Check directory structure and permissions.
@return Generator
|
[
"Check",
"directory",
"structure",
"and",
"permissions",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/Generator.php#L77-L91
|
train
|
DarkaOnLine/L5-Swagger
|
src/Generator.php
|
Generator.defineConstants
|
protected function defineConstants()
{
if (! empty($this->constants)) {
foreach ($this->constants as $key => $value) {
defined($key) || define($key, $value);
}
}
return $this;
}
|
php
|
protected function defineConstants()
{
if (! empty($this->constants)) {
foreach ($this->constants as $key => $value) {
defined($key) || define($key, $value);
}
}
return $this;
}
|
[
"protected",
"function",
"defineConstants",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"constants",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"constants",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"defined",
"(",
"$",
"key",
")",
"||",
"define",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Define constant which will be replaced.
@return Generator
|
[
"Define",
"constant",
"which",
"will",
"be",
"replaced",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/Generator.php#L98-L107
|
train
|
DarkaOnLine/L5-Swagger
|
src/Generator.php
|
Generator.scanFilesForDocumentation
|
protected function scanFilesForDocumentation()
{
if ($this->isOpenApi()) {
$this->swagger = \OpenApi\scan(
$this->appDir,
['exclude' => $this->excludedDirs]
);
}
if (! $this->isOpenApi()) {
$this->swagger = \Swagger\scan(
$this->appDir,
['exclude' => $this->excludedDirs]
);
}
return $this;
}
|
php
|
protected function scanFilesForDocumentation()
{
if ($this->isOpenApi()) {
$this->swagger = \OpenApi\scan(
$this->appDir,
['exclude' => $this->excludedDirs]
);
}
if (! $this->isOpenApi()) {
$this->swagger = \Swagger\scan(
$this->appDir,
['exclude' => $this->excludedDirs]
);
}
return $this;
}
|
[
"protected",
"function",
"scanFilesForDocumentation",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOpenApi",
"(",
")",
")",
"{",
"$",
"this",
"->",
"swagger",
"=",
"\\",
"OpenApi",
"\\",
"scan",
"(",
"$",
"this",
"->",
"appDir",
",",
"[",
"'exclude'",
"=>",
"$",
"this",
"->",
"excludedDirs",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isOpenApi",
"(",
")",
")",
"{",
"$",
"this",
"->",
"swagger",
"=",
"\\",
"Swagger",
"\\",
"scan",
"(",
"$",
"this",
"->",
"appDir",
",",
"[",
"'exclude'",
"=>",
"$",
"this",
"->",
"excludedDirs",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Scan directory and create Swagger.
@return Generator
|
[
"Scan",
"directory",
"and",
"create",
"Swagger",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/Generator.php#L114-L131
|
train
|
DarkaOnLine/L5-Swagger
|
src/Generator.php
|
Generator.populateServers
|
protected function populateServers()
{
if (config('l5-swagger.paths.base') !== null) {
if ($this->isOpenApi()) {
$this->swagger->servers = [
new \OpenApi\Annotations\Server(['url' => config('l5-swagger.paths.base')]),
];
}
if (! $this->isOpenApi()) {
$this->swagger->basePath = config('l5-swagger.paths.base');
}
}
return $this;
}
|
php
|
protected function populateServers()
{
if (config('l5-swagger.paths.base') !== null) {
if ($this->isOpenApi()) {
$this->swagger->servers = [
new \OpenApi\Annotations\Server(['url' => config('l5-swagger.paths.base')]),
];
}
if (! $this->isOpenApi()) {
$this->swagger->basePath = config('l5-swagger.paths.base');
}
}
return $this;
}
|
[
"protected",
"function",
"populateServers",
"(",
")",
"{",
"if",
"(",
"config",
"(",
"'l5-swagger.paths.base'",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOpenApi",
"(",
")",
")",
"{",
"$",
"this",
"->",
"swagger",
"->",
"servers",
"=",
"[",
"new",
"\\",
"OpenApi",
"\\",
"Annotations",
"\\",
"Server",
"(",
"[",
"'url'",
"=>",
"config",
"(",
"'l5-swagger.paths.base'",
")",
"]",
")",
",",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isOpenApi",
"(",
")",
")",
"{",
"$",
"this",
"->",
"swagger",
"->",
"basePath",
"=",
"config",
"(",
"'l5-swagger.paths.base'",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Generate servers section or basePath depending on Swagger version.
@return Generator
|
[
"Generate",
"servers",
"section",
"or",
"basePath",
"depending",
"on",
"Swagger",
"version",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/Generator.php#L138-L153
|
train
|
DarkaOnLine/L5-Swagger
|
src/Generator.php
|
Generator.saveJson
|
protected function saveJson()
{
$this->swagger->saveAs($this->docsFile);
$security = new SecurityDefinitions();
$security->generate($this->docsFile);
return $this;
}
|
php
|
protected function saveJson()
{
$this->swagger->saveAs($this->docsFile);
$security = new SecurityDefinitions();
$security->generate($this->docsFile);
return $this;
}
|
[
"protected",
"function",
"saveJson",
"(",
")",
"{",
"$",
"this",
"->",
"swagger",
"->",
"saveAs",
"(",
"$",
"this",
"->",
"docsFile",
")",
";",
"$",
"security",
"=",
"new",
"SecurityDefinitions",
"(",
")",
";",
"$",
"security",
"->",
"generate",
"(",
"$",
"this",
"->",
"docsFile",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Save documentation as json file.
@return Generator
|
[
"Save",
"documentation",
"as",
"json",
"file",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/Generator.php#L160-L168
|
train
|
DarkaOnLine/L5-Swagger
|
src/Generator.php
|
Generator.makeYamlCopy
|
protected function makeYamlCopy()
{
if ($this->yamlCopyRequired) {
file_put_contents(
$this->yamlDocsFile,
(new YamlDumper(2))->dump(json_decode(file_get_contents($this->docsFile), true), 20)
);
}
}
|
php
|
protected function makeYamlCopy()
{
if ($this->yamlCopyRequired) {
file_put_contents(
$this->yamlDocsFile,
(new YamlDumper(2))->dump(json_decode(file_get_contents($this->docsFile), true), 20)
);
}
}
|
[
"protected",
"function",
"makeYamlCopy",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"yamlCopyRequired",
")",
"{",
"file_put_contents",
"(",
"$",
"this",
"->",
"yamlDocsFile",
",",
"(",
"new",
"YamlDumper",
"(",
"2",
")",
")",
"->",
"dump",
"(",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"docsFile",
")",
",",
"true",
")",
",",
"20",
")",
")",
";",
"}",
"}"
] |
Save documentation as yaml file.
@return Generator
|
[
"Save",
"documentation",
"as",
"yaml",
"file",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/Generator.php#L175-L183
|
train
|
DarkaOnLine/L5-Swagger
|
src/SecurityDefinitions.php
|
SecurityDefinitions.generateSwaggerApi
|
public function generateSwaggerApi(Collection $documentation, array $securityConfig)
{
$securityDefinitions = collect();
if ($documentation->has('securityDefinitions')) {
$securityDefinitions = collect($documentation->get('securityDefinitions'));
}
foreach ($securityConfig as $key => $cfg) {
$securityDefinitions->offsetSet($key, self::arrayToObject($cfg));
}
$documentation->offsetSet('securityDefinitions', $securityDefinitions);
return $documentation;
}
|
php
|
public function generateSwaggerApi(Collection $documentation, array $securityConfig)
{
$securityDefinitions = collect();
if ($documentation->has('securityDefinitions')) {
$securityDefinitions = collect($documentation->get('securityDefinitions'));
}
foreach ($securityConfig as $key => $cfg) {
$securityDefinitions->offsetSet($key, self::arrayToObject($cfg));
}
$documentation->offsetSet('securityDefinitions', $securityDefinitions);
return $documentation;
}
|
[
"public",
"function",
"generateSwaggerApi",
"(",
"Collection",
"$",
"documentation",
",",
"array",
"$",
"securityConfig",
")",
"{",
"$",
"securityDefinitions",
"=",
"collect",
"(",
")",
";",
"if",
"(",
"$",
"documentation",
"->",
"has",
"(",
"'securityDefinitions'",
")",
")",
"{",
"$",
"securityDefinitions",
"=",
"collect",
"(",
"$",
"documentation",
"->",
"get",
"(",
"'securityDefinitions'",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"securityConfig",
"as",
"$",
"key",
"=>",
"$",
"cfg",
")",
"{",
"$",
"securityDefinitions",
"->",
"offsetSet",
"(",
"$",
"key",
",",
"self",
"::",
"arrayToObject",
"(",
"$",
"cfg",
")",
")",
";",
"}",
"$",
"documentation",
"->",
"offsetSet",
"(",
"'securityDefinitions'",
",",
"$",
"securityDefinitions",
")",
";",
"return",
"$",
"documentation",
";",
"}"
] |
Inject security settings for Swagger 1 & 2.
@param Collection $documentation The parse json
@param array $securityConfig The security settings from l5-swagger
@return Collection
|
[
"Inject",
"security",
"settings",
"for",
"Swagger",
"1",
"&",
"2",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/SecurityDefinitions.php#L41-L55
|
train
|
DarkaOnLine/L5-Swagger
|
src/SecurityDefinitions.php
|
SecurityDefinitions.generateOpenApi
|
public function generateOpenApi(Collection $documentation, array $securityConfig)
{
$components = collect();
if ($documentation->has('components')) {
$components = collect($documentation->get('components'));
}
$securitySchemes = collect();
if ($components->has('securitySchemes')) {
$securitySchemes = collect($components->get('securitySchemes'));
}
foreach ($securityConfig as $key => $cfg) {
$securitySchemes->offsetSet($key, self::arrayToObject($cfg));
}
$components->offsetSet('securitySchemes', $securitySchemes);
$documentation->offsetSet('components', $components);
return $documentation;
}
|
php
|
public function generateOpenApi(Collection $documentation, array $securityConfig)
{
$components = collect();
if ($documentation->has('components')) {
$components = collect($documentation->get('components'));
}
$securitySchemes = collect();
if ($components->has('securitySchemes')) {
$securitySchemes = collect($components->get('securitySchemes'));
}
foreach ($securityConfig as $key => $cfg) {
$securitySchemes->offsetSet($key, self::arrayToObject($cfg));
}
$components->offsetSet('securitySchemes', $securitySchemes);
$documentation->offsetSet('components', $components);
return $documentation;
}
|
[
"public",
"function",
"generateOpenApi",
"(",
"Collection",
"$",
"documentation",
",",
"array",
"$",
"securityConfig",
")",
"{",
"$",
"components",
"=",
"collect",
"(",
")",
";",
"if",
"(",
"$",
"documentation",
"->",
"has",
"(",
"'components'",
")",
")",
"{",
"$",
"components",
"=",
"collect",
"(",
"$",
"documentation",
"->",
"get",
"(",
"'components'",
")",
")",
";",
"}",
"$",
"securitySchemes",
"=",
"collect",
"(",
")",
";",
"if",
"(",
"$",
"components",
"->",
"has",
"(",
"'securitySchemes'",
")",
")",
"{",
"$",
"securitySchemes",
"=",
"collect",
"(",
"$",
"components",
"->",
"get",
"(",
"'securitySchemes'",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"securityConfig",
"as",
"$",
"key",
"=>",
"$",
"cfg",
")",
"{",
"$",
"securitySchemes",
"->",
"offsetSet",
"(",
"$",
"key",
",",
"self",
"::",
"arrayToObject",
"(",
"$",
"cfg",
")",
")",
";",
"}",
"$",
"components",
"->",
"offsetSet",
"(",
"'securitySchemes'",
",",
"$",
"securitySchemes",
")",
";",
"$",
"documentation",
"->",
"offsetSet",
"(",
"'components'",
",",
"$",
"components",
")",
";",
"return",
"$",
"documentation",
";",
"}"
] |
Inject security settings for OpenApi 3.
@param Collection $documentation The parse json
@param array $securityConfig The security settings from l5-swagger
@return Collection
|
[
"Inject",
"security",
"settings",
"for",
"OpenApi",
"3",
"."
] |
fc1d262688a1f932ce298603ecb6305bbeecb293
|
https://github.com/DarkaOnLine/L5-Swagger/blob/fc1d262688a1f932ce298603ecb6305bbeecb293/src/SecurityDefinitions.php#L65-L86
|
train
|
antonioribeiro/tracker
|
src/Tracker.php
|
Tracker.updateGeoIp
|
public function updateGeoIp()
{
$updater = new GeoIpUpdater();
$success = $updater->updateGeoIpFiles($this->config->get('geoip_database_path'));
$this->messageRepository->addMessage($updater->getMessages());
return $success;
}
|
php
|
public function updateGeoIp()
{
$updater = new GeoIpUpdater();
$success = $updater->updateGeoIpFiles($this->config->get('geoip_database_path'));
$this->messageRepository->addMessage($updater->getMessages());
return $success;
}
|
[
"public",
"function",
"updateGeoIp",
"(",
")",
"{",
"$",
"updater",
"=",
"new",
"GeoIpUpdater",
"(",
")",
";",
"$",
"success",
"=",
"$",
"updater",
"->",
"updateGeoIpFiles",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'geoip_database_path'",
")",
")",
";",
"$",
"this",
"->",
"messageRepository",
"->",
"addMessage",
"(",
"$",
"updater",
"->",
"getMessages",
"(",
")",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Update the GeoIp2 database.
@return bool
|
[
"Update",
"the",
"GeoIp2",
"database",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Tracker.php#L552-L561
|
train
|
antonioribeiro/tracker
|
src/Repositories/Message.php
|
Message.addMessage
|
public function addMessage($message)
{
collect((array) $message)->each(function ($item) {
collect($item)->flatten()->each(function ($flattened) {
$this->messageList->push($flattened);
});
});
}
|
php
|
public function addMessage($message)
{
collect((array) $message)->each(function ($item) {
collect($item)->flatten()->each(function ($flattened) {
$this->messageList->push($flattened);
});
});
}
|
[
"public",
"function",
"addMessage",
"(",
"$",
"message",
")",
"{",
"collect",
"(",
"(",
"array",
")",
"$",
"message",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"collect",
"(",
"$",
"item",
")",
"->",
"flatten",
"(",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"flattened",
")",
"{",
"$",
"this",
"->",
"messageList",
"->",
"push",
"(",
"$",
"flattened",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Add a message to the messages list.
@param $message
@return void
|
[
"Add",
"a",
"message",
"to",
"the",
"messages",
"list",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Repositories/Message.php#L29-L36
|
train
|
antonioribeiro/tracker
|
src/Support/RefererParser.php
|
RefererParser.parse
|
public function parse($refererUrl, $pageUrl)
{
$this->setReferer($this->parser->parse($refererUrl, $pageUrl));
return $this;
}
|
php
|
public function parse($refererUrl, $pageUrl)
{
$this->setReferer($this->parser->parse($refererUrl, $pageUrl));
return $this;
}
|
[
"public",
"function",
"parse",
"(",
"$",
"refererUrl",
",",
"$",
"pageUrl",
")",
"{",
"$",
"this",
"->",
"setReferer",
"(",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"$",
"refererUrl",
",",
"$",
"pageUrl",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Parse a referer.
@return RefererParser
|
[
"Parse",
"a",
"referer",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Support/RefererParser.php#L38-L43
|
train
|
antonioribeiro/tracker
|
src/Vendor/Laravel/Artisan/UpdateGeoIp.php
|
UpdateGeoIp.fire
|
public function fire()
{
$tracker = app('tracker');
$type = $tracker->updateGeoIp()
? 'info'
: 'error';
$this->displayMessages($type, $tracker->getMessages());
}
|
php
|
public function fire()
{
$tracker = app('tracker');
$type = $tracker->updateGeoIp()
? 'info'
: 'error';
$this->displayMessages($type, $tracker->getMessages());
}
|
[
"public",
"function",
"fire",
"(",
")",
"{",
"$",
"tracker",
"=",
"app",
"(",
"'tracker'",
")",
";",
"$",
"type",
"=",
"$",
"tracker",
"->",
"updateGeoIp",
"(",
")",
"?",
"'info'",
":",
"'error'",
";",
"$",
"this",
"->",
"displayMessages",
"(",
"$",
"type",
",",
"$",
"tracker",
"->",
"getMessages",
"(",
")",
")",
";",
"}"
] |
Update the geo ip database.
@return void
|
[
"Update",
"the",
"geo",
"ip",
"database",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Vendor/Laravel/Artisan/UpdateGeoIp.php#L26-L35
|
train
|
antonioribeiro/tracker
|
src/Vendor/Laravel/Artisan/Base.php
|
Base.display
|
public function display($result, $method = 'info')
{
if ($result) {
if (is_array($result)) {
$this->displayTable($result);
} elseif (is_bool($result)) {
$this->{$method}($result ? 'Statement executed sucessfully.' : 'And error ocurred while executing the statement.');
} else {
$this->{$method}($result);
}
}
}
|
php
|
public function display($result, $method = 'info')
{
if ($result) {
if (is_array($result)) {
$this->displayTable($result);
} elseif (is_bool($result)) {
$this->{$method}($result ? 'Statement executed sucessfully.' : 'And error ocurred while executing the statement.');
} else {
$this->{$method}($result);
}
}
}
|
[
"public",
"function",
"display",
"(",
"$",
"result",
",",
"$",
"method",
"=",
"'info'",
")",
"{",
"if",
"(",
"$",
"result",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"displayTable",
"(",
"$",
"result",
")",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"result",
"?",
"'Statement executed sucessfully.'",
":",
"'And error ocurred while executing the statement.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"result",
")",
";",
"}",
"}",
"}"
] |
Display results.
@param $result
@param string $method
|
[
"Display",
"results",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Vendor/Laravel/Artisan/Base.php#L63-L74
|
train
|
antonioribeiro/tracker
|
src/Vendor/Laravel/Artisan/Base.php
|
Base.displayTable
|
public function displayTable($table)
{
$headers = $this->makeHeaders($table[0]);
$rows = [];
foreach ($table as $row) {
$rows[] = (array) $row;
}
$this->table = $this->getHelperSet()->get('table');
$this->table->setHeaders($headers)->setRows($rows);
$this->table->render($this->getOutput());
}
|
php
|
public function displayTable($table)
{
$headers = $this->makeHeaders($table[0]);
$rows = [];
foreach ($table as $row) {
$rows[] = (array) $row;
}
$this->table = $this->getHelperSet()->get('table');
$this->table->setHeaders($headers)->setRows($rows);
$this->table->render($this->getOutput());
}
|
[
"public",
"function",
"displayTable",
"(",
"$",
"table",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"makeHeaders",
"(",
"$",
"table",
"[",
"0",
"]",
")",
";",
"$",
"rows",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"as",
"$",
"row",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"row",
";",
"}",
"$",
"this",
"->",
"table",
"=",
"$",
"this",
"->",
"getHelperSet",
"(",
")",
"->",
"get",
"(",
"'table'",
")",
";",
"$",
"this",
"->",
"table",
"->",
"setHeaders",
"(",
"$",
"headers",
")",
"->",
"setRows",
"(",
"$",
"rows",
")",
";",
"$",
"this",
"->",
"table",
"->",
"render",
"(",
"$",
"this",
"->",
"getOutput",
"(",
")",
")",
";",
"}"
] |
Display results in table format.
@param $table
|
[
"Display",
"results",
"in",
"table",
"format",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Vendor/Laravel/Artisan/Base.php#L81-L96
|
train
|
antonioribeiro/tracker
|
src/Vendor/Laravel/ServiceProvider.php
|
ServiceProvider.registerTracker
|
protected function registerTracker()
{
$this->app->singleton('tracker', function ($app) {
$app['tracker.loaded'] = true;
return new Tracker(
$app['tracker.config'],
$app['tracker.repositories'],
$app['request'],
$app['router'],
$app['log'],
$app,
$app['tracker.messages']
);
});
}
|
php
|
protected function registerTracker()
{
$this->app->singleton('tracker', function ($app) {
$app['tracker.loaded'] = true;
return new Tracker(
$app['tracker.config'],
$app['tracker.repositories'],
$app['request'],
$app['router'],
$app['log'],
$app,
$app['tracker.messages']
);
});
}
|
[
"protected",
"function",
"registerTracker",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'tracker'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"app",
"[",
"'tracker.loaded'",
"]",
"=",
"true",
";",
"return",
"new",
"Tracker",
"(",
"$",
"app",
"[",
"'tracker.config'",
"]",
",",
"$",
"app",
"[",
"'tracker.repositories'",
"]",
",",
"$",
"app",
"[",
"'request'",
"]",
",",
"$",
"app",
"[",
"'router'",
"]",
",",
"$",
"app",
"[",
"'log'",
"]",
",",
"$",
"app",
",",
"$",
"app",
"[",
"'tracker.messages'",
"]",
")",
";",
"}",
")",
";",
"}"
] |
Takes all the components of Tracker and glues them
together to create Tracker.
@return void
|
[
"Takes",
"all",
"the",
"components",
"of",
"Tracker",
"and",
"glues",
"them",
"together",
"to",
"create",
"Tracker",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Vendor/Laravel/ServiceProvider.php#L155-L170
|
train
|
antonioribeiro/tracker
|
src/Vendor/Laravel/ServiceProvider.php
|
ServiceProvider.registerGlobalViewComposers
|
protected function registerGlobalViewComposers()
{
$me = $this;
$this->app->make('view')->composer('pragmarx/tracker::*', function ($view) use ($me) {
$view->with('stats_layout', $me->getConfig('stats_layout'));
$template_path = url('/').$me->getConfig('stats_template_path');
$view->with('stats_template_path', $template_path);
});
}
|
php
|
protected function registerGlobalViewComposers()
{
$me = $this;
$this->app->make('view')->composer('pragmarx/tracker::*', function ($view) use ($me) {
$view->with('stats_layout', $me->getConfig('stats_layout'));
$template_path = url('/').$me->getConfig('stats_template_path');
$view->with('stats_template_path', $template_path);
});
}
|
[
"protected",
"function",
"registerGlobalViewComposers",
"(",
")",
"{",
"$",
"me",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'view'",
")",
"->",
"composer",
"(",
"'pragmarx/tracker::*'",
",",
"function",
"(",
"$",
"view",
")",
"use",
"(",
"$",
"me",
")",
"{",
"$",
"view",
"->",
"with",
"(",
"'stats_layout'",
",",
"$",
"me",
"->",
"getConfig",
"(",
"'stats_layout'",
")",
")",
";",
"$",
"template_path",
"=",
"url",
"(",
"'/'",
")",
".",
"$",
"me",
"->",
"getConfig",
"(",
"'stats_template_path'",
")",
";",
"$",
"view",
"->",
"with",
"(",
"'stats_template_path'",
",",
"$",
"template_path",
")",
";",
"}",
")",
";",
"}"
] |
Register global view composers.
|
[
"Register",
"global",
"view",
"composers",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Vendor/Laravel/ServiceProvider.php#L596-L607
|
train
|
antonioribeiro/tracker
|
src/Support/Minutes.php
|
Minutes.calculateStartEnd
|
private function calculateStartEnd()
{
if ($this->minutes == 0) {
$this->setToday();
} else {
$this->start = Carbon::now()->subMinutes($this->minutes);
$this->end = Carbon::now();
}
}
|
php
|
private function calculateStartEnd()
{
if ($this->minutes == 0) {
$this->setToday();
} else {
$this->start = Carbon::now()->subMinutes($this->minutes);
$this->end = Carbon::now();
}
}
|
[
"private",
"function",
"calculateStartEnd",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"minutes",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"setToday",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"start",
"=",
"Carbon",
"::",
"now",
"(",
")",
"->",
"subMinutes",
"(",
"$",
"this",
"->",
"minutes",
")",
";",
"$",
"this",
"->",
"end",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"}",
"}"
] |
Calculate start and end dates.
|
[
"Calculate",
"start",
"and",
"end",
"dates",
"."
] |
e1ec4926402958bdad565a61b65457238536aa12
|
https://github.com/antonioribeiro/tracker/blob/e1ec4926402958bdad565a61b65457238536aa12/src/Support/Minutes.php#L49-L58
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.slug
|
public function slug(Model $model, bool $force = false): bool
{
$this->setModel($model);
$attributes = [];
foreach ($this->model->sluggable() as $attribute => $config) {
if (is_numeric($attribute)) {
$attribute = $config;
$config = $this->getConfiguration();
} else {
$config = $this->getConfiguration($config);
}
$slug = $this->buildSlug($attribute, $config, $force);
if ($slug !== null) {
$this->model->setAttribute($attribute, $slug);
$attributes[] = $attribute;
}
}
return $this->model->isDirty($attributes);
}
|
php
|
public function slug(Model $model, bool $force = false): bool
{
$this->setModel($model);
$attributes = [];
foreach ($this->model->sluggable() as $attribute => $config) {
if (is_numeric($attribute)) {
$attribute = $config;
$config = $this->getConfiguration();
} else {
$config = $this->getConfiguration($config);
}
$slug = $this->buildSlug($attribute, $config, $force);
if ($slug !== null) {
$this->model->setAttribute($attribute, $slug);
$attributes[] = $attribute;
}
}
return $this->model->isDirty($attributes);
}
|
[
"public",
"function",
"slug",
"(",
"Model",
"$",
"model",
",",
"bool",
"$",
"force",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"setModel",
"(",
"$",
"model",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"model",
"->",
"sluggable",
"(",
")",
"as",
"$",
"attribute",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"attribute",
")",
")",
"{",
"$",
"attribute",
"=",
"$",
"config",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
"$",
"config",
")",
";",
"}",
"$",
"slug",
"=",
"$",
"this",
"->",
"buildSlug",
"(",
"$",
"attribute",
",",
"$",
"config",
",",
"$",
"force",
")",
";",
"if",
"(",
"$",
"slug",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"setAttribute",
"(",
"$",
"attribute",
",",
"$",
"slug",
")",
";",
"$",
"attributes",
"[",
"]",
"=",
"$",
"attribute",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"model",
"->",
"isDirty",
"(",
"$",
"attributes",
")",
";",
"}"
] |
Slug the current model.
@param \Illuminate\Database\Eloquent\Model $model
@param bool $force
@return bool
|
[
"Slug",
"the",
"current",
"model",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L29-L52
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.buildSlug
|
public function buildSlug(string $attribute, array $config, bool $force = null)
{
$slug = $this->model->getAttribute($attribute);
if ($force || $this->needsSlugging($attribute, $config)) {
$source = $this->getSlugSource($config['source']);
if ($source || is_numeric($source)) {
$slug = $this->generateSlug($source, $config, $attribute);
$slug = $this->validateSlug($slug, $config, $attribute);
$slug = $this->makeSlugUnique($slug, $config, $attribute);
}
}
return $slug;
}
|
php
|
public function buildSlug(string $attribute, array $config, bool $force = null)
{
$slug = $this->model->getAttribute($attribute);
if ($force || $this->needsSlugging($attribute, $config)) {
$source = $this->getSlugSource($config['source']);
if ($source || is_numeric($source)) {
$slug = $this->generateSlug($source, $config, $attribute);
$slug = $this->validateSlug($slug, $config, $attribute);
$slug = $this->makeSlugUnique($slug, $config, $attribute);
}
}
return $slug;
}
|
[
"public",
"function",
"buildSlug",
"(",
"string",
"$",
"attribute",
",",
"array",
"$",
"config",
",",
"bool",
"$",
"force",
"=",
"null",
")",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"model",
"->",
"getAttribute",
"(",
"$",
"attribute",
")",
";",
"if",
"(",
"$",
"force",
"||",
"$",
"this",
"->",
"needsSlugging",
"(",
"$",
"attribute",
",",
"$",
"config",
")",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"getSlugSource",
"(",
"$",
"config",
"[",
"'source'",
"]",
")",
";",
"if",
"(",
"$",
"source",
"||",
"is_numeric",
"(",
"$",
"source",
")",
")",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"generateSlug",
"(",
"$",
"source",
",",
"$",
"config",
",",
"$",
"attribute",
")",
";",
"$",
"slug",
"=",
"$",
"this",
"->",
"validateSlug",
"(",
"$",
"slug",
",",
"$",
"config",
",",
"$",
"attribute",
")",
";",
"$",
"slug",
"=",
"$",
"this",
"->",
"makeSlugUnique",
"(",
"$",
"slug",
",",
"$",
"config",
",",
"$",
"attribute",
")",
";",
"}",
"}",
"return",
"$",
"slug",
";",
"}"
] |
Build the slug for the given attribute of the current model.
@param string $attribute
@param array $config
@param bool $force
@return null|string
|
[
"Build",
"the",
"slug",
"for",
"the",
"given",
"attribute",
"of",
"the",
"current",
"model",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L78-L93
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.getSlugSource
|
protected function getSlugSource($from): string
{
if (is_null($from)) {
return $this->model->__toString();
}
$sourceStrings = array_map(function($key) {
$value = data_get($this->model, $key);
if (is_bool($value)) {
$value = (int) $value;
}
return $value;
}, (array) $from);
return implode($sourceStrings, ' ');
}
|
php
|
protected function getSlugSource($from): string
{
if (is_null($from)) {
return $this->model->__toString();
}
$sourceStrings = array_map(function($key) {
$value = data_get($this->model, $key);
if (is_bool($value)) {
$value = (int) $value;
}
return $value;
}, (array) $from);
return implode($sourceStrings, ' ');
}
|
[
"protected",
"function",
"getSlugSource",
"(",
"$",
"from",
")",
":",
"string",
"{",
"if",
"(",
"is_null",
"(",
"$",
"from",
")",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"__toString",
"(",
")",
";",
"}",
"$",
"sourceStrings",
"=",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"data_get",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"key",
")",
";",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"return",
"$",
"value",
";",
"}",
",",
"(",
"array",
")",
"$",
"from",
")",
";",
"return",
"implode",
"(",
"$",
"sourceStrings",
",",
"' '",
")",
";",
"}"
] |
Get the source string for the slug.
@param mixed $from
@return string
|
[
"Get",
"the",
"source",
"string",
"for",
"the",
"slug",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L126-L142
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.generateSlug
|
protected function generateSlug(string $source, array $config, string $attribute): string
{
$separator = $config['separator'];
$method = $config['method'];
$maxLength = $config['maxLength'];
$maxLengthKeepWords = $config['maxLengthKeepWords'];
if ($method === null) {
$slugEngine = $this->getSlugEngine($attribute);
$slug = $slugEngine->slugify($source, $separator);
} elseif (is_callable($method)) {
$slug = call_user_func($method, $source, $separator);
} else {
throw new \UnexpectedValueException('Sluggable "method" for ' . get_class($this->model) . ':' . $attribute . ' is not callable nor null.');
}
$len = mb_strlen($slug);
if (is_string($slug) && $maxLength && $len > $maxLength) {
$reverseOffset = $maxLength - $len;
$lastSeparatorPos = mb_strrpos($slug, $separator, $reverseOffset);
if ($maxLengthKeepWords && $lastSeparatorPos !== false) {
$slug = mb_substr($slug, 0, $lastSeparatorPos);
} else {
$slug = trim(mb_substr($slug, 0, $maxLength), $separator);
}
}
return $slug;
}
|
php
|
protected function generateSlug(string $source, array $config, string $attribute): string
{
$separator = $config['separator'];
$method = $config['method'];
$maxLength = $config['maxLength'];
$maxLengthKeepWords = $config['maxLengthKeepWords'];
if ($method === null) {
$slugEngine = $this->getSlugEngine($attribute);
$slug = $slugEngine->slugify($source, $separator);
} elseif (is_callable($method)) {
$slug = call_user_func($method, $source, $separator);
} else {
throw new \UnexpectedValueException('Sluggable "method" for ' . get_class($this->model) . ':' . $attribute . ' is not callable nor null.');
}
$len = mb_strlen($slug);
if (is_string($slug) && $maxLength && $len > $maxLength) {
$reverseOffset = $maxLength - $len;
$lastSeparatorPos = mb_strrpos($slug, $separator, $reverseOffset);
if ($maxLengthKeepWords && $lastSeparatorPos !== false) {
$slug = mb_substr($slug, 0, $lastSeparatorPos);
} else {
$slug = trim(mb_substr($slug, 0, $maxLength), $separator);
}
}
return $slug;
}
|
[
"protected",
"function",
"generateSlug",
"(",
"string",
"$",
"source",
",",
"array",
"$",
"config",
",",
"string",
"$",
"attribute",
")",
":",
"string",
"{",
"$",
"separator",
"=",
"$",
"config",
"[",
"'separator'",
"]",
";",
"$",
"method",
"=",
"$",
"config",
"[",
"'method'",
"]",
";",
"$",
"maxLength",
"=",
"$",
"config",
"[",
"'maxLength'",
"]",
";",
"$",
"maxLengthKeepWords",
"=",
"$",
"config",
"[",
"'maxLengthKeepWords'",
"]",
";",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"$",
"slugEngine",
"=",
"$",
"this",
"->",
"getSlugEngine",
"(",
"$",
"attribute",
")",
";",
"$",
"slug",
"=",
"$",
"slugEngine",
"->",
"slugify",
"(",
"$",
"source",
",",
"$",
"separator",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"method",
")",
")",
"{",
"$",
"slug",
"=",
"call_user_func",
"(",
"$",
"method",
",",
"$",
"source",
",",
"$",
"separator",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Sluggable \"method\" for '",
".",
"get_class",
"(",
"$",
"this",
"->",
"model",
")",
".",
"':'",
".",
"$",
"attribute",
".",
"' is not callable nor null.'",
")",
";",
"}",
"$",
"len",
"=",
"mb_strlen",
"(",
"$",
"slug",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"slug",
")",
"&&",
"$",
"maxLength",
"&&",
"$",
"len",
">",
"$",
"maxLength",
")",
"{",
"$",
"reverseOffset",
"=",
"$",
"maxLength",
"-",
"$",
"len",
";",
"$",
"lastSeparatorPos",
"=",
"mb_strrpos",
"(",
"$",
"slug",
",",
"$",
"separator",
",",
"$",
"reverseOffset",
")",
";",
"if",
"(",
"$",
"maxLengthKeepWords",
"&&",
"$",
"lastSeparatorPos",
"!==",
"false",
")",
"{",
"$",
"slug",
"=",
"mb_substr",
"(",
"$",
"slug",
",",
"0",
",",
"$",
"lastSeparatorPos",
")",
";",
"}",
"else",
"{",
"$",
"slug",
"=",
"trim",
"(",
"mb_substr",
"(",
"$",
"slug",
",",
"0",
",",
"$",
"maxLength",
")",
",",
"$",
"separator",
")",
";",
"}",
"}",
"return",
"$",
"slug",
";",
"}"
] |
Generate a slug from the given source string.
@param string $source
@param array $config
@param string $attribute
@return string
@throws \UnexpectedValueException
|
[
"Generate",
"a",
"slug",
"from",
"the",
"given",
"source",
"string",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L154-L182
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.validateSlug
|
protected function validateSlug(string $slug, array $config, string $attribute): string
{
$separator = $config['separator'];
$reserved = $config['reserved'];
if ($reserved === null) {
return $slug;
}
// check for reserved names
if ($reserved instanceof \Closure) {
$reserved = $reserved($this->model);
}
if (is_array($reserved)) {
if (in_array($slug, $reserved)) {
$method = $config['uniqueSuffix'];
if ($method === null) {
$suffix = $this->generateSuffix($slug, $separator, collect($reserved));
} elseif (is_callable($method)) {
$suffix = $method($slug, $separator, collect($reserved));
} else {
throw new \UnexpectedValueException('Sluggable "uniqueSuffix" for ' . get_class($this->model) . ':' . $attribute . ' is not null, or a closure.');
}
return $slug . $separator . $suffix;
}
return $slug;
}
throw new \UnexpectedValueException('Sluggable "reserved" for ' . get_class($this->model) . ':' . $attribute . ' is not null, an array, or a closure that returns null/array.');
}
|
php
|
protected function validateSlug(string $slug, array $config, string $attribute): string
{
$separator = $config['separator'];
$reserved = $config['reserved'];
if ($reserved === null) {
return $slug;
}
// check for reserved names
if ($reserved instanceof \Closure) {
$reserved = $reserved($this->model);
}
if (is_array($reserved)) {
if (in_array($slug, $reserved)) {
$method = $config['uniqueSuffix'];
if ($method === null) {
$suffix = $this->generateSuffix($slug, $separator, collect($reserved));
} elseif (is_callable($method)) {
$suffix = $method($slug, $separator, collect($reserved));
} else {
throw new \UnexpectedValueException('Sluggable "uniqueSuffix" for ' . get_class($this->model) . ':' . $attribute . ' is not null, or a closure.');
}
return $slug . $separator . $suffix;
}
return $slug;
}
throw new \UnexpectedValueException('Sluggable "reserved" for ' . get_class($this->model) . ':' . $attribute . ' is not null, an array, or a closure that returns null/array.');
}
|
[
"protected",
"function",
"validateSlug",
"(",
"string",
"$",
"slug",
",",
"array",
"$",
"config",
",",
"string",
"$",
"attribute",
")",
":",
"string",
"{",
"$",
"separator",
"=",
"$",
"config",
"[",
"'separator'",
"]",
";",
"$",
"reserved",
"=",
"$",
"config",
"[",
"'reserved'",
"]",
";",
"if",
"(",
"$",
"reserved",
"===",
"null",
")",
"{",
"return",
"$",
"slug",
";",
"}",
"// check for reserved names",
"if",
"(",
"$",
"reserved",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"reserved",
"=",
"$",
"reserved",
"(",
"$",
"this",
"->",
"model",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"reserved",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"slug",
",",
"$",
"reserved",
")",
")",
"{",
"$",
"method",
"=",
"$",
"config",
"[",
"'uniqueSuffix'",
"]",
";",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"$",
"suffix",
"=",
"$",
"this",
"->",
"generateSuffix",
"(",
"$",
"slug",
",",
"$",
"separator",
",",
"collect",
"(",
"$",
"reserved",
")",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"method",
")",
")",
"{",
"$",
"suffix",
"=",
"$",
"method",
"(",
"$",
"slug",
",",
"$",
"separator",
",",
"collect",
"(",
"$",
"reserved",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Sluggable \"uniqueSuffix\" for '",
".",
"get_class",
"(",
"$",
"this",
"->",
"model",
")",
".",
"':'",
".",
"$",
"attribute",
".",
"' is not null, or a closure.'",
")",
";",
"}",
"return",
"$",
"slug",
".",
"$",
"separator",
".",
"$",
"suffix",
";",
"}",
"return",
"$",
"slug",
";",
"}",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Sluggable \"reserved\" for '",
".",
"get_class",
"(",
"$",
"this",
"->",
"model",
")",
".",
"':'",
".",
"$",
"attribute",
".",
"' is not null, an array, or a closure that returns null/array.'",
")",
";",
"}"
] |
Checks that the given slug is not a reserved word.
@param string $slug
@param array $config
@param string $attribute
@return string
@throws \UnexpectedValueException
|
[
"Checks",
"that",
"the",
"given",
"slug",
"is",
"not",
"a",
"reserved",
"word",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L220-L252
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.makeSlugUnique
|
protected function makeSlugUnique(string $slug, array $config, string $attribute): string
{
if (!$config['unique']) {
return $slug;
}
$separator = $config['separator'];
// find all models where the slug is like the current one
$list = $this->getExistingSlugs($slug, $attribute, $config);
// if ...
// a) the list is empty, or
// b) our slug isn't in the list
// ... we are okay
if (
$list->count() === 0 ||
$list->contains($slug) === false
) {
return $slug;
}
// if our slug is in the list, but
// a) it's for our model, or
// b) it looks like a suffixed version of our slug
// ... we are also okay (use the current slug)
if ($list->has($this->model->getKey())) {
$currentSlug = $list->get($this->model->getKey());
if (
$currentSlug === $slug ||
strpos($currentSlug, $slug) === 0
) {
return $currentSlug;
}
}
$method = $config['uniqueSuffix'];
if ($method === null) {
$suffix = $this->generateSuffix($slug, $separator, $list);
} elseif (is_callable($method)) {
$suffix = $method($slug, $separator, $list);
} else {
throw new \UnexpectedValueException('Sluggable "uniqueSuffix" for ' . get_class($this->model) . ':' . $attribute . ' is not null, or a closure.');
}
return $slug . $separator . $suffix;
}
|
php
|
protected function makeSlugUnique(string $slug, array $config, string $attribute): string
{
if (!$config['unique']) {
return $slug;
}
$separator = $config['separator'];
// find all models where the slug is like the current one
$list = $this->getExistingSlugs($slug, $attribute, $config);
// if ...
// a) the list is empty, or
// b) our slug isn't in the list
// ... we are okay
if (
$list->count() === 0 ||
$list->contains($slug) === false
) {
return $slug;
}
// if our slug is in the list, but
// a) it's for our model, or
// b) it looks like a suffixed version of our slug
// ... we are also okay (use the current slug)
if ($list->has($this->model->getKey())) {
$currentSlug = $list->get($this->model->getKey());
if (
$currentSlug === $slug ||
strpos($currentSlug, $slug) === 0
) {
return $currentSlug;
}
}
$method = $config['uniqueSuffix'];
if ($method === null) {
$suffix = $this->generateSuffix($slug, $separator, $list);
} elseif (is_callable($method)) {
$suffix = $method($slug, $separator, $list);
} else {
throw new \UnexpectedValueException('Sluggable "uniqueSuffix" for ' . get_class($this->model) . ':' . $attribute . ' is not null, or a closure.');
}
return $slug . $separator . $suffix;
}
|
[
"protected",
"function",
"makeSlugUnique",
"(",
"string",
"$",
"slug",
",",
"array",
"$",
"config",
",",
"string",
"$",
"attribute",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"config",
"[",
"'unique'",
"]",
")",
"{",
"return",
"$",
"slug",
";",
"}",
"$",
"separator",
"=",
"$",
"config",
"[",
"'separator'",
"]",
";",
"// find all models where the slug is like the current one",
"$",
"list",
"=",
"$",
"this",
"->",
"getExistingSlugs",
"(",
"$",
"slug",
",",
"$",
"attribute",
",",
"$",
"config",
")",
";",
"// if ...",
"// \ta) the list is empty, or",
"// \tb) our slug isn't in the list",
"// ... we are okay",
"if",
"(",
"$",
"list",
"->",
"count",
"(",
")",
"===",
"0",
"||",
"$",
"list",
"->",
"contains",
"(",
"$",
"slug",
")",
"===",
"false",
")",
"{",
"return",
"$",
"slug",
";",
"}",
"// if our slug is in the list, but",
"// \ta) it's for our model, or",
"// b) it looks like a suffixed version of our slug",
"// ... we are also okay (use the current slug)",
"if",
"(",
"$",
"list",
"->",
"has",
"(",
"$",
"this",
"->",
"model",
"->",
"getKey",
"(",
")",
")",
")",
"{",
"$",
"currentSlug",
"=",
"$",
"list",
"->",
"get",
"(",
"$",
"this",
"->",
"model",
"->",
"getKey",
"(",
")",
")",
";",
"if",
"(",
"$",
"currentSlug",
"===",
"$",
"slug",
"||",
"strpos",
"(",
"$",
"currentSlug",
",",
"$",
"slug",
")",
"===",
"0",
")",
"{",
"return",
"$",
"currentSlug",
";",
"}",
"}",
"$",
"method",
"=",
"$",
"config",
"[",
"'uniqueSuffix'",
"]",
";",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"$",
"suffix",
"=",
"$",
"this",
"->",
"generateSuffix",
"(",
"$",
"slug",
",",
"$",
"separator",
",",
"$",
"list",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"method",
")",
")",
"{",
"$",
"suffix",
"=",
"$",
"method",
"(",
"$",
"slug",
",",
"$",
"separator",
",",
"$",
"list",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Sluggable \"uniqueSuffix\" for '",
".",
"get_class",
"(",
"$",
"this",
"->",
"model",
")",
".",
"':'",
".",
"$",
"attribute",
".",
"' is not null, or a closure.'",
")",
";",
"}",
"return",
"$",
"slug",
".",
"$",
"separator",
".",
"$",
"suffix",
";",
"}"
] |
Checks if the slug should be unique, and makes it so if needed.
@param string $slug
@param array $config
@param string $attribute
@return string
@throws \UnexpectedValueException
|
[
"Checks",
"if",
"the",
"slug",
"should",
"be",
"unique",
"and",
"makes",
"it",
"so",
"if",
"needed",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L264-L311
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.generateSuffix
|
protected function generateSuffix(string $slug, string $separator, Collection $list): string
{
$len = strlen($slug . $separator);
// If the slug already exists, but belongs to
// our model, return the current suffix.
if ($list->search($slug) === $this->model->getKey()) {
$suffix = explode($separator, $slug);
return end($suffix);
}
$list->transform(function($value, $key) use ($len) {
return (int) substr($value, $len);
});
// find the highest value and return one greater.
return $list->max() + 1;
}
|
php
|
protected function generateSuffix(string $slug, string $separator, Collection $list): string
{
$len = strlen($slug . $separator);
// If the slug already exists, but belongs to
// our model, return the current suffix.
if ($list->search($slug) === $this->model->getKey()) {
$suffix = explode($separator, $slug);
return end($suffix);
}
$list->transform(function($value, $key) use ($len) {
return (int) substr($value, $len);
});
// find the highest value and return one greater.
return $list->max() + 1;
}
|
[
"protected",
"function",
"generateSuffix",
"(",
"string",
"$",
"slug",
",",
"string",
"$",
"separator",
",",
"Collection",
"$",
"list",
")",
":",
"string",
"{",
"$",
"len",
"=",
"strlen",
"(",
"$",
"slug",
".",
"$",
"separator",
")",
";",
"// If the slug already exists, but belongs to",
"// our model, return the current suffix.",
"if",
"(",
"$",
"list",
"->",
"search",
"(",
"$",
"slug",
")",
"===",
"$",
"this",
"->",
"model",
"->",
"getKey",
"(",
")",
")",
"{",
"$",
"suffix",
"=",
"explode",
"(",
"$",
"separator",
",",
"$",
"slug",
")",
";",
"return",
"end",
"(",
"$",
"suffix",
")",
";",
"}",
"$",
"list",
"->",
"transform",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"$",
"len",
")",
"{",
"return",
"(",
"int",
")",
"substr",
"(",
"$",
"value",
",",
"$",
"len",
")",
";",
"}",
")",
";",
"// find the highest value and return one greater.",
"return",
"$",
"list",
"->",
"max",
"(",
")",
"+",
"1",
";",
"}"
] |
Generate a unique suffix for the given slug (and list of existing, "similar" slugs.
@param string $slug
@param string $separator
@param \Illuminate\Support\Collection $list
@return string
|
[
"Generate",
"a",
"unique",
"suffix",
"for",
"the",
"given",
"slug",
"(",
"and",
"list",
"of",
"existing",
"similar",
"slugs",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L322-L340
|
train
|
cviebrock/eloquent-sluggable
|
src/Services/SlugService.php
|
SlugService.createSlug
|
public static function createSlug($model, string $attribute, string $fromString, array $config = null): string
{
if (is_string($model)) {
$model = new $model;
}
/** @var static $instance */
$instance = (new static())->setModel($model);
if ($config === null) {
$config = Arr::get($model->sluggable(), $attribute);
if ($config === null) {
$modelClass = get_class($model);
throw new \InvalidArgumentException("Argument 2 passed to SlugService::createSlug ['{$attribute}'] is not a valid slug attribute for model {$modelClass}.");
}
} elseif (!is_array($config)) {
throw new \UnexpectedValueException('SlugService::createSlug expects an array or null as the fourth argument; ' . gettype($config) . ' given.');
}
$config = $instance->getConfiguration($config);
$slug = $instance->generateSlug($fromString, $config, $attribute);
$slug = $instance->validateSlug($slug, $config, $attribute);
$slug = $instance->makeSlugUnique($slug, $config, $attribute);
return $slug;
}
|
php
|
public static function createSlug($model, string $attribute, string $fromString, array $config = null): string
{
if (is_string($model)) {
$model = new $model;
}
/** @var static $instance */
$instance = (new static())->setModel($model);
if ($config === null) {
$config = Arr::get($model->sluggable(), $attribute);
if ($config === null) {
$modelClass = get_class($model);
throw new \InvalidArgumentException("Argument 2 passed to SlugService::createSlug ['{$attribute}'] is not a valid slug attribute for model {$modelClass}.");
}
} elseif (!is_array($config)) {
throw new \UnexpectedValueException('SlugService::createSlug expects an array or null as the fourth argument; ' . gettype($config) . ' given.');
}
$config = $instance->getConfiguration($config);
$slug = $instance->generateSlug($fromString, $config, $attribute);
$slug = $instance->validateSlug($slug, $config, $attribute);
$slug = $instance->makeSlugUnique($slug, $config, $attribute);
return $slug;
}
|
[
"public",
"static",
"function",
"createSlug",
"(",
"$",
"model",
",",
"string",
"$",
"attribute",
",",
"string",
"$",
"fromString",
",",
"array",
"$",
"config",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"is_string",
"(",
"$",
"model",
")",
")",
"{",
"$",
"model",
"=",
"new",
"$",
"model",
";",
"}",
"/** @var static $instance */",
"$",
"instance",
"=",
"(",
"new",
"static",
"(",
")",
")",
"->",
"setModel",
"(",
"$",
"model",
")",
";",
"if",
"(",
"$",
"config",
"===",
"null",
")",
"{",
"$",
"config",
"=",
"Arr",
"::",
"get",
"(",
"$",
"model",
"->",
"sluggable",
"(",
")",
",",
"$",
"attribute",
")",
";",
"if",
"(",
"$",
"config",
"===",
"null",
")",
"{",
"$",
"modelClass",
"=",
"get_class",
"(",
"$",
"model",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Argument 2 passed to SlugService::createSlug ['{$attribute}'] is not a valid slug attribute for model {$modelClass}.\"",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'SlugService::createSlug expects an array or null as the fourth argument; '",
".",
"gettype",
"(",
"$",
"config",
")",
".",
"' given.'",
")",
";",
"}",
"$",
"config",
"=",
"$",
"instance",
"->",
"getConfiguration",
"(",
"$",
"config",
")",
";",
"$",
"slug",
"=",
"$",
"instance",
"->",
"generateSlug",
"(",
"$",
"fromString",
",",
"$",
"config",
",",
"$",
"attribute",
")",
";",
"$",
"slug",
"=",
"$",
"instance",
"->",
"validateSlug",
"(",
"$",
"slug",
",",
"$",
"config",
",",
"$",
"attribute",
")",
";",
"$",
"slug",
"=",
"$",
"instance",
"->",
"makeSlugUnique",
"(",
"$",
"slug",
",",
"$",
"config",
",",
"$",
"attribute",
")",
";",
"return",
"$",
"slug",
";",
"}"
] |
Generate a unique slug for a given string.
@param \Illuminate\Database\Eloquent\Model|string $model
@param string $attribute
@param string $fromString
@param array|null $config
@return string
@throws \InvalidArgumentException
@throws \UnexpectedValueException
|
[
"Generate",
"a",
"unique",
"slug",
"for",
"a",
"given",
"string",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Services/SlugService.php#L399-L424
|
train
|
cviebrock/eloquent-sluggable
|
src/Sluggable.php
|
Sluggable.scopeFindSimilarSlugs
|
public function scopeFindSimilarSlugs(Builder $query, string $attribute, array $config, string $slug): Builder
{
$separator = $config['separator'];
return $query->where(function(Builder $q) use ($attribute, $slug, $separator) {
$q->where($attribute, '=', $slug)
->orWhere($attribute, 'LIKE', $slug . $separator . '%');
});
}
|
php
|
public function scopeFindSimilarSlugs(Builder $query, string $attribute, array $config, string $slug): Builder
{
$separator = $config['separator'];
return $query->where(function(Builder $q) use ($attribute, $slug, $separator) {
$q->where($attribute, '=', $slug)
->orWhere($attribute, 'LIKE', $slug . $separator . '%');
});
}
|
[
"public",
"function",
"scopeFindSimilarSlugs",
"(",
"Builder",
"$",
"query",
",",
"string",
"$",
"attribute",
",",
"array",
"$",
"config",
",",
"string",
"$",
"slug",
")",
":",
"Builder",
"{",
"$",
"separator",
"=",
"$",
"config",
"[",
"'separator'",
"]",
";",
"return",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"Builder",
"$",
"q",
")",
"use",
"(",
"$",
"attribute",
",",
"$",
"slug",
",",
"$",
"separator",
")",
"{",
"$",
"q",
"->",
"where",
"(",
"$",
"attribute",
",",
"'='",
",",
"$",
"slug",
")",
"->",
"orWhere",
"(",
"$",
"attribute",
",",
"'LIKE'",
",",
"$",
"slug",
".",
"$",
"separator",
".",
"'%'",
")",
";",
"}",
")",
";",
"}"
] |
Query scope for finding "similar" slugs, used to determine uniqueness.
@param \Illuminate\Database\Eloquent\Builder $query
@param string $attribute
@param array $config
@param string $slug
@return \Illuminate\Database\Eloquent\Builder
|
[
"Query",
"scope",
"for",
"finding",
"similar",
"slugs",
"used",
"to",
"determine",
"uniqueness",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/Sluggable.php#L67-L75
|
train
|
cviebrock/eloquent-sluggable
|
src/SluggableScopeHelpers.php
|
SluggableScopeHelpers.getSlugKeyName
|
public function getSlugKeyName(): string
{
if (property_exists($this, 'slugKeyName')) {
return $this->slugKeyName;
}
$config = $this->sluggable();
$name = reset($config);
$key = key($config);
// check for short configuration
if ($key === 0) {
return $name;
}
return $key;
}
|
php
|
public function getSlugKeyName(): string
{
if (property_exists($this, 'slugKeyName')) {
return $this->slugKeyName;
}
$config = $this->sluggable();
$name = reset($config);
$key = key($config);
// check for short configuration
if ($key === 0) {
return $name;
}
return $key;
}
|
[
"public",
"function",
"getSlugKeyName",
"(",
")",
":",
"string",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"'slugKeyName'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"slugKeyName",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"sluggable",
"(",
")",
";",
"$",
"name",
"=",
"reset",
"(",
"$",
"config",
")",
";",
"$",
"key",
"=",
"key",
"(",
"$",
"config",
")",
";",
"// check for short configuration",
"if",
"(",
"$",
"key",
"===",
"0",
")",
"{",
"return",
"$",
"name",
";",
"}",
"return",
"$",
"key",
";",
"}"
] |
Primary slug column of this model.
@return string
|
[
"Primary",
"slug",
"column",
"of",
"this",
"model",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/SluggableScopeHelpers.php#L21-L37
|
train
|
cviebrock/eloquent-sluggable
|
src/SluggableScopeHelpers.php
|
SluggableScopeHelpers.scopeWhereSlug
|
public function scopeWhereSlug(Builder $scope, string $slug): Builder
{
return $scope->where($this->getSlugKeyName(), $slug);
}
|
php
|
public function scopeWhereSlug(Builder $scope, string $slug): Builder
{
return $scope->where($this->getSlugKeyName(), $slug);
}
|
[
"public",
"function",
"scopeWhereSlug",
"(",
"Builder",
"$",
"scope",
",",
"string",
"$",
"slug",
")",
":",
"Builder",
"{",
"return",
"$",
"scope",
"->",
"where",
"(",
"$",
"this",
"->",
"getSlugKeyName",
"(",
")",
",",
"$",
"slug",
")",
";",
"}"
] |
Query scope for finding a model by its primary slug.
@param \Illuminate\Database\Eloquent\Builder $scope
@param string $slug
@return \Illuminate\Database\Eloquent\Builder
|
[
"Query",
"scope",
"for",
"finding",
"a",
"model",
"by",
"its",
"primary",
"slug",
"."
] |
805b75b8adaa9d387eeabd7dd6b6978893cc948a
|
https://github.com/cviebrock/eloquent-sluggable/blob/805b75b8adaa9d387eeabd7dd6b6978893cc948a/src/SluggableScopeHelpers.php#L56-L59
|
train
|
heroku/heroku-buildpack-php
|
support/installer/src/Downloader.php
|
Downloader.extract
|
protected function extract($file, $path)
{
// we must use cmdline tar, as PharData::extract() messes up symlinks
$command = 'tar -xzf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
throw new \RuntimeException("Failed to execute '$command'\n\n" . $this->process->getErrorOutput());
}
|
php
|
protected function extract($file, $path)
{
// we must use cmdline tar, as PharData::extract() messes up symlinks
$command = 'tar -xzf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);
if (0 === $this->process->execute($command, $ignoredOutput)) {
return;
}
throw new \RuntimeException("Failed to execute '$command'\n\n" . $this->process->getErrorOutput());
}
|
[
"protected",
"function",
"extract",
"(",
"$",
"file",
",",
"$",
"path",
")",
"{",
"// we must use cmdline tar, as PharData::extract() messes up symlinks",
"$",
"command",
"=",
"'tar -xzf '",
".",
"ProcessExecutor",
"::",
"escape",
"(",
"$",
"file",
")",
".",
"' -C '",
".",
"ProcessExecutor",
"::",
"escape",
"(",
"$",
"path",
")",
";",
"if",
"(",
"0",
"===",
"$",
"this",
"->",
"process",
"->",
"execute",
"(",
"$",
"command",
",",
"$",
"ignoredOutput",
")",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Failed to execute '$command'\\n\\n\"",
".",
"$",
"this",
"->",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"}"
] |
extract using cmdline tar, which merges with existing files and folders
|
[
"extract",
"using",
"cmdline",
"tar",
"which",
"merges",
"with",
"existing",
"files",
"and",
"folders"
] |
2625279c4b3caf5e2937308d07d4357b411d04d0
|
https://github.com/heroku/heroku-buildpack-php/blob/2625279c4b3caf5e2937308d07d4357b411d04d0/support/installer/src/Downloader.php#L25-L35
|
train
|
heroku/heroku-buildpack-php
|
support/installer/src/Downloader.php
|
Downloader.download
|
public function download(PackageInterface $package, $path, $output = true)
{
$temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8);
$this->filesystem->ensureDirectoryExists($temporaryDir);
// START: from FileDownloader::download()
if (!$package->getDistUrl()) {
throw new \InvalidArgumentException('The given package is missing url information');
}
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
$urls = $package->getDistUrls();
while ($url = array_shift($urls)) {
try {
$fileName = $this->doDownload($package, $temporaryDir, $url);
} catch (\Exception $e) {
if ($this->io->isDebug()) {
$this->io->writeError('');
$this->io->writeError('Failed: ['.get_class($e).'] '.$e->getCode().': '.$e->getMessage());
} elseif (count($urls)) {
$this->io->writeError('');
$this->io->writeError(' Failed, trying the next URL ('.$e->getCode().': '.$e->getMessage().')');
}
if (!count($urls)) {
throw $e;
}
}
}
// END: from FileDownloader::download()
// START: from ArchiveDownloader::download()
$this->io->writeError(' Extracting archive', true, IOInterface::VERBOSE);
try {
$this->extract($fileName, $path);
} catch (\Exception $e) {
// remove cache if the file was corrupted
parent::clearLastCacheWrite($package);
throw $e;
}
$this->filesystem->unlink($fileName);
if ($this->filesystem->isDirEmpty($this->config->get('vendor-dir').'/composer/')) {
$this->filesystem->removeDirectory($this->config->get('vendor-dir').'/composer/');
}
if ($this->filesystem->isDirEmpty($this->config->get('vendor-dir'))) {
$this->filesystem->removeDirectory($this->config->get('vendor-dir'));
}
$this->io->writeError('');
// END: from ArchiveDownloader::download()
}
|
php
|
public function download(PackageInterface $package, $path, $output = true)
{
$temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8);
$this->filesystem->ensureDirectoryExists($temporaryDir);
// START: from FileDownloader::download()
if (!$package->getDistUrl()) {
throw new \InvalidArgumentException('The given package is missing url information');
}
$this->io->writeError(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getFullPrettyVersion() . "</comment>)");
$urls = $package->getDistUrls();
while ($url = array_shift($urls)) {
try {
$fileName = $this->doDownload($package, $temporaryDir, $url);
} catch (\Exception $e) {
if ($this->io->isDebug()) {
$this->io->writeError('');
$this->io->writeError('Failed: ['.get_class($e).'] '.$e->getCode().': '.$e->getMessage());
} elseif (count($urls)) {
$this->io->writeError('');
$this->io->writeError(' Failed, trying the next URL ('.$e->getCode().': '.$e->getMessage().')');
}
if (!count($urls)) {
throw $e;
}
}
}
// END: from FileDownloader::download()
// START: from ArchiveDownloader::download()
$this->io->writeError(' Extracting archive', true, IOInterface::VERBOSE);
try {
$this->extract($fileName, $path);
} catch (\Exception $e) {
// remove cache if the file was corrupted
parent::clearLastCacheWrite($package);
throw $e;
}
$this->filesystem->unlink($fileName);
if ($this->filesystem->isDirEmpty($this->config->get('vendor-dir').'/composer/')) {
$this->filesystem->removeDirectory($this->config->get('vendor-dir').'/composer/');
}
if ($this->filesystem->isDirEmpty($this->config->get('vendor-dir'))) {
$this->filesystem->removeDirectory($this->config->get('vendor-dir'));
}
$this->io->writeError('');
// END: from ArchiveDownloader::download()
}
|
[
"public",
"function",
"download",
"(",
"PackageInterface",
"$",
"package",
",",
"$",
"path",
",",
"$",
"output",
"=",
"true",
")",
"{",
"$",
"temporaryDir",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
".",
"'/composer/'",
".",
"substr",
"(",
"md5",
"(",
"uniqid",
"(",
"''",
",",
"true",
")",
")",
",",
"0",
",",
"8",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"ensureDirectoryExists",
"(",
"$",
"temporaryDir",
")",
";",
"// START: from FileDownloader::download()",
"if",
"(",
"!",
"$",
"package",
"->",
"getDistUrl",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The given package is missing url information'",
")",
";",
"}",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"\" - Installing <info>\"",
".",
"$",
"package",
"->",
"getName",
"(",
")",
".",
"\"</info> (<comment>\"",
".",
"$",
"package",
"->",
"getFullPrettyVersion",
"(",
")",
".",
"\"</comment>)\"",
")",
";",
"$",
"urls",
"=",
"$",
"package",
"->",
"getDistUrls",
"(",
")",
";",
"while",
"(",
"$",
"url",
"=",
"array_shift",
"(",
"$",
"urls",
")",
")",
"{",
"try",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"doDownload",
"(",
"$",
"package",
",",
"$",
"temporaryDir",
",",
"$",
"url",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"io",
"->",
"isDebug",
"(",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"''",
")",
";",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"'Failed: ['",
".",
"get_class",
"(",
"$",
"e",
")",
".",
"'] '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"urls",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"''",
")",
";",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"' Failed, trying the next URL ('",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"')'",
")",
";",
"}",
"if",
"(",
"!",
"count",
"(",
"$",
"urls",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"// END: from FileDownloader::download()",
"// START: from ArchiveDownloader::download()",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"' Extracting archive'",
",",
"true",
",",
"IOInterface",
"::",
"VERBOSE",
")",
";",
"try",
"{",
"$",
"this",
"->",
"extract",
"(",
"$",
"fileName",
",",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// remove cache if the file was corrupted",
"parent",
"::",
"clearLastCacheWrite",
"(",
"$",
"package",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"filesystem",
"->",
"unlink",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"isDirEmpty",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
".",
"'/composer/'",
")",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"removeDirectory",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
".",
"'/composer/'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"isDirEmpty",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
")",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"removeDirectory",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
")",
";",
"}",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"''",
")",
";",
"// END: from ArchiveDownloader::download()",
"}"
] |
we can't do that, since we need our contents to be merged into the probably existing folder structure
|
[
"we",
"can",
"t",
"do",
"that",
"since",
"we",
"need",
"our",
"contents",
"to",
"be",
"merged",
"into",
"the",
"probably",
"existing",
"folder",
"structure"
] |
2625279c4b3caf5e2937308d07d4357b411d04d0
|
https://github.com/heroku/heroku-buildpack-php/blob/2625279c4b3caf5e2937308d07d4357b411d04d0/support/installer/src/Downloader.php#L39-L97
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/DecoratorPlugin.php
|
Swift_Plugins_DecoratorPlugin.setReplacements
|
public function setReplacements($replacements)
{
if (!($replacements instanceof Swift_Plugins_Decorator_Replacements)) {
$this->replacements = (array) $replacements;
} else {
$this->replacements = $replacements;
}
}
|
php
|
public function setReplacements($replacements)
{
if (!($replacements instanceof Swift_Plugins_Decorator_Replacements)) {
$this->replacements = (array) $replacements;
} else {
$this->replacements = $replacements;
}
}
|
[
"public",
"function",
"setReplacements",
"(",
"$",
"replacements",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"replacements",
"instanceof",
"Swift_Plugins_Decorator_Replacements",
")",
")",
"{",
"$",
"this",
"->",
"replacements",
"=",
"(",
"array",
")",
"$",
"replacements",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"replacements",
"=",
"$",
"replacements",
";",
"}",
"}"
] |
Sets replacements.
@param mixed $replacements Array or Swift_Plugins_Decorator_Replacements
@see __construct()
|
[
"Sets",
"replacements",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/DecoratorPlugin.php#L66-L73
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/DecoratorPlugin.php
|
Swift_Plugins_DecoratorPlugin.getReplacementsFor
|
public function getReplacementsFor($address)
{
if ($this->replacements instanceof Swift_Plugins_Decorator_Replacements) {
return $this->replacements->getReplacementsFor($address);
}
return $this->replacements[$address] ?? null;
}
|
php
|
public function getReplacementsFor($address)
{
if ($this->replacements instanceof Swift_Plugins_Decorator_Replacements) {
return $this->replacements->getReplacementsFor($address);
}
return $this->replacements[$address] ?? null;
}
|
[
"public",
"function",
"getReplacementsFor",
"(",
"$",
"address",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"replacements",
"instanceof",
"Swift_Plugins_Decorator_Replacements",
")",
"{",
"return",
"$",
"this",
"->",
"replacements",
"->",
"getReplacementsFor",
"(",
"$",
"address",
")",
";",
"}",
"return",
"$",
"this",
"->",
"replacements",
"[",
"$",
"address",
"]",
"??",
"null",
";",
"}"
] |
Find a map of replacements for the address.
If this plugin was provided with a delegate instance of
{@link Swift_Plugins_Decorator_Replacements} then the call will be
delegated to it. Otherwise, it will attempt to find the replacements
from the array provided in the constructor.
If no replacements can be found, an empty value (NULL) is returned.
@param string $address
@return array
|
[
"Find",
"a",
"map",
"of",
"replacements",
"for",
"the",
"address",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/DecoratorPlugin.php#L154-L161
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Plugins/DecoratorPlugin.php
|
Swift_Plugins_DecoratorPlugin.restoreMessage
|
private function restoreMessage(Swift_Mime_SimpleMessage $message)
{
if ($this->lastMessage === $message) {
if (isset($this->originalBody)) {
$message->setBody($this->originalBody);
$this->originalBody = null;
}
if (!empty($this->originalHeaders)) {
foreach ($message->getHeaders()->getAll() as $header) {
if (array_key_exists($header->getFieldName(), $this->originalHeaders)) {
$header->setFieldBodyModel($this->originalHeaders[$header->getFieldName()]);
}
}
$this->originalHeaders = [];
}
if (!empty($this->originalChildBodies)) {
$children = (array) $message->getChildren();
foreach ($children as $child) {
$id = $child->getId();
if (array_key_exists($id, $this->originalChildBodies)) {
$child->setBody($this->originalChildBodies[$id]);
}
}
$this->originalChildBodies = [];
}
$this->lastMessage = null;
}
}
|
php
|
private function restoreMessage(Swift_Mime_SimpleMessage $message)
{
if ($this->lastMessage === $message) {
if (isset($this->originalBody)) {
$message->setBody($this->originalBody);
$this->originalBody = null;
}
if (!empty($this->originalHeaders)) {
foreach ($message->getHeaders()->getAll() as $header) {
if (array_key_exists($header->getFieldName(), $this->originalHeaders)) {
$header->setFieldBodyModel($this->originalHeaders[$header->getFieldName()]);
}
}
$this->originalHeaders = [];
}
if (!empty($this->originalChildBodies)) {
$children = (array) $message->getChildren();
foreach ($children as $child) {
$id = $child->getId();
if (array_key_exists($id, $this->originalChildBodies)) {
$child->setBody($this->originalChildBodies[$id]);
}
}
$this->originalChildBodies = [];
}
$this->lastMessage = null;
}
}
|
[
"private",
"function",
"restoreMessage",
"(",
"Swift_Mime_SimpleMessage",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lastMessage",
"===",
"$",
"message",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"originalBody",
")",
")",
"{",
"$",
"message",
"->",
"setBody",
"(",
"$",
"this",
"->",
"originalBody",
")",
";",
"$",
"this",
"->",
"originalBody",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"originalHeaders",
")",
")",
"{",
"foreach",
"(",
"$",
"message",
"->",
"getHeaders",
"(",
")",
"->",
"getAll",
"(",
")",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"header",
"->",
"getFieldName",
"(",
")",
",",
"$",
"this",
"->",
"originalHeaders",
")",
")",
"{",
"$",
"header",
"->",
"setFieldBodyModel",
"(",
"$",
"this",
"->",
"originalHeaders",
"[",
"$",
"header",
"->",
"getFieldName",
"(",
")",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"originalHeaders",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"originalChildBodies",
")",
")",
"{",
"$",
"children",
"=",
"(",
"array",
")",
"$",
"message",
"->",
"getChildren",
"(",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"id",
"=",
"$",
"child",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"originalChildBodies",
")",
")",
"{",
"$",
"child",
"->",
"setBody",
"(",
"$",
"this",
"->",
"originalChildBodies",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"originalChildBodies",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"lastMessage",
"=",
"null",
";",
"}",
"}"
] |
Restore a changed message back to its original state
|
[
"Restore",
"a",
"changed",
"message",
"back",
"to",
"its",
"original",
"state"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Plugins/DecoratorPlugin.php#L172-L199
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/DKIMSigner.php
|
Swift_Signers_DKIMSigner.reset
|
public function reset()
{
$this->headerHash = null;
$this->signedHeaders = [];
$this->bodyHash = null;
$this->bodyHashHandler = null;
$this->bodyCanonIgnoreStart = 2;
$this->bodyCanonEmptyCounter = 0;
$this->bodyCanonLastChar = null;
$this->bodyCanonSpace = false;
}
|
php
|
public function reset()
{
$this->headerHash = null;
$this->signedHeaders = [];
$this->bodyHash = null;
$this->bodyHashHandler = null;
$this->bodyCanonIgnoreStart = 2;
$this->bodyCanonEmptyCounter = 0;
$this->bodyCanonLastChar = null;
$this->bodyCanonSpace = false;
}
|
[
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"headerHash",
"=",
"null",
";",
"$",
"this",
"->",
"signedHeaders",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"bodyHash",
"=",
"null",
";",
"$",
"this",
"->",
"bodyHashHandler",
"=",
"null",
";",
"$",
"this",
"->",
"bodyCanonIgnoreStart",
"=",
"2",
";",
"$",
"this",
"->",
"bodyCanonEmptyCounter",
"=",
"0",
";",
"$",
"this",
"->",
"bodyCanonLastChar",
"=",
"null",
";",
"$",
"this",
"->",
"bodyCanonSpace",
"=",
"false",
";",
"}"
] |
Reset the Signer.
@see Swift_Signer::reset()
|
[
"Reset",
"the",
"Signer",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/DKIMSigner.php#L190-L200
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/DKIMSigner.php
|
Swift_Signers_DKIMSigner.setHashAlgorithm
|
public function setHashAlgorithm($hash)
{
switch ($hash) {
case 'rsa-sha1':
$this->hashAlgorithm = 'rsa-sha1';
break;
case 'rsa-sha256':
$this->hashAlgorithm = 'rsa-sha256';
if (!defined('OPENSSL_ALGO_SHA256')) {
throw new Swift_SwiftException('Unable to set sha256 as it is not supported by OpenSSL.');
}
break;
default:
throw new Swift_SwiftException('Unable to set the hash algorithm, must be one of rsa-sha1 or rsa-sha256 (%s given).', $hash);
}
return $this;
}
|
php
|
public function setHashAlgorithm($hash)
{
switch ($hash) {
case 'rsa-sha1':
$this->hashAlgorithm = 'rsa-sha1';
break;
case 'rsa-sha256':
$this->hashAlgorithm = 'rsa-sha256';
if (!defined('OPENSSL_ALGO_SHA256')) {
throw new Swift_SwiftException('Unable to set sha256 as it is not supported by OpenSSL.');
}
break;
default:
throw new Swift_SwiftException('Unable to set the hash algorithm, must be one of rsa-sha1 or rsa-sha256 (%s given).', $hash);
}
return $this;
}
|
[
"public",
"function",
"setHashAlgorithm",
"(",
"$",
"hash",
")",
"{",
"switch",
"(",
"$",
"hash",
")",
"{",
"case",
"'rsa-sha1'",
":",
"$",
"this",
"->",
"hashAlgorithm",
"=",
"'rsa-sha1'",
";",
"break",
";",
"case",
"'rsa-sha256'",
":",
"$",
"this",
"->",
"hashAlgorithm",
"=",
"'rsa-sha256'",
";",
"if",
"(",
"!",
"defined",
"(",
"'OPENSSL_ALGO_SHA256'",
")",
")",
"{",
"throw",
"new",
"Swift_SwiftException",
"(",
"'Unable to set sha256 as it is not supported by OpenSSL.'",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"Swift_SwiftException",
"(",
"'Unable to set the hash algorithm, must be one of rsa-sha1 or rsa-sha256 (%s given).'",
",",
"$",
"hash",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set hash_algorithm, must be one of rsa-sha256 | rsa-sha1.
@param string $hash 'rsa-sha1' or 'rsa-sha256'
@throws Swift_SwiftException
@return $this
|
[
"Set",
"hash_algorithm",
"must",
"be",
"one",
"of",
"rsa",
"-",
"sha256",
"|",
"rsa",
"-",
"sha1",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/DKIMSigner.php#L290-L307
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/DKIMSigner.php
|
Swift_Signers_DKIMSigner.setBodySignedLen
|
public function setBodySignedLen($len)
{
if (true === $len) {
$this->showLen = true;
$this->maxLen = PHP_INT_MAX;
} elseif (false === $len) {
$this->showLen = false;
$this->maxLen = PHP_INT_MAX;
} else {
$this->showLen = true;
$this->maxLen = (int) $len;
}
return $this;
}
|
php
|
public function setBodySignedLen($len)
{
if (true === $len) {
$this->showLen = true;
$this->maxLen = PHP_INT_MAX;
} elseif (false === $len) {
$this->showLen = false;
$this->maxLen = PHP_INT_MAX;
} else {
$this->showLen = true;
$this->maxLen = (int) $len;
}
return $this;
}
|
[
"public",
"function",
"setBodySignedLen",
"(",
"$",
"len",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"len",
")",
"{",
"$",
"this",
"->",
"showLen",
"=",
"true",
";",
"$",
"this",
"->",
"maxLen",
"=",
"PHP_INT_MAX",
";",
"}",
"elseif",
"(",
"false",
"===",
"$",
"len",
")",
"{",
"$",
"this",
"->",
"showLen",
"=",
"false",
";",
"$",
"this",
"->",
"maxLen",
"=",
"PHP_INT_MAX",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"showLen",
"=",
"true",
";",
"$",
"this",
"->",
"maxLen",
"=",
"(",
"int",
")",
"$",
"len",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the length of the body to sign.
@param mixed $len (bool or int)
@return $this
|
[
"Set",
"the",
"length",
"of",
"the",
"body",
"to",
"sign",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/DKIMSigner.php#L366-L380
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/DKIMSigner.php
|
Swift_Signers_DKIMSigner.startBody
|
public function startBody()
{
// Init
switch ($this->hashAlgorithm) {
case 'rsa-sha256':
$this->bodyHashHandler = hash_init('sha256');
break;
case 'rsa-sha1':
$this->bodyHashHandler = hash_init('sha1');
break;
}
$this->bodyCanonLine = '';
}
|
php
|
public function startBody()
{
// Init
switch ($this->hashAlgorithm) {
case 'rsa-sha256':
$this->bodyHashHandler = hash_init('sha256');
break;
case 'rsa-sha1':
$this->bodyHashHandler = hash_init('sha1');
break;
}
$this->bodyCanonLine = '';
}
|
[
"public",
"function",
"startBody",
"(",
")",
"{",
"// Init",
"switch",
"(",
"$",
"this",
"->",
"hashAlgorithm",
")",
"{",
"case",
"'rsa-sha256'",
":",
"$",
"this",
"->",
"bodyHashHandler",
"=",
"hash_init",
"(",
"'sha256'",
")",
";",
"break",
";",
"case",
"'rsa-sha1'",
":",
"$",
"this",
"->",
"bodyHashHandler",
"=",
"hash_init",
"(",
"'sha1'",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"bodyCanonLine",
"=",
"''",
";",
"}"
] |
Start Body.
|
[
"Start",
"Body",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/DKIMSigner.php#L427-L439
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/DKIMSigner.php
|
Swift_Signers_DKIMSigner.setHeaders
|
public function setHeaders(Swift_Mime_SimpleHeaderSet $headers)
{
$this->headerCanonData = '';
// Loop through Headers
$listHeaders = $headers->listAll();
foreach ($listHeaders as $hName) {
// Check if we need to ignore Header
if (!isset($this->ignoredHeaders[strtolower($hName)])) {
if ($headers->has($hName)) {
$tmp = $headers->getAll($hName);
foreach ($tmp as $header) {
if ('' != $header->getFieldBody()) {
$this->addHeader($header->toString());
$this->signedHeaders[] = $header->getFieldName();
}
}
}
}
}
return $this;
}
|
php
|
public function setHeaders(Swift_Mime_SimpleHeaderSet $headers)
{
$this->headerCanonData = '';
// Loop through Headers
$listHeaders = $headers->listAll();
foreach ($listHeaders as $hName) {
// Check if we need to ignore Header
if (!isset($this->ignoredHeaders[strtolower($hName)])) {
if ($headers->has($hName)) {
$tmp = $headers->getAll($hName);
foreach ($tmp as $header) {
if ('' != $header->getFieldBody()) {
$this->addHeader($header->toString());
$this->signedHeaders[] = $header->getFieldName();
}
}
}
}
}
return $this;
}
|
[
"public",
"function",
"setHeaders",
"(",
"Swift_Mime_SimpleHeaderSet",
"$",
"headers",
")",
"{",
"$",
"this",
"->",
"headerCanonData",
"=",
"''",
";",
"// Loop through Headers",
"$",
"listHeaders",
"=",
"$",
"headers",
"->",
"listAll",
"(",
")",
";",
"foreach",
"(",
"$",
"listHeaders",
"as",
"$",
"hName",
")",
"{",
"// Check if we need to ignore Header",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"ignoredHeaders",
"[",
"strtolower",
"(",
"$",
"hName",
")",
"]",
")",
")",
"{",
"if",
"(",
"$",
"headers",
"->",
"has",
"(",
"$",
"hName",
")",
")",
"{",
"$",
"tmp",
"=",
"$",
"headers",
"->",
"getAll",
"(",
"$",
"hName",
")",
";",
"foreach",
"(",
"$",
"tmp",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"''",
"!=",
"$",
"header",
"->",
"getFieldBody",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addHeader",
"(",
"$",
"header",
"->",
"toString",
"(",
")",
")",
";",
"$",
"this",
"->",
"signedHeaders",
"[",
"]",
"=",
"$",
"header",
"->",
"getFieldName",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the headers to sign.
@return Swift_Signers_DKIMSigner
|
[
"Set",
"the",
"headers",
"to",
"sign",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/DKIMSigner.php#L482-L503
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/AbstractHeader.php
|
Swift_Mime_Headers_AbstractHeader.setLanguage
|
public function setLanguage($lang)
{
$this->clearCachedValueIf($this->lang != $lang);
$this->lang = $lang;
}
|
php
|
public function setLanguage($lang)
{
$this->clearCachedValueIf($this->lang != $lang);
$this->lang = $lang;
}
|
[
"public",
"function",
"setLanguage",
"(",
"$",
"lang",
")",
"{",
"$",
"this",
"->",
"clearCachedValueIf",
"(",
"$",
"this",
"->",
"lang",
"!=",
"$",
"lang",
")",
";",
"$",
"this",
"->",
"lang",
"=",
"$",
"lang",
";",
"}"
] |
Set the language used in this Header.
For example, for US English, 'en-us'.
This can be unspecified.
@param string $lang
|
[
"Set",
"the",
"language",
"used",
"in",
"this",
"Header",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/AbstractHeader.php#L94-L98
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/AbstractHeader.php
|
Swift_Mime_Headers_AbstractHeader.getEncodableWordTokens
|
protected function getEncodableWordTokens($string)
{
$tokens = [];
$encodedToken = '';
// Split at all whitespace boundaries
foreach (preg_split('~(?=[\t ])~', $string) as $token) {
if ($this->tokenNeedsEncoding($token)) {
$encodedToken .= $token;
} else {
if (strlen($encodedToken) > 0) {
$tokens[] = $encodedToken;
$encodedToken = '';
}
$tokens[] = $token;
}
}
if (strlen($encodedToken)) {
$tokens[] = $encodedToken;
}
return $tokens;
}
|
php
|
protected function getEncodableWordTokens($string)
{
$tokens = [];
$encodedToken = '';
// Split at all whitespace boundaries
foreach (preg_split('~(?=[\t ])~', $string) as $token) {
if ($this->tokenNeedsEncoding($token)) {
$encodedToken .= $token;
} else {
if (strlen($encodedToken) > 0) {
$tokens[] = $encodedToken;
$encodedToken = '';
}
$tokens[] = $token;
}
}
if (strlen($encodedToken)) {
$tokens[] = $encodedToken;
}
return $tokens;
}
|
[
"protected",
"function",
"getEncodableWordTokens",
"(",
"$",
"string",
")",
"{",
"$",
"tokens",
"=",
"[",
"]",
";",
"$",
"encodedToken",
"=",
"''",
";",
"// Split at all whitespace boundaries",
"foreach",
"(",
"preg_split",
"(",
"'~(?=[\\t ])~'",
",",
"$",
"string",
")",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"tokenNeedsEncoding",
"(",
"$",
"token",
")",
")",
"{",
"$",
"encodedToken",
".=",
"$",
"token",
";",
"}",
"else",
"{",
"if",
"(",
"strlen",
"(",
"$",
"encodedToken",
")",
">",
"0",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"encodedToken",
";",
"$",
"encodedToken",
"=",
"''",
";",
"}",
"$",
"tokens",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"}",
"if",
"(",
"strlen",
"(",
"$",
"encodedToken",
")",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"encodedToken",
";",
"}",
"return",
"$",
"tokens",
";",
"}"
] |
Splits a string into tokens in blocks of words which can be encoded quickly.
@param string $string
@return string[]
|
[
"Splits",
"a",
"string",
"into",
"tokens",
"in",
"blocks",
"of",
"words",
"which",
"can",
"be",
"encoded",
"quickly",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/AbstractHeader.php#L306-L328
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Signers/DomainKeySigner.php
|
Swift_Signers_DomainKeySigner.reset
|
public function reset()
{
$this->hashHandler = null;
$this->bodyCanonIgnoreStart = 2;
$this->bodyCanonEmptyCounter = 0;
$this->bodyCanonLastChar = null;
$this->bodyCanonSpace = false;
return $this;
}
|
php
|
public function reset()
{
$this->hashHandler = null;
$this->bodyCanonIgnoreStart = 2;
$this->bodyCanonEmptyCounter = 0;
$this->bodyCanonLastChar = null;
$this->bodyCanonSpace = false;
return $this;
}
|
[
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"hashHandler",
"=",
"null",
";",
"$",
"this",
"->",
"bodyCanonIgnoreStart",
"=",
"2",
";",
"$",
"this",
"->",
"bodyCanonEmptyCounter",
"=",
"0",
";",
"$",
"this",
"->",
"bodyCanonLastChar",
"=",
"null",
";",
"$",
"this",
"->",
"bodyCanonSpace",
"=",
"false",
";",
"return",
"$",
"this",
";",
"}"
] |
Resets internal states.
@return $this
|
[
"Resets",
"internal",
"states",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Signers/DomainKeySigner.php#L130-L139
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/MailboxHeader.php
|
Swift_Mime_Headers_MailboxHeader.setNameAddresses
|
public function setNameAddresses($mailboxes)
{
$this->mailboxes = $this->normalizeMailboxes((array) $mailboxes);
$this->setCachedValue(null); //Clear any cached value
}
|
php
|
public function setNameAddresses($mailboxes)
{
$this->mailboxes = $this->normalizeMailboxes((array) $mailboxes);
$this->setCachedValue(null); //Clear any cached value
}
|
[
"public",
"function",
"setNameAddresses",
"(",
"$",
"mailboxes",
")",
"{",
"$",
"this",
"->",
"mailboxes",
"=",
"$",
"this",
"->",
"normalizeMailboxes",
"(",
"(",
"array",
")",
"$",
"mailboxes",
")",
";",
"$",
"this",
"->",
"setCachedValue",
"(",
"null",
")",
";",
"//Clear any cached value",
"}"
] |
Set a list of mailboxes to be shown in this Header.
The mailboxes can be a simple array of addresses, or an array of
key=>value pairs where (email => personalName).
Example:
<code>
<?php
//Sets two mailboxes in the Header, one with a personal name
$header->setNameAddresses(array(
'chris@swiftmailer.org' => 'Chris Corbyn',
'mark@swiftmailer.org' //No associated personal name
));
?>
</code>
@see __construct()
@see setAddresses()
@see setValue()
@param string|string[] $mailboxes
@throws Swift_RfcComplianceException
|
[
"Set",
"a",
"list",
"of",
"mailboxes",
"to",
"be",
"shown",
"in",
"this",
"Header",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/MailboxHeader.php#L115-L119
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/MailboxHeader.php
|
Swift_Mime_Headers_MailboxHeader.removeAddresses
|
public function removeAddresses($addresses)
{
$this->setCachedValue(null);
foreach ((array) $addresses as $address) {
unset($this->mailboxes[$address]);
}
}
|
php
|
public function removeAddresses($addresses)
{
$this->setCachedValue(null);
foreach ((array) $addresses as $address) {
unset($this->mailboxes[$address]);
}
}
|
[
"public",
"function",
"removeAddresses",
"(",
"$",
"addresses",
")",
"{",
"$",
"this",
"->",
"setCachedValue",
"(",
"null",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"addresses",
"as",
"$",
"address",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"mailboxes",
"[",
"$",
"address",
"]",
")",
";",
"}",
"}"
] |
Remove one or more addresses from this Header.
@param string|string[] $addresses
|
[
"Remove",
"one",
"or",
"more",
"addresses",
"from",
"this",
"Header",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/MailboxHeader.php#L222-L228
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/MailboxHeader.php
|
Swift_Mime_Headers_MailboxHeader.normalizeMailboxes
|
protected function normalizeMailboxes(array $mailboxes)
{
$actualMailboxes = [];
foreach ($mailboxes as $key => $value) {
if (is_string($key)) {
//key is email addr
$address = $key;
$name = $value;
} else {
$address = $value;
$name = null;
}
$this->assertValidAddress($address);
$actualMailboxes[$address] = $name;
}
return $actualMailboxes;
}
|
php
|
protected function normalizeMailboxes(array $mailboxes)
{
$actualMailboxes = [];
foreach ($mailboxes as $key => $value) {
if (is_string($key)) {
//key is email addr
$address = $key;
$name = $value;
} else {
$address = $value;
$name = null;
}
$this->assertValidAddress($address);
$actualMailboxes[$address] = $name;
}
return $actualMailboxes;
}
|
[
"protected",
"function",
"normalizeMailboxes",
"(",
"array",
"$",
"mailboxes",
")",
"{",
"$",
"actualMailboxes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"mailboxes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"//key is email addr",
"$",
"address",
"=",
"$",
"key",
";",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"address",
"=",
"$",
"value",
";",
"$",
"name",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"assertValidAddress",
"(",
"$",
"address",
")",
";",
"$",
"actualMailboxes",
"[",
"$",
"address",
"]",
"=",
"$",
"name",
";",
"}",
"return",
"$",
"actualMailboxes",
";",
"}"
] |
Normalizes a user-input list of mailboxes into consistent key=>value pairs.
@param string[] $mailboxes
@return string[]
|
[
"Normalizes",
"a",
"user",
"-",
"input",
"list",
"of",
"mailboxes",
"into",
"consistent",
"key",
"=",
">",
"value",
"pairs",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/MailboxHeader.php#L259-L277
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/MailboxHeader.php
|
Swift_Mime_Headers_MailboxHeader.createDisplayNameString
|
protected function createDisplayNameString($displayName, $shorten = false)
{
return $this->createPhrase($this, $displayName, $this->getCharset(), $this->getEncoder(), $shorten);
}
|
php
|
protected function createDisplayNameString($displayName, $shorten = false)
{
return $this->createPhrase($this, $displayName, $this->getCharset(), $this->getEncoder(), $shorten);
}
|
[
"protected",
"function",
"createDisplayNameString",
"(",
"$",
"displayName",
",",
"$",
"shorten",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"createPhrase",
"(",
"$",
"this",
",",
"$",
"displayName",
",",
"$",
"this",
"->",
"getCharset",
"(",
")",
",",
"$",
"this",
"->",
"getEncoder",
"(",
")",
",",
"$",
"shorten",
")",
";",
"}"
] |
Produces a compliant, formatted display-name based on the string given.
@param string $displayName as displayed
@param bool $shorten the first line to make remove for header name
@return string
|
[
"Produces",
"a",
"compliant",
"formatted",
"display",
"-",
"name",
"based",
"on",
"the",
"string",
"given",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/MailboxHeader.php#L287-L290
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/MailboxHeader.php
|
Swift_Mime_Headers_MailboxHeader.createNameAddressStrings
|
private function createNameAddressStrings(array $mailboxes)
{
$strings = [];
foreach ($mailboxes as $email => $name) {
$mailboxStr = $this->addressEncoder->encodeString($email);
if (null !== $name) {
$nameStr = $this->createDisplayNameString($name, empty($strings));
$mailboxStr = $nameStr.' <'.$mailboxStr.'>';
}
$strings[] = $mailboxStr;
}
return $strings;
}
|
php
|
private function createNameAddressStrings(array $mailboxes)
{
$strings = [];
foreach ($mailboxes as $email => $name) {
$mailboxStr = $this->addressEncoder->encodeString($email);
if (null !== $name) {
$nameStr = $this->createDisplayNameString($name, empty($strings));
$mailboxStr = $nameStr.' <'.$mailboxStr.'>';
}
$strings[] = $mailboxStr;
}
return $strings;
}
|
[
"private",
"function",
"createNameAddressStrings",
"(",
"array",
"$",
"mailboxes",
")",
"{",
"$",
"strings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"mailboxes",
"as",
"$",
"email",
"=>",
"$",
"name",
")",
"{",
"$",
"mailboxStr",
"=",
"$",
"this",
"->",
"addressEncoder",
"->",
"encodeString",
"(",
"$",
"email",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"name",
")",
"{",
"$",
"nameStr",
"=",
"$",
"this",
"->",
"createDisplayNameString",
"(",
"$",
"name",
",",
"empty",
"(",
"$",
"strings",
")",
")",
";",
"$",
"mailboxStr",
"=",
"$",
"nameStr",
".",
"' <'",
".",
"$",
"mailboxStr",
".",
"'>'",
";",
"}",
"$",
"strings",
"[",
"]",
"=",
"$",
"mailboxStr",
";",
"}",
"return",
"$",
"strings",
";",
"}"
] |
Return an array of strings conforming the the name-addr spec of RFC 2822.
@param string[] $mailboxes
@return string[]
|
[
"Return",
"an",
"array",
"of",
"strings",
"conforming",
"the",
"the",
"name",
"-",
"addr",
"spec",
"of",
"RFC",
"2822",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/MailboxHeader.php#L329-L343
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Events/SimpleEventDispatcher.php
|
Swift_Events_SimpleEventDispatcher.bindEventListener
|
public function bindEventListener(Swift_Events_EventListener $listener)
{
foreach ($this->listeners as $l) {
// Already loaded
if ($l === $listener) {
return;
}
}
$this->listeners[] = $listener;
}
|
php
|
public function bindEventListener(Swift_Events_EventListener $listener)
{
foreach ($this->listeners as $l) {
// Already loaded
if ($l === $listener) {
return;
}
}
$this->listeners[] = $listener;
}
|
[
"public",
"function",
"bindEventListener",
"(",
"Swift_Events_EventListener",
"$",
"listener",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"listeners",
"as",
"$",
"l",
")",
"{",
"// Already loaded",
"if",
"(",
"$",
"l",
"===",
"$",
"listener",
")",
"{",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"listeners",
"[",
"]",
"=",
"$",
"listener",
";",
"}"
] |
Bind an event listener to this dispatcher.
|
[
"Bind",
"an",
"event",
"listener",
"to",
"this",
"dispatcher",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Events/SimpleEventDispatcher.php#L100-L109
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Events/SimpleEventDispatcher.php
|
Swift_Events_SimpleEventDispatcher.dispatchEvent
|
public function dispatchEvent(Swift_Events_EventObject $evt, $target)
{
$this->prepareBubbleQueue($evt);
$this->bubble($evt, $target);
}
|
php
|
public function dispatchEvent(Swift_Events_EventObject $evt, $target)
{
$this->prepareBubbleQueue($evt);
$this->bubble($evt, $target);
}
|
[
"public",
"function",
"dispatchEvent",
"(",
"Swift_Events_EventObject",
"$",
"evt",
",",
"$",
"target",
")",
"{",
"$",
"this",
"->",
"prepareBubbleQueue",
"(",
"$",
"evt",
")",
";",
"$",
"this",
"->",
"bubble",
"(",
"$",
"evt",
",",
"$",
"target",
")",
";",
"}"
] |
Dispatch the given Event to all suitable listeners.
@param string $target method
|
[
"Dispatch",
"the",
"given",
"Event",
"to",
"all",
"suitable",
"listeners",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Events/SimpleEventDispatcher.php#L116-L120
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/KeyCache/DiskKeyCache.php
|
Swift_KeyCache_DiskKeyCache.getHandle
|
private function getHandle($nsKey, $itemKey, $position)
{
if (!isset($this->keys[$nsKey][$itemKey])) {
$openMode = $this->hasKey($nsKey, $itemKey) ? 'r+b' : 'w+b';
$fp = fopen($this->path.'/'.$nsKey.'/'.$itemKey, $openMode);
$this->keys[$nsKey][$itemKey] = $fp;
}
if (self::POSITION_START == $position) {
fseek($this->keys[$nsKey][$itemKey], 0, SEEK_SET);
} elseif (self::POSITION_END == $position) {
fseek($this->keys[$nsKey][$itemKey], 0, SEEK_END);
}
return $this->keys[$nsKey][$itemKey];
}
|
php
|
private function getHandle($nsKey, $itemKey, $position)
{
if (!isset($this->keys[$nsKey][$itemKey])) {
$openMode = $this->hasKey($nsKey, $itemKey) ? 'r+b' : 'w+b';
$fp = fopen($this->path.'/'.$nsKey.'/'.$itemKey, $openMode);
$this->keys[$nsKey][$itemKey] = $fp;
}
if (self::POSITION_START == $position) {
fseek($this->keys[$nsKey][$itemKey], 0, SEEK_SET);
} elseif (self::POSITION_END == $position) {
fseek($this->keys[$nsKey][$itemKey], 0, SEEK_END);
}
return $this->keys[$nsKey][$itemKey];
}
|
[
"private",
"function",
"getHandle",
"(",
"$",
"nsKey",
",",
"$",
"itemKey",
",",
"$",
"position",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"nsKey",
"]",
"[",
"$",
"itemKey",
"]",
")",
")",
"{",
"$",
"openMode",
"=",
"$",
"this",
"->",
"hasKey",
"(",
"$",
"nsKey",
",",
"$",
"itemKey",
")",
"?",
"'r+b'",
":",
"'w+b'",
";",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"$",
"nsKey",
".",
"'/'",
".",
"$",
"itemKey",
",",
"$",
"openMode",
")",
";",
"$",
"this",
"->",
"keys",
"[",
"$",
"nsKey",
"]",
"[",
"$",
"itemKey",
"]",
"=",
"$",
"fp",
";",
"}",
"if",
"(",
"self",
"::",
"POSITION_START",
"==",
"$",
"position",
")",
"{",
"fseek",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"nsKey",
"]",
"[",
"$",
"itemKey",
"]",
",",
"0",
",",
"SEEK_SET",
")",
";",
"}",
"elseif",
"(",
"self",
"::",
"POSITION_END",
"==",
"$",
"position",
")",
"{",
"fseek",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"nsKey",
"]",
"[",
"$",
"itemKey",
"]",
",",
"0",
",",
"SEEK_END",
")",
";",
"}",
"return",
"$",
"this",
"->",
"keys",
"[",
"$",
"nsKey",
"]",
"[",
"$",
"itemKey",
"]",
";",
"}"
] |
Get a file handle on the cache item.
@param string $nsKey
@param string $itemKey
@param int $position
@return resource
|
[
"Get",
"a",
"file",
"handle",
"on",
"the",
"cache",
"item",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/KeyCache/DiskKeyCache.php#L263-L277
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/ParameterizedHeader.php
|
Swift_Mime_Headers_ParameterizedHeader.setParameters
|
public function setParameters(array $parameters)
{
$this->clearCachedValueIf($this->params != $parameters);
$this->params = $parameters;
}
|
php
|
public function setParameters(array $parameters)
{
$this->clearCachedValueIf($this->params != $parameters);
$this->params = $parameters;
}
|
[
"public",
"function",
"setParameters",
"(",
"array",
"$",
"parameters",
")",
"{",
"$",
"this",
"->",
"clearCachedValueIf",
"(",
"$",
"this",
"->",
"params",
"!=",
"$",
"parameters",
")",
";",
"$",
"this",
"->",
"params",
"=",
"$",
"parameters",
";",
"}"
] |
Set an associative array of parameter names mapped to values.
@param string[] $parameters
|
[
"Set",
"an",
"associative",
"array",
"of",
"parameter",
"names",
"mapped",
"to",
"values",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/ParameterizedHeader.php#L106-L110
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Headers/ParameterizedHeader.php
|
Swift_Mime_Headers_ParameterizedHeader.getEndOfParameterValue
|
private function getEndOfParameterValue($value, $encoded = false, $firstLine = false)
{
if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
$value = '"'.$value.'"';
}
$prepend = '=';
if ($encoded) {
$prepend = '*=';
if ($firstLine) {
$prepend = '*='.$this->getCharset()."'".$this->getLanguage().
"'";
}
}
return $prepend.$value;
}
|
php
|
private function getEndOfParameterValue($value, $encoded = false, $firstLine = false)
{
if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
$value = '"'.$value.'"';
}
$prepend = '=';
if ($encoded) {
$prepend = '*=';
if ($firstLine) {
$prepend = '*='.$this->getCharset()."'".$this->getLanguage().
"'";
}
}
return $prepend.$value;
}
|
[
"private",
"function",
"getEndOfParameterValue",
"(",
"$",
"value",
",",
"$",
"encoded",
"=",
"false",
",",
"$",
"firstLine",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^'",
".",
"self",
"::",
"TOKEN_REGEX",
".",
"'$/D'",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"'\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"}",
"$",
"prepend",
"=",
"'='",
";",
"if",
"(",
"$",
"encoded",
")",
"{",
"$",
"prepend",
"=",
"'*='",
";",
"if",
"(",
"$",
"firstLine",
")",
"{",
"$",
"prepend",
"=",
"'*='",
".",
"$",
"this",
"->",
"getCharset",
"(",
")",
".",
"\"'\"",
".",
"$",
"this",
"->",
"getLanguage",
"(",
")",
".",
"\"'\"",
";",
"}",
"}",
"return",
"$",
"prepend",
".",
"$",
"value",
";",
"}"
] |
Returns the parameter value from the "=" and beyond.
@param string $value to append
@param bool $encoded
@param bool $firstLine
@return string
|
[
"Returns",
"the",
"parameter",
"value",
"from",
"the",
"=",
"and",
"beyond",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Headers/ParameterizedHeader.php#L239-L254
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php
|
Swift_Transport_Esmtp_Auth_CramMd5Authenticator.getResponse
|
private function getResponse($secret, $challenge)
{
if (strlen($secret) > 64) {
$secret = pack('H32', md5($secret));
}
if (strlen($secret) < 64) {
$secret = str_pad($secret, 64, chr(0));
}
$k_ipad = substr($secret, 0, 64) ^ str_repeat(chr(0x36), 64);
$k_opad = substr($secret, 0, 64) ^ str_repeat(chr(0x5C), 64);
$inner = pack('H32', md5($k_ipad.$challenge));
$digest = md5($k_opad.$inner);
return $digest;
}
|
php
|
private function getResponse($secret, $challenge)
{
if (strlen($secret) > 64) {
$secret = pack('H32', md5($secret));
}
if (strlen($secret) < 64) {
$secret = str_pad($secret, 64, chr(0));
}
$k_ipad = substr($secret, 0, 64) ^ str_repeat(chr(0x36), 64);
$k_opad = substr($secret, 0, 64) ^ str_repeat(chr(0x5C), 64);
$inner = pack('H32', md5($k_ipad.$challenge));
$digest = md5($k_opad.$inner);
return $digest;
}
|
[
"private",
"function",
"getResponse",
"(",
"$",
"secret",
",",
"$",
"challenge",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"secret",
")",
">",
"64",
")",
"{",
"$",
"secret",
"=",
"pack",
"(",
"'H32'",
",",
"md5",
"(",
"$",
"secret",
")",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"secret",
")",
"<",
"64",
")",
"{",
"$",
"secret",
"=",
"str_pad",
"(",
"$",
"secret",
",",
"64",
",",
"chr",
"(",
"0",
")",
")",
";",
"}",
"$",
"k_ipad",
"=",
"substr",
"(",
"$",
"secret",
",",
"0",
",",
"64",
")",
"^",
"str_repeat",
"(",
"chr",
"(",
"0x36",
")",
",",
"64",
")",
";",
"$",
"k_opad",
"=",
"substr",
"(",
"$",
"secret",
",",
"0",
",",
"64",
")",
"^",
"str_repeat",
"(",
"chr",
"(",
"0x5C",
")",
",",
"64",
")",
";",
"$",
"inner",
"=",
"pack",
"(",
"'H32'",
",",
"md5",
"(",
"$",
"k_ipad",
".",
"$",
"challenge",
")",
")",
";",
"$",
"digest",
"=",
"md5",
"(",
"$",
"k_opad",
".",
"$",
"inner",
")",
";",
"return",
"$",
"digest",
";",
"}"
] |
Generate a CRAM-MD5 response from a server challenge.
@param string $secret
@param string $challenge
@return string
|
[
"Generate",
"a",
"CRAM",
"-",
"MD5",
"response",
"from",
"a",
"server",
"challenge",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php#L57-L74
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/CharacterStream/NgCharacterStream.php
|
Swift_CharacterStream_NgCharacterStream.setCharacterSet
|
public function setCharacterSet($charset)
{
$this->charset = $charset;
$this->charReader = null;
$this->mapType = 0;
}
|
php
|
public function setCharacterSet($charset)
{
$this->charset = $charset;
$this->charReader = null;
$this->mapType = 0;
}
|
[
"public",
"function",
"setCharacterSet",
"(",
"$",
"charset",
")",
"{",
"$",
"this",
"->",
"charset",
"=",
"$",
"charset",
";",
"$",
"this",
"->",
"charReader",
"=",
"null",
";",
"$",
"this",
"->",
"mapType",
"=",
"0",
";",
"}"
] |
Set the character set used in this CharacterStream.
@param string $charset
|
[
"Set",
"the",
"character",
"set",
"used",
"in",
"this",
"CharacterStream",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/CharacterStream/NgCharacterStream.php#L99-L104
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/AuthHandler.php
|
Swift_Transport_Esmtp_AuthHandler.afterEhlo
|
public function afterEhlo(Swift_Transport_SmtpAgent $agent)
{
if ($this->username) {
$count = 0;
$errors = [];
foreach ($this->getAuthenticatorsForAgent() as $authenticator) {
if (in_array(strtolower($authenticator->getAuthKeyword()), array_map('strtolower', $this->esmtpParams))) {
++$count;
try {
if ($authenticator->authenticate($agent, $this->username, $this->password)) {
return;
}
} catch (Swift_TransportException $e) {
// keep the error message, but tries the other authenticators
$errors[] = [$authenticator->getAuthKeyword(), $e->getMessage()];
}
}
}
$message = 'Failed to authenticate on SMTP server with username "'.$this->username.'" using '.$count.' possible authenticators.';
foreach ($errors as $error) {
$message .= ' Authenticator '.$error[0].' returned '.$error[1].'.';
}
throw new Swift_TransportException($message);
}
}
|
php
|
public function afterEhlo(Swift_Transport_SmtpAgent $agent)
{
if ($this->username) {
$count = 0;
$errors = [];
foreach ($this->getAuthenticatorsForAgent() as $authenticator) {
if (in_array(strtolower($authenticator->getAuthKeyword()), array_map('strtolower', $this->esmtpParams))) {
++$count;
try {
if ($authenticator->authenticate($agent, $this->username, $this->password)) {
return;
}
} catch (Swift_TransportException $e) {
// keep the error message, but tries the other authenticators
$errors[] = [$authenticator->getAuthKeyword(), $e->getMessage()];
}
}
}
$message = 'Failed to authenticate on SMTP server with username "'.$this->username.'" using '.$count.' possible authenticators.';
foreach ($errors as $error) {
$message .= ' Authenticator '.$error[0].' returned '.$error[1].'.';
}
throw new Swift_TransportException($message);
}
}
|
[
"public",
"function",
"afterEhlo",
"(",
"Swift_Transport_SmtpAgent",
"$",
"agent",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"username",
")",
"{",
"$",
"count",
"=",
"0",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAuthenticatorsForAgent",
"(",
")",
"as",
"$",
"authenticator",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"authenticator",
"->",
"getAuthKeyword",
"(",
")",
")",
",",
"array_map",
"(",
"'strtolower'",
",",
"$",
"this",
"->",
"esmtpParams",
")",
")",
")",
"{",
"++",
"$",
"count",
";",
"try",
"{",
"if",
"(",
"$",
"authenticator",
"->",
"authenticate",
"(",
"$",
"agent",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
")",
")",
"{",
"return",
";",
"}",
"}",
"catch",
"(",
"Swift_TransportException",
"$",
"e",
")",
"{",
"// keep the error message, but tries the other authenticators",
"$",
"errors",
"[",
"]",
"=",
"[",
"$",
"authenticator",
"->",
"getAuthKeyword",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"}",
"}",
"$",
"message",
"=",
"'Failed to authenticate on SMTP server with username \"'",
".",
"$",
"this",
"->",
"username",
".",
"'\" using '",
".",
"$",
"count",
".",
"' possible authenticators.'",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"{",
"$",
"message",
".=",
"' Authenticator '",
".",
"$",
"error",
"[",
"0",
"]",
".",
"' returned '",
".",
"$",
"error",
"[",
"1",
"]",
".",
"'.'",
";",
"}",
"throw",
"new",
"Swift_TransportException",
"(",
"$",
"message",
")",
";",
"}",
"}"
] |
Runs immediately after a EHLO has been issued.
@param Swift_Transport_SmtpAgent $agent to read/write
|
[
"Runs",
"immediately",
"after",
"a",
"EHLO",
"has",
"been",
"issued",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/AuthHandler.php#L168-L193
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/Esmtp/AuthHandler.php
|
Swift_Transport_Esmtp_AuthHandler.getAuthenticatorsForAgent
|
protected function getAuthenticatorsForAgent()
{
if (!$mode = strtolower($this->auth_mode)) {
return $this->authenticators;
}
foreach ($this->authenticators as $authenticator) {
if (strtolower($authenticator->getAuthKeyword()) == $mode) {
return [$authenticator];
}
}
throw new Swift_TransportException('Auth mode '.$mode.' is invalid');
}
|
php
|
protected function getAuthenticatorsForAgent()
{
if (!$mode = strtolower($this->auth_mode)) {
return $this->authenticators;
}
foreach ($this->authenticators as $authenticator) {
if (strtolower($authenticator->getAuthKeyword()) == $mode) {
return [$authenticator];
}
}
throw new Swift_TransportException('Auth mode '.$mode.' is invalid');
}
|
[
"protected",
"function",
"getAuthenticatorsForAgent",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"mode",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"auth_mode",
")",
")",
"{",
"return",
"$",
"this",
"->",
"authenticators",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"authenticators",
"as",
"$",
"authenticator",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"authenticator",
"->",
"getAuthKeyword",
"(",
")",
")",
"==",
"$",
"mode",
")",
"{",
"return",
"[",
"$",
"authenticator",
"]",
";",
"}",
"}",
"throw",
"new",
"Swift_TransportException",
"(",
"'Auth mode '",
".",
"$",
"mode",
".",
"' is invalid'",
")",
";",
"}"
] |
Returns the authenticator list for the given agent.
@return array
|
[
"Returns",
"the",
"authenticator",
"list",
"for",
"the",
"given",
"agent",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/Esmtp/AuthHandler.php#L254-L267
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/FileSpool.php
|
Swift_FileSpool.queueMessage
|
public function queueMessage(Swift_Mime_SimpleMessage $message)
{
$ser = serialize($message);
$fileName = $this->path.'/'.$this->getRandomString(10);
for ($i = 0; $i < $this->retryLimit; ++$i) {
/* We try an exclusive creation of the file. This is an atomic operation, it avoid locking mechanism */
$fp = @fopen($fileName.'.message', 'xb');
if (false !== $fp) {
if (false === fwrite($fp, $ser)) {
return false;
}
return fclose($fp);
} else {
/* The file already exists, we try a longer fileName */
$fileName .= $this->getRandomString(1);
}
}
throw new Swift_IoException(sprintf('Unable to create a file for enqueuing Message in "%s".', $this->path));
}
|
php
|
public function queueMessage(Swift_Mime_SimpleMessage $message)
{
$ser = serialize($message);
$fileName = $this->path.'/'.$this->getRandomString(10);
for ($i = 0; $i < $this->retryLimit; ++$i) {
/* We try an exclusive creation of the file. This is an atomic operation, it avoid locking mechanism */
$fp = @fopen($fileName.'.message', 'xb');
if (false !== $fp) {
if (false === fwrite($fp, $ser)) {
return false;
}
return fclose($fp);
} else {
/* The file already exists, we try a longer fileName */
$fileName .= $this->getRandomString(1);
}
}
throw new Swift_IoException(sprintf('Unable to create a file for enqueuing Message in "%s".', $this->path));
}
|
[
"public",
"function",
"queueMessage",
"(",
"Swift_Mime_SimpleMessage",
"$",
"message",
")",
"{",
"$",
"ser",
"=",
"serialize",
"(",
"$",
"message",
")",
";",
"$",
"fileName",
"=",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"$",
"this",
"->",
"getRandomString",
"(",
"10",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"retryLimit",
";",
"++",
"$",
"i",
")",
"{",
"/* We try an exclusive creation of the file. This is an atomic operation, it avoid locking mechanism */",
"$",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"fileName",
".",
"'.message'",
",",
"'xb'",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"fp",
")",
"{",
"if",
"(",
"false",
"===",
"fwrite",
"(",
"$",
"fp",
",",
"$",
"ser",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"fclose",
"(",
"$",
"fp",
")",
";",
"}",
"else",
"{",
"/* The file already exists, we try a longer fileName */",
"$",
"fileName",
".=",
"$",
"this",
"->",
"getRandomString",
"(",
"1",
")",
";",
"}",
"}",
"throw",
"new",
"Swift_IoException",
"(",
"sprintf",
"(",
"'Unable to create a file for enqueuing Message in \"%s\".'",
",",
"$",
"this",
"->",
"path",
")",
")",
";",
"}"
] |
Queues a message.
@param Swift_Mime_SimpleMessage $message The message to store
@throws Swift_IoException
@return bool
|
[
"Queues",
"a",
"message",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/FileSpool.php#L92-L112
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/FileSpool.php
|
Swift_FileSpool.recover
|
public function recover($timeout = 900)
{
foreach (new DirectoryIterator($this->path) as $file) {
$file = $file->getRealPath();
if ('.message.sending' == substr($file, -16)) {
$lockedtime = filectime($file);
if ((time() - $lockedtime) > $timeout) {
rename($file, substr($file, 0, -8));
}
}
}
}
|
php
|
public function recover($timeout = 900)
{
foreach (new DirectoryIterator($this->path) as $file) {
$file = $file->getRealPath();
if ('.message.sending' == substr($file, -16)) {
$lockedtime = filectime($file);
if ((time() - $lockedtime) > $timeout) {
rename($file, substr($file, 0, -8));
}
}
}
}
|
[
"public",
"function",
"recover",
"(",
"$",
"timeout",
"=",
"900",
")",
"{",
"foreach",
"(",
"new",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"path",
")",
"as",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"if",
"(",
"'.message.sending'",
"==",
"substr",
"(",
"$",
"file",
",",
"-",
"16",
")",
")",
"{",
"$",
"lockedtime",
"=",
"filectime",
"(",
"$",
"file",
")",
";",
"if",
"(",
"(",
"time",
"(",
")",
"-",
"$",
"lockedtime",
")",
">",
"$",
"timeout",
")",
"{",
"rename",
"(",
"$",
"file",
",",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"-",
"8",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Execute a recovery if for any reason a process is sending for too long.
@param int $timeout in second Defaults is for very slow smtp responses
|
[
"Execute",
"a",
"recovery",
"if",
"for",
"any",
"reason",
"a",
"process",
"is",
"sending",
"for",
"too",
"long",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/FileSpool.php#L119-L131
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Attachment.php
|
Swift_Mime_Attachment.setDisposition
|
public function setDisposition($disposition)
{
if (!$this->setHeaderFieldModel('Content-Disposition', $disposition)) {
$this->getHeaders()->addParameterizedHeader('Content-Disposition', $disposition);
}
return $this;
}
|
php
|
public function setDisposition($disposition)
{
if (!$this->setHeaderFieldModel('Content-Disposition', $disposition)) {
$this->getHeaders()->addParameterizedHeader('Content-Disposition', $disposition);
}
return $this;
}
|
[
"public",
"function",
"setDisposition",
"(",
"$",
"disposition",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"setHeaderFieldModel",
"(",
"'Content-Disposition'",
",",
"$",
"disposition",
")",
")",
"{",
"$",
"this",
"->",
"getHeaders",
"(",
")",
"->",
"addParameterizedHeader",
"(",
"'Content-Disposition'",
",",
"$",
"disposition",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the Content-Disposition of this attachment.
@param string $disposition
@return $this
|
[
"Set",
"the",
"Content",
"-",
"Disposition",
"of",
"this",
"attachment",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Attachment.php#L65-L72
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Mime/Attachment.php
|
Swift_Mime_Attachment.setFile
|
public function setFile(Swift_FileStream $file, $contentType = null)
{
$this->setFilename(basename($file->getPath()));
$this->setBody($file, $contentType);
if (!isset($contentType)) {
$extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
if (array_key_exists($extension, $this->mimeTypes)) {
$this->setContentType($this->mimeTypes[$extension]);
}
}
return $this;
}
|
php
|
public function setFile(Swift_FileStream $file, $contentType = null)
{
$this->setFilename(basename($file->getPath()));
$this->setBody($file, $contentType);
if (!isset($contentType)) {
$extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
if (array_key_exists($extension, $this->mimeTypes)) {
$this->setContentType($this->mimeTypes[$extension]);
}
}
return $this;
}
|
[
"public",
"function",
"setFile",
"(",
"Swift_FileStream",
"$",
"file",
",",
"$",
"contentType",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"setFilename",
"(",
"basename",
"(",
"$",
"file",
"->",
"getPath",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"setBody",
"(",
"$",
"file",
",",
"$",
"contentType",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"contentType",
")",
")",
"{",
"$",
"extension",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"file",
"->",
"getPath",
"(",
")",
",",
"strrpos",
"(",
"$",
"file",
"->",
"getPath",
"(",
")",
",",
"'.'",
")",
"+",
"1",
")",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"extension",
",",
"$",
"this",
"->",
"mimeTypes",
")",
")",
"{",
"$",
"this",
"->",
"setContentType",
"(",
"$",
"this",
"->",
"mimeTypes",
"[",
"$",
"extension",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set the file that this attachment is for.
@param string $contentType optional
@return $this
|
[
"Set",
"the",
"file",
"that",
"this",
"attachment",
"is",
"for",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Mime/Attachment.php#L130-L143
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php
|
Swift_CharacterReaderFactory_SimpleCharacterReaderFactory.getReaderFor
|
public function getReaderFor($charset)
{
$charset = strtolower(trim($charset));
foreach (self::$map as $pattern => $spec) {
$re = '/^'.$pattern.'$/D';
if (preg_match($re, $charset)) {
if (!array_key_exists($pattern, self::$loaded)) {
$reflector = new ReflectionClass($spec['class']);
if ($reflector->getConstructor()) {
$reader = $reflector->newInstanceArgs($spec['constructor']);
} else {
$reader = $reflector->newInstance();
}
self::$loaded[$pattern] = $reader;
}
return self::$loaded[$pattern];
}
}
}
|
php
|
public function getReaderFor($charset)
{
$charset = strtolower(trim($charset));
foreach (self::$map as $pattern => $spec) {
$re = '/^'.$pattern.'$/D';
if (preg_match($re, $charset)) {
if (!array_key_exists($pattern, self::$loaded)) {
$reflector = new ReflectionClass($spec['class']);
if ($reflector->getConstructor()) {
$reader = $reflector->newInstanceArgs($spec['constructor']);
} else {
$reader = $reflector->newInstance();
}
self::$loaded[$pattern] = $reader;
}
return self::$loaded[$pattern];
}
}
}
|
[
"public",
"function",
"getReaderFor",
"(",
"$",
"charset",
")",
"{",
"$",
"charset",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"charset",
")",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"map",
"as",
"$",
"pattern",
"=>",
"$",
"spec",
")",
"{",
"$",
"re",
"=",
"'/^'",
".",
"$",
"pattern",
".",
"'$/D'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"re",
",",
"$",
"charset",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"pattern",
",",
"self",
"::",
"$",
"loaded",
")",
")",
"{",
"$",
"reflector",
"=",
"new",
"ReflectionClass",
"(",
"$",
"spec",
"[",
"'class'",
"]",
")",
";",
"if",
"(",
"$",
"reflector",
"->",
"getConstructor",
"(",
")",
")",
"{",
"$",
"reader",
"=",
"$",
"reflector",
"->",
"newInstanceArgs",
"(",
"$",
"spec",
"[",
"'constructor'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"reader",
"=",
"$",
"reflector",
"->",
"newInstance",
"(",
")",
";",
"}",
"self",
"::",
"$",
"loaded",
"[",
"$",
"pattern",
"]",
"=",
"$",
"reader",
";",
"}",
"return",
"self",
"::",
"$",
"loaded",
"[",
"$",
"pattern",
"]",
";",
"}",
"}",
"}"
] |
Returns a CharacterReader suitable for the charset applied.
@param string $charset
@return Swift_CharacterReader
|
[
"Returns",
"a",
"CharacterReader",
"suitable",
"for",
"the",
"charset",
"applied",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php#L104-L123
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/StreamBuffer.php
|
Swift_Transport_StreamBuffer.terminate
|
public function terminate()
{
if (isset($this->stream)) {
switch ($this->params['type']) {
case self::TYPE_PROCESS:
fclose($this->in);
fclose($this->out);
proc_close($this->stream);
break;
case self::TYPE_SOCKET:
default:
fclose($this->stream);
break;
}
}
$this->stream = null;
$this->out = null;
$this->in = null;
}
|
php
|
public function terminate()
{
if (isset($this->stream)) {
switch ($this->params['type']) {
case self::TYPE_PROCESS:
fclose($this->in);
fclose($this->out);
proc_close($this->stream);
break;
case self::TYPE_SOCKET:
default:
fclose($this->stream);
break;
}
}
$this->stream = null;
$this->out = null;
$this->in = null;
}
|
[
"public",
"function",
"terminate",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"stream",
")",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"params",
"[",
"'type'",
"]",
")",
"{",
"case",
"self",
"::",
"TYPE_PROCESS",
":",
"fclose",
"(",
"$",
"this",
"->",
"in",
")",
";",
"fclose",
"(",
"$",
"this",
"->",
"out",
")",
";",
"proc_close",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_SOCKET",
":",
"default",
":",
"fclose",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"stream",
"=",
"null",
";",
"$",
"this",
"->",
"out",
"=",
"null",
";",
"$",
"this",
"->",
"in",
"=",
"null",
";",
"}"
] |
Perform any shutdown logic needed.
|
[
"Perform",
"any",
"shutdown",
"logic",
"needed",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/StreamBuffer.php#L100-L118
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/StreamBuffer.php
|
Swift_Transport_StreamBuffer.setWriteTranslations
|
public function setWriteTranslations(array $replacements)
{
foreach ($this->translations as $search => $replace) {
if (!isset($replacements[$search])) {
$this->removeFilter($search);
unset($this->translations[$search]);
}
}
foreach ($replacements as $search => $replace) {
if (!isset($this->translations[$search])) {
$this->addFilter(
$this->replacementFactory->createFilter($search, $replace), $search
);
$this->translations[$search] = true;
}
}
}
|
php
|
public function setWriteTranslations(array $replacements)
{
foreach ($this->translations as $search => $replace) {
if (!isset($replacements[$search])) {
$this->removeFilter($search);
unset($this->translations[$search]);
}
}
foreach ($replacements as $search => $replace) {
if (!isset($this->translations[$search])) {
$this->addFilter(
$this->replacementFactory->createFilter($search, $replace), $search
);
$this->translations[$search] = true;
}
}
}
|
[
"public",
"function",
"setWriteTranslations",
"(",
"array",
"$",
"replacements",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"search",
"=>",
"$",
"replace",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"replacements",
"[",
"$",
"search",
"]",
")",
")",
"{",
"$",
"this",
"->",
"removeFilter",
"(",
"$",
"search",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"translations",
"[",
"$",
"search",
"]",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"replacements",
"as",
"$",
"search",
"=>",
"$",
"replace",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translations",
"[",
"$",
"search",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addFilter",
"(",
"$",
"this",
"->",
"replacementFactory",
"->",
"createFilter",
"(",
"$",
"search",
",",
"$",
"replace",
")",
",",
"$",
"search",
")",
";",
"$",
"this",
"->",
"translations",
"[",
"$",
"search",
"]",
"=",
"true",
";",
"}",
"}",
"}"
] |
Set an array of string replacements which should be made on data written
to the buffer.
This could replace LF with CRLF for example.
@param string[] $replacements
|
[
"Set",
"an",
"array",
"of",
"string",
"replacements",
"which",
"should",
"be",
"made",
"on",
"data",
"written",
"to",
"the",
"buffer",
"."
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/StreamBuffer.php#L128-L145
|
train
|
swiftmailer/swiftmailer
|
lib/classes/Swift/Transport/StreamBuffer.php
|
Swift_Transport_StreamBuffer.doCommit
|
protected function doCommit($bytes)
{
if (isset($this->in)) {
$bytesToWrite = strlen($bytes);
$totalBytesWritten = 0;
while ($totalBytesWritten < $bytesToWrite) {
$bytesWritten = fwrite($this->in, substr($bytes, $totalBytesWritten));
if (false === $bytesWritten || 0 === $bytesWritten) {
break;
}
$totalBytesWritten += $bytesWritten;
}
if ($totalBytesWritten > 0) {
return ++$this->sequence;
}
}
}
|
php
|
protected function doCommit($bytes)
{
if (isset($this->in)) {
$bytesToWrite = strlen($bytes);
$totalBytesWritten = 0;
while ($totalBytesWritten < $bytesToWrite) {
$bytesWritten = fwrite($this->in, substr($bytes, $totalBytesWritten));
if (false === $bytesWritten || 0 === $bytesWritten) {
break;
}
$totalBytesWritten += $bytesWritten;
}
if ($totalBytesWritten > 0) {
return ++$this->sequence;
}
}
}
|
[
"protected",
"function",
"doCommit",
"(",
"$",
"bytes",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"in",
")",
")",
"{",
"$",
"bytesToWrite",
"=",
"strlen",
"(",
"$",
"bytes",
")",
";",
"$",
"totalBytesWritten",
"=",
"0",
";",
"while",
"(",
"$",
"totalBytesWritten",
"<",
"$",
"bytesToWrite",
")",
"{",
"$",
"bytesWritten",
"=",
"fwrite",
"(",
"$",
"this",
"->",
"in",
",",
"substr",
"(",
"$",
"bytes",
",",
"$",
"totalBytesWritten",
")",
")",
";",
"if",
"(",
"false",
"===",
"$",
"bytesWritten",
"||",
"0",
"===",
"$",
"bytesWritten",
")",
"{",
"break",
";",
"}",
"$",
"totalBytesWritten",
"+=",
"$",
"bytesWritten",
";",
"}",
"if",
"(",
"$",
"totalBytesWritten",
">",
"0",
")",
"{",
"return",
"++",
"$",
"this",
"->",
"sequence",
";",
"}",
"}",
"}"
] |
Write this bytes to the stream
|
[
"Write",
"this",
"bytes",
"to",
"the",
"stream"
] |
b22e508d2db967630445c553572d1e9eb997ecef
|
https://github.com/swiftmailer/swiftmailer/blob/b22e508d2db967630445c553572d1e9eb997ecef/lib/classes/Swift/Transport/StreamBuffer.php#L224-L243
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.