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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
phpmyadmin/shapefile | src/ShapeFile.php | ShapeFile._openFile | private function _openFile($toWrite, $extension, $name)
{
$shp_name = $this->_getFilename($extension);
$result = @fopen($shp_name, ($toWrite ? 'wb+' : 'rb'));
if (! $result) {
$this->setError(sprintf('It wasn\'t possible to open the %s file "%s"', $name, $shp_name));
return false;
}
return $result;
} | php | private function _openFile($toWrite, $extension, $name)
{
$shp_name = $this->_getFilename($extension);
$result = @fopen($shp_name, ($toWrite ? 'wb+' : 'rb'));
if (! $result) {
$this->setError(sprintf('It wasn\'t possible to open the %s file "%s"', $name, $shp_name));
return false;
}
return $result;
} | [
"private",
"function",
"_openFile",
"(",
"$",
"toWrite",
",",
"$",
"extension",
",",
"$",
"name",
")",
"{",
"$",
"shp_name",
"=",
"$",
"this",
"->",
"_getFilename",
"(",
"$",
"extension",
")",
";",
"$",
"result",
"=",
"@",
"fopen",
"(",
"$",
"shp_nam... | Generic interface to open files.
@param bool $toWrite Whether file should be opened for writing
@param string $extension File extension
@param string $name Verbose file name to report errors
@return file|false File handle | [
"Generic",
"interface",
"to",
"open",
"files",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L468-L479 | train |
phpmyadmin/shapefile | src/ShapeFile.php | ShapeFile._openSHPFile | private function _openSHPFile($toWrite = false)
{
$this->SHPFile = $this->_openFile($toWrite, '.shp', 'Shape');
if (! $this->SHPFile) {
return false;
}
return true;
} | php | private function _openSHPFile($toWrite = false)
{
$this->SHPFile = $this->_openFile($toWrite, '.shp', 'Shape');
if (! $this->SHPFile) {
return false;
}
return true;
} | [
"private",
"function",
"_openSHPFile",
"(",
"$",
"toWrite",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"SHPFile",
"=",
"$",
"this",
"->",
"_openFile",
"(",
"$",
"toWrite",
",",
"'.shp'",
",",
"'Shape'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
... | Opens SHP file.
@param bool $toWrite Whether file should be opened for writing
@return bool | [
"Opens",
"SHP",
"file",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L488-L496 | train |
phpmyadmin/shapefile | src/ShapeFile.php | ShapeFile._openSHXFile | private function _openSHXFile($toWrite = false)
{
$this->SHXFile = $this->_openFile($toWrite, '.shx', 'Index');
if (! $this->SHXFile) {
return false;
}
return true;
} | php | private function _openSHXFile($toWrite = false)
{
$this->SHXFile = $this->_openFile($toWrite, '.shx', 'Index');
if (! $this->SHXFile) {
return false;
}
return true;
} | [
"private",
"function",
"_openSHXFile",
"(",
"$",
"toWrite",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"SHXFile",
"=",
"$",
"this",
"->",
"_openFile",
"(",
"$",
"toWrite",
",",
"'.shx'",
",",
"'Index'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
... | Opens SHX file.
@param bool $toWrite Whether file should be opened for writing
@return bool | [
"Opens",
"SHX",
"file",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L516-L524 | train |
phpmyadmin/shapefile | src/ShapeFile.php | ShapeFile._createDBFFile | private function _createDBFFile()
{
if (! self::supportsDbase() || ! is_array($this->DBFHeader) || count($this->DBFHeader) == 0) {
$this->DBFFile = null;
return true;
}
$dbf_name = $this->_getFilename('.dbf');
/* Unlink existing file */
if (file_exists($dbf_name)) {
unlink($dbf_name);
}
/* Create new file */
$this->DBFFile = @dbase_create($dbf_name, $this->DBFHeader);
if ($this->DBFFile === false) {
$this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbf_name));
return false;
}
return true;
} | php | private function _createDBFFile()
{
if (! self::supportsDbase() || ! is_array($this->DBFHeader) || count($this->DBFHeader) == 0) {
$this->DBFFile = null;
return true;
}
$dbf_name = $this->_getFilename('.dbf');
/* Unlink existing file */
if (file_exists($dbf_name)) {
unlink($dbf_name);
}
/* Create new file */
$this->DBFFile = @dbase_create($dbf_name, $this->DBFHeader);
if ($this->DBFFile === false) {
$this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbf_name));
return false;
}
return true;
} | [
"private",
"function",
"_createDBFFile",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"supportsDbase",
"(",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"DBFHeader",
")",
"||",
"count",
"(",
"$",
"this",
"->",
"DBFHeader",
")",
"==",
"0",
")",... | Creates DBF file.
@return bool | [
"Creates",
"DBF",
"file",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L542-L565 | train |
phpmyadmin/shapefile | src/ShapeFile.php | ShapeFile._openDBFFile | private function _openDBFFile()
{
if (! self::supportsDbase()) {
$this->DBFFile = null;
return true;
}
$dbf_name = $this->_getFilename('.dbf');
if (is_readable($dbf_name)) {
$this->DBFFile = @dbase_open($dbf_name, 0);
if (! $this->DBFFile) {
$this->setError(sprintf('It wasn\'t possible to open the DBase file "%s"', $dbf_name));
return false;
}
} else {
$this->setError(sprintf('It wasn\'t possible to find the DBase file "%s"', $dbf_name));
return false;
}
return true;
} | php | private function _openDBFFile()
{
if (! self::supportsDbase()) {
$this->DBFFile = null;
return true;
}
$dbf_name = $this->_getFilename('.dbf');
if (is_readable($dbf_name)) {
$this->DBFFile = @dbase_open($dbf_name, 0);
if (! $this->DBFFile) {
$this->setError(sprintf('It wasn\'t possible to open the DBase file "%s"', $dbf_name));
return false;
}
} else {
$this->setError(sprintf('It wasn\'t possible to find the DBase file "%s"', $dbf_name));
return false;
}
return true;
} | [
"private",
"function",
"_openDBFFile",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"supportsDbase",
"(",
")",
")",
"{",
"$",
"this",
"->",
"DBFFile",
"=",
"null",
";",
"return",
"true",
";",
"}",
"$",
"dbf_name",
"=",
"$",
"this",
"->",
"_getFilenam... | Loads DBF file if supported.
@return bool | [
"Loads",
"DBF",
"file",
"if",
"supported",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/ShapeFile.php#L572-L594 | train |
phpmyadmin/shapefile | src/Util.php | Util.swap | public static function swap($binValue)
{
$result = $binValue[strlen($binValue) - 1];
for ($i = strlen($binValue) - 2; $i >= 0; --$i) {
$result .= $binValue[$i];
}
return $result;
} | php | public static function swap($binValue)
{
$result = $binValue[strlen($binValue) - 1];
for ($i = strlen($binValue) - 2; $i >= 0; --$i) {
$result .= $binValue[$i];
}
return $result;
} | [
"public",
"static",
"function",
"swap",
"(",
"$",
"binValue",
")",
"{",
"$",
"result",
"=",
"$",
"binValue",
"[",
"strlen",
"(",
"$",
"binValue",
")",
"-",
"1",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"strlen",
"(",
"$",
"binValue",
")",
"-",
"2",
... | Changes endianity.
@param string $binValue Binary value
@return string | [
"Changes",
"endianity",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/Util.php#L72-L80 | train |
phpmyadmin/shapefile | src/Util.php | Util.packDouble | public static function packDouble($value)
{
$bin = pack('d', (float) $value);
if (is_null(self::$little_endian)) {
self::$little_endian = (pack('L', 1) == pack('V', 1));
}
if (self::$little_endian) {
return $bin;
}
return self::swap($bin);
} | php | public static function packDouble($value)
{
$bin = pack('d', (float) $value);
if (is_null(self::$little_endian)) {
self::$little_endian = (pack('L', 1) == pack('V', 1));
}
if (self::$little_endian) {
return $bin;
}
return self::swap($bin);
} | [
"public",
"static",
"function",
"packDouble",
"(",
"$",
"value",
")",
"{",
"$",
"bin",
"=",
"pack",
"(",
"'d'",
",",
"(",
"float",
")",
"$",
"value",
")",
";",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"little_endian",
")",
")",
"{",
"self",
... | Encodes double value to correct endianity.
@param float $value Value to pack
@return string | [
"Encodes",
"double",
"value",
"to",
"correct",
"endianity",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/Util.php#L89-L102 | train |
phpmyadmin/shapefile | src/Util.php | Util.nameShape | public static function nameShape($type)
{
if (isset(self::$shape_names[$type])) {
return self::$shape_names[$type];
}
return sprintf('Shape %d', $type);
} | php | public static function nameShape($type)
{
if (isset(self::$shape_names[$type])) {
return self::$shape_names[$type];
}
return sprintf('Shape %d', $type);
} | [
"public",
"static",
"function",
"nameShape",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"shape_names",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"shape_names",
"[",
"$",
"type",
"]",
";",
"}",
... | Returns shape name.
@param int $type
@return string | [
"Returns",
"shape",
"name",
"."
] | f4f359b58ea3065ea85e3aa3bb8b677a24861363 | https://github.com/phpmyadmin/shapefile/blob/f4f359b58ea3065ea85e3aa3bb8b677a24861363/src/Util.php#L111-L118 | train |
phpab/phpab | src/Storage/Adapter/Cookie.php | Cookie.parseExistingCookie | protected function parseExistingCookie()
{
if (is_array($this->data)) {
return;
}
$cookiesContent = filter_input_array(INPUT_COOKIE);
if (empty($cookiesContent) || !array_key_exists($this->cookieName, $cookiesContent)) {
$this->data = [];
return;
}
$deserializedCookie = json_decode($cookiesContent[$this->cookieName], true);
if (is_null($deserializedCookie)) {
$this->data = [];
return;
}
$this->data = $deserializedCookie;
} | php | protected function parseExistingCookie()
{
if (is_array($this->data)) {
return;
}
$cookiesContent = filter_input_array(INPUT_COOKIE);
if (empty($cookiesContent) || !array_key_exists($this->cookieName, $cookiesContent)) {
$this->data = [];
return;
}
$deserializedCookie = json_decode($cookiesContent[$this->cookieName], true);
if (is_null($deserializedCookie)) {
$this->data = [];
return;
}
$this->data = $deserializedCookie;
} | [
"protected",
"function",
"parseExistingCookie",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
";",
"}",
"$",
"cookiesContent",
"=",
"filter_input_array",
"(",
"INPUT_COOKIE",
")",
";",
"if",
"(",
"empty",
... | Parses any previous cookie and stores it internally | [
"Parses",
"any",
"previous",
"cookie",
"and",
"stores",
"it",
"internally"
] | 2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf | https://github.com/phpab/phpab/blob/2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf/src/Storage/Adapter/Cookie.php#L65-L86 | train |
phpab/phpab | src/Engine/Engine.php | Engine.activateVariant | private function activateVariant(Bag $bag, VariantInterface $variant)
{
$this->dispatcher->dispatch('phpab.participation.variant_run', [$this, $bag, $variant]);
$variant->run();
} | php | private function activateVariant(Bag $bag, VariantInterface $variant)
{
$this->dispatcher->dispatch('phpab.participation.variant_run', [$this, $bag, $variant]);
$variant->run();
} | [
"private",
"function",
"activateVariant",
"(",
"Bag",
"$",
"bag",
",",
"VariantInterface",
"$",
"variant",
")",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"'phpab.participation.variant_run'",
",",
"[",
"$",
"this",
",",
"$",
"bag",
",",
"$"... | Runs the Variant and dispatches subscriptions
@param Bag $bag
@param VariantInterface $variant | [
"Runs",
"the",
"Variant",
"and",
"dispatches",
"subscriptions"
] | 2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf | https://github.com/phpab/phpab/blob/2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf/src/Engine/Engine.php#L237-L242 | train |
phpab/phpab | src/Participation/Manager.php | Manager.getParticipatingVariant | public function getParticipatingVariant($test)
{
$test = $test instanceof TestInterface ? $test->getIdentifier() : $test;
if ($this->storage->has($test)) {
return $this->storage->get($test);
}
return null;
} | php | public function getParticipatingVariant($test)
{
$test = $test instanceof TestInterface ? $test->getIdentifier() : $test;
if ($this->storage->has($test)) {
return $this->storage->get($test);
}
return null;
} | [
"public",
"function",
"getParticipatingVariant",
"(",
"$",
"test",
")",
"{",
"$",
"test",
"=",
"$",
"test",
"instanceof",
"TestInterface",
"?",
"$",
"test",
"->",
"getIdentifier",
"(",
")",
":",
"$",
"test",
";",
"if",
"(",
"$",
"this",
"->",
"storage",
... | Gets the variant the user is participating in for the given test.
@param TestInterface|string $test The identifier of the test to get the variant for.
@return string|null Returns the identifier of the variant or null if not participating. | [
"Gets",
"the",
"variant",
"the",
"user",
"is",
"participating",
"in",
"for",
"the",
"given",
"test",
"."
] | 2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf | https://github.com/phpab/phpab/blob/2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf/src/Participation/Manager.php#L46-L55 | train |
phpab/phpab | src/Event/Dispatcher.php | Dispatcher.addSubscriber | public function addSubscriber(SubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscribedEvents() as $eventName => $callable) {
$this->addListener($eventName, $callable);
}
} | php | public function addSubscriber(SubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscribedEvents() as $eventName => $callable) {
$this->addListener($eventName, $callable);
}
} | [
"public",
"function",
"addSubscriber",
"(",
"SubscriberInterface",
"$",
"subscriber",
")",
"{",
"foreach",
"(",
"$",
"subscriber",
"->",
"getSubscribedEvents",
"(",
")",
"as",
"$",
"eventName",
"=>",
"$",
"callable",
")",
"{",
"$",
"this",
"->",
"addListener",... | Adds a subscriber to this dispatcher which in its turn adds all the subscribed events.
@param SubscriberInterface $subscriber The subscriber which can subscribe to multiple events | [
"Adds",
"a",
"subscriber",
"to",
"this",
"dispatcher",
"which",
"in",
"its",
"turn",
"adds",
"all",
"the",
"subscribed",
"events",
"."
] | 2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf | https://github.com/phpab/phpab/blob/2ba5bbc61cadedc8a611780f3b8a3a7ffb8ee0cf/src/Event/Dispatcher.php#L45-L50 | train |
eko/GoogleTranslateBundle | Translate/Method.php | Method.startProfiling | protected function startProfiling($name, $query, $source = null, $target = null)
{
if ($this->stopwatch instanceof Stopwatch) {
$this->profiles[$this->counter] = [
'query' => urldecode($query),
'source' => $source,
'target' => $target,
'duration' => null,
'memory_start' => memory_get_usage(true),
'memory_end' => null,
'memory_peak' => null,
];
return $this->stopwatch->start($name);
}
} | php | protected function startProfiling($name, $query, $source = null, $target = null)
{
if ($this->stopwatch instanceof Stopwatch) {
$this->profiles[$this->counter] = [
'query' => urldecode($query),
'source' => $source,
'target' => $target,
'duration' => null,
'memory_start' => memory_get_usage(true),
'memory_end' => null,
'memory_peak' => null,
];
return $this->stopwatch->start($name);
}
} | [
"protected",
"function",
"startProfiling",
"(",
"$",
"name",
",",
"$",
"query",
",",
"$",
"source",
"=",
"null",
",",
"$",
"target",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stopwatch",
"instanceof",
"Stopwatch",
")",
"{",
"$",
"this",
"... | Starts profiling.
@param string $name Method name
@param string $query Query text
@param string $source Source language
@param string $target Target language
@return StopwatchEvent | [
"Starts",
"profiling",
"."
] | 8649b6e2d1aa6c4208ab779759e7e4105dfaf680 | https://github.com/eko/GoogleTranslateBundle/blob/8649b6e2d1aa6c4208ab779759e7e4105dfaf680/Translate/Method.php#L100-L115 | train |
eko/GoogleTranslateBundle | DependencyInjection/EkoGoogleTranslateExtension.php | EkoGoogleTranslateExtension.loadProfilerCollector | protected function loadProfilerCollector(ContainerBuilder $container, XmlFileLoader $loader)
{
if ($container->getParameter('kernel.debug')) {
$loader->load('collector.xml');
$services = $container->findTaggedServiceIds('eko.google_translate.method');
$identifiers = array_keys($services);
foreach ($identifiers as $identifier) {
$serviceDefinition = $container->getDefinition($identifier);
$serviceDefinition->addArgument(new Reference('debug.stopwatch'));
$container->setDefinition($identifier, $serviceDefinition);
}
}
} | php | protected function loadProfilerCollector(ContainerBuilder $container, XmlFileLoader $loader)
{
if ($container->getParameter('kernel.debug')) {
$loader->load('collector.xml');
$services = $container->findTaggedServiceIds('eko.google_translate.method');
$identifiers = array_keys($services);
foreach ($identifiers as $identifier) {
$serviceDefinition = $container->getDefinition($identifier);
$serviceDefinition->addArgument(new Reference('debug.stopwatch'));
$container->setDefinition($identifier, $serviceDefinition);
}
}
} | [
"protected",
"function",
"loadProfilerCollector",
"(",
"ContainerBuilder",
"$",
"container",
",",
"XmlFileLoader",
"$",
"loader",
")",
"{",
"if",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.debug'",
")",
")",
"{",
"$",
"loader",
"->",
"load",
"(... | Loads profiler collector for correct environments.
@param ContainerBuilder $container Symfony dependency injection container
@param XmlFileLoader $loader XML file loader | [
"Loads",
"profiler",
"collector",
"for",
"correct",
"environments",
"."
] | 8649b6e2d1aa6c4208ab779759e7e4105dfaf680 | https://github.com/eko/GoogleTranslateBundle/blob/8649b6e2d1aa6c4208ab779759e7e4105dfaf680/DependencyInjection/EkoGoogleTranslateExtension.php#L49-L64 | train |
eko/GoogleTranslateBundle | Translate/Method/Translator.php | Translator.translate | public function translate($query, $target, $source = null, $economic = false, $plainText = false)
{
if (!is_array($query)) {
return $this->handle($query, $target, $source, $plainText);
}
if ($economic) {
$results = $this->handle(implode(self::ECONOMIC_DELIMITER, $query), $target, $source, $plainText);
$results = explode(self::ECONOMIC_DELIMITER, $results);
return array_map('trim', $results);
}
$results = [];
foreach ($query as $item) {
$results[] = $this->handle($item, $target, $source, $plainText);
}
return $results;
} | php | public function translate($query, $target, $source = null, $economic = false, $plainText = false)
{
if (!is_array($query)) {
return $this->handle($query, $target, $source, $plainText);
}
if ($economic) {
$results = $this->handle(implode(self::ECONOMIC_DELIMITER, $query), $target, $source, $plainText);
$results = explode(self::ECONOMIC_DELIMITER, $results);
return array_map('trim', $results);
}
$results = [];
foreach ($query as $item) {
$results[] = $this->handle($item, $target, $source, $plainText);
}
return $results;
} | [
"public",
"function",
"translate",
"(",
"$",
"query",
",",
"$",
"target",
",",
"$",
"source",
"=",
"null",
",",
"$",
"economic",
"=",
"false",
",",
"$",
"plainText",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"query",
")",
")",
... | Translates given string in given target language from a source language via the Google Translate API.
If source language is not defined, it use detector method to detect string language.
@param string|array $query A query string to translate
@param string $target A target language
@param string $source A source language
@param bool $economic Enable the economic mode? (only 1 request)
@param bool $plainText The source (and response) are plain text
@return array|string | [
"Translates",
"given",
"string",
"in",
"given",
"target",
"language",
"from",
"a",
"source",
"language",
"via",
"the",
"Google",
"Translate",
"API",
".",
"If",
"source",
"language",
"is",
"not",
"defined",
"it",
"use",
"detector",
"method",
"to",
"detect",
"... | 8649b6e2d1aa6c4208ab779759e7e4105dfaf680 | https://github.com/eko/GoogleTranslateBundle/blob/8649b6e2d1aa6c4208ab779759e7e4105dfaf680/Translate/Method/Translator.php#L87-L107 | train |
eko/GoogleTranslateBundle | Translate/Method/Translator.php | Translator.handle | protected function handle($query, $target, $source = null, $plainText = false)
{
if (null === $source) {
$source = $this->getDetector()->detect($query);
}
// Split up the query if it is too long. See MAXIMUM_TEXT_SIZE description for more info.
{
$queryArray = [];
$remainingQuery = $query;
while (strlen($remainingQuery) >= self::MAXIMUM_TEXT_SIZE) {
// Get closest breaking character, but not farther than MAXIMUM_TEXT_SIZE characters away.
$i = 0;
$find = ["\n", '.', ' '];
while (false === ($pos = strrpos($remainingQuery, $find[$i], -(strlen($remainingQuery) - self::MAXIMUM_TEXT_SIZE)))) {
$i++;
if ($i >= count($find)) {
break;
}
}
if (false === $pos || 0 === $pos) {
break;
}
// Split.
$queryArray[] = substr($remainingQuery, 0, $pos);
$remainingQuery = substr($remainingQuery, $pos);
}
$queryArray[] = $remainingQuery;
}
// Translate piece by piece.
$result = '';
foreach ($queryArray as $subQuery) {
$options = [
'key' => $this->apiKey,
'q' => $subQuery,
'source' => $source,
'target' => $target,
'format' => ($plainText ? 'text' : 'html'),
];
$result .= $this->process($options);
}
return $result;
} | php | protected function handle($query, $target, $source = null, $plainText = false)
{
if (null === $source) {
$source = $this->getDetector()->detect($query);
}
// Split up the query if it is too long. See MAXIMUM_TEXT_SIZE description for more info.
{
$queryArray = [];
$remainingQuery = $query;
while (strlen($remainingQuery) >= self::MAXIMUM_TEXT_SIZE) {
// Get closest breaking character, but not farther than MAXIMUM_TEXT_SIZE characters away.
$i = 0;
$find = ["\n", '.', ' '];
while (false === ($pos = strrpos($remainingQuery, $find[$i], -(strlen($remainingQuery) - self::MAXIMUM_TEXT_SIZE)))) {
$i++;
if ($i >= count($find)) {
break;
}
}
if (false === $pos || 0 === $pos) {
break;
}
// Split.
$queryArray[] = substr($remainingQuery, 0, $pos);
$remainingQuery = substr($remainingQuery, $pos);
}
$queryArray[] = $remainingQuery;
}
// Translate piece by piece.
$result = '';
foreach ($queryArray as $subQuery) {
$options = [
'key' => $this->apiKey,
'q' => $subQuery,
'source' => $source,
'target' => $target,
'format' => ($plainText ? 'text' : 'html'),
];
$result .= $this->process($options);
}
return $result;
} | [
"protected",
"function",
"handle",
"(",
"$",
"query",
",",
"$",
"target",
",",
"$",
"source",
"=",
"null",
",",
"$",
"plainText",
"=",
"false",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"source",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"g... | Handles a translation request.
@param string $query A query string to translate
@param string $target A target language
@param string $source A source language
@param bool $plainText The source (and response) are plain text
@return string | [
"Handles",
"a",
"translation",
"request",
"."
] | 8649b6e2d1aa6c4208ab779759e7e4105dfaf680 | https://github.com/eko/GoogleTranslateBundle/blob/8649b6e2d1aa6c4208ab779759e7e4105dfaf680/Translate/Method/Translator.php#L119-L166 | train |
eko/GoogleTranslateBundle | Translate/Method/Languages.php | Languages.get | public function get($target = null)
{
$options = ['key' => $this->apiKey];
if (null !== $target) {
$this->url = sprintf('%s&target={target}', $this->url);
$options['target'] = $target;
}
return $this->process($options);
} | php | public function get($target = null)
{
$options = ['key' => $this->apiKey];
if (null !== $target) {
$this->url = sprintf('%s&target={target}', $this->url);
$options['target'] = $target;
}
return $this->process($options);
} | [
"public",
"function",
"get",
"(",
"$",
"target",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"[",
"'key'",
"=>",
"$",
"this",
"->",
"apiKey",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"target",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"sprintf",
... | Retrieves all languages availables with Google Translate API
If a target language is specified, returns languages name translated in target language.
@param string $target A target language to translate languages names
@return string | [
"Retrieves",
"all",
"languages",
"availables",
"with",
"Google",
"Translate",
"API",
"If",
"a",
"target",
"language",
"is",
"specified",
"returns",
"languages",
"name",
"translated",
"in",
"target",
"language",
"."
] | 8649b6e2d1aa6c4208ab779759e7e4105dfaf680 | https://github.com/eko/GoogleTranslateBundle/blob/8649b6e2d1aa6c4208ab779759e7e4105dfaf680/Translate/Method/Languages.php#L38-L49 | train |
eko/GoogleTranslateBundle | Translate/Method/Languages.php | Languages.process | protected function process(array $options)
{
$event = $this->startProfiling($this->getName(), 'get');
$response = $this->getClient()->get($this->url, ['query' => $options]);
$json = json_decode($response->getBody()->getContents(), true);
$result = isset($json['data']['languages']) ? $json['data']['languages'] : [];
$this->stopProfiling($event, $this->getName(), $result);
return $result;
} | php | protected function process(array $options)
{
$event = $this->startProfiling($this->getName(), 'get');
$response = $this->getClient()->get($this->url, ['query' => $options]);
$json = json_decode($response->getBody()->getContents(), true);
$result = isset($json['data']['languages']) ? $json['data']['languages'] : [];
$this->stopProfiling($event, $this->getName(), $result);
return $result;
} | [
"protected",
"function",
"process",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"startProfiling",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'get'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getClie... | Process request and retrieve JSON result.
@param array $options
@return array | [
"Process",
"request",
"and",
"retrieve",
"JSON",
"result",
"."
] | 8649b6e2d1aa6c4208ab779759e7e4105dfaf680 | https://github.com/eko/GoogleTranslateBundle/blob/8649b6e2d1aa6c4208ab779759e7e4105dfaf680/Translate/Method/Languages.php#L58-L70 | train |
opis/database | src/SQL/ColumnExpression.php | ColumnExpression.columns | public function columns(array $columns): self
{
foreach ($columns as $name => $alias) {
if (!is_string($name)) {
$this->column($alias, null);
continue;
}
if (is_string($alias)) {
$this->column($name, $alias);
} else {
$this->column($alias, $name);
}
}
return $this;
} | php | public function columns(array $columns): self
{
foreach ($columns as $name => $alias) {
if (!is_string($name)) {
$this->column($alias, null);
continue;
}
if (is_string($alias)) {
$this->column($name, $alias);
} else {
$this->column($alias, $name);
}
}
return $this;
} | [
"public",
"function",
"columns",
"(",
"array",
"$",
"columns",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"name",
"=>",
"$",
"alias",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->"... | Add multiple columns at once
@param array $columns Columns
@return $this | [
"Add",
"multiple",
"columns",
"at",
"once"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/ColumnExpression.php#L57-L71 | train |
opis/database | src/SQL/ColumnExpression.php | ColumnExpression.count | public function count($column = '*', string $alias = null, bool $distinct = false): self
{
return $this->column((new Expression())->count($column, $distinct), $alias);
} | php | public function count($column = '*', string $alias = null, bool $distinct = false): self
{
return $this->column((new Expression())->count($column, $distinct), $alias);
} | [
"public",
"function",
"count",
"(",
"$",
"column",
"=",
"'*'",
",",
"string",
"$",
"alias",
"=",
"null",
",",
"bool",
"$",
"distinct",
"=",
"false",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"column",
"(",
"(",
"new",
"Expression",
"(",
"... | Add a `COUNT` expression
@param string|array|Expression $column Column
@param string $alias (optional) Column's alias
@param bool $distinct (optional) Distinct column
@return $this | [
"Add",
"a",
"COUNT",
"expression"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/ColumnExpression.php#L82-L85 | train |
opis/database | src/SQL/ColumnExpression.php | ColumnExpression.ucase | public function ucase($column, string $alias = null): self
{
return $this->column((new Expression())->ucase($column), $alias);
} | php | public function ucase($column, string $alias = null): self
{
return $this->column((new Expression())->ucase($column), $alias);
} | [
"public",
"function",
"ucase",
"(",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"column",
"(",
"(",
"new",
"Expression",
"(",
")",
")",
"->",
"ucase",
"(",
"$",
"column",
")",
",",
... | Add a `UCASE` expression
@param string|Expression $column Column
@param string $alias (optional) Alias
@return $this | [
"Add",
"a",
"UCASE",
"expression"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/ColumnExpression.php#L151-L154 | train |
opis/database | src/SQL/ColumnExpression.php | ColumnExpression.lcase | public function lcase($column, string $alias = null): self
{
return $this->column((new Expression())->lcase($column), $alias);
} | php | public function lcase($column, string $alias = null): self
{
return $this->column((new Expression())->lcase($column), $alias);
} | [
"public",
"function",
"lcase",
"(",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"column",
"(",
"(",
"new",
"Expression",
"(",
")",
")",
"->",
"lcase",
"(",
"$",
"column",
")",
",",
... | Add a `LCASE` expression
@param string|Expression $column Column
@param string $alias (optional) Alias
@return $this | [
"Add",
"a",
"LCASE",
"expression"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/ColumnExpression.php#L164-L167 | train |
opis/database | src/SQL/ColumnExpression.php | ColumnExpression.mid | public function mid($column, int $start = 1, string $alias = null, int $length = 0): self
{
return $this->column((new Expression())->mid($column, $start, $length), $alias);
} | php | public function mid($column, int $start = 1, string $alias = null, int $length = 0): self
{
return $this->column((new Expression())->mid($column, $start, $length), $alias);
} | [
"public",
"function",
"mid",
"(",
"$",
"column",
",",
"int",
"$",
"start",
"=",
"1",
",",
"string",
"$",
"alias",
"=",
"null",
",",
"int",
"$",
"length",
"=",
"0",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"column",
"(",
"(",
"new",
"... | Add a `MID` expression
@param string|Expression $column Column
@param int $start (optional) Substring start
@param string $alias (optional) Alias
@param int $length (optional) Substring length
@return $this | [
"Add",
"a",
"MID",
"expression"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/ColumnExpression.php#L179-L182 | train |
opis/database | src/SQL/ColumnExpression.php | ColumnExpression.len | public function len($column, string $alias = null): self
{
return $this->column((new Expression())->len($column), $alias);
} | php | public function len($column, string $alias = null): self
{
return $this->column((new Expression())->len($column), $alias);
} | [
"public",
"function",
"len",
"(",
"$",
"column",
",",
"string",
"$",
"alias",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"column",
"(",
"(",
"new",
"Expression",
"(",
")",
")",
"->",
"len",
"(",
"$",
"column",
")",
",",
"$",... | Add a `LEN` expression
@param string|Expression $column Column
@param string $alias (optional) Alias
@return $this | [
"Add",
"a",
"LEN",
"expression"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/ColumnExpression.php#L192-L195 | train |
opis/database | src/ResultSet.php | ResultSet.all | public function all($callable = null, $fetchStyle = 0)
{
if ($callable === null) {
return $this->statement->fetchAll($fetchStyle);
}
return $this->statement->fetchAll($fetchStyle | PDO::FETCH_FUNC, $callable);
} | php | public function all($callable = null, $fetchStyle = 0)
{
if ($callable === null) {
return $this->statement->fetchAll($fetchStyle);
}
return $this->statement->fetchAll($fetchStyle | PDO::FETCH_FUNC, $callable);
} | [
"public",
"function",
"all",
"(",
"$",
"callable",
"=",
"null",
",",
"$",
"fetchStyle",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"callable",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"statement",
"->",
"fetchAll",
"(",
"$",
"fetchStyle",
")",
... | Fetch all results
@param callable $callable (optional) Callback function
@param int $fetchStyle (optional) PDO fetch style
@return array | [
"Fetch",
"all",
"results"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/ResultSet.php#L65-L71 | train |
opis/database | src/ResultSet.php | ResultSet.first | public function first($callable = null)
{
if ($callable !== null) {
$result = $this->statement->fetch(PDO::FETCH_ASSOC);
$this->statement->closeCursor();
if (is_array($result)) {
$result = call_user_func_array($callable, $result);
}
} else {
$result = $this->statement->fetch();
$this->statement->closeCursor();
}
return $result;
} | php | public function first($callable = null)
{
if ($callable !== null) {
$result = $this->statement->fetch(PDO::FETCH_ASSOC);
$this->statement->closeCursor();
if (is_array($result)) {
$result = call_user_func_array($callable, $result);
}
} else {
$result = $this->statement->fetch();
$this->statement->closeCursor();
}
return $result;
} | [
"public",
"function",
"first",
"(",
"$",
"callable",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"callable",
"!==",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"statement",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"thi... | Fetch first result
@param callable $callable (optional) Callback function
@return mixed | [
"Fetch",
"first",
"result"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/ResultSet.php#L95-L109 | train |
philipbrown/signature-php | src/Request.php | Request.sign | public function sign(Token $token, $prefix = self::PREFIX)
{
$auth = [
$prefix . 'version' => self::VERSION,
$prefix . 'key' => $token->key(),
$prefix . 'timestamp' => $this->timestamp,
];
$payload = $this->payload($auth, $this->params);
$signature = $this->signature($payload, $this->method, $this->uri, $token->secret());
$auth[$prefix . 'signature'] = $signature;
return $auth;
} | php | public function sign(Token $token, $prefix = self::PREFIX)
{
$auth = [
$prefix . 'version' => self::VERSION,
$prefix . 'key' => $token->key(),
$prefix . 'timestamp' => $this->timestamp,
];
$payload = $this->payload($auth, $this->params);
$signature = $this->signature($payload, $this->method, $this->uri, $token->secret());
$auth[$prefix . 'signature'] = $signature;
return $auth;
} | [
"public",
"function",
"sign",
"(",
"Token",
"$",
"token",
",",
"$",
"prefix",
"=",
"self",
"::",
"PREFIX",
")",
"{",
"$",
"auth",
"=",
"[",
"$",
"prefix",
".",
"'version'",
"=>",
"self",
"::",
"VERSION",
",",
"$",
"prefix",
".",
"'key'",
"=>",
"$",... | Sign the Request with a Token
@param Token $token
@param string $prefix
@return array | [
"Sign",
"the",
"Request",
"with",
"a",
"Token"
] | 2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b | https://github.com/philipbrown/signature-php/blob/2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b/src/Request.php#L52-L67 | train |
philipbrown/signature-php | src/Request.php | Request.payload | private function payload(array $auth, array $params)
{
$payload = array_merge($auth, $params);
$payload = array_change_key_case($payload, CASE_LOWER);
ksort($payload);
return $payload;
} | php | private function payload(array $auth, array $params)
{
$payload = array_merge($auth, $params);
$payload = array_change_key_case($payload, CASE_LOWER);
ksort($payload);
return $payload;
} | [
"private",
"function",
"payload",
"(",
"array",
"$",
"auth",
",",
"array",
"$",
"params",
")",
"{",
"$",
"payload",
"=",
"array_merge",
"(",
"$",
"auth",
",",
"$",
"params",
")",
";",
"$",
"payload",
"=",
"array_change_key_case",
"(",
"$",
"payload",
"... | Create the payload
@param array $auth
@param array $params
@return array | [
"Create",
"the",
"payload"
] | 2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b | https://github.com/philipbrown/signature-php/blob/2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b/src/Request.php#L76-L84 | train |
philipbrown/signature-php | src/Request.php | Request.signature | private function signature(array $payload, $method, $uri, $secret)
{
$payload = urldecode(http_build_query($payload));
$payload = implode("\n", [$method, $uri, $payload]);
return hash_hmac('sha256', $payload, $secret);
} | php | private function signature(array $payload, $method, $uri, $secret)
{
$payload = urldecode(http_build_query($payload));
$payload = implode("\n", [$method, $uri, $payload]);
return hash_hmac('sha256', $payload, $secret);
} | [
"private",
"function",
"signature",
"(",
"array",
"$",
"payload",
",",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"secret",
")",
"{",
"$",
"payload",
"=",
"urldecode",
"(",
"http_build_query",
"(",
"$",
"payload",
")",
")",
";",
"$",
"payload",
"=",
"... | Create the signature
@param array $payload
@param string $method
@param string $uri
@param string $secret
@return string | [
"Create",
"the",
"signature"
] | 2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b | https://github.com/philipbrown/signature-php/blob/2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b/src/Request.php#L95-L102 | train |
opis/database | src/Schema.php | Schema.getCurrentDatabase | public function getCurrentDatabase()
{
if ($this->currentDatabase === null) {
$compiler = $this->connection->schemaCompiler();
$result = $compiler->currentDatabase($this->connection->getDSN());
if (is_array($result)) {
$this->currentDatabase = $this->connection->column($result['sql'], $result['params']);
} else {
$this->currentDatabase = $result;
}
}
return $this->currentDatabase;
} | php | public function getCurrentDatabase()
{
if ($this->currentDatabase === null) {
$compiler = $this->connection->schemaCompiler();
$result = $compiler->currentDatabase($this->connection->getDSN());
if (is_array($result)) {
$this->currentDatabase = $this->connection->column($result['sql'], $result['params']);
} else {
$this->currentDatabase = $result;
}
}
return $this->currentDatabase;
} | [
"public",
"function",
"getCurrentDatabase",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentDatabase",
"===",
"null",
")",
"{",
"$",
"compiler",
"=",
"$",
"this",
"->",
"connection",
"->",
"schemaCompiler",
"(",
")",
";",
"$",
"result",
"=",
"$",
... | Get the name of the currently used database
@return string
@throws \Exception | [
"Get",
"the",
"name",
"of",
"the",
"currently",
"used",
"database"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L53-L67 | train |
opis/database | src/Schema.php | Schema.hasTable | public function hasTable(string $table, bool $clear = false): bool
{
$list = $this->getTables($clear);
return isset($list[strtolower($table)]);
} | php | public function hasTable(string $table, bool $clear = false): bool
{
$list = $this->getTables($clear);
return isset($list[strtolower($table)]);
} | [
"public",
"function",
"hasTable",
"(",
"string",
"$",
"table",
",",
"bool",
"$",
"clear",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"getTables",
"(",
"$",
"clear",
")",
";",
"return",
"isset",
"(",
"$",
"list",
"[",
... | Check if the specified table exists
@param string $table Table name
@param boolean $clear (optional) Refresh table list
@return boolean
@throws \Exception | [
"Check",
"if",
"the",
"specified",
"table",
"exists"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L78-L82 | train |
opis/database | src/Schema.php | Schema.getTables | public function getTables(bool $clear = false): array
{
if ($clear) {
$this->tableList = null;
}
if ($this->tableList === null) {
$compiler = $this->connection->schemaCompiler();
$database = $this->getCurrentDatabase();
$sql = $compiler->getTables($database);
$results = $this->connection
->query($sql['sql'], $sql['params'])
->fetchNum()
->all();
$this->tableList = [];
foreach ($results as $result) {
$this->tableList[strtolower($result[0])] = $result[0];
}
}
return $this->tableList;
} | php | public function getTables(bool $clear = false): array
{
if ($clear) {
$this->tableList = null;
}
if ($this->tableList === null) {
$compiler = $this->connection->schemaCompiler();
$database = $this->getCurrentDatabase();
$sql = $compiler->getTables($database);
$results = $this->connection
->query($sql['sql'], $sql['params'])
->fetchNum()
->all();
$this->tableList = [];
foreach ($results as $result) {
$this->tableList[strtolower($result[0])] = $result[0];
}
}
return $this->tableList;
} | [
"public",
"function",
"getTables",
"(",
"bool",
"$",
"clear",
"=",
"false",
")",
":",
"array",
"{",
"if",
"(",
"$",
"clear",
")",
"{",
"$",
"this",
"->",
"tableList",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"tableList",
"===",
"null",
... | Get a list with all tables that belong to the currently used database
@param boolean $clear (optional) Refresh table list
@return string[]
@throws \Exception | [
"Get",
"a",
"list",
"with",
"all",
"tables",
"that",
"belong",
"to",
"the",
"currently",
"used",
"database"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L92-L118 | train |
opis/database | src/Schema.php | Schema.getColumns | public function getColumns(string $table, bool $clear = false, bool $names = true)
{
if ($clear) {
unset($this->columns[$table]);
}
if (!$this->hasTable($table, $clear)) {
return false;
}
if (!isset($this->columns[$table])) {
$compiler = $this->connection->schemaCompiler();
$database = $this->getCurrentDatabase();
$sql = $compiler->getColumns($database, $table);
$results = $this->connection
->query($sql['sql'], $sql['params'])
->fetchAssoc()
->all();
$columns = [];
foreach ($results as $ord => &$col) {
$columns[$col['name']] = [
'name' => $col['name'],
'type' => $col['type'],
];
}
$this->columns[$table] = $columns;
}
return $names ? array_keys($this->columns[$table]) : $this->columns[$table];
} | php | public function getColumns(string $table, bool $clear = false, bool $names = true)
{
if ($clear) {
unset($this->columns[$table]);
}
if (!$this->hasTable($table, $clear)) {
return false;
}
if (!isset($this->columns[$table])) {
$compiler = $this->connection->schemaCompiler();
$database = $this->getCurrentDatabase();
$sql = $compiler->getColumns($database, $table);
$results = $this->connection
->query($sql['sql'], $sql['params'])
->fetchAssoc()
->all();
$columns = [];
foreach ($results as $ord => &$col) {
$columns[$col['name']] = [
'name' => $col['name'],
'type' => $col['type'],
];
}
$this->columns[$table] = $columns;
}
return $names ? array_keys($this->columns[$table]) : $this->columns[$table];
} | [
"public",
"function",
"getColumns",
"(",
"string",
"$",
"table",
",",
"bool",
"$",
"clear",
"=",
"false",
",",
"bool",
"$",
"names",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"clear",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"columns",
"[",
"$",
"... | Get a list with all columns that belong to the specified table
@param string $table
@param boolean $clear (optional) Refresh column list
@param boolean $names (optional) Return only the column names
@return false|string[]
@throws \Exception | [
"Get",
"a",
"list",
"with",
"all",
"columns",
"that",
"belong",
"to",
"the",
"specified",
"table"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L130-L165 | train |
opis/database | src/Schema.php | Schema.create | public function create(string $table, callable $callback)
{
$compiler = $this->connection->schemaCompiler();
$schema = new CreateTable($table);
$callback($schema);
foreach ($compiler->create($schema) as $result) {
$this->connection->command($result['sql'], $result['params']);
}
//clear table list
$this->tableList = null;
} | php | public function create(string $table, callable $callback)
{
$compiler = $this->connection->schemaCompiler();
$schema = new CreateTable($table);
$callback($schema);
foreach ($compiler->create($schema) as $result) {
$this->connection->command($result['sql'], $result['params']);
}
//clear table list
$this->tableList = null;
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"table",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"compiler",
"=",
"$",
"this",
"->",
"connection",
"->",
"schemaCompiler",
"(",
")",
";",
"$",
"schema",
"=",
"new",
"CreateTable",
"(",
"$",
"... | Creates a new table
@param string $table Table name
@param callable $callback A callback that will define table's fields and indexes
@throws \Exception | [
"Creates",
"a",
"new",
"table"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L174-L188 | train |
opis/database | src/Schema.php | Schema.alter | public function alter(string $table, callable $callback)
{
$compiler = $this->connection->schemaCompiler();
$schema = new AlterTable($table);
$callback($schema);
unset($this->columns[strtolower($table)]);
foreach ($compiler->alter($schema) as $result) {
$this->connection->command($result['sql'], $result['params']);
}
} | php | public function alter(string $table, callable $callback)
{
$compiler = $this->connection->schemaCompiler();
$schema = new AlterTable($table);
$callback($schema);
unset($this->columns[strtolower($table)]);
foreach ($compiler->alter($schema) as $result) {
$this->connection->command($result['sql'], $result['params']);
}
} | [
"public",
"function",
"alter",
"(",
"string",
"$",
"table",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"compiler",
"=",
"$",
"this",
"->",
"connection",
"->",
"schemaCompiler",
"(",
")",
";",
"$",
"schema",
"=",
"new",
"AlterTable",
"(",
"$",
"ta... | Alters a table's definition
@param string $table Table name
@param callable $callback A callback that will add or remove fields or indexes
@throws \Exception | [
"Alters",
"a",
"table",
"s",
"definition"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L197-L210 | train |
opis/database | src/Schema.php | Schema.renameTable | public function renameTable(string $table, string $name)
{
$result = $this->connection->schemaCompiler()->renameTable($table, $name);
$this->connection->command($result['sql'], $result['params']);
$this->tableList = null;
unset($this->columns[strtolower($table)]);
} | php | public function renameTable(string $table, string $name)
{
$result = $this->connection->schemaCompiler()->renameTable($table, $name);
$this->connection->command($result['sql'], $result['params']);
$this->tableList = null;
unset($this->columns[strtolower($table)]);
} | [
"public",
"function",
"renameTable",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"connection",
"->",
"schemaCompiler",
"(",
")",
"->",
"renameTable",
"(",
"$",
"table",
",",
"$",
"name",
")"... | Change a table's name
@param string $table The table
@param string $name The new name of the table
@throws \Exception | [
"Change",
"a",
"table",
"s",
"name"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L219-L225 | train |
opis/database | src/Schema.php | Schema.drop | public function drop(string $table)
{
$compiler = $this->connection->schemaCompiler();
$result = $compiler->drop($table);
$this->connection->command($result['sql'], $result['params']);
//clear table list
$this->tableList = null;
unset($this->columns[strtolower($table)]);
} | php | public function drop(string $table)
{
$compiler = $this->connection->schemaCompiler();
$result = $compiler->drop($table);
$this->connection->command($result['sql'], $result['params']);
//clear table list
$this->tableList = null;
unset($this->columns[strtolower($table)]);
} | [
"public",
"function",
"drop",
"(",
"string",
"$",
"table",
")",
"{",
"$",
"compiler",
"=",
"$",
"this",
"->",
"connection",
"->",
"schemaCompiler",
"(",
")",
";",
"$",
"result",
"=",
"$",
"compiler",
"->",
"drop",
"(",
"$",
"table",
")",
";",
"$",
... | Deletes a table
@param string $table Table name
@throws \Exception | [
"Deletes",
"a",
"table"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L233-L244 | train |
opis/database | src/Schema.php | Schema.truncate | public function truncate(string $table)
{
$compiler = $this->connection->schemaCompiler();
$result = $compiler->truncate($table);
$this->connection->command($result['sql'], $result['params']);
} | php | public function truncate(string $table)
{
$compiler = $this->connection->schemaCompiler();
$result = $compiler->truncate($table);
$this->connection->command($result['sql'], $result['params']);
} | [
"public",
"function",
"truncate",
"(",
"string",
"$",
"table",
")",
"{",
"$",
"compiler",
"=",
"$",
"this",
"->",
"connection",
"->",
"schemaCompiler",
"(",
")",
";",
"$",
"result",
"=",
"$",
"compiler",
"->",
"truncate",
"(",
"$",
"table",
")",
";",
... | Deletes all records from a table
@param string $table Table name
@throws \Exception | [
"Deletes",
"all",
"records",
"from",
"a",
"table"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Schema.php#L252-L259 | train |
opis/database | src/Connection.php | Connection.initCommand | public function initCommand(string $query, array $params = []): self
{
$this->commands[] = [
'sql' => $query,
'params' => $params,
];
return $this;
} | php | public function initCommand(string $query, array $params = []): self
{
$this->commands[] = [
'sql' => $query,
'params' => $params,
];
return $this;
} | [
"public",
"function",
"initCommand",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"this",
"->",
"commands",
"[",
"]",
"=",
"[",
"'sql'",
"=>",
"$",
"query",
",",
"'params'",
"=>",
"$",
"params... | Add an init command
@param string $query SQL command
@param array $params (optional) Params
@return Connection | [
"Add",
"an",
"init",
"command"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L140-L148 | train |
opis/database | src/Connection.php | Connection.options | public function options(array $options): self
{
foreach ($options as $name => $value) {
$this->option($name, $value);
}
return $this;
} | php | public function options(array $options): self
{
foreach ($options as $name => $value) {
$this->option($name, $value);
}
return $this;
} | [
"public",
"function",
"options",
"(",
"array",
"$",
"options",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"option",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}"... | Set PDO connection options
@param array $options PDO options
@return Connection | [
"Set",
"PDO",
"connection",
"options"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L183-L190 | train |
opis/database | src/Connection.php | Connection.persistent | public function persistent(bool $value = true): self
{
return $this->option(PDO::ATTR_PERSISTENT, $value);
} | php | public function persistent(bool $value = true): self
{
return $this->option(PDO::ATTR_PERSISTENT, $value);
} | [
"public",
"function",
"persistent",
"(",
"bool",
"$",
"value",
"=",
"true",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"option",
"(",
"PDO",
"::",
"ATTR_PERSISTENT",
",",
"$",
"value",
")",
";",
"}"
] | Use persistent connections
@param bool $value (optional) Value
@return Connection | [
"Use",
"persistent",
"connections"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L213-L216 | train |
opis/database | src/Connection.php | Connection.setWrapperFormat | public function setWrapperFormat(string $wrapper): self
{
$this->compilerOptions['wrapper'] = $wrapper;
$this->schemaCompilerOptions['wrapper'] = $wrapper;
return $this;
} | php | public function setWrapperFormat(string $wrapper): self
{
$this->compilerOptions['wrapper'] = $wrapper;
$this->schemaCompilerOptions['wrapper'] = $wrapper;
return $this;
} | [
"public",
"function",
"setWrapperFormat",
"(",
"string",
"$",
"wrapper",
")",
":",
"self",
"{",
"$",
"this",
"->",
"compilerOptions",
"[",
"'wrapper'",
"]",
"=",
"$",
"wrapper",
";",
"$",
"this",
"->",
"schemaCompilerOptions",
"[",
"'wrapper'",
"]",
"=",
"... | Set identifier wrapper
@param string $wrapper Identifier wrapper
@return Connection | [
"Set",
"identifier",
"wrapper"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L238-L243 | train |
opis/database | src/Connection.php | Connection.getDriver | public function getDriver()
{
if ($this->driver === null) {
$this->driver = $this->getPDO()->getAttribute(PDO::ATTR_DRIVER_NAME);
}
return $this->driver;
} | php | public function getDriver()
{
if ($this->driver === null) {
$this->driver = $this->getPDO()->getAttribute(PDO::ATTR_DRIVER_NAME);
}
return $this->driver;
} | [
"public",
"function",
"getDriver",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"driver",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"driver",
"=",
"$",
"this",
"->",
"getPDO",
"(",
")",
"->",
"getAttribute",
"(",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")... | Returns the driver's name
@return string | [
"Returns",
"the",
"driver",
"s",
"name"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L260-L267 | train |
opis/database | src/Connection.php | Connection.getSchema | public function getSchema(): Schema
{
if ($this->schema === null) {
$this->schema = new Schema($this);
}
return $this->schema;
} | php | public function getSchema(): Schema
{
if ($this->schema === null) {
$this->schema = new Schema($this);
}
return $this->schema;
} | [
"public",
"function",
"getSchema",
"(",
")",
":",
"Schema",
"{",
"if",
"(",
"$",
"this",
"->",
"schema",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"schema",
"=",
"new",
"Schema",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sc... | Returns the schema associated with this connection
@return Schema | [
"Returns",
"the",
"schema",
"associated",
"with",
"this",
"connection"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L274-L281 | train |
opis/database | src/Connection.php | Connection.getPDO | public function getPDO(): PDO
{
if ($this->pdo == null) {
$this->pdo = new PDO($this->getDSN(), $this->username, $this->password, $this->options);
foreach ($this->commands as $command) {
$this->command($command['sql'], $command['params']);
}
}
return $this->pdo;
} | php | public function getPDO(): PDO
{
if ($this->pdo == null) {
$this->pdo = new PDO($this->getDSN(), $this->username, $this->password, $this->options);
foreach ($this->commands as $command) {
$this->command($command['sql'], $command['params']);
}
}
return $this->pdo;
} | [
"public",
"function",
"getPDO",
"(",
")",
":",
"PDO",
"{",
"if",
"(",
"$",
"this",
"->",
"pdo",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"pdo",
"=",
"new",
"PDO",
"(",
"$",
"this",
"->",
"getDSN",
"(",
")",
",",
"$",
"this",
"->",
"username",... | Returns the PDO object associated with this connection
@return PDO | [
"Returns",
"the",
"PDO",
"object",
"associated",
"with",
"this",
"connection"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L288-L299 | train |
opis/database | src/Connection.php | Connection.getCompiler | public function getCompiler(): SQL\Compiler
{
if ($this->compiler === null) {
switch ($this->getDriver()) {
case 'mysql':
$this->compiler = new SQL\Compiler\MySQL();
break;
case 'dblib':
case 'mssql':
case 'sqlsrv':
case 'sybase':
$this->compiler = new SQL\Compiler\SQLServer();
break;
case 'oci':
case 'oracle':
$this->compiler = new SQL\Compiler\Oracle();
break;
case 'firebird':
$this->compiler = new SQL\Compiler\Firebird();
break;
case 'db2':
case 'ibm':
case 'odbc':
$this->compiler = new SQL\Compiler\DB2();
break;
case 'nuodb':
$this->compiler = new SQL\Compiler\NuoDB();
break;
default:
$this->compiler = new SQL\Compiler();
}
$this->compiler->setOptions($this->compilerOptions);
}
return $this->compiler;
} | php | public function getCompiler(): SQL\Compiler
{
if ($this->compiler === null) {
switch ($this->getDriver()) {
case 'mysql':
$this->compiler = new SQL\Compiler\MySQL();
break;
case 'dblib':
case 'mssql':
case 'sqlsrv':
case 'sybase':
$this->compiler = new SQL\Compiler\SQLServer();
break;
case 'oci':
case 'oracle':
$this->compiler = new SQL\Compiler\Oracle();
break;
case 'firebird':
$this->compiler = new SQL\Compiler\Firebird();
break;
case 'db2':
case 'ibm':
case 'odbc':
$this->compiler = new SQL\Compiler\DB2();
break;
case 'nuodb':
$this->compiler = new SQL\Compiler\NuoDB();
break;
default:
$this->compiler = new SQL\Compiler();
}
$this->compiler->setOptions($this->compilerOptions);
}
return $this->compiler;
} | [
"public",
"function",
"getCompiler",
"(",
")",
":",
"SQL",
"\\",
"Compiler",
"{",
"if",
"(",
"$",
"this",
"->",
"compiler",
"===",
"null",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
"{",
"case",
"'mysql'",
":",
"$",
"th... | Returns an instance of the compiler associated with this connection
@return SQL\Compiler | [
"Returns",
"an",
"instance",
"of",
"the",
"compiler",
"associated",
"with",
"this",
"connection"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L306-L342 | train |
opis/database | src/Connection.php | Connection.schemaCompiler | public function schemaCompiler(): Schema\Compiler
{
if ($this->schemaCompiler === null) {
switch ($this->getDriver()) {
case 'mysql':
$this->schemaCompiler = new Schema\Compiler\MySQL($this);
break;
case 'pgsql':
$this->schemaCompiler = new Schema\Compiler\PostgreSQL($this);
break;
case 'dblib':
case 'mssql':
case 'sqlsrv':
case 'sybase':
$this->schemaCompiler = new Schema\Compiler\SQLServer($this);
break;
case 'sqlite':
$this->schemaCompiler = new Schema\Compiler\SQLite($this);
break;
case 'oci':
case 'oracle':
$this->schemaCompiler = new Schema\Compiler\Oracle($this);
break;
default:
throw new \Exception('Schema not supported yet');
}
$this->schemaCompiler->setOptions($this->schemaCompilerOptions);
}
return $this->schemaCompiler;
} | php | public function schemaCompiler(): Schema\Compiler
{
if ($this->schemaCompiler === null) {
switch ($this->getDriver()) {
case 'mysql':
$this->schemaCompiler = new Schema\Compiler\MySQL($this);
break;
case 'pgsql':
$this->schemaCompiler = new Schema\Compiler\PostgreSQL($this);
break;
case 'dblib':
case 'mssql':
case 'sqlsrv':
case 'sybase':
$this->schemaCompiler = new Schema\Compiler\SQLServer($this);
break;
case 'sqlite':
$this->schemaCompiler = new Schema\Compiler\SQLite($this);
break;
case 'oci':
case 'oracle':
$this->schemaCompiler = new Schema\Compiler\Oracle($this);
break;
default:
throw new \Exception('Schema not supported yet');
}
$this->schemaCompiler->setOptions($this->schemaCompilerOptions);
}
return $this->schemaCompiler;
} | [
"public",
"function",
"schemaCompiler",
"(",
")",
":",
"Schema",
"\\",
"Compiler",
"{",
"if",
"(",
"$",
"this",
"->",
"schemaCompiler",
"===",
"null",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getDriver",
"(",
")",
")",
"{",
"case",
"'mysql'",
":",
... | Returns an instance of the schema compiler associated with this connection
@throws \Exception
@return Schema\Compiler | [
"Returns",
"an",
"instance",
"of",
"the",
"schema",
"compiler",
"associated",
"with",
"this",
"connection"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L351-L382 | train |
opis/database | src/Connection.php | Connection.command | public function command(string $sql, array $params = [])
{
return $this->execute($this->prepare($sql, $params));
} | php | public function command(string $sql, array $params = [])
{
return $this->execute($this->prepare($sql, $params));
} | [
"public",
"function",
"command",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"this",
"->",
"prepare",
"(",
"$",
"sql",
",",
"$",
"params",
")",
")",
";",
"}"
] | Execute a non-query SQL command
@param string $sql SQL Command
@param array $params (optional) Command params
@return mixed Command result | [
"Execute",
"a",
"non",
"-",
"query",
"SQL",
"command"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L425-L428 | train |
opis/database | src/Connection.php | Connection.count | public function count(string $sql, array $params = [])
{
$prepared = $this->prepare($sql, $params);
$this->execute($prepared);
$result = $prepared['statement']->rowCount();
$prepared['statement']->closeCursor();
return $result;
} | php | public function count(string $sql, array $params = [])
{
$prepared = $this->prepare($sql, $params);
$this->execute($prepared);
$result = $prepared['statement']->rowCount();
$prepared['statement']->closeCursor();
return $result;
} | [
"public",
"function",
"count",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"prepared",
"=",
"$",
"this",
"->",
"prepare",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"execute",
"(",
... | Execute a query and return the number of affected rows
@param string $sql SQL Query
@param array $params (optional) Query params
@return int | [
"Execute",
"a",
"query",
"and",
"return",
"the",
"number",
"of",
"affected",
"rows"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L438-L445 | train |
opis/database | src/Connection.php | Connection.column | public function column(string $sql, array $params = [])
{
$prepared = $this->prepare($sql, $params);
$this->execute($prepared);
$result = $prepared['statement']->fetchColumn();
$prepared['statement']->closeCursor();
return $result;
} | php | public function column(string $sql, array $params = [])
{
$prepared = $this->prepare($sql, $params);
$this->execute($prepared);
$result = $prepared['statement']->fetchColumn();
$prepared['statement']->closeCursor();
return $result;
} | [
"public",
"function",
"column",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"prepared",
"=",
"$",
"this",
"->",
"prepare",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"execute",
"(",... | Execute a query and fetch the first column
@param string $sql SQL Query
@param array $params (optional) Query params
@return mixed | [
"Execute",
"a",
"query",
"and",
"fetch",
"the",
"first",
"column"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L455-L462 | train |
opis/database | src/Connection.php | Connection.replaceParams | protected function replaceParams(string $query, array $params): string
{
$compiler = $this->getCompiler();
return preg_replace_callback('/\?/', function () use (&$params, $compiler) {
$param = array_shift($params);
$param = is_object($param) ? get_class($param) : $param;
if (is_int($param) || is_float($param)) {
return $param;
} elseif ($param === null) {
return 'NULL';
} elseif (is_bool($param)) {
return $param ? 'TRUE' : 'FALSE';
} else {
return $compiler->quote($param);
}
}, $query);
} | php | protected function replaceParams(string $query, array $params): string
{
$compiler = $this->getCompiler();
return preg_replace_callback('/\?/', function () use (&$params, $compiler) {
$param = array_shift($params);
$param = is_object($param) ? get_class($param) : $param;
if (is_int($param) || is_float($param)) {
return $param;
} elseif ($param === null) {
return 'NULL';
} elseif (is_bool($param)) {
return $param ? 'TRUE' : 'FALSE';
} else {
return $compiler->quote($param);
}
}, $query);
} | [
"protected",
"function",
"replaceParams",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"params",
")",
":",
"string",
"{",
"$",
"compiler",
"=",
"$",
"this",
"->",
"getCompiler",
"(",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/\\?/'",
",",
"fun... | Replace placeholders with parameters.
@param string $query SQL query
@param array $params Query parameters
@return string | [
"Replace",
"placeholders",
"with",
"parameters",
"."
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L510-L528 | train |
opis/database | src/Connection.php | Connection.execute | protected function execute(array $prepared)
{
if ($this->logQueries) {
$start = microtime(true);
$log = [
'query' => $this->replaceParams($prepared['query'], $prepared['params']),
];
$this->log[] = &$log;
}
try {
if ($prepared['params']) {
$this->bindValues($prepared['statement'], $prepared['params']);
}
$result = $prepared['statement']->execute();
} catch (PDOException $e) {
throw new PDOException($e->getMessage() . ' [ ' . $this->replaceParams($prepared['query'],
$prepared['params']) . ' ] ', (int)$e->getCode(), $e->getPrevious());
}
if ($this->logQueries) {
/** @noinspection PhpUndefinedVariableInspection */
$log['time'] = microtime(true) - $start;
}
return $result;
} | php | protected function execute(array $prepared)
{
if ($this->logQueries) {
$start = microtime(true);
$log = [
'query' => $this->replaceParams($prepared['query'], $prepared['params']),
];
$this->log[] = &$log;
}
try {
if ($prepared['params']) {
$this->bindValues($prepared['statement'], $prepared['params']);
}
$result = $prepared['statement']->execute();
} catch (PDOException $e) {
throw new PDOException($e->getMessage() . ' [ ' . $this->replaceParams($prepared['query'],
$prepared['params']) . ' ] ', (int)$e->getCode(), $e->getPrevious());
}
if ($this->logQueries) {
/** @noinspection PhpUndefinedVariableInspection */
$log['time'] = microtime(true) - $start;
}
return $result;
} | [
"protected",
"function",
"execute",
"(",
"array",
"$",
"prepared",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logQueries",
")",
"{",
"$",
"start",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"log",
"=",
"[",
"'query'",
"=>",
"$",
"this",
"->",
"rep... | Executes a prepared query and returns TRUE on success or FALSE on failure.
@param array $prepared Prepared query
@return boolean | [
"Executes",
"a",
"prepared",
"query",
"and",
"returns",
"TRUE",
"on",
"success",
"or",
"FALSE",
"on",
"failure",
"."
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/Connection.php#L557-L583 | train |
opis/database | src/SQL/Compiler.php | Compiler.insert | public function insert(SQLStatement $insert): string
{
$columns = $this->handleColumns($insert->getColumns());
$sql = 'INSERT INTO ';
$sql .= $this->handleTables($insert->getTables());
$sql .= ($columns === '*') ? '' : ' (' . $columns . ')';
$sql .= $this->handleInsertValues($insert->getValues());
return $sql;
} | php | public function insert(SQLStatement $insert): string
{
$columns = $this->handleColumns($insert->getColumns());
$sql = 'INSERT INTO ';
$sql .= $this->handleTables($insert->getTables());
$sql .= ($columns === '*') ? '' : ' (' . $columns . ')';
$sql .= $this->handleInsertValues($insert->getValues());
return $sql;
} | [
"public",
"function",
"insert",
"(",
"SQLStatement",
"$",
"insert",
")",
":",
"string",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"handleColumns",
"(",
"$",
"insert",
"->",
"getColumns",
"(",
")",
")",
";",
"$",
"sql",
"=",
"'INSERT INTO '",
";",
"$... | Returns the SQL for an insert statement
@param SQLStatement $insert
@return string | [
"Returns",
"the",
"SQL",
"for",
"an",
"insert",
"statement"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L64-L74 | train |
opis/database | src/SQL/Compiler.php | Compiler.update | public function update(SQLStatement $update): string
{
$sql = 'UPDATE ';
$sql .= $this->handleTables($update->getTables());
$sql .= $this->handleJoins($update->getJoins());
$sql .= $this->handleSetColumns($update->getColumns());
$sql .= $this->handleWheres($update->getWheres());
return $sql;
} | php | public function update(SQLStatement $update): string
{
$sql = 'UPDATE ';
$sql .= $this->handleTables($update->getTables());
$sql .= $this->handleJoins($update->getJoins());
$sql .= $this->handleSetColumns($update->getColumns());
$sql .= $this->handleWheres($update->getWheres());
return $sql;
} | [
"public",
"function",
"update",
"(",
"SQLStatement",
"$",
"update",
")",
":",
"string",
"{",
"$",
"sql",
"=",
"'UPDATE '",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"handleTables",
"(",
"$",
"update",
"->",
"getTables",
"(",
")",
")",
";",
"$",
"sql"... | Returns the SQL for an update statement
@param SQLStatement $update
@return string | [
"Returns",
"the",
"SQL",
"for",
"an",
"update",
"statement"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L83-L92 | train |
opis/database | src/SQL/Compiler.php | Compiler.delete | public function delete(SQLStatement $delete): string
{
$sql = 'DELETE ' . $this->handleTables($delete->getTables());
$sql .= $sql === 'DELETE ' ? 'FROM ' : ' FROM ';
$sql .= $this->handleTables($delete->getFrom());
$sql .= $this->handleJoins($delete->getJoins());
$sql .= $this->handleWheres($delete->getWheres());
return $sql;
} | php | public function delete(SQLStatement $delete): string
{
$sql = 'DELETE ' . $this->handleTables($delete->getTables());
$sql .= $sql === 'DELETE ' ? 'FROM ' : ' FROM ';
$sql .= $this->handleTables($delete->getFrom());
$sql .= $this->handleJoins($delete->getJoins());
$sql .= $this->handleWheres($delete->getWheres());
return $sql;
} | [
"public",
"function",
"delete",
"(",
"SQLStatement",
"$",
"delete",
")",
":",
"string",
"{",
"$",
"sql",
"=",
"'DELETE '",
".",
"$",
"this",
"->",
"handleTables",
"(",
"$",
"delete",
"->",
"getTables",
"(",
")",
")",
";",
"$",
"sql",
".=",
"$",
"sql"... | Returns the SQL for a delete statement
@param SQLStatement $delete
@return string | [
"Returns",
"the",
"SQL",
"for",
"a",
"delete",
"statement"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L100-L109 | train |
opis/database | src/SQL/Compiler.php | Compiler.wrap | protected function wrap($value)
{
if ($value instanceof Expression) {
return $this->handleExpressions($value->getExpressions());
}
$wrapped = [];
foreach (explode('.', $value) as $segment) {
if ($segment == '*') {
$wrapped[] = $segment;
} else {
$wrapped[] = sprintf($this->wrapper, $segment);
}
}
return implode('.', $wrapped);
} | php | protected function wrap($value)
{
if ($value instanceof Expression) {
return $this->handleExpressions($value->getExpressions());
}
$wrapped = [];
foreach (explode('.', $value) as $segment) {
if ($segment == '*') {
$wrapped[] = $segment;
} else {
$wrapped[] = sprintf($this->wrapper, $segment);
}
}
return implode('.', $wrapped);
} | [
"protected",
"function",
"wrap",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Expression",
")",
"{",
"return",
"$",
"this",
"->",
"handleExpressions",
"(",
"$",
"value",
"->",
"getExpressions",
"(",
")",
")",
";",
"}",
"$",
"wra... | Wrap a value
@param mixed $value
@return string | [
"Wrap",
"a",
"value"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L181-L198 | train |
opis/database | src/SQL/Compiler.php | Compiler.param | protected function param($value)
{
if ($value instanceof Expression) {
return $this->handleExpressions($value->getExpressions());
} elseif ($value instanceof DateTime) {
$this->params[] = $value->format($this->dateFormat);
} else {
$this->params[] = $value;
}
return '?';
} | php | protected function param($value)
{
if ($value instanceof Expression) {
return $this->handleExpressions($value->getExpressions());
} elseif ($value instanceof DateTime) {
$this->params[] = $value->format($this->dateFormat);
} else {
$this->params[] = $value;
}
return '?';
} | [
"protected",
"function",
"param",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Expression",
")",
"{",
"return",
"$",
"this",
"->",
"handleExpressions",
"(",
"$",
"value",
"->",
"getExpressions",
"(",
")",
")",
";",
"}",
"elseif",
... | Stores a query param
@param mixed $value
@return string | [
"Stores",
"a",
"query",
"param"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L207-L218 | train |
opis/database | src/SQL/Compiler.php | Compiler.handleExpressions | protected function handleExpressions(array $expressions)
{
$sql = [];
foreach ($expressions as $expr) {
switch ($expr['type']) {
case 'column':
$sql[] = $this->wrap($expr['value']);
break;
case 'op':
$sql[] = $expr['value'];
break;
case 'value':
$sql[] = $this->param($expr['value']);
break;
case 'group':
/** @var Expression $expression */
$expression = $expr['value'];
$sql[] = '(' . $this->handleExpressions($expression->getExpressions()) . ')';
break;
case 'function':
$sql[] = $this->handleSqlFunction($expr['value']);
break;
case 'subquery':
/** @var Subquery $subquery */
$subquery = $expr['value'];
$sql[] = '(' . $this->select($subquery->getSQLStatement()) . ')';
break;
}
}
return implode(' ', $sql);
} | php | protected function handleExpressions(array $expressions)
{
$sql = [];
foreach ($expressions as $expr) {
switch ($expr['type']) {
case 'column':
$sql[] = $this->wrap($expr['value']);
break;
case 'op':
$sql[] = $expr['value'];
break;
case 'value':
$sql[] = $this->param($expr['value']);
break;
case 'group':
/** @var Expression $expression */
$expression = $expr['value'];
$sql[] = '(' . $this->handleExpressions($expression->getExpressions()) . ')';
break;
case 'function':
$sql[] = $this->handleSqlFunction($expr['value']);
break;
case 'subquery':
/** @var Subquery $subquery */
$subquery = $expr['value'];
$sql[] = '(' . $this->select($subquery->getSQLStatement()) . ')';
break;
}
}
return implode(' ', $sql);
} | [
"protected",
"function",
"handleExpressions",
"(",
"array",
"$",
"expressions",
")",
"{",
"$",
"sql",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"expressions",
"as",
"$",
"expr",
")",
"{",
"switch",
"(",
"$",
"expr",
"[",
"'type'",
"]",
")",
"{",
"case... | Handle all expressions
@param array $expressions
@return string | [
"Handle",
"all",
"expressions"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L227-L259 | train |
opis/database | src/SQL/Compiler.php | Compiler.handleWheres | protected function handleWheres(array $wheres, $prefix = true)
{
if (empty($wheres)) {
return '';
}
$sql[] = $this->{$wheres[0]['type']}($wheres[0]);
$count = count($wheres);
for ($i = 1; $i < $count; $i++) {
$sql[] = $wheres[$i]['separator'] . ' ' . $this->{$wheres[$i]['type']}($wheres[$i]);
}
return ($prefix ? ' WHERE ' : '') . implode(' ', $sql);
} | php | protected function handleWheres(array $wheres, $prefix = true)
{
if (empty($wheres)) {
return '';
}
$sql[] = $this->{$wheres[0]['type']}($wheres[0]);
$count = count($wheres);
for ($i = 1; $i < $count; $i++) {
$sql[] = $wheres[$i]['separator'] . ' ' . $this->{$wheres[$i]['type']}($wheres[$i]);
}
return ($prefix ? ' WHERE ' : '') . implode(' ', $sql);
} | [
"protected",
"function",
"handleWheres",
"(",
"array",
"$",
"wheres",
",",
"$",
"prefix",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"wheres",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"sql",
"[",
"]",
"=",
"$",
"this",
"->",
"{",
... | Handle WHERE conditions
@param array $wheres
@param bool $prefix (optional)
@return string | [
"Handle",
"WHERE",
"conditions"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L348-L363 | train |
opis/database | src/SQL/Compiler.php | Compiler.handleJoins | protected function handleJoins(array $joins)
{
if (empty($joins)) {
return '';
}
$sql = [];
foreach ($joins as $join) {
/** @var Join $joinObject */
$joinObject = $join['join'];
$on = '';
if ($joinObject) {
$on = $this->handleJoinConditions($joinObject->getJoinConditions());
}
if ($on !== '') {
$on = ' ON ' . $on;
}
$sql[] = $join['type'] . ' JOIN ' . $this->handleTables($join['table']) . $on;
}
return ' ' . implode(' ', $sql);
} | php | protected function handleJoins(array $joins)
{
if (empty($joins)) {
return '';
}
$sql = [];
foreach ($joins as $join) {
/** @var Join $joinObject */
$joinObject = $join['join'];
$on = '';
if ($joinObject) {
$on = $this->handleJoinConditions($joinObject->getJoinConditions());
}
if ($on !== '') {
$on = ' ON ' . $on;
}
$sql[] = $join['type'] . ' JOIN ' . $this->handleTables($join['table']) . $on;
}
return ' ' . implode(' ', $sql);
} | [
"protected",
"function",
"handleJoins",
"(",
"array",
"$",
"joins",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"joins",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"sql",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"joins",
"as",
"$",
"join",
")",
... | Handle JOIN clauses
@param array $joins
@return string | [
"Handle",
"JOIN",
"clauses"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L384-L405 | train |
opis/database | src/SQL/Compiler.php | Compiler.handleJoinConditions | protected function handleJoinConditions(array $conditions)
{
if (empty($conditions)) {
return '';
}
$sql[] = $this->{$conditions[0]['type']}($conditions[0]);
$count = count($conditions);
for ($i = 1; $i < $count; $i++) {
$sql[] = $conditions[$i]['separator'] . ' ' . $this->{$conditions[$i]['type']}($conditions[$i]);
}
return implode(' ', $sql);
} | php | protected function handleJoinConditions(array $conditions)
{
if (empty($conditions)) {
return '';
}
$sql[] = $this->{$conditions[0]['type']}($conditions[0]);
$count = count($conditions);
for ($i = 1; $i < $count; $i++) {
$sql[] = $conditions[$i]['separator'] . ' ' . $this->{$conditions[$i]['type']}($conditions[$i]);
}
return implode(' ', $sql);
} | [
"protected",
"function",
"handleJoinConditions",
"(",
"array",
"$",
"conditions",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"sql",
"[",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"conditions",
"["... | Handle JOIN conditions
@param array $conditions
@return string | [
"Handle",
"JOIN",
"conditions"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L414-L425 | train |
opis/database | src/SQL/Compiler.php | Compiler.handleHavings | protected function handleHavings(array $havings, $prefix = true)
{
if (empty($havings)) {
return '';
}
$sql[] = $this->{$havings[0]['type']}($havings[0]);
$count = count($havings);
for ($i = 1; $i < $count; $i++) {
$sql[] = $havings[$i]['separator'] . ' ' . $this->{$havings[$i]['type']}($havings[$i]);
}
return ($prefix ? ' HAVING ' : '') . implode(' ', $sql);
} | php | protected function handleHavings(array $havings, $prefix = true)
{
if (empty($havings)) {
return '';
}
$sql[] = $this->{$havings[0]['type']}($havings[0]);
$count = count($havings);
for ($i = 1; $i < $count; $i++) {
$sql[] = $havings[$i]['separator'] . ' ' . $this->{$havings[$i]['type']}($havings[$i]);
}
return ($prefix ? ' HAVING ' : '') . implode(' ', $sql);
} | [
"protected",
"function",
"handleHavings",
"(",
"array",
"$",
"havings",
",",
"$",
"prefix",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"havings",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"sql",
"[",
"]",
"=",
"$",
"this",
"->",
"{"... | Handle HAVING clause
@param array $havings
@param bool $prefix (optional)
@return string | [
"Handle",
"HAVING",
"clause"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler.php#L435-L451 | train |
codemix/yii2-streamlog | src/Target.php | Target.export | public function export()
{
$text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";
fwrite($this->getFp(), $text);
} | php | public function export()
{
$text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";
fwrite($this->getFp(), $text);
} | [
"public",
"function",
"export",
"(",
")",
"{",
"$",
"text",
"=",
"implode",
"(",
"\"\\n\"",
",",
"array_map",
"(",
"[",
"$",
"this",
",",
"'formatMessage'",
"]",
",",
"$",
"this",
"->",
"messages",
")",
")",
".",
"\"\\n\"",
";",
"fwrite",
"(",
"$",
... | Writes a log message to the given target URL
@throws InvalidConfigException if unable to open the stream for writing | [
"Writes",
"a",
"log",
"message",
"to",
"the",
"given",
"target",
"URL"
] | 46717733b46a91dd323888349b323fb0bd989e2e | https://github.com/codemix/yii2-streamlog/blob/46717733b46a91dd323888349b323fb0bd989e2e/src/Target.php#L83-L87 | train |
philipbrown/signature-php | src/Auth.php | Auth.attempt | public function attempt(Token $token, $prefix = Request::PREFIX)
{
$auth = $this->getAuthParams($prefix);
$body = $this->getBodyParams($prefix);
$request = new Request($this->method, $this->uri, $body, $auth[$prefix . 'timestamp']);
$signature = $request->sign($token, $prefix);
foreach ($this->guards as $guard) {
$guard->check($auth, $signature, $prefix);
}
return true;
} | php | public function attempt(Token $token, $prefix = Request::PREFIX)
{
$auth = $this->getAuthParams($prefix);
$body = $this->getBodyParams($prefix);
$request = new Request($this->method, $this->uri, $body, $auth[$prefix . 'timestamp']);
$signature = $request->sign($token, $prefix);
foreach ($this->guards as $guard) {
$guard->check($auth, $signature, $prefix);
}
return true;
} | [
"public",
"function",
"attempt",
"(",
"Token",
"$",
"token",
",",
"$",
"prefix",
"=",
"Request",
"::",
"PREFIX",
")",
"{",
"$",
"auth",
"=",
"$",
"this",
"->",
"getAuthParams",
"(",
"$",
"prefix",
")",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"get... | Attempt to authenticate a request
@param Token $token
@param string $prefix
@return bool | [
"Attempt",
"to",
"authenticate",
"a",
"request"
] | 2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b | https://github.com/philipbrown/signature-php/blob/2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b/src/Auth.php#L54-L67 | train |
philipbrown/signature-php | src/Auth.php | Auth.getAuthParams | private function getAuthParams($prefix)
{
return array_intersect_key($this->params, array_flip($this->addPrefix($this->auth, $prefix)));
} | php | private function getAuthParams($prefix)
{
return array_intersect_key($this->params, array_flip($this->addPrefix($this->auth, $prefix)));
} | [
"private",
"function",
"getAuthParams",
"(",
"$",
"prefix",
")",
"{",
"return",
"array_intersect_key",
"(",
"$",
"this",
"->",
"params",
",",
"array_flip",
"(",
"$",
"this",
"->",
"addPrefix",
"(",
"$",
"this",
"->",
"auth",
",",
"$",
"prefix",
")",
")",... | Get the auth params
@param $prefix
@return array | [
"Get",
"the",
"auth",
"params"
] | 2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b | https://github.com/philipbrown/signature-php/blob/2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b/src/Auth.php#L75-L78 | train |
philipbrown/signature-php | src/Auth.php | Auth.getBodyParams | private function getBodyParams($prefix)
{
return array_diff_key($this->params, array_flip($this->addPrefix($this->auth, $prefix)));
} | php | private function getBodyParams($prefix)
{
return array_diff_key($this->params, array_flip($this->addPrefix($this->auth, $prefix)));
} | [
"private",
"function",
"getBodyParams",
"(",
"$",
"prefix",
")",
"{",
"return",
"array_diff_key",
"(",
"$",
"this",
"->",
"params",
",",
"array_flip",
"(",
"$",
"this",
"->",
"addPrefix",
"(",
"$",
"this",
"->",
"auth",
",",
"$",
"prefix",
")",
")",
")... | Get the body params
@param $prefix
@return array | [
"Get",
"the",
"body",
"params"
] | 2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b | https://github.com/philipbrown/signature-php/blob/2a8cecb1f63c3ae5fedb7ee6c1821af9548c233b/src/Auth.php#L86-L89 | train |
opis/database | src/SQL/Compiler/SQLServer.php | SQLServer.select | public function select(SQLStatement $select): string
{
$limit = $select->getLimit();
if ($limit <= 0) {
return parent::select($select);
}
$offset = $select->getOffset();
if ($offset < 0) {
$sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
$sql .= 'TOP ' . $limit . ' ';
$sql .= $this->handleColumns($select->getColumns());
$sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
$sql .= ' FROM ';
$sql .= $this->handleTables($select->getTables());
$sql .= $this->handleJoins($select->getJoins());
$sql .= $this->handleWheres($select->getWheres());
$sql .= $this->handleGroupings($select->getGroupBy());
$sql .= $this->handleOrderings($select->getOrder());
$sql .= $this->handleHavings($select->getHaving());
return $sql;
}
$order = trim($this->handleOrderings($select->getOrder()));
if (empty($order)) {
$order = 'ORDER BY (SELECT 0)';
}
$sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
$sql .= $this->handleColumns($select->getColumns());
$sql .= ', ROW_NUMBER() OVER (' . $order . ') AS opis_rownum';
$sql .= ' FROM ';
$sql .= $this->handleTables($select->getTables());
$sql .= $this->handleJoins($select->getJoins());
$sql .= $this->handleWheres($select->getWheres());
$sql .= $this->handleGroupings($select->getGroupBy());
$sql .= $this->handleHavings($select->getHaving());
$limit += $offset;
$offset++;
return 'SELECT * FROM (' . $sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $offset . ' AND ' . $limit;
} | php | public function select(SQLStatement $select): string
{
$limit = $select->getLimit();
if ($limit <= 0) {
return parent::select($select);
}
$offset = $select->getOffset();
if ($offset < 0) {
$sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
$sql .= 'TOP ' . $limit . ' ';
$sql .= $this->handleColumns($select->getColumns());
$sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
$sql .= ' FROM ';
$sql .= $this->handleTables($select->getTables());
$sql .= $this->handleJoins($select->getJoins());
$sql .= $this->handleWheres($select->getWheres());
$sql .= $this->handleGroupings($select->getGroupBy());
$sql .= $this->handleOrderings($select->getOrder());
$sql .= $this->handleHavings($select->getHaving());
return $sql;
}
$order = trim($this->handleOrderings($select->getOrder()));
if (empty($order)) {
$order = 'ORDER BY (SELECT 0)';
}
$sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
$sql .= $this->handleColumns($select->getColumns());
$sql .= ', ROW_NUMBER() OVER (' . $order . ') AS opis_rownum';
$sql .= ' FROM ';
$sql .= $this->handleTables($select->getTables());
$sql .= $this->handleJoins($select->getJoins());
$sql .= $this->handleWheres($select->getWheres());
$sql .= $this->handleGroupings($select->getGroupBy());
$sql .= $this->handleHavings($select->getHaving());
$limit += $offset;
$offset++;
return 'SELECT * FROM (' . $sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $offset . ' AND ' . $limit;
} | [
"public",
"function",
"select",
"(",
"SQLStatement",
"$",
"select",
")",
":",
"string",
"{",
"$",
"limit",
"=",
"$",
"select",
"->",
"getLimit",
"(",
")",
";",
"if",
"(",
"$",
"limit",
"<=",
"0",
")",
"{",
"return",
"parent",
"::",
"select",
"(",
"... | Compiles a SELECT query
@param SQLStatement $select
@return string | [
"Compiles",
"a",
"SELECT",
"query"
] | a750c8e58da37b23b70cc4b10fa5a97376db2bc7 | https://github.com/opis/database/blob/a750c8e58da37b23b70cc4b10fa5a97376db2bc7/src/SQL/Compiler/SQLServer.php#L37-L83 | train |
thephpleague/shunt | src/League/Shunt/BaseObject.php | BaseObject.printVerbose | public function printVerbose($message)
{
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->printOut($message);
}
} | php | public function printVerbose($message)
{
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->printOut($message);
}
} | [
"public",
"function",
"printVerbose",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"output",
"->",
"getVerbosity",
"(",
")",
">=",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
"{",
"$",
"this",
"->",
"printOut",
"(",
"$",
"message",
... | Print verbose information
@param string | [
"Print",
"verbose",
"information"
] | 518487136985e6c9147a0964e4fde84862f4017c | https://github.com/thephpleague/shunt/blob/518487136985e6c9147a0964e4fde84862f4017c/src/League/Shunt/BaseObject.php#L62-L67 | train |
thephpleague/shunt | src/League/Shunt/BaseObject.php | BaseObject.printDebug | public function printDebug($message)
{
if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_DEBUG) {
$this->printOut('[DEBUG] '.$message);
}
} | php | public function printDebug($message)
{
if ($this->output->getVerbosity() == OutputInterface::VERBOSITY_DEBUG) {
$this->printOut('[DEBUG] '.$message);
}
} | [
"public",
"function",
"printDebug",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"output",
"->",
"getVerbosity",
"(",
")",
"==",
"OutputInterface",
"::",
"VERBOSITY_DEBUG",
")",
"{",
"$",
"this",
"->",
"printOut",
"(",
"'[DEBUG] '",
".",
... | Print debug information
@param string | [
"Print",
"debug",
"information"
] | 518487136985e6c9147a0964e4fde84862f4017c | https://github.com/thephpleague/shunt/blob/518487136985e6c9147a0964e4fde84862f4017c/src/League/Shunt/BaseObject.php#L74-L79 | train |
thephpleague/shunt | src/League/Shunt/Auth.php | Auth.parse | public function parse($credential = array())
{
if (array_key_exists(self::PUBKEY_FILE, $credential)) {
$type = self::PUBKEY_FILE;
$data = $credential[self::PUBKEY_FILE];
} elseif (array_key_exists(self::PASSWORD, $credential)) {
$type = self::PASSWORD;
$data = $credential[self::PASSWORD];
} else {
$type = self::NONE;
$data = isset($credential[self::NONE]) ? $credential[self::NONE] : array();
}
return array($type, $data);
} | php | public function parse($credential = array())
{
if (array_key_exists(self::PUBKEY_FILE, $credential)) {
$type = self::PUBKEY_FILE;
$data = $credential[self::PUBKEY_FILE];
} elseif (array_key_exists(self::PASSWORD, $credential)) {
$type = self::PASSWORD;
$data = $credential[self::PASSWORD];
} else {
$type = self::NONE;
$data = isset($credential[self::NONE]) ? $credential[self::NONE] : array();
}
return array($type, $data);
} | [
"public",
"function",
"parse",
"(",
"$",
"credential",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"self",
"::",
"PUBKEY_FILE",
",",
"$",
"credential",
")",
")",
"{",
"$",
"type",
"=",
"self",
"::",
"PUBKEY_FILE",
";",
"$",
... | Helper to parse the session
@param array
@return array | [
"Helper",
"to",
"parse",
"the",
"session"
] | 518487136985e6c9147a0964e4fde84862f4017c | https://github.com/thephpleague/shunt/blob/518487136985e6c9147a0964e4fde84862f4017c/src/League/Shunt/Auth.php#L74-L88 | train |
rap2hpoutre/similar-text-finder | src/Finder.php | Finder.sortHaystack | protected function sortHaystack()
{
$sorted_haystack = [];
foreach ($this->haystack as $string) {
$sorted_haystack[$string] = $this->levenshteinUtf8($this->needle, $string);
}
// Apply threshold when set.
if(!is_null($this->threshold)){
$sorted_haystack = array_filter($sorted_haystack, function ($score){
return $score <= $this->threshold;
});
}
asort($sorted_haystack);
$this->sorted_haystack = $sorted_haystack;
} | php | protected function sortHaystack()
{
$sorted_haystack = [];
foreach ($this->haystack as $string) {
$sorted_haystack[$string] = $this->levenshteinUtf8($this->needle, $string);
}
// Apply threshold when set.
if(!is_null($this->threshold)){
$sorted_haystack = array_filter($sorted_haystack, function ($score){
return $score <= $this->threshold;
});
}
asort($sorted_haystack);
$this->sorted_haystack = $sorted_haystack;
} | [
"protected",
"function",
"sortHaystack",
"(",
")",
"{",
"$",
"sorted_haystack",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"haystack",
"as",
"$",
"string",
")",
"{",
"$",
"sorted_haystack",
"[",
"$",
"string",
"]",
"=",
"$",
"this",
"->",
... | Sort Haystack.
@return void | [
"Sort",
"Haystack",
"."
] | 8e9a5dfc0a35261c02f7f980a6d3cb391087576e | https://github.com/rap2hpoutre/similar-text-finder/blob/8e9a5dfc0a35261c02f7f980a6d3cb391087576e/src/Finder.php#L52-L69 | train |
rap2hpoutre/similar-text-finder | src/Finder.php | Finder.utf8ToExtendedAscii | protected function utf8ToExtendedAscii($str, &$map)
{
// Find all multi-byte characters (cf. utf-8 encoding specs).
$matches = array();
if (!preg_match_all('/[\xC0-\xF7][\x80-\xBF]+/', $str, $matches)) {
return $str; // plain ascii string
}
// Update the encoding map with the characters not already met.
foreach ($matches[0] as $mbc) {
if (!isset($map[$mbc])) {
$map[$mbc] = chr(128 + count($map));
}
}
// Finally remap non-ascii characters.
return strtr($str, $map);
} | php | protected function utf8ToExtendedAscii($str, &$map)
{
// Find all multi-byte characters (cf. utf-8 encoding specs).
$matches = array();
if (!preg_match_all('/[\xC0-\xF7][\x80-\xBF]+/', $str, $matches)) {
return $str; // plain ascii string
}
// Update the encoding map with the characters not already met.
foreach ($matches[0] as $mbc) {
if (!isset($map[$mbc])) {
$map[$mbc] = chr(128 + count($map));
}
}
// Finally remap non-ascii characters.
return strtr($str, $map);
} | [
"protected",
"function",
"utf8ToExtendedAscii",
"(",
"$",
"str",
",",
"&",
"$",
"map",
")",
"{",
"// Find all multi-byte characters (cf. utf-8 encoding specs).",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"preg_match_all",
"(",
"'/[\\xC0-\\xF7][\\x... | Ensure a string only uses ascii characters.
@param string $str
@param array $map
@return string | [
"Ensure",
"a",
"string",
"only",
"uses",
"ascii",
"characters",
"."
] | 8e9a5dfc0a35261c02f7f980a6d3cb391087576e | https://github.com/rap2hpoutre/similar-text-finder/blob/8e9a5dfc0a35261c02f7f980a6d3cb391087576e/src/Finder.php#L125-L142 | train |
rap2hpoutre/similar-text-finder | src/Finder.php | Finder.levenshteinUtf8 | protected function levenshteinUtf8($string1, $string2)
{
$charMap = array();
$string1 = $this->utf8ToExtendedAscii($string1, $charMap);
$string2 = $this->utf8ToExtendedAscii($string2, $charMap);
return levenshtein($string1, $string2);
} | php | protected function levenshteinUtf8($string1, $string2)
{
$charMap = array();
$string1 = $this->utf8ToExtendedAscii($string1, $charMap);
$string2 = $this->utf8ToExtendedAscii($string2, $charMap);
return levenshtein($string1, $string2);
} | [
"protected",
"function",
"levenshteinUtf8",
"(",
"$",
"string1",
",",
"$",
"string2",
")",
"{",
"$",
"charMap",
"=",
"array",
"(",
")",
";",
"$",
"string1",
"=",
"$",
"this",
"->",
"utf8ToExtendedAscii",
"(",
"$",
"string1",
",",
"$",
"charMap",
")",
"... | Calculate the levenshtein distance between two strings.
@param string $string1
@param string $string2
@return int | [
"Calculate",
"the",
"levenshtein",
"distance",
"between",
"two",
"strings",
"."
] | 8e9a5dfc0a35261c02f7f980a6d3cb391087576e | https://github.com/rap2hpoutre/similar-text-finder/blob/8e9a5dfc0a35261c02f7f980a6d3cb391087576e/src/Finder.php#L151-L158 | train |
jbowens/jBBCode | JBBCode/CodeDefinition.php | CodeDefinition.construct | public static function construct($tagName, $replacementText, $useOption = false,
$parseContent = true, $nestLimit = -1, $optionValidator = array(),
$bodyValidator = null)
{
$def = new CodeDefinition();
$def->elCounter = 0;
$def->setTagName($tagName);
$def->setReplacementText($replacementText);
$def->useOption = $useOption;
$def->parseContent = $parseContent;
$def->nestLimit = $nestLimit;
$def->optionValidator = $optionValidator;
$def->bodyValidator = $bodyValidator;
return $def;
} | php | public static function construct($tagName, $replacementText, $useOption = false,
$parseContent = true, $nestLimit = -1, $optionValidator = array(),
$bodyValidator = null)
{
$def = new CodeDefinition();
$def->elCounter = 0;
$def->setTagName($tagName);
$def->setReplacementText($replacementText);
$def->useOption = $useOption;
$def->parseContent = $parseContent;
$def->nestLimit = $nestLimit;
$def->optionValidator = $optionValidator;
$def->bodyValidator = $bodyValidator;
return $def;
} | [
"public",
"static",
"function",
"construct",
"(",
"$",
"tagName",
",",
"$",
"replacementText",
",",
"$",
"useOption",
"=",
"false",
",",
"$",
"parseContent",
"=",
"true",
",",
"$",
"nestLimit",
"=",
"-",
"1",
",",
"$",
"optionValidator",
"=",
"array",
"(... | Constructs a new CodeDefinition. | [
"Constructs",
"a",
"new",
"CodeDefinition",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/CodeDefinition.php#L41-L55 | train |
jbowens/jBBCode | JBBCode/CodeDefinition.php | CodeDefinition.hasValidInputs | public function hasValidInputs(ElementNode $el)
{
if ($this->usesOption() && $this->optionValidator) {
$att = $el->getAttribute();
foreach ($att as $name => $value) {
if (isset($this->optionValidator[$name]) && !$this->optionValidator[$name]->validate($value)) {
return false;
}
}
}
if (!$this->parseContent() && $this->bodyValidator) {
/* We only evaluate the content if we're not parsing the content. */
$content = "";
foreach ($el->getChildren() as $child) {
$content .= $child->getAsBBCode();
}
if (!$this->bodyValidator->validate($content)) {
/* The content of the element is not valid. */
return false;
}
}
return true;
} | php | public function hasValidInputs(ElementNode $el)
{
if ($this->usesOption() && $this->optionValidator) {
$att = $el->getAttribute();
foreach ($att as $name => $value) {
if (isset($this->optionValidator[$name]) && !$this->optionValidator[$name]->validate($value)) {
return false;
}
}
}
if (!$this->parseContent() && $this->bodyValidator) {
/* We only evaluate the content if we're not parsing the content. */
$content = "";
foreach ($el->getChildren() as $child) {
$content .= $child->getAsBBCode();
}
if (!$this->bodyValidator->validate($content)) {
/* The content of the element is not valid. */
return false;
}
}
return true;
} | [
"public",
"function",
"hasValidInputs",
"(",
"ElementNode",
"$",
"el",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"usesOption",
"(",
")",
"&&",
"$",
"this",
"->",
"optionValidator",
")",
"{",
"$",
"att",
"=",
"$",
"el",
"->",
"getAttribute",
"(",
")",
"... | Determines if the arguments to the given element are valid based on
any validators attached to this CodeDefinition.
@param ElementNode $el the ElementNode to validate
@return boolean true if the ElementNode's {option} and {param} are OK, false if they're not | [
"Determines",
"if",
"the",
"arguments",
"to",
"the",
"given",
"element",
"are",
"valid",
"based",
"on",
"any",
"validators",
"attached",
"to",
"this",
"CodeDefinition",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/CodeDefinition.php#L84-L109 | train |
jbowens/jBBCode | JBBCode/CodeDefinition.php | CodeDefinition.asText | public function asText(ElementNode $el)
{
if (!$this->hasValidInputs($el)) {
return $el->getAsBBCode();
}
$s = "";
foreach ($el->getChildren() as $child) {
$s .= $child->getAsText();
}
return $s;
} | php | public function asText(ElementNode $el)
{
if (!$this->hasValidInputs($el)) {
return $el->getAsBBCode();
}
$s = "";
foreach ($el->getChildren() as $child) {
$s .= $child->getAsText();
}
return $s;
} | [
"public",
"function",
"asText",
"(",
"ElementNode",
"$",
"el",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasValidInputs",
"(",
"$",
"el",
")",
")",
"{",
"return",
"$",
"el",
"->",
"getAsBBCode",
"(",
")",
";",
"}",
"$",
"s",
"=",
"\"\"",
";",... | Accepts an ElementNode that is defined by this CodeDefinition and returns the text
representation of the element. This may be overridden by a custom CodeDefinition.
@param ElementNode $el the element to return a text representation of
@return string the text representation of $el | [
"Accepts",
"an",
"ElementNode",
"that",
"is",
"defined",
"by",
"this",
"CodeDefinition",
"and",
"returns",
"the",
"text",
"representation",
"of",
"the",
"element",
".",
"This",
"may",
"be",
"overridden",
"by",
"a",
"custom",
"CodeDefinition",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/CodeDefinition.php#L171-L182 | train |
jbowens/jBBCode | JBBCode/Parser.php | Parser.addCodeDefinition | public function addCodeDefinition(CodeDefinition $definition)
{
$this->bbcodes[$definition->getTagName()][$definition->usesOption()] = $definition;
return $this;
} | php | public function addCodeDefinition(CodeDefinition $definition)
{
$this->bbcodes[$definition->getTagName()][$definition->usesOption()] = $definition;
return $this;
} | [
"public",
"function",
"addCodeDefinition",
"(",
"CodeDefinition",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"bbcodes",
"[",
"$",
"definition",
"->",
"getTagName",
"(",
")",
"]",
"[",
"$",
"definition",
"->",
"usesOption",
"(",
")",
"]",
"=",
"$",
"... | Adds a complex bbcode definition. You may subclass the CodeDefinition class, instantiate a definition of your new
class and add it to the parser through this method.
@param CodeDefinition $definition the bbcode definition to add
@return Parser | [
"Adds",
"a",
"complex",
"bbcode",
"definition",
".",
"You",
"may",
"subclass",
"the",
"CodeDefinition",
"class",
"instantiate",
"a",
"definition",
"of",
"your",
"new",
"class",
"and",
"add",
"it",
"to",
"the",
"parser",
"through",
"this",
"method",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/Parser.php#L92-L96 | train |
jbowens/jBBCode | JBBCode/Parser.php | Parser.addCodeDefinitionSet | public function addCodeDefinitionSet(CodeDefinitionSet $set)
{
foreach ($set->getCodeDefinitions() as $def) {
$this->addCodeDefinition($def);
}
return $this;
} | php | public function addCodeDefinitionSet(CodeDefinitionSet $set)
{
foreach ($set->getCodeDefinitions() as $def) {
$this->addCodeDefinition($def);
}
return $this;
} | [
"public",
"function",
"addCodeDefinitionSet",
"(",
"CodeDefinitionSet",
"$",
"set",
")",
"{",
"foreach",
"(",
"$",
"set",
"->",
"getCodeDefinitions",
"(",
")",
"as",
"$",
"def",
")",
"{",
"$",
"this",
"->",
"addCodeDefinition",
"(",
"$",
"def",
")",
";",
... | Adds a set of CodeDefinitions.
@param CodeDefinitionSet $set the set of definitions to add
@return Parser | [
"Adds",
"a",
"set",
"of",
"CodeDefinitions",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/Parser.php#L105-L112 | train |
jbowens/jBBCode | JBBCode/Parser.php | Parser.parseStartState | protected function parseStartState(ElementNode $parent, Tokenizer $tokenizer)
{
$next = $tokenizer->next();
if ('[' == $next) {
return $this->parseTagOpen($parent, $tokenizer);
} else {
$this->createTextNode($parent, $next);
/* Drop back into the main parse loop which will call this
* same method again. */
return $parent;
}
} | php | protected function parseStartState(ElementNode $parent, Tokenizer $tokenizer)
{
$next = $tokenizer->next();
if ('[' == $next) {
return $this->parseTagOpen($parent, $tokenizer);
} else {
$this->createTextNode($parent, $next);
/* Drop back into the main parse loop which will call this
* same method again. */
return $parent;
}
} | [
"protected",
"function",
"parseStartState",
"(",
"ElementNode",
"$",
"parent",
",",
"Tokenizer",
"$",
"tokenizer",
")",
"{",
"$",
"next",
"=",
"$",
"tokenizer",
"->",
"next",
"(",
")",
";",
"if",
"(",
"'['",
"==",
"$",
"next",
")",
"{",
"return",
"$",
... | jBBCode parsing logic is loosely modelled after a FSM. While not every function maps
to a unique DFSM state, each function handles the logic of one or more FSM states.
This function handles the beginning parse state when we're not currently in a tag
name.
@param ElementNode $parent the current parent node we're under
@param Tokenizer $tokenizer the tokenizer we're using
@return ElementNode the new parent we should use for the next iteration. | [
"jBBCode",
"parsing",
"logic",
"is",
"loosely",
"modelled",
"after",
"a",
"FSM",
".",
"While",
"not",
"every",
"function",
"maps",
"to",
"a",
"unique",
"DFSM",
"state",
"each",
"function",
"handles",
"the",
"logic",
"of",
"one",
"or",
"more",
"FSM",
"state... | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/Parser.php#L294-L306 | train |
jbowens/jBBCode | JBBCode/Parser.php | Parser.parseTagOpen | protected function parseTagOpen(ElementNode $parent, Tokenizer $tokenizer)
{
if (!$tokenizer->hasNext()) {
/* The [ that sent us to this state was just a trailing [, not the
* opening for a new tag. Treat it as such. */
$this->createTextNode($parent, '[');
return $parent;
}
$next = $tokenizer->next();
/* This while loop could be replaced by a recursive call to this same method,
* which would likely be a lot clearer but I decided to use a while loop to
* prevent stack overflow with a string like [[[[[[[[[...[[[.
*/
while ('[' == $next) {
/* The previous [ was just a random bracket that should be treated as text.
* Continue until we get a non open bracket. */
$this->createTextNode($parent, '[');
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, '[');
return $parent;
}
$next = $tokenizer->next();
}
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, '['.$next);
return $parent;
}
$after_next = $tokenizer->next();
$tokenizer->stepBack();
if ($after_next != ']') {
$this->createTextNode($parent, '['.$next);
return $parent;
}
/* At this point $next is either ']' or plain text. */
if (']' == $next) {
$this->createTextNode($parent, '[');
$this->createTextNode($parent, ']');
return $parent;
} else {
/* $next is plain text... likely a tag name. */
return $this->parseTag($parent, $tokenizer, $next);
}
} | php | protected function parseTagOpen(ElementNode $parent, Tokenizer $tokenizer)
{
if (!$tokenizer->hasNext()) {
/* The [ that sent us to this state was just a trailing [, not the
* opening for a new tag. Treat it as such. */
$this->createTextNode($parent, '[');
return $parent;
}
$next = $tokenizer->next();
/* This while loop could be replaced by a recursive call to this same method,
* which would likely be a lot clearer but I decided to use a while loop to
* prevent stack overflow with a string like [[[[[[[[[...[[[.
*/
while ('[' == $next) {
/* The previous [ was just a random bracket that should be treated as text.
* Continue until we get a non open bracket. */
$this->createTextNode($parent, '[');
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, '[');
return $parent;
}
$next = $tokenizer->next();
}
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, '['.$next);
return $parent;
}
$after_next = $tokenizer->next();
$tokenizer->stepBack();
if ($after_next != ']') {
$this->createTextNode($parent, '['.$next);
return $parent;
}
/* At this point $next is either ']' or plain text. */
if (']' == $next) {
$this->createTextNode($parent, '[');
$this->createTextNode($parent, ']');
return $parent;
} else {
/* $next is plain text... likely a tag name. */
return $this->parseTag($parent, $tokenizer, $next);
}
} | [
"protected",
"function",
"parseTagOpen",
"(",
"ElementNode",
"$",
"parent",
",",
"Tokenizer",
"$",
"tokenizer",
")",
"{",
"if",
"(",
"!",
"$",
"tokenizer",
"->",
"hasNext",
"(",
")",
")",
"{",
"/* The [ that sent us to this state was just a trailing [, not the\n ... | This function handles parsing the beginnings of an open tag. When we see a [
at an appropriate time, this function is entered.
@param ElementNode $parent the current parent node
@param Tokenizer $tokenizer the tokenizer we're using
@return ElementNode the new parent node | [
"This",
"function",
"handles",
"parsing",
"the",
"beginnings",
"of",
"an",
"open",
"tag",
".",
"When",
"we",
"see",
"a",
"[",
"at",
"an",
"appropriate",
"time",
"this",
"function",
"is",
"entered",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/Parser.php#L317-L365 | train |
jbowens/jBBCode | JBBCode/Parser.php | Parser.parseTag | protected function parseTag(ElementNode $parent, Tokenizer $tokenizer, $tagContent)
{
if (!$tokenizer->hasNext() || ($next = $tokenizer->next()) != ']') {
/* This is a malformed tag. Both the previous [ and the tagContent
* is really just plain text. */
$this->createTextNode($parent, '[');
$this->createTextNode($parent, $tagContent);
return $parent;
}
/* This is a well-formed tag consisting of [something] or [/something], but
* we still need to ensure that 'something' is a valid tag name. Additionally,
* if it's a closing tag, we need to ensure that there was a previous matching
* opening tag.
*/
/* There could be attributes. */
list($tmpTagName, $options) = $this->parseOptions($tagContent);
// $tagPieces = explode('=', $tagContent);
// $tmpTagName = $tagPieces[0];
$actualTagName = $tmpTagName;
if ('' != $tmpTagName && '/' == $tmpTagName[0]) {
/* This is a closing tag name. */
$actualTagName = substr($tmpTagName, 1);
}
if ('' != $tmpTagName && '/' == $tmpTagName[0]) {
/* This is attempting to close an open tag. We must verify that there exists an
* open tag of the same type and that there is no option (options on closing
* tags don't make any sense). */
$elToClose = $parent->closestParentOfType($actualTagName);
if (null == $elToClose || count($options) > 1) {
/* Closing an unopened tag or has an option. Treat everything as plain text. */
$this->createTextNode($parent, '[');
$this->createTextNode($parent, $tagContent);
$this->createTextNode($parent, ']');
return $parent;
} else {
/* We're closing $elToClose. In order to do that, we just need to return
* $elToClose's parent, since that will change our effective parent to be
* elToClose's parent. */
return $elToClose->getParent();
}
}
/* Verify that this is a known bbcode tag name. */
if ('' == $actualTagName || !$this->codeExists($actualTagName, !empty($options))) {
/* This is an invalid tag name! Treat everything we've seen as plain text. */
$this->createTextNode($parent, '[');
$this->createTextNode($parent, $tagContent);
$this->createTextNode($parent, ']');
return $parent;
}
/* If we're here, this is a valid opening tag. Let's make a new node for it. */
$el = new ElementNode();
$code = $this->getCode($actualTagName, !empty($options));
$el->setCodeDefinition($code);
if (!empty($options)) {
/* We have an attribute we should save. */
$el->setAttribute($options);
}
$parent->addChild($el);
return $el;
} | php | protected function parseTag(ElementNode $parent, Tokenizer $tokenizer, $tagContent)
{
if (!$tokenizer->hasNext() || ($next = $tokenizer->next()) != ']') {
/* This is a malformed tag. Both the previous [ and the tagContent
* is really just plain text. */
$this->createTextNode($parent, '[');
$this->createTextNode($parent, $tagContent);
return $parent;
}
/* This is a well-formed tag consisting of [something] or [/something], but
* we still need to ensure that 'something' is a valid tag name. Additionally,
* if it's a closing tag, we need to ensure that there was a previous matching
* opening tag.
*/
/* There could be attributes. */
list($tmpTagName, $options) = $this->parseOptions($tagContent);
// $tagPieces = explode('=', $tagContent);
// $tmpTagName = $tagPieces[0];
$actualTagName = $tmpTagName;
if ('' != $tmpTagName && '/' == $tmpTagName[0]) {
/* This is a closing tag name. */
$actualTagName = substr($tmpTagName, 1);
}
if ('' != $tmpTagName && '/' == $tmpTagName[0]) {
/* This is attempting to close an open tag. We must verify that there exists an
* open tag of the same type and that there is no option (options on closing
* tags don't make any sense). */
$elToClose = $parent->closestParentOfType($actualTagName);
if (null == $elToClose || count($options) > 1) {
/* Closing an unopened tag or has an option. Treat everything as plain text. */
$this->createTextNode($parent, '[');
$this->createTextNode($parent, $tagContent);
$this->createTextNode($parent, ']');
return $parent;
} else {
/* We're closing $elToClose. In order to do that, we just need to return
* $elToClose's parent, since that will change our effective parent to be
* elToClose's parent. */
return $elToClose->getParent();
}
}
/* Verify that this is a known bbcode tag name. */
if ('' == $actualTagName || !$this->codeExists($actualTagName, !empty($options))) {
/* This is an invalid tag name! Treat everything we've seen as plain text. */
$this->createTextNode($parent, '[');
$this->createTextNode($parent, $tagContent);
$this->createTextNode($parent, ']');
return $parent;
}
/* If we're here, this is a valid opening tag. Let's make a new node for it. */
$el = new ElementNode();
$code = $this->getCode($actualTagName, !empty($options));
$el->setCodeDefinition($code);
if (!empty($options)) {
/* We have an attribute we should save. */
$el->setAttribute($options);
}
$parent->addChild($el);
return $el;
} | [
"protected",
"function",
"parseTag",
"(",
"ElementNode",
"$",
"parent",
",",
"Tokenizer",
"$",
"tokenizer",
",",
"$",
"tagContent",
")",
"{",
"if",
"(",
"!",
"$",
"tokenizer",
"->",
"hasNext",
"(",
")",
"||",
"(",
"$",
"next",
"=",
"$",
"tokenizer",
"-... | This is the next step in parsing a tag. It's possible for it to still be invalid at this
point but many of the basic invalid tag name conditions have already been handled.
@param ElementNode $parent the current parent element
@param Tokenizer $tokenizer the tokenizer we're using
@param string $tagContent the text between the [ and the ], assuming there is actually a ]
@return ElementNode the new parent element | [
"This",
"is",
"the",
"next",
"step",
"in",
"parsing",
"a",
"tag",
".",
"It",
"s",
"possible",
"for",
"it",
"to",
"still",
"be",
"invalid",
"at",
"this",
"point",
"but",
"many",
"of",
"the",
"basic",
"invalid",
"tag",
"name",
"conditions",
"have",
"alre... | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/Parser.php#L530-L595 | train |
jbowens/jBBCode | JBBCode/Parser.php | Parser.parseAsTextUntilClose | protected function parseAsTextUntilClose(ElementNode $parent, Tokenizer $tokenizer)
{
/* $parent's code definition doesn't allow its contents to be parsed. Here we use
* a sliding window of three tokens until we find [ /tagname ], signifying the
* end of the parent. */
if (!$tokenizer->hasNext()) {
return $parent;
}
$prevPrev = $tokenizer->next();
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, $prevPrev);
return $parent;
}
$prev = $tokenizer->next();
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, $prevPrev);
$this->createTextNode($parent, $prev);
return $parent;
}
$curr = $tokenizer->next();
while ('[' != $prevPrev || '/'.$parent->getTagName() != strtolower($prev) ||
']' != $curr) {
$this->createTextNode($parent, $prevPrev);
$prevPrev = $prev;
$prev = $curr;
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, $prevPrev);
$this->createTextNode($parent, $prev);
return $parent;
}
$curr = $tokenizer->next();
}
} | php | protected function parseAsTextUntilClose(ElementNode $parent, Tokenizer $tokenizer)
{
/* $parent's code definition doesn't allow its contents to be parsed. Here we use
* a sliding window of three tokens until we find [ /tagname ], signifying the
* end of the parent. */
if (!$tokenizer->hasNext()) {
return $parent;
}
$prevPrev = $tokenizer->next();
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, $prevPrev);
return $parent;
}
$prev = $tokenizer->next();
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, $prevPrev);
$this->createTextNode($parent, $prev);
return $parent;
}
$curr = $tokenizer->next();
while ('[' != $prevPrev || '/'.$parent->getTagName() != strtolower($prev) ||
']' != $curr) {
$this->createTextNode($parent, $prevPrev);
$prevPrev = $prev;
$prev = $curr;
if (!$tokenizer->hasNext()) {
$this->createTextNode($parent, $prevPrev);
$this->createTextNode($parent, $prev);
return $parent;
}
$curr = $tokenizer->next();
}
} | [
"protected",
"function",
"parseAsTextUntilClose",
"(",
"ElementNode",
"$",
"parent",
",",
"Tokenizer",
"$",
"tokenizer",
")",
"{",
"/* $parent's code definition doesn't allow its contents to be parsed. Here we use\n * a sliding window of three tokens until we find [ /tagname ], sig... | Handles parsing elements whose CodeDefinitions disable parsing of element
contents. This function uses a rolling window of 3 tokens until it finds the
appropriate closing tag or reaches the end of the token stream.
@param ElementNode $parent the current parent element
@param Tokenizer $tokenizer the tokenizer we're using
@return ElementNode the new parent element | [
"Handles",
"parsing",
"elements",
"whose",
"CodeDefinitions",
"disable",
"parsing",
"of",
"element",
"contents",
".",
"This",
"function",
"uses",
"a",
"rolling",
"window",
"of",
"3",
"tokens",
"until",
"it",
"finds",
"the",
"appropriate",
"closing",
"tag",
"or",... | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/Parser.php#L607-L639 | train |
jbowens/jBBCode | JBBCode/CodeDefinitionBuilder.php | CodeDefinitionBuilder.setNestLimit | public function setNestLimit($limit)
{
if (!is_int($limit) || ($limit <= 0 && -1 != $limit)) {
throw new \InvalidArgumentException("A nest limit must be a positive integer " .
"or -1.");
}
$this->nestLimit = $limit;
return $this;
} | php | public function setNestLimit($limit)
{
if (!is_int($limit) || ($limit <= 0 && -1 != $limit)) {
throw new \InvalidArgumentException("A nest limit must be a positive integer " .
"or -1.");
}
$this->nestLimit = $limit;
return $this;
} | [
"public",
"function",
"setNestLimit",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"limit",
")",
"||",
"(",
"$",
"limit",
"<=",
"0",
"&&",
"-",
"1",
"!=",
"$",
"limit",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentExcept... | Sets the nest limit for this code definition.
@param integer $limit a positive integer, or -1 if there is no limit.
@throws \InvalidArgumentException if the nest limit is invalid
@return self | [
"Sets",
"the",
"nest",
"limit",
"for",
"this",
"code",
"definition",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/CodeDefinitionBuilder.php#L101-L109 | train |
jbowens/jBBCode | JBBCode/CodeDefinitionBuilder.php | CodeDefinitionBuilder.setOptionValidator | public function setOptionValidator(\JBBCode\InputValidator $validator, $option=null)
{
if (empty($option)) {
$option = $this->tagName;
}
$this->optionValidator[$option] = $validator;
return $this;
} | php | public function setOptionValidator(\JBBCode\InputValidator $validator, $option=null)
{
if (empty($option)) {
$option = $this->tagName;
}
$this->optionValidator[$option] = $validator;
return $this;
} | [
"public",
"function",
"setOptionValidator",
"(",
"\\",
"JBBCode",
"\\",
"InputValidator",
"$",
"validator",
",",
"$",
"option",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"option",
")",
")",
"{",
"$",
"option",
"=",
"$",
"this",
"->",
"tagNam... | Sets the InputValidator that option arguments should be validated with.
@param InputValidator $validator the InputValidator instance to use
@return self | [
"Sets",
"the",
"InputValidator",
"that",
"option",
"arguments",
"should",
"be",
"validated",
"with",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/CodeDefinitionBuilder.php#L117-L124 | train |
jbowens/jBBCode | JBBCode/CodeDefinitionBuilder.php | CodeDefinitionBuilder.build | public function build()
{
$definition = CodeDefinition::construct($this->tagName,
$this->replacementText,
$this->useOption,
$this->parseContent,
$this->nestLimit,
$this->optionValidator,
$this->bodyValidator);
return $definition;
} | php | public function build()
{
$definition = CodeDefinition::construct($this->tagName,
$this->replacementText,
$this->useOption,
$this->parseContent,
$this->nestLimit,
$this->optionValidator,
$this->bodyValidator);
return $definition;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"definition",
"=",
"CodeDefinition",
"::",
"construct",
"(",
"$",
"this",
"->",
"tagName",
",",
"$",
"this",
"->",
"replacementText",
",",
"$",
"this",
"->",
"useOption",
",",
"$",
"this",
"->",
"parseCo... | Builds a CodeDefinition with the current state of the builder.
@return CodeDefinition a new CodeDefinition instance | [
"Builds",
"a",
"CodeDefinition",
"with",
"the",
"current",
"state",
"of",
"the",
"builder",
"."
] | 740092873a687e61b980d2a094f6323b0d3b273c | https://github.com/jbowens/jBBCode/blob/740092873a687e61b980d2a094f6323b0d3b273c/JBBCode/CodeDefinitionBuilder.php#L163-L173 | train |
cerbero90/query-filters | src/QueryFilters.php | QueryFilters.applyToQuery | public function applyToQuery(Builder $query)
{
$this->query = $query;
foreach ($this->request->all() as $filter => $value) {
$method = Str::camel($filter);
if ($this->filterCanBeApplied($method, $value)) {
call_user_func([$this, $method], $value);
}
}
return $query;
} | php | public function applyToQuery(Builder $query)
{
$this->query = $query;
foreach ($this->request->all() as $filter => $value) {
$method = Str::camel($filter);
if ($this->filterCanBeApplied($method, $value)) {
call_user_func([$this, $method], $value);
}
}
return $query;
} | [
"public",
"function",
"applyToQuery",
"(",
"Builder",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"query",
"=",
"$",
"query",
";",
"foreach",
"(",
"$",
"this",
"->",
"request",
"->",
"all",
"(",
")",
"as",
"$",
"filter",
"=>",
"$",
"value",
")",
"{"... | Apply all the filters to the given query.
@param Illuminate\Database\Eloquent\Builder $query
@return Illuminate\Database\Eloquent\Builder | [
"Apply",
"all",
"the",
"filters",
"to",
"the",
"given",
"query",
"."
] | ce37f01330467b90ae1939802703d4b8a72e811f | https://github.com/cerbero90/query-filters/blob/ce37f01330467b90ae1939802703d4b8a72e811f/src/QueryFilters.php#L66-L79 | train |
cerbero90/query-filters | src/QueryFilters.php | QueryFilters.filterCanBeApplied | protected function filterCanBeApplied($filter, $value)
{
$filterExists = method_exists($this, $filter);
$hasValue = $value !== '' && $value !== null;
$valueIsLegit = $hasValue || in_array($filter, $this->implicitFilters);
return $filterExists && $valueIsLegit;
} | php | protected function filterCanBeApplied($filter, $value)
{
$filterExists = method_exists($this, $filter);
$hasValue = $value !== '' && $value !== null;
$valueIsLegit = $hasValue || in_array($filter, $this->implicitFilters);
return $filterExists && $valueIsLegit;
} | [
"protected",
"function",
"filterCanBeApplied",
"(",
"$",
"filter",
",",
"$",
"value",
")",
"{",
"$",
"filterExists",
"=",
"method_exists",
"(",
"$",
"this",
",",
"$",
"filter",
")",
";",
"$",
"hasValue",
"=",
"$",
"value",
"!==",
"''",
"&&",
"$",
"valu... | Determine whether the given filter can be applied with the provided value.
@param string $filter
@param mixed $value
@return boolean | [
"Determine",
"whether",
"the",
"given",
"filter",
"can",
"be",
"applied",
"with",
"the",
"provided",
"value",
"."
] | ce37f01330467b90ae1939802703d4b8a72e811f | https://github.com/cerbero90/query-filters/blob/ce37f01330467b90ae1939802703d4b8a72e811f/src/QueryFilters.php#L88-L95 | train |
eloquent/phony | src/Reflection/FunctionSignatureInspector.php | FunctionSignatureInspector.instance | public static function instance(): self
{
if (!self::$instance) {
self::$instance = new self(FeatureDetector::instance());
}
return self::$instance;
} | php | public static function instance(): self
{
if (!self::$instance) {
self::$instance = new self(FeatureDetector::instance());
}
return self::$instance;
} | [
"public",
"static",
"function",
"instance",
"(",
")",
":",
"self",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"instance",
")",
"{",
"self",
"::",
"$",
"instance",
"=",
"new",
"self",
"(",
"FeatureDetector",
"::",
"instance",
"(",
")",
")",
";",
"}",
"... | Get the static instance of this inspector.
@return PhpFunctionSignatureInspector The static inspector. | [
"Get",
"the",
"static",
"instance",
"of",
"this",
"inspector",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Reflection/FunctionSignatureInspector.php#L19-L26 | train |
eloquent/phony | src/Reflection/FunctionSignatureInspector.php | FunctionSignatureInspector.signature | public function signature(ReflectionFunctionAbstract $function): array
{
$isMatch = preg_match_all(
static::PARAMETER_PATTERN,
(string) $function,
$matches,
PREG_SET_ORDER
);
if (!$isMatch) {
return [];
}
$parameters = $function->getParameters();
$signature = [];
$index = -1;
foreach ($matches as $match) {
$parameter = $parameters[++$index];
$typehint = $match[2];
if ('self ' === $typehint) {
$typehint = '\\' . $parameter->getDeclaringClass()->getName()
. ' ';
} elseif (
'' !== $typehint &&
'array ' !== $typehint &&
'bool ' !== $typehint &&
'callable ' !== $typehint &&
'int ' !== $typehint &&
'iterable ' !== $typehint &&
(
!$this->isObjectTypeHintSupported ||
'object ' !== $typehint
)
) {
if (
'integer ' === $typehint &&
$parameter->getType()->isBuiltin()
) {
$typehint = 'int ';
} elseif (
'boolean ' === $typehint &&
$parameter->getType()->isBuiltin()
) {
$typehint = 'bool ';
} elseif ('float ' !== $typehint && 'string ' !== $typehint) {
$typehint = '\\' . $typehint;
}
}
$byReference = $match[4];
if ($parameter->isVariadic()) {
$variadic = '...';
$optional = false;
} else {
$variadic = '';
$optional = 'optional' === $match[1];
}
if (isset($match[6])) {
if (' = NULL' === $match[6]) {
$defaultValue = ' = null';
} else {
$defaultValue = ' = ' .
var_export($parameter->getDefaultValue(), true);
}
} elseif ($optional || $match[3]) {
$defaultValue = ' = null';
} else {
$defaultValue = '';
}
$signature[$match[5]] =
[$typehint, $byReference, $variadic, $defaultValue];
}
return $signature;
} | php | public function signature(ReflectionFunctionAbstract $function): array
{
$isMatch = preg_match_all(
static::PARAMETER_PATTERN,
(string) $function,
$matches,
PREG_SET_ORDER
);
if (!$isMatch) {
return [];
}
$parameters = $function->getParameters();
$signature = [];
$index = -1;
foreach ($matches as $match) {
$parameter = $parameters[++$index];
$typehint = $match[2];
if ('self ' === $typehint) {
$typehint = '\\' . $parameter->getDeclaringClass()->getName()
. ' ';
} elseif (
'' !== $typehint &&
'array ' !== $typehint &&
'bool ' !== $typehint &&
'callable ' !== $typehint &&
'int ' !== $typehint &&
'iterable ' !== $typehint &&
(
!$this->isObjectTypeHintSupported ||
'object ' !== $typehint
)
) {
if (
'integer ' === $typehint &&
$parameter->getType()->isBuiltin()
) {
$typehint = 'int ';
} elseif (
'boolean ' === $typehint &&
$parameter->getType()->isBuiltin()
) {
$typehint = 'bool ';
} elseif ('float ' !== $typehint && 'string ' !== $typehint) {
$typehint = '\\' . $typehint;
}
}
$byReference = $match[4];
if ($parameter->isVariadic()) {
$variadic = '...';
$optional = false;
} else {
$variadic = '';
$optional = 'optional' === $match[1];
}
if (isset($match[6])) {
if (' = NULL' === $match[6]) {
$defaultValue = ' = null';
} else {
$defaultValue = ' = ' .
var_export($parameter->getDefaultValue(), true);
}
} elseif ($optional || $match[3]) {
$defaultValue = ' = null';
} else {
$defaultValue = '';
}
$signature[$match[5]] =
[$typehint, $byReference, $variadic, $defaultValue];
}
return $signature;
} | [
"public",
"function",
"signature",
"(",
"ReflectionFunctionAbstract",
"$",
"function",
")",
":",
"array",
"{",
"$",
"isMatch",
"=",
"preg_match_all",
"(",
"static",
"::",
"PARAMETER_PATTERN",
",",
"(",
"string",
")",
"$",
"function",
",",
"$",
"matches",
",",
... | Get the function signature of the supplied function.
@param ReflectionFunctionAbstract $function The function.
@return array<string,array<string>> The function signature. | [
"Get",
"the",
"function",
"signature",
"of",
"the",
"supplied",
"function",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Reflection/FunctionSignatureInspector.php#L48-L128 | train |
eloquent/phony | src/Verification/IterableVerifier.php | IterableVerifier.firstCall | public function firstCall(): Call
{
if (isset($this->calls[0])) {
return $this->callVerifierFactory->fromCall($this->calls[0]);
}
throw new UndefinedCallException(0);
} | php | public function firstCall(): Call
{
if (isset($this->calls[0])) {
return $this->callVerifierFactory->fromCall($this->calls[0]);
}
throw new UndefinedCallException(0);
} | [
"public",
"function",
"firstCall",
"(",
")",
":",
"Call",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"calls",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"callVerifierFactory",
"->",
"fromCall",
"(",
"$",
"this",
"->",
"calls",
... | Get the first call.
@return Call The call.
@throws UndefinedCallException If there are no calls. | [
"Get",
"the",
"first",
"call",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/IterableVerifier.php#L186-L193 | train |
eloquent/phony | src/Verification/IterableVerifier.php | IterableVerifier.checkUsed | public function checkUsed(): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
foreach ($this->calls as $call) {
foreach ($call->iterableEvents() as $event) {
if ($event instanceof UsedEvent) {
$matchingEvents[] = $event;
++$matchCount;
}
}
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkUsed(): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
foreach ($this->calls as $call) {
foreach ($call->iterableEvents() as $event) {
if ($event instanceof UsedEvent) {
$matchingEvents[] = $event;
++$matchCount;
}
}
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkUsed",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"subject",
"instanceof",
"Call",
")",
"{",
"$",
"cardinality",
"->... | Checks if iteration of the subject commenced.
@return EventCollection|null The result. | [
"Checks",
"if",
"iteration",
"of",
"the",
"subject",
"commenced",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/IterableVerifier.php#L246-L271 | train |
eloquent/phony | src/Verification/IterableVerifier.php | IterableVerifier.used | public function used(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkUsed()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderIterableUsed(
$this->subject,
$cardinality,
$this->isGenerator
)
);
} | php | public function used(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkUsed()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderIterableUsed(
$this->subject,
$cardinality,
$this->isGenerator
)
);
} | [
"public",
"function",
"used",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"checkUsed",
"(",
")",
")",
"{",
"return",
"$",
"result",
";",... | Throws an exception unless iteration of the subject commenced.
@return EventCollection|null The result, or null if the assertion recorder does not throw exceptions.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"iteration",
"of",
"the",
"subject",
"commenced",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/IterableVerifier.php#L279-L294 | train |
eloquent/phony | src/Verification/IterableVerifier.php | IterableVerifier.checkProduced | public function checkProduced(
$keyOrValue = null,
$value = null
): ?EventCollection {
$cardinality = $this->resetCardinality();
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$checkKey = false;
$checkValue = false;
} elseif (1 === $argumentCount) {
$checkKey = false;
$checkValue = true;
$value = $this->matcherFactory->adapt($keyOrValue);
} else {
$checkKey = true;
$checkValue = true;
$key = $this->matcherFactory->adapt($keyOrValue);
$value = $this->matcherFactory->adapt($value);
}
$isCall = $this->subject instanceof Call;
$matchingEvents = [];
$matchCount = 0;
$eventCount = 0;
foreach ($this->calls as $call) {
$isMatchingCall = false;
foreach ($call->iterableEvents() as $event) {
if ($event instanceof ProducedEvent) {
++$eventCount;
if ($checkKey && !$key->matches($event->key())) {
continue;
}
if ($checkValue && !$value->matches($event->value())) {
continue;
}
$matchingEvents[] = $event;
$isMatchingCall = true;
if ($isCall) {
++$matchCount;
}
}
}
if (!$isCall && $isMatchingCall) {
++$matchCount;
}
}
if ($isCall) {
$totalCount = $eventCount;
} else {
$totalCount = $this->callCount;
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkProduced(
$keyOrValue = null,
$value = null
): ?EventCollection {
$cardinality = $this->resetCardinality();
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$checkKey = false;
$checkValue = false;
} elseif (1 === $argumentCount) {
$checkKey = false;
$checkValue = true;
$value = $this->matcherFactory->adapt($keyOrValue);
} else {
$checkKey = true;
$checkValue = true;
$key = $this->matcherFactory->adapt($keyOrValue);
$value = $this->matcherFactory->adapt($value);
}
$isCall = $this->subject instanceof Call;
$matchingEvents = [];
$matchCount = 0;
$eventCount = 0;
foreach ($this->calls as $call) {
$isMatchingCall = false;
foreach ($call->iterableEvents() as $event) {
if ($event instanceof ProducedEvent) {
++$eventCount;
if ($checkKey && !$key->matches($event->key())) {
continue;
}
if ($checkValue && !$value->matches($event->value())) {
continue;
}
$matchingEvents[] = $event;
$isMatchingCall = true;
if ($isCall) {
++$matchCount;
}
}
}
if (!$isCall && $isMatchingCall) {
++$matchCount;
}
}
if ($isCall) {
$totalCount = $eventCount;
} else {
$totalCount = $this->callCount;
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkProduced",
"(",
"$",
"keyOrValue",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"$",
"argumentCount",
"=",
"... | Checks if the subject produced the supplied values.
When called with no arguments, this method simply checks that the subject
produced any value.
With a single argument, it checks that a value matching the argument was
produced.
With two arguments, it checks that a key and value matching the
respective arguments were produced together.
@param mixed $keyOrValue The key or value.
@param mixed $value The value.
@return EventCollection|null The result. | [
"Checks",
"if",
"the",
"subject",
"produced",
"the",
"supplied",
"values",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/IterableVerifier.php#L313-L379 | train |
eloquent/phony | src/Verification/IterableVerifier.php | IterableVerifier.produced | public function produced(
$keyOrValue = null,
$value = null
): ?EventCollection {
$cardinality = $this->cardinality;
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$key = null;
$arguments = [];
} elseif (1 === $argumentCount) {
$key = null;
$value = $this->matcherFactory->adapt($keyOrValue);
$arguments = [$value];
} else {
$key = $this->matcherFactory->adapt($keyOrValue);
$value = $this->matcherFactory->adapt($value);
$arguments = [$key, $value];
}
if ($result = $this->checkProduced(...$arguments)) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderIterableProduced(
$this->subject,
$cardinality,
$this->isGenerator,
$key,
$value
)
);
} | php | public function produced(
$keyOrValue = null,
$value = null
): ?EventCollection {
$cardinality = $this->cardinality;
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$key = null;
$arguments = [];
} elseif (1 === $argumentCount) {
$key = null;
$value = $this->matcherFactory->adapt($keyOrValue);
$arguments = [$value];
} else {
$key = $this->matcherFactory->adapt($keyOrValue);
$value = $this->matcherFactory->adapt($value);
$arguments = [$key, $value];
}
if ($result = $this->checkProduced(...$arguments)) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderIterableProduced(
$this->subject,
$cardinality,
$this->isGenerator,
$key,
$value
)
);
} | [
"public",
"function",
"produced",
"(",
"$",
"keyOrValue",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"$",
"argumentCount",
"=",
"func_num_args",
"(",
... | Throws an exception unless the subject produced the supplied values.
When called with no arguments, this method simply checks that the subject
produced any value.
With a single argument, it checks that a value matching the argument was
produced.
With two arguments, it checks that a key and value matching the
respective arguments were produced together.
@param mixed $keyOrValue The key or value.
@param mixed $value The value.
@return EventCollection|null The result, or null if the assertion recorder does not throw exceptions.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"the",
"subject",
"produced",
"the",
"supplied",
"values",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/IterableVerifier.php#L399-L432 | train |
eloquent/phony | src/Verification/IterableVerifier.php | IterableVerifier.checkConsumed | public function checkConsumed(): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
foreach ($this->calls as $call) {
if (!$endEvent = $call->endEvent()) {
continue;
}
if (!$call->isIterable()) {
continue;
}
++$matchCount;
$matchingEvents[] = $endEvent;
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkConsumed(): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
foreach ($this->calls as $call) {
if (!$endEvent = $call->endEvent()) {
continue;
}
if (!$call->isIterable()) {
continue;
}
++$matchCount;
$matchingEvents[] = $endEvent;
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkConsumed",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"subject",
"instanceof",
"Call",
")",
"{",
"$",
"cardinality",
... | Checks if the subject was completely consumed.
@return EventCollection|null The result. | [
"Checks",
"if",
"the",
"subject",
"was",
"completely",
"consumed",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/IterableVerifier.php#L439-L467 | train |
eloquent/phony | src/Verification/IterableVerifier.php | IterableVerifier.consumed | public function consumed(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkConsumed()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderIterableConsumed(
$this->subject,
$cardinality,
$this->isGenerator
)
);
} | php | public function consumed(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkConsumed()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderIterableConsumed(
$this->subject,
$cardinality,
$this->isGenerator
)
);
} | [
"public",
"function",
"consumed",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"checkConsumed",
"(",
")",
")",
"{",
"return",
"$",
"result"... | Throws an exception unless the subject was completely consumed.
@return EventCollection|null The result, or null if the assertion recorder does not throw exceptions.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"the",
"subject",
"was",
"completely",
"consumed",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/IterableVerifier.php#L475-L490 | train |
eloquent/phony | src/Hook/FunctionHookGenerator.php | FunctionHookGenerator.generateHook | public function generateHook(
string $name,
string $namespace,
array $signature
): string {
$source = "namespace $namespace;\n\nfunction $name";
$parameterCount = count($signature);
if ($parameterCount > 0) {
$index = -1;
$isFirst = true;
foreach ($signature as $parameter) {
if ($isFirst) {
$isFirst = false;
$source .= "(\n ";
} else {
$source .= ",\n ";
}
$source .= $parameter[0] .
$parameter[1] .
$parameter[2] .
'$a' .
++$index .
$parameter[3];
}
$source .= "\n) {\n";
} else {
$source .= "()\n{\n";
}
$variadicIndex = -1;
$variadicReference = '';
if ($parameterCount > 0) {
$argumentPacking = "\n";
$index = -1;
foreach ($signature as $parameter) {
if ($parameter[2]) {
--$parameterCount;
$variadicIndex = ++$index;
$variadicReference = $parameter[1];
} else {
$argumentPacking .=
"\n if (\$argumentCount > " .
++$index .
") {\n \$arguments[] = " .
$parameter[1] .
'$a' .
$index .
";\n }";
}
}
} else {
$argumentPacking = '';
}
$source .=
" \$argumentCount = \\func_num_args();\n" .
' $arguments = [];' .
$argumentPacking .
"\n\n for (\$i = " .
$parameterCount .
"; \$i < \$argumentCount; ++\$i) {\n";
if ($variadicIndex > -1) {
$source .=
" \$arguments[] = $variadicReference\$a" .
$variadicIndex . "[\$i - $variadicIndex];\n" .
' }';
} else {
$source .=
" \$arguments[] = \\func_get_arg(\$i);\n" .
' }';
}
$ret = 'ret' . 'urn';
$renderedName = var_export(strtolower($namespace . '\\' . $name), true);
$source .=
"\n\n \$name = $renderedName;\n\n if (" .
"\n !isset(\n " .
'\Eloquent\Phony\Hook\FunctionHookManager::$hooks[$name]' .
"['callback']\n )\n ) {\n " .
"$ret \\$name(...\$arguments);" .
"\n }\n\n \$callback =\n " .
'\Eloquent\Phony\Hook\FunctionHookManager::$hooks' .
"[\$name]['callback'];\n\n" .
' if ($callback instanceof ' .
"\Eloquent\Phony\Invocation\Invocable) {\n" .
" $ret \$callback->invokeWith(\$arguments);\n" .
" }\n\n " .
"$ret \$callback(...\$arguments);\n}\n";
// @codeCoverageIgnoreStart
if ("\n" !== PHP_EOL) {
$source = str_replace("\n", PHP_EOL, $source);
}
// @codeCoverageIgnoreEnd
return $source;
} | php | public function generateHook(
string $name,
string $namespace,
array $signature
): string {
$source = "namespace $namespace;\n\nfunction $name";
$parameterCount = count($signature);
if ($parameterCount > 0) {
$index = -1;
$isFirst = true;
foreach ($signature as $parameter) {
if ($isFirst) {
$isFirst = false;
$source .= "(\n ";
} else {
$source .= ",\n ";
}
$source .= $parameter[0] .
$parameter[1] .
$parameter[2] .
'$a' .
++$index .
$parameter[3];
}
$source .= "\n) {\n";
} else {
$source .= "()\n{\n";
}
$variadicIndex = -1;
$variadicReference = '';
if ($parameterCount > 0) {
$argumentPacking = "\n";
$index = -1;
foreach ($signature as $parameter) {
if ($parameter[2]) {
--$parameterCount;
$variadicIndex = ++$index;
$variadicReference = $parameter[1];
} else {
$argumentPacking .=
"\n if (\$argumentCount > " .
++$index .
") {\n \$arguments[] = " .
$parameter[1] .
'$a' .
$index .
";\n }";
}
}
} else {
$argumentPacking = '';
}
$source .=
" \$argumentCount = \\func_num_args();\n" .
' $arguments = [];' .
$argumentPacking .
"\n\n for (\$i = " .
$parameterCount .
"; \$i < \$argumentCount; ++\$i) {\n";
if ($variadicIndex > -1) {
$source .=
" \$arguments[] = $variadicReference\$a" .
$variadicIndex . "[\$i - $variadicIndex];\n" .
' }';
} else {
$source .=
" \$arguments[] = \\func_get_arg(\$i);\n" .
' }';
}
$ret = 'ret' . 'urn';
$renderedName = var_export(strtolower($namespace . '\\' . $name), true);
$source .=
"\n\n \$name = $renderedName;\n\n if (" .
"\n !isset(\n " .
'\Eloquent\Phony\Hook\FunctionHookManager::$hooks[$name]' .
"['callback']\n )\n ) {\n " .
"$ret \\$name(...\$arguments);" .
"\n }\n\n \$callback =\n " .
'\Eloquent\Phony\Hook\FunctionHookManager::$hooks' .
"[\$name]['callback'];\n\n" .
' if ($callback instanceof ' .
"\Eloquent\Phony\Invocation\Invocable) {\n" .
" $ret \$callback->invokeWith(\$arguments);\n" .
" }\n\n " .
"$ret \$callback(...\$arguments);\n}\n";
// @codeCoverageIgnoreStart
if ("\n" !== PHP_EOL) {
$source = str_replace("\n", PHP_EOL, $source);
}
// @codeCoverageIgnoreEnd
return $source;
} | [
"public",
"function",
"generateHook",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"namespace",
",",
"array",
"$",
"signature",
")",
":",
"string",
"{",
"$",
"source",
"=",
"\"namespace $namespace;\\n\\nfunction $name\"",
";",
"$",
"parameterCount",
"=",
"cou... | Generate the source code for a function hook.
@param string $name The function name.
@param string $namespace The namespace.
@param array<string,array<string>> $signature The function signature.
@return string The source code. | [
"Generate",
"the",
"source",
"code",
"for",
"a",
"function",
"hook",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Hook/FunctionHookGenerator.php#L35-L140 | train |
eloquent/phony | src/Verification/CardinalityVerifierTrait.php | CardinalityVerifierTrait.times | public function times(int $times): CardinalityVerifier
{
$this->cardinality = new Cardinality($times, $times);
return $this;
} | php | public function times(int $times): CardinalityVerifier
{
$this->cardinality = new Cardinality($times, $times);
return $this;
} | [
"public",
"function",
"times",
"(",
"int",
"$",
"times",
")",
":",
"CardinalityVerifier",
"{",
"$",
"this",
"->",
"cardinality",
"=",
"new",
"Cardinality",
"(",
"$",
"times",
",",
"$",
"times",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Requires that the next verification matches an exact number of times.
@param int $times The match count.
@return $this This verifier. | [
"Requires",
"that",
"the",
"next",
"verification",
"matches",
"an",
"exact",
"number",
"of",
"times",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/CardinalityVerifierTrait.php#L69-L74 | train |
eloquent/phony | src/Call/Arguments.php | Arguments.copy | public function copy(): self
{
$arguments = [];
foreach ($this->arguments as $argument) {
$arguments[] = $argument;
}
return new self($arguments);
} | php | public function copy(): self
{
$arguments = [];
foreach ($this->arguments as $argument) {
$arguments[] = $argument;
}
return new self($arguments);
} | [
"public",
"function",
"copy",
"(",
")",
":",
"self",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"arguments",
"as",
"$",
"argument",
")",
"{",
"$",
"arguments",
"[",
"]",
"=",
"$",
"argument",
";",
"}",
"return",
... | Copy these arguments, breaking any references.
@return Arguments The copied arguments. | [
"Copy",
"these",
"arguments",
"breaking",
"any",
"references",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Arguments.php#L46-L55 | train |
eloquent/phony | src/Call/Arguments.php | Arguments.set | public function set($indexOrValue = null, $value = null): self
{
if (func_num_args() > 1) {
$index = $indexOrValue;
} else {
$index = 0;
$normalized = 0;
$value = $indexOrValue;
}
if (!$this->normalizeIndex($this->count, $index, $normalized)) {
throw new UndefinedArgumentException($index);
}
$this->arguments[$normalized] = $value;
return $this;
} | php | public function set($indexOrValue = null, $value = null): self
{
if (func_num_args() > 1) {
$index = $indexOrValue;
} else {
$index = 0;
$normalized = 0;
$value = $indexOrValue;
}
if (!$this->normalizeIndex($this->count, $index, $normalized)) {
throw new UndefinedArgumentException($index);
}
$this->arguments[$normalized] = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"indexOrValue",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"$",
"index",
"=",
"$",
"indexOrValue",
";",
"}",
"else",
"{",
"$... | Set an argument by index.
If called with no arguments, sets the first argument to null.
If called with one argument, sets the first argument to `$indexOrValue`.
If called with two arguments, sets the argument at `$indexOrValue` to
`$value`.
@param mixed $indexOrValue The index, or value if no index is specified.
@param mixed $value The value.
@return $this This arguments object.
@throws UndefinedArgumentException If the requested argument is undefined. | [
"Set",
"an",
"argument",
"by",
"index",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/Arguments.php#L85-L102 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.