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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
danielgp/common-lib
source/DomComponentsByDanielGP.php
DomComponentsByDanielGP.setTableHeader
private function setTableHeader($aElements, $bHeadersBreaked) { $aTableHeader = $aElements; if ($bHeadersBreaked) { $aTableHeader = $this->setArrayToArrayKbr($aElements); } $sReturn = []; foreach (array_keys($aTableHeader) as $value) { $sReturn[] = $this->setStringIntoTag($value, 'th'); } return implode('', $sReturn); }
php
private function setTableHeader($aElements, $bHeadersBreaked) { $aTableHeader = $aElements; if ($bHeadersBreaked) { $aTableHeader = $this->setArrayToArrayKbr($aElements); } $sReturn = []; foreach (array_keys($aTableHeader) as $value) { $sReturn[] = $this->setStringIntoTag($value, 'th'); } return implode('', $sReturn); }
[ "private", "function", "setTableHeader", "(", "$", "aElements", ",", "$", "bHeadersBreaked", ")", "{", "$", "aTableHeader", "=", "$", "aElements", ";", "if", "(", "$", "bHeadersBreaked", ")", "{", "$", "aTableHeader", "=", "$", "this", "->", "setArrayToArrayKbr", "(", "$", "aElements", ")", ";", "}", "$", "sReturn", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "aTableHeader", ")", "as", "$", "value", ")", "{", "$", "sReturn", "[", "]", "=", "$", "this", "->", "setStringIntoTag", "(", "$", "value", ",", "'th'", ")", ";", "}", "return", "implode", "(", "''", ",", "$", "sReturn", ")", ";", "}" ]
Generates a table header @param array $aElements @param boolean $bHeadersBreaked @return string
[ "Generates", "a", "table", "header" ]
627b99b4408414c7cd21a6c8016f6468dc9216b2
https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomComponentsByDanielGP.php#L527-L538
train
RockPhp/Datet
src/Rock/Datet/DateUtil.php
Rock_Datet_DateUtil.setNovaData
public function setNovaData(Rock_Datet_DateObj $dateObj) { $this->format = $dateObj->getFormat(); $this->ts = $dateObj->getTimeStamp(); }
php
public function setNovaData(Rock_Datet_DateObj $dateObj) { $this->format = $dateObj->getFormat(); $this->ts = $dateObj->getTimeStamp(); }
[ "public", "function", "setNovaData", "(", "Rock_Datet_DateObj", "$", "dateObj", ")", "{", "$", "this", "->", "format", "=", "$", "dateObj", "->", "getFormat", "(", ")", ";", "$", "this", "->", "ts", "=", "$", "dateObj", "->", "getTimeStamp", "(", ")", ";", "}" ]
Substituir data de referencia por uma nova. @param Rock_Datet_DateObj $dateObj
[ "Substituir", "data", "de", "referencia", "por", "uma", "nova", "." ]
10eb9320efbe0a5c5acb2ffb262b514a36476bf0
https://github.com/RockPhp/Datet/blob/10eb9320efbe0a5c5acb2ffb262b514a36476bf0/src/Rock/Datet/DateUtil.php#L42-L46
train
RockPhp/Datet
src/Rock/Datet/DateUtil.php
Rock_Datet_DateUtil.somaDia
private function somaDia($qtdDias) { $somaDia = $qtdDias; if ($qtdDias > 0) { $somaDia = "+$qtdDias"; } $ts = strtotime("$somaDia day", $this->ts); return $ts; }
php
private function somaDia($qtdDias) { $somaDia = $qtdDias; if ($qtdDias > 0) { $somaDia = "+$qtdDias"; } $ts = strtotime("$somaDia day", $this->ts); return $ts; }
[ "private", "function", "somaDia", "(", "$", "qtdDias", ")", "{", "$", "somaDia", "=", "$", "qtdDias", ";", "if", "(", "$", "qtdDias", ">", "0", ")", "{", "$", "somaDia", "=", "\"+$qtdDias\"", ";", "}", "$", "ts", "=", "strtotime", "(", "\"$somaDia day\"", ",", "$", "this", "->", "ts", ")", ";", "return", "$", "ts", ";", "}" ]
Soma dias. @param integer $qtdDias @return integer Timestamp
[ "Soma", "dias", "." ]
10eb9320efbe0a5c5acb2ffb262b514a36476bf0
https://github.com/RockPhp/Datet/blob/10eb9320efbe0a5c5acb2ffb262b514a36476bf0/src/Rock/Datet/DateUtil.php#L54-L63
train
RockPhp/Datet
src/Rock/Datet/DateUtil.php
Rock_Datet_DateUtil.ultimoDiaMes
private function ultimoDiaMes() { $ts = $this->ts; $mesAtual = strftime('%m', $ts); $mesTmp = $mesAtual; $i = 0; while ($mesAtual == $mesTmp) { $ts = $this->somaDia(++ $i); $mesTmp = strftime('%m', $ts); } return $this->somaDia(-- $i); }
php
private function ultimoDiaMes() { $ts = $this->ts; $mesAtual = strftime('%m', $ts); $mesTmp = $mesAtual; $i = 0; while ($mesAtual == $mesTmp) { $ts = $this->somaDia(++ $i); $mesTmp = strftime('%m', $ts); } return $this->somaDia(-- $i); }
[ "private", "function", "ultimoDiaMes", "(", ")", "{", "$", "ts", "=", "$", "this", "->", "ts", ";", "$", "mesAtual", "=", "strftime", "(", "'%m'", ",", "$", "ts", ")", ";", "$", "mesTmp", "=", "$", "mesAtual", ";", "$", "i", "=", "0", ";", "while", "(", "$", "mesAtual", "==", "$", "mesTmp", ")", "{", "$", "ts", "=", "$", "this", "->", "somaDia", "(", "++", "$", "i", ")", ";", "$", "mesTmp", "=", "strftime", "(", "'%m'", ",", "$", "ts", ")", ";", "}", "return", "$", "this", "->", "somaDia", "(", "--", "$", "i", ")", ";", "}" ]
Calcula ultimo dia do mes. @return integer Timestamp
[ "Calcula", "ultimo", "dia", "do", "mes", "." ]
10eb9320efbe0a5c5acb2ffb262b514a36476bf0
https://github.com/RockPhp/Datet/blob/10eb9320efbe0a5c5acb2ffb262b514a36476bf0/src/Rock/Datet/DateUtil.php#L70-L82
train
WellCommerce/DistributionBundle
Manager/PackageManager.php
PackageManager.syncPackages
public function syncPackages($type) { $criteria = ['type' => $type]; $em = $this->getDoctrineHelper()->getEntityManager(); $searchResults = $this->getHelper()->getPackages($criteria); foreach ($searchResults as $result) { $package = $this->getHelper()->getPackage($result); $this->syncPackage($package); } $em->flush(); }
php
public function syncPackages($type) { $criteria = ['type' => $type]; $em = $this->getDoctrineHelper()->getEntityManager(); $searchResults = $this->getHelper()->getPackages($criteria); foreach ($searchResults as $result) { $package = $this->getHelper()->getPackage($result); $this->syncPackage($package); } $em->flush(); }
[ "public", "function", "syncPackages", "(", "$", "type", ")", "{", "$", "criteria", "=", "[", "'type'", "=>", "$", "type", "]", ";", "$", "em", "=", "$", "this", "->", "getDoctrineHelper", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "searchResults", "=", "$", "this", "->", "getHelper", "(", ")", "->", "getPackages", "(", "$", "criteria", ")", ";", "foreach", "(", "$", "searchResults", "as", "$", "result", ")", "{", "$", "package", "=", "$", "this", "->", "getHelper", "(", ")", "->", "getPackage", "(", "$", "result", ")", ";", "$", "this", "->", "syncPackage", "(", "$", "package", ")", ";", "}", "$", "em", "->", "flush", "(", ")", ";", "}" ]
Searches for all packages of particular type and adds them to Smuggler
[ "Searches", "for", "all", "packages", "of", "particular", "type", "and", "adds", "them", "to", "Smuggler" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Manager/PackageManager.php#L34-L46
train
WellCommerce/DistributionBundle
Manager/PackageManager.php
PackageManager.getConsoleCommandArguments
public function getConsoleCommandArguments(Request $request) { $port = (int)$request->attributes->get('port'); $package = $request->attributes->get('id'); $operation = $request->attributes->get('operation'); return [ 'app/console', 'wellcommerce:package:' . $operation, '--port=' . $port, '--package=' . $package ]; }
php
public function getConsoleCommandArguments(Request $request) { $port = (int)$request->attributes->get('port'); $package = $request->attributes->get('id'); $operation = $request->attributes->get('operation'); return [ 'app/console', 'wellcommerce:package:' . $operation, '--port=' . $port, '--package=' . $package ]; }
[ "public", "function", "getConsoleCommandArguments", "(", "Request", "$", "request", ")", "{", "$", "port", "=", "(", "int", ")", "$", "request", "->", "attributes", "->", "get", "(", "'port'", ")", ";", "$", "package", "=", "$", "request", "->", "attributes", "->", "get", "(", "'id'", ")", ";", "$", "operation", "=", "$", "request", "->", "attributes", "->", "get", "(", "'operation'", ")", ";", "return", "[", "'app/console'", ",", "'wellcommerce:package:'", ".", "$", "operation", ",", "'--port='", ".", "$", "port", ",", "'--package='", ".", "$", "package", "]", ";", "}" ]
Returns console command arguments @param Request $request @return array
[ "Returns", "console", "command", "arguments" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Manager/PackageManager.php#L88-L100
train
WellCommerce/DistributionBundle
Manager/PackageManager.php
PackageManager.changePackageStatus
public function changePackageStatus(Request $request) { /** * @var $package \WellCommerce\Bundle\DistributionBundle\Entity\Package */ $id = $request->attributes->get('id'); $em = $this->getDoctrineHelper()->getEntityManager(); $repository = $this->getRepository(); $package = $repository->find($id); if (null === $package) { throw new EntityNotFoundException($repository->getMetaData()->getName(), $id); } $this->setPackageVersions($package); $em->flush(); }
php
public function changePackageStatus(Request $request) { /** * @var $package \WellCommerce\Bundle\DistributionBundle\Entity\Package */ $id = $request->attributes->get('id'); $em = $this->getDoctrineHelper()->getEntityManager(); $repository = $this->getRepository(); $package = $repository->find($id); if (null === $package) { throw new EntityNotFoundException($repository->getMetaData()->getName(), $id); } $this->setPackageVersions($package); $em->flush(); }
[ "public", "function", "changePackageStatus", "(", "Request", "$", "request", ")", "{", "/**\n * @var $package \\WellCommerce\\Bundle\\DistributionBundle\\Entity\\Package\n */", "$", "id", "=", "$", "request", "->", "attributes", "->", "get", "(", "'id'", ")", ";", "$", "em", "=", "$", "this", "->", "getDoctrineHelper", "(", ")", "->", "getEntityManager", "(", ")", ";", "$", "repository", "=", "$", "this", "->", "getRepository", "(", ")", ";", "$", "package", "=", "$", "repository", "->", "find", "(", "$", "id", ")", ";", "if", "(", "null", "===", "$", "package", ")", "{", "throw", "new", "EntityNotFoundException", "(", "$", "repository", "->", "getMetaData", "(", ")", "->", "getName", "(", ")", ",", "$", "id", ")", ";", "}", "$", "this", "->", "setPackageVersions", "(", "$", "package", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "}" ]
Changes package info according to operation and data fetched from PackagistAPI @param Request $request @throws EntityNotFoundException
[ "Changes", "package", "info", "according", "to", "operation", "and", "data", "fetched", "from", "PackagistAPI" ]
82b1b4c2c5a59536aaae22506b23ccd5d141cbb0
https://github.com/WellCommerce/DistributionBundle/blob/82b1b4c2c5a59536aaae22506b23ccd5d141cbb0/Manager/PackageManager.php#L110-L127
train
dms-org/common.structure
src/DateTime/TimezonedDateTime.php
TimezonedDateTime.fromString
public static function fromString(string $dateTimeString, string $timeZoneId) : TimezonedDateTime { return new self(new \DateTimeImmutable($dateTimeString, new \DateTimeZone($timeZoneId))); }
php
public static function fromString(string $dateTimeString, string $timeZoneId) : TimezonedDateTime { return new self(new \DateTimeImmutable($dateTimeString, new \DateTimeZone($timeZoneId))); }
[ "public", "static", "function", "fromString", "(", "string", "$", "dateTimeString", ",", "string", "$", "timeZoneId", ")", ":", "TimezonedDateTime", "{", "return", "new", "self", "(", "new", "\\", "DateTimeImmutable", "(", "$", "dateTimeString", ",", "new", "\\", "DateTimeZone", "(", "$", "timeZoneId", ")", ")", ")", ";", "}" ]
Creates a DateTime object from the supplied date string @param string $dateTimeString @param string $timeZoneId @return TimezonedDateTime
[ "Creates", "a", "DateTime", "object", "from", "the", "supplied", "date", "string" ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimezonedDateTime.php#L35-L38
train
dms-org/common.structure
src/DateTime/TimezonedDateTime.php
TimezonedDateTime.convertTimezone
public function convertTimezone(string $timezoneId) : TimezonedDateTime { return new TimezonedDateTime( (new \DateTimeImmutable('now', new \DateTimeZone($timezoneId))) ->setTimestamp($this->dateTime->getTimestamp()) ); }
php
public function convertTimezone(string $timezoneId) : TimezonedDateTime { return new TimezonedDateTime( (new \DateTimeImmutable('now', new \DateTimeZone($timezoneId))) ->setTimestamp($this->dateTime->getTimestamp()) ); }
[ "public", "function", "convertTimezone", "(", "string", "$", "timezoneId", ")", ":", "TimezonedDateTime", "{", "return", "new", "TimezonedDateTime", "(", "(", "new", "\\", "DateTimeImmutable", "(", "'now'", ",", "new", "\\", "DateTimeZone", "(", "$", "timezoneId", ")", ")", ")", "->", "setTimestamp", "(", "$", "this", "->", "dateTime", "->", "getTimestamp", "(", ")", ")", ")", ";", "}" ]
Returns the current date time according to the supplied timezone @param string $timezoneId @return TimezonedDateTime
[ "Returns", "the", "current", "date", "time", "according", "to", "the", "supplied", "timezone" ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimezonedDateTime.php#L179-L185
train
rzajac/phptools
src/Date/DateCalc.php
DateCalc.secondsSinceMidnightStr
public static function secondsSinceMidnightStr($time) { $time_a = explode(':', $time); switch (count($time_a)) { case 0: case 1: return null; case 2: // Add seconds $time_a[] = 0; break; case 3: break; default: return null; } return self::secondsSinceMidnight((int) $time_a[0], (int) $time_a[1], (int) $time_a[2]); }
php
public static function secondsSinceMidnightStr($time) { $time_a = explode(':', $time); switch (count($time_a)) { case 0: case 1: return null; case 2: // Add seconds $time_a[] = 0; break; case 3: break; default: return null; } return self::secondsSinceMidnight((int) $time_a[0], (int) $time_a[1], (int) $time_a[2]); }
[ "public", "static", "function", "secondsSinceMidnightStr", "(", "$", "time", ")", "{", "$", "time_a", "=", "explode", "(", "':'", ",", "$", "time", ")", ";", "switch", "(", "count", "(", "$", "time_a", ")", ")", "{", "case", "0", ":", "case", "1", ":", "return", "null", ";", "case", "2", ":", "// Add seconds", "$", "time_a", "[", "]", "=", "0", ";", "break", ";", "case", "3", ":", "break", ";", "default", ":", "return", "null", ";", "}", "return", "self", "::", "secondsSinceMidnight", "(", "(", "int", ")", "$", "time_a", "[", "0", "]", ",", "(", "int", ")", "$", "time_a", "[", "1", "]", ",", "(", "int", ")", "$", "time_a", "[", "2", "]", ")", ";", "}" ]
Return number of seconds since midnight. @param string $time The time in format: HH:MM:SS or HH:MM @return int|null Returns null on error
[ "Return", "number", "of", "seconds", "since", "midnight", "." ]
3cbece7645942d244603c14ba897d8a676ee3088
https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Date/DateCalc.php#L74-L96
train
rzajac/phptools
src/Date/DateCalc.php
DateCalc.formatStrTime
public static function formatStrTime($time, $withSeconds = true) { // Pad left with 0 in case we get numbers like 123, 12, 122015 $time = str_pad($time.'', 6, '0', STR_PAD_LEFT); $_time = array(); $_time[] = substr($time, 0, 2); $_time[] = substr($time, 2, 2); if ($withSeconds) { $_seconds = substr($time, 4, 2); $_time[] = $_seconds; } return implode(':', $_time); }
php
public static function formatStrTime($time, $withSeconds = true) { // Pad left with 0 in case we get numbers like 123, 12, 122015 $time = str_pad($time.'', 6, '0', STR_PAD_LEFT); $_time = array(); $_time[] = substr($time, 0, 2); $_time[] = substr($time, 2, 2); if ($withSeconds) { $_seconds = substr($time, 4, 2); $_time[] = $_seconds; } return implode(':', $_time); }
[ "public", "static", "function", "formatStrTime", "(", "$", "time", ",", "$", "withSeconds", "=", "true", ")", "{", "// Pad left with 0 in case we get numbers like 123, 12, 122015", "$", "time", "=", "str_pad", "(", "$", "time", ".", "''", ",", "6", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "_time", "=", "array", "(", ")", ";", "$", "_time", "[", "]", "=", "substr", "(", "$", "time", ",", "0", ",", "2", ")", ";", "$", "_time", "[", "]", "=", "substr", "(", "$", "time", ",", "2", ",", "2", ")", ";", "if", "(", "$", "withSeconds", ")", "{", "$", "_seconds", "=", "substr", "(", "$", "time", ",", "4", ",", "2", ")", ";", "$", "_time", "[", "]", "=", "$", "_seconds", ";", "}", "return", "implode", "(", "':'", ",", "$", "_time", ")", ";", "}" ]
Takes time in hhmmss format and returns formatted string. @param int|string $time The time in hhmmss or hhmm format @param bool $withSeconds Set to true to add seconds if not provided @return string The formatted string hh:mm:ss or hh:mm
[ "Takes", "time", "in", "hhmmss", "format", "and", "returns", "formatted", "string", "." ]
3cbece7645942d244603c14ba897d8a676ee3088
https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Date/DateCalc.php#L106-L122
train
shgysk8zer0/core_api
traits/logger_interpolation.php
Logger_Interpolation.interpolate
final public function interpolate($message, array $context = array()) { return strtr( $message, array_combine( array_map( function($key) { return "{{$key}}"; }, array_keys($context) ), array_values($context) ) ); }
php
final public function interpolate($message, array $context = array()) { return strtr( $message, array_combine( array_map( function($key) { return "{{$key}}"; }, array_keys($context) ), array_values($context) ) ); }
[ "final", "public", "function", "interpolate", "(", "$", "message", ",", "array", "$", "context", "=", "array", "(", ")", ")", "{", "return", "strtr", "(", "$", "message", ",", "array_combine", "(", "array_map", "(", "function", "(", "$", "key", ")", "{", "return", "\"{{$key}}\"", ";", "}", ",", "array_keys", "(", "$", "context", ")", ")", ",", "array_values", "(", "$", "context", ")", ")", ")", ";", "}" ]
This is the default method for interpolating in PSR-3 loggers @param string $message The template given @param array $context An array of values to assign to templatte @return string
[ "This", "is", "the", "default", "method", "for", "interpolating", "in", "PSR", "-", "3", "loggers" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/logger_interpolation.php#L36-L51
train
Erebot/Module_Wordlists
src/Wordlists/Base.php
Base.isWord
public static function isWord($word) { if (!is_string($word)) { return false; } return (bool) preg_match(self::WORD_FILTER, $word); }
php
public static function isWord($word) { if (!is_string($word)) { return false; } return (bool) preg_match(self::WORD_FILTER, $word); }
[ "public", "static", "function", "isWord", "(", "$", "word", ")", "{", "if", "(", "!", "is_string", "(", "$", "word", ")", ")", "{", "return", "false", ";", "}", "return", "(", "bool", ")", "preg_match", "(", "self", "::", "WORD_FILTER", ",", "$", "word", ")", ";", "}" ]
Filters non-words out. Only texts that passed this filtering step are considered as propositions for the game. \param string $word A possible "word" to test. \retval bool TRUE if the given $word really is a word, FALSE otherwise. \note This method uses a rather broad definition of what is a word. In particular, it accepts sequences of (alphanumeric and other) characters separated by a single space (eg. "Fo'o. B4-r_").
[ "Filters", "non", "-", "words", "out", "." ]
121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7
https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists/Base.php#L98-L104
train
PhoxPHP/Console
src/ErrorHandler.php
ErrorHandler.handleError
public function handleError($errNumber, $errString, $errFile ='', $errLine = 0) { $interfaceSettings = $this->cmd->getConfigOpt('interface'); $textColor = $interfaceSettings['error']['text_color']; $textBgColor = $interfaceSettings['error']['text_background']; $this->env->sendOutput('Error: ' . $errString, $textColor, $textBgColor); exit; }
php
public function handleError($errNumber, $errString, $errFile ='', $errLine = 0) { $interfaceSettings = $this->cmd->getConfigOpt('interface'); $textColor = $interfaceSettings['error']['text_color']; $textBgColor = $interfaceSettings['error']['text_background']; $this->env->sendOutput('Error: ' . $errString, $textColor, $textBgColor); exit; }
[ "public", "function", "handleError", "(", "$", "errNumber", ",", "$", "errString", ",", "$", "errFile", "=", "''", ",", "$", "errLine", "=", "0", ")", "{", "$", "interfaceSettings", "=", "$", "this", "->", "cmd", "->", "getConfigOpt", "(", "'interface'", ")", ";", "$", "textColor", "=", "$", "interfaceSettings", "[", "'error'", "]", "[", "'text_color'", "]", ";", "$", "textBgColor", "=", "$", "interfaceSettings", "[", "'error'", "]", "[", "'text_background'", "]", ";", "$", "this", "->", "env", "->", "sendOutput", "(", "'Error: '", ".", "$", "errString", ",", "$", "textColor", ",", "$", "textBgColor", ")", ";", "exit", ";", "}" ]
Handles generated errors. @param $errNumber <Integer> @param $errString <String> @param $errFile <String> @param $errLine <Integer> @access public @return <void>
[ "Handles", "generated", "errors", "." ]
fee1238cfdb3592964bb5d5a2336e70b8ffd20e9
https://github.com/PhoxPHP/Console/blob/fee1238cfdb3592964bb5d5a2336e70b8ffd20e9/src/ErrorHandler.php#L66-L74
train
theopera/framework
src/Component/Http/Response.php
Response.redirect
public static function redirect($url, array $parameters = [], int $statusCode = Response::STATUS_MOVED_PERMANENTLY) : Response { if (!empty($parameters)) { $url = $url . '?' . http_build_query($parameters); } $headers = new Headers(); $headers->add(new Header('Location', $url)); return new Response('', $statusCode, $headers); }
php
public static function redirect($url, array $parameters = [], int $statusCode = Response::STATUS_MOVED_PERMANENTLY) : Response { if (!empty($parameters)) { $url = $url . '?' . http_build_query($parameters); } $headers = new Headers(); $headers->add(new Header('Location', $url)); return new Response('', $statusCode, $headers); }
[ "public", "static", "function", "redirect", "(", "$", "url", ",", "array", "$", "parameters", "=", "[", "]", ",", "int", "$", "statusCode", "=", "Response", "::", "STATUS_MOVED_PERMANENTLY", ")", ":", "Response", "{", "if", "(", "!", "empty", "(", "$", "parameters", ")", ")", "{", "$", "url", "=", "$", "url", ".", "'?'", ".", "http_build_query", "(", "$", "parameters", ")", ";", "}", "$", "headers", "=", "new", "Headers", "(", ")", ";", "$", "headers", "->", "add", "(", "new", "Header", "(", "'Location'", ",", "$", "url", ")", ")", ";", "return", "new", "Response", "(", "''", ",", "$", "statusCode", ",", "$", "headers", ")", ";", "}" ]
Redirect to a url @param string $url @param string[] $parameters @param int $statusCode @return Response
[ "Redirect", "to", "a", "url" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Http/Response.php#L186-L196
train
theopera/framework
src/Component/Http/Response.php
Response.createFromString
public static function createFromString(string $string) : Response { $lines = explode("\r\n", $string); list($httpVersion, $statusCode, $statusText) = explode(' ', array_shift($lines), 3); $headers = new Headers(); foreach ($lines as $index => $line) { unset($lines[$index]); if($line !== ''){ $headers->add(Header::createFromString($line)); }else{ // We are done with the header part break; } } return new Response(implode("\r\n", $lines), $statusCode, $headers); }
php
public static function createFromString(string $string) : Response { $lines = explode("\r\n", $string); list($httpVersion, $statusCode, $statusText) = explode(' ', array_shift($lines), 3); $headers = new Headers(); foreach ($lines as $index => $line) { unset($lines[$index]); if($line !== ''){ $headers->add(Header::createFromString($line)); }else{ // We are done with the header part break; } } return new Response(implode("\r\n", $lines), $statusCode, $headers); }
[ "public", "static", "function", "createFromString", "(", "string", "$", "string", ")", ":", "Response", "{", "$", "lines", "=", "explode", "(", "\"\\r\\n\"", ",", "$", "string", ")", ";", "list", "(", "$", "httpVersion", ",", "$", "statusCode", ",", "$", "statusText", ")", "=", "explode", "(", "' '", ",", "array_shift", "(", "$", "lines", ")", ",", "3", ")", ";", "$", "headers", "=", "new", "Headers", "(", ")", ";", "foreach", "(", "$", "lines", "as", "$", "index", "=>", "$", "line", ")", "{", "unset", "(", "$", "lines", "[", "$", "index", "]", ")", ";", "if", "(", "$", "line", "!==", "''", ")", "{", "$", "headers", "->", "add", "(", "Header", "::", "createFromString", "(", "$", "line", ")", ")", ";", "}", "else", "{", "// We are done with the header part", "break", ";", "}", "}", "return", "new", "Response", "(", "implode", "(", "\"\\r\\n\"", ",", "$", "lines", ")", ",", "$", "statusCode", ",", "$", "headers", ")", ";", "}" ]
Create a Response object from a string @param string $string @return Response
[ "Create", "a", "Response", "object", "from", "a", "string" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Http/Response.php#L204-L224
train
theopera/framework
src/Component/Http/Response.php
Response.getStatusLine
public function getStatusLine() : string { return sprintf('HTTP/%s %s %s', self::HTTP_VERSION, $this->statusCode, self::getStatusText($this->statusCode)); }
php
public function getStatusLine() : string { return sprintf('HTTP/%s %s %s', self::HTTP_VERSION, $this->statusCode, self::getStatusText($this->statusCode)); }
[ "public", "function", "getStatusLine", "(", ")", ":", "string", "{", "return", "sprintf", "(", "'HTTP/%s %s %s'", ",", "self", "::", "HTTP_VERSION", ",", "$", "this", "->", "statusCode", ",", "self", "::", "getStatusText", "(", "$", "this", "->", "statusCode", ")", ")", ";", "}" ]
Get the complete status line @return string
[ "Get", "the", "complete", "status", "line" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Http/Response.php#L251-L254
train
theopera/framework
src/Component/Http/Response.php
Response.send
public function send() { if (headers_sent()) { throw new HttpException(Response::STATUS_INTERNAL_SERVER_ERROR, 'Headers already send'); } header($this->getStatusLine()); foreach ($this->headers as $header) { header($header); } echo $this->body; }
php
public function send() { if (headers_sent()) { throw new HttpException(Response::STATUS_INTERNAL_SERVER_ERROR, 'Headers already send'); } header($this->getStatusLine()); foreach ($this->headers as $header) { header($header); } echo $this->body; }
[ "public", "function", "send", "(", ")", "{", "if", "(", "headers_sent", "(", ")", ")", "{", "throw", "new", "HttpException", "(", "Response", "::", "STATUS_INTERNAL_SERVER_ERROR", ",", "'Headers already send'", ")", ";", "}", "header", "(", "$", "this", "->", "getStatusLine", "(", ")", ")", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "header", ")", "{", "header", "(", "$", "header", ")", ";", "}", "echo", "$", "this", "->", "body", ";", "}" ]
Sends the response to the web server @return void
[ "Sends", "the", "response", "to", "the", "web", "server" ]
fa6165d3891a310faa580c81dee49a63c150c711
https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Http/Response.php#L297-L311
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.isTranslatable
public function isTranslatable($vid) { if (!is_numeric($vid)) { $vid = $this->vocabulary($vid); } return $this->vocabularyById[$vid]->isTranslatable(); }
php
public function isTranslatable($vid) { if (!is_numeric($vid)) { $vid = $this->vocabulary($vid); } return $this->vocabularyById[$vid]->isTranslatable(); }
[ "public", "function", "isTranslatable", "(", "$", "vid", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "vid", ")", ")", "{", "$", "vid", "=", "$", "this", "->", "vocabulary", "(", "$", "vid", ")", ";", "}", "return", "$", "this", "->", "vocabularyById", "[", "$", "vid", "]", "->", "isTranslatable", "(", ")", ";", "}" ]
Is this vocabulary translatable ? @param int|string $vid @return bool
[ "Is", "this", "vocabulary", "translatable", "?" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L82-L89
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.getLanguage
public function getLanguage($vocabulary_id, $language_id = null) { if (!$this->isTranslatable($vocabulary_id)) { return 1; } if ($language_id === null) { return I18N::getCurrentId(); } return $language_id; }
php
public function getLanguage($vocabulary_id, $language_id = null) { if (!$this->isTranslatable($vocabulary_id)) { return 1; } if ($language_id === null) { return I18N::getCurrentId(); } return $language_id; }
[ "public", "function", "getLanguage", "(", "$", "vocabulary_id", ",", "$", "language_id", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "isTranslatable", "(", "$", "vocabulary_id", ")", ")", "{", "return", "1", ";", "}", "if", "(", "$", "language_id", "===", "null", ")", "{", "return", "I18N", "::", "getCurrentId", "(", ")", ";", "}", "return", "$", "language_id", ";", "}" ]
Get the internal language for the vocabulary This will return the language_id if the vocabulary is translated or 1 if it's not @param int|string $vocabulary_id @param int $language_id @return int|null
[ "Get", "the", "internal", "language", "for", "the", "vocabulary" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L100-L111
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.vocabulary
public function vocabulary($key) { if (is_numeric($key)) { return $this->vocabularyById[$key]->machine_name; } return $this->vocabularyByName[$key]->id; }
php
public function vocabulary($key) { if (is_numeric($key)) { return $this->vocabularyById[$key]->machine_name; } return $this->vocabularyByName[$key]->id; }
[ "public", "function", "vocabulary", "(", "$", "key", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "vocabularyById", "[", "$", "key", "]", "->", "machine_name", ";", "}", "return", "$", "this", "->", "vocabularyByName", "[", "$", "key", "]", "->", "id", ";", "}" ]
Get a vocabulary by name or ID Taxonomy::vocabulary(1); returns 'tags' Taxonomy::vocabulary('tags'); returns 1 @param int|string $key @return mixed
[ "Get", "a", "vocabulary", "by", "name", "or", "ID" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L125-L132
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.uncacheTerm
public function uncacheTerm($term_id) { if (array_key_exists($term_id, $this->terms)) { unset($this->terms[$term_id]); } return $this->termRepository->uncacheTerm($term_id); }
php
public function uncacheTerm($term_id) { if (array_key_exists($term_id, $this->terms)) { unset($this->terms[$term_id]); } return $this->termRepository->uncacheTerm($term_id); }
[ "public", "function", "uncacheTerm", "(", "$", "term_id", ")", "{", "if", "(", "array_key_exists", "(", "$", "term_id", ",", "$", "this", "->", "terms", ")", ")", "{", "unset", "(", "$", "this", "->", "terms", "[", "$", "term_id", "]", ")", ";", "}", "return", "$", "this", "->", "termRepository", "->", "uncacheTerm", "(", "$", "term_id", ")", ";", "}" ]
Remove a term from the cache @param int $term_id @return bool
[ "Remove", "a", "term", "from", "the", "cache" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L169-L176
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.addParent
public function addParent($term_id, $parent_id) { $this->testCanAddParents($term_id, 1); $this->termHierarchyRepository->addParent($term_id, $parent_id); }
php
public function addParent($term_id, $parent_id) { $this->testCanAddParents($term_id, 1); $this->termHierarchyRepository->addParent($term_id, $parent_id); }
[ "public", "function", "addParent", "(", "$", "term_id", ",", "$", "parent_id", ")", "{", "$", "this", "->", "testCanAddParents", "(", "$", "term_id", ",", "1", ")", ";", "$", "this", "->", "termHierarchyRepository", "->", "addParent", "(", "$", "term_id", ",", "$", "parent_id", ")", ";", "}" ]
Add one parent to a term @param int $term_id @param int $parent_id
[ "Add", "one", "parent", "to", "a", "term" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L226-L231
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.addParents
public function addParents($term_id, array $parent_ids) { $this->testCanAddParents($term_id, count($parent_ids)); foreach ($parent_ids as $id) { $this->termHierarchyRepository->addParent($term_id, $id); } }
php
public function addParents($term_id, array $parent_ids) { $this->testCanAddParents($term_id, count($parent_ids)); foreach ($parent_ids as $id) { $this->termHierarchyRepository->addParent($term_id, $id); } }
[ "public", "function", "addParents", "(", "$", "term_id", ",", "array", "$", "parent_ids", ")", "{", "$", "this", "->", "testCanAddParents", "(", "$", "term_id", ",", "count", "(", "$", "parent_ids", ")", ")", ";", "foreach", "(", "$", "parent_ids", "as", "$", "id", ")", "{", "$", "this", "->", "termHierarchyRepository", "->", "addParent", "(", "$", "term_id", ",", "$", "id", ")", ";", "}", "}" ]
Add a list of parents to a term @param int $term_id @param array<integer> $parent_ids
[ "Add", "a", "list", "of", "parents", "to", "a", "term" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L239-L246
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.getTermsForVocabulary
public function getTermsForVocabulary($vocabulary_id) { return $this->cache->remember( 'Rocket::Taxonomy::Terms::' . $vocabulary_id, 60, function () use ($vocabulary_id) { $terms = TermContainer::where('vocabulary_id', $vocabulary_id)->get(['id']); $results = []; if (!empty($terms)) { foreach ($terms as $term) { $results[] = $term->id; } } return $results; } ); }
php
public function getTermsForVocabulary($vocabulary_id) { return $this->cache->remember( 'Rocket::Taxonomy::Terms::' . $vocabulary_id, 60, function () use ($vocabulary_id) { $terms = TermContainer::where('vocabulary_id', $vocabulary_id)->get(['id']); $results = []; if (!empty($terms)) { foreach ($terms as $term) { $results[] = $term->id; } } return $results; } ); }
[ "public", "function", "getTermsForVocabulary", "(", "$", "vocabulary_id", ")", "{", "return", "$", "this", "->", "cache", "->", "remember", "(", "'Rocket::Taxonomy::Terms::'", ".", "$", "vocabulary_id", ",", "60", ",", "function", "(", ")", "use", "(", "$", "vocabulary_id", ")", "{", "$", "terms", "=", "TermContainer", "::", "where", "(", "'vocabulary_id'", ",", "$", "vocabulary_id", ")", "->", "get", "(", "[", "'id'", "]", ")", ";", "$", "results", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "terms", ")", ")", "{", "foreach", "(", "$", "terms", "as", "$", "term", ")", "{", "$", "results", "[", "]", "=", "$", "term", "->", "id", ";", "}", "}", "return", "$", "results", ";", "}", ")", ";", "}" ]
Get all the terms of a vocabulary @param int $vocabulary_id @return array
[ "Get", "all", "the", "terms", "of", "a", "vocabulary" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L291-L309
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.searchTerm
public function searchTerm($term, $vocabulary_id, $language_id = null, $exclude = []) { $language_id = $this->getLanguage($vocabulary_id, $language_id); $term = trim($term); if ($term == '') { return; } $query = TermData::select('taxonomy_terms.id') ->join('taxonomy_terms', 'taxonomy_terms.id', '=', 'taxonomy_terms_data.term_id') ->where('taxonomy_terms.vocabulary_id', $vocabulary_id) ->where('taxonomy_terms_data.language_id', $language_id) ->where('taxonomy_terms_data.title', $term); if (count($exclude)) { $query->whereNotIn('taxonomy_terms.id', $exclude); } return $query->value('id'); }
php
public function searchTerm($term, $vocabulary_id, $language_id = null, $exclude = []) { $language_id = $this->getLanguage($vocabulary_id, $language_id); $term = trim($term); if ($term == '') { return; } $query = TermData::select('taxonomy_terms.id') ->join('taxonomy_terms', 'taxonomy_terms.id', '=', 'taxonomy_terms_data.term_id') ->where('taxonomy_terms.vocabulary_id', $vocabulary_id) ->where('taxonomy_terms_data.language_id', $language_id) ->where('taxonomy_terms_data.title', $term); if (count($exclude)) { $query->whereNotIn('taxonomy_terms.id', $exclude); } return $query->value('id'); }
[ "public", "function", "searchTerm", "(", "$", "term", ",", "$", "vocabulary_id", ",", "$", "language_id", "=", "null", ",", "$", "exclude", "=", "[", "]", ")", "{", "$", "language_id", "=", "$", "this", "->", "getLanguage", "(", "$", "vocabulary_id", ",", "$", "language_id", ")", ";", "$", "term", "=", "trim", "(", "$", "term", ")", ";", "if", "(", "$", "term", "==", "''", ")", "{", "return", ";", "}", "$", "query", "=", "TermData", "::", "select", "(", "'taxonomy_terms.id'", ")", "->", "join", "(", "'taxonomy_terms'", ",", "'taxonomy_terms.id'", ",", "'='", ",", "'taxonomy_terms_data.term_id'", ")", "->", "where", "(", "'taxonomy_terms.vocabulary_id'", ",", "$", "vocabulary_id", ")", "->", "where", "(", "'taxonomy_terms_data.language_id'", ",", "$", "language_id", ")", "->", "where", "(", "'taxonomy_terms_data.title'", ",", "$", "term", ")", ";", "if", "(", "count", "(", "$", "exclude", ")", ")", "{", "$", "query", "->", "whereNotIn", "(", "'taxonomy_terms.id'", ",", "$", "exclude", ")", ";", "}", "return", "$", "query", "->", "value", "(", "'id'", ")", ";", "}" ]
Search a specific term, if it doesn't exist, returns false @param string $term @param int $vocabulary_id @param int $language_id @param array $exclude @return int|null
[ "Search", "a", "specific", "term", "if", "it", "doesn", "t", "exist", "returns", "false" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L320-L340
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.getTermId
public function getTermId($title, $vocabulary_id, $language_id = null, $type = 0) { $title = trim($title); if ($title == '') { return false; } if (!is_numeric($vocabulary_id)) { $vocabulary_id = $this->vocabulary($vocabulary_id); } $language_id = $this->getLanguage($vocabulary_id, $language_id); $search = $this->searchTerm($title, $vocabulary_id, $language_id); if ($search !== null) { return $search; } // Add term $term = new TermContainer(['vocabulary_id' => $vocabulary_id]); if ($type !== 0) { $term->type = $type; } $term->save(); // Add translation $translation = [ 'language_id' => $language_id, 'title' => $title, ]; $term->translations()->save(new TermData($translation)); return $term->id; }
php
public function getTermId($title, $vocabulary_id, $language_id = null, $type = 0) { $title = trim($title); if ($title == '') { return false; } if (!is_numeric($vocabulary_id)) { $vocabulary_id = $this->vocabulary($vocabulary_id); } $language_id = $this->getLanguage($vocabulary_id, $language_id); $search = $this->searchTerm($title, $vocabulary_id, $language_id); if ($search !== null) { return $search; } // Add term $term = new TermContainer(['vocabulary_id' => $vocabulary_id]); if ($type !== 0) { $term->type = $type; } $term->save(); // Add translation $translation = [ 'language_id' => $language_id, 'title' => $title, ]; $term->translations()->save(new TermData($translation)); return $term->id; }
[ "public", "function", "getTermId", "(", "$", "title", ",", "$", "vocabulary_id", ",", "$", "language_id", "=", "null", ",", "$", "type", "=", "0", ")", "{", "$", "title", "=", "trim", "(", "$", "title", ")", ";", "if", "(", "$", "title", "==", "''", ")", "{", "return", "false", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "vocabulary_id", ")", ")", "{", "$", "vocabulary_id", "=", "$", "this", "->", "vocabulary", "(", "$", "vocabulary_id", ")", ";", "}", "$", "language_id", "=", "$", "this", "->", "getLanguage", "(", "$", "vocabulary_id", ",", "$", "language_id", ")", ";", "$", "search", "=", "$", "this", "->", "searchTerm", "(", "$", "title", ",", "$", "vocabulary_id", ",", "$", "language_id", ")", ";", "if", "(", "$", "search", "!==", "null", ")", "{", "return", "$", "search", ";", "}", "// Add term", "$", "term", "=", "new", "TermContainer", "(", "[", "'vocabulary_id'", "=>", "$", "vocabulary_id", "]", ")", ";", "if", "(", "$", "type", "!==", "0", ")", "{", "$", "term", "->", "type", "=", "$", "type", ";", "}", "$", "term", "->", "save", "(", ")", ";", "// Add translation", "$", "translation", "=", "[", "'language_id'", "=>", "$", "language_id", ",", "'title'", "=>", "$", "title", ",", "]", ";", "$", "term", "->", "translations", "(", ")", "->", "save", "(", "new", "TermData", "(", "$", "translation", ")", ")", ";", "return", "$", "term", "->", "id", ";", "}" ]
Returns the id of a term, if it doesn't exist, creates it. @param string $title @param int $vocabulary_id @param int $language_id @param int $type @return bool|int
[ "Returns", "the", "id", "of", "a", "term", "if", "it", "doesn", "t", "exist", "creates", "it", "." ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L351-L385
train
RocketPropelledTortoise/Core
src/Taxonomy/Taxonomy.php
Taxonomy.getTermIds
public function getTermIds($taxonomies) { $tags = []; foreach ($taxonomies as $voc => $terms) { $vocabulary_id = $this->vocabulary($voc); $exploded = is_array($terms) ? $terms : explode(',', $terms); foreach ($exploded as $term) { $result = $this->getTermId($term, $vocabulary_id); if ($result) { $tags[] = $result; } } } return $tags; }
php
public function getTermIds($taxonomies) { $tags = []; foreach ($taxonomies as $voc => $terms) { $vocabulary_id = $this->vocabulary($voc); $exploded = is_array($terms) ? $terms : explode(',', $terms); foreach ($exploded as $term) { $result = $this->getTermId($term, $vocabulary_id); if ($result) { $tags[] = $result; } } } return $tags; }
[ "public", "function", "getTermIds", "(", "$", "taxonomies", ")", "{", "$", "tags", "=", "[", "]", ";", "foreach", "(", "$", "taxonomies", "as", "$", "voc", "=>", "$", "terms", ")", "{", "$", "vocabulary_id", "=", "$", "this", "->", "vocabulary", "(", "$", "voc", ")", ";", "$", "exploded", "=", "is_array", "(", "$", "terms", ")", "?", "$", "terms", ":", "explode", "(", "','", ",", "$", "terms", ")", ";", "foreach", "(", "$", "exploded", "as", "$", "term", ")", "{", "$", "result", "=", "$", "this", "->", "getTermId", "(", "$", "term", ",", "$", "vocabulary_id", ")", ";", "if", "(", "$", "result", ")", "{", "$", "tags", "[", "]", "=", "$", "result", ";", "}", "}", "}", "return", "$", "tags", ";", "}" ]
Adds one or more tags and returns an array of id's @param array $taxonomies @return array
[ "Adds", "one", "or", "more", "tags", "and", "returns", "an", "array", "of", "id", "s" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Taxonomy.php#L393-L409
train
bytic/http
src/Request.php
Request.getHttp
public function getHttp() { if (!$this->http) { $this->http = new Http(); $this->http->setRequest($this); } return $this->http; }
php
public function getHttp() { if (!$this->http) { $this->http = new Http(); $this->http->setRequest($this); } return $this->http; }
[ "public", "function", "getHttp", "(", ")", "{", "if", "(", "!", "$", "this", "->", "http", ")", "{", "$", "this", "->", "http", "=", "new", "Http", "(", ")", ";", "$", "this", "->", "http", "->", "setRequest", "(", "$", "this", ")", ";", "}", "return", "$", "this", "->", "http", ";", "}" ]
Returns Http object @return Http
[ "Returns", "Http", "object" ]
0d22507a8bcf05575d3d1d6c6a87c2026778c47c
https://github.com/bytic/http/blob/0d22507a8bcf05575d3d1d6c6a87c2026778c47c/src/Request.php#L93-L101
train
nails/module-blog
blog/models/blog_category_model.php
NAILS_Blog_category_model.getCountCommon
protected function getCountCommon($data = array()) { parent::getCountCommon($data); // -------------------------------------------------------------------------- $oDb = Factory::service('Database'); $oDb->select($this->tableAlias . '.*'); if (!empty($data['include_count'])) { $subQuery = ' SELECT COUNT(DISTINCT post_id) FROM ' . NAILS_DB_PREFIX . 'blog_post_category WHERE category_id = ' . $this->tableAlias . '.id'; $oDb->select('(' . $subQuery . ') post_count'); } // Default sort if (empty($data['sort'])) { $oDb->order_by($this->tableAlias . '.label'); } }
php
protected function getCountCommon($data = array()) { parent::getCountCommon($data); // -------------------------------------------------------------------------- $oDb = Factory::service('Database'); $oDb->select($this->tableAlias . '.*'); if (!empty($data['include_count'])) { $subQuery = ' SELECT COUNT(DISTINCT post_id) FROM ' . NAILS_DB_PREFIX . 'blog_post_category WHERE category_id = ' . $this->tableAlias . '.id'; $oDb->select('(' . $subQuery . ') post_count'); } // Default sort if (empty($data['sort'])) { $oDb->order_by($this->tableAlias . '.label'); } }
[ "protected", "function", "getCountCommon", "(", "$", "data", "=", "array", "(", ")", ")", "{", "parent", "::", "getCountCommon", "(", "$", "data", ")", ";", "// --------------------------------------------------------------------------", "$", "oDb", "=", "Factory", "::", "service", "(", "'Database'", ")", ";", "$", "oDb", "->", "select", "(", "$", "this", "->", "tableAlias", ".", "'.*'", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "[", "'include_count'", "]", ")", ")", "{", "$", "subQuery", "=", "'\n SELECT\n COUNT(DISTINCT post_id)\n FROM '", ".", "NAILS_DB_PREFIX", ".", "'blog_post_category\n WHERE\n category_id = '", ".", "$", "this", "->", "tableAlias", ".", "'.id'", ";", "$", "oDb", "->", "select", "(", "'('", ".", "$", "subQuery", ".", "') post_count'", ")", ";", "}", "// Default sort", "if", "(", "empty", "(", "$", "data", "[", "'sort'", "]", ")", ")", "{", "$", "oDb", "->", "order_by", "(", "$", "this", "->", "tableAlias", ".", "'.label'", ")", ";", "}", "}" ]
Set some common data @param array $data Data passed from the calling method @return void
[ "Set", "some", "common", "data" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/blog/models/blog_category_model.php#L38-L64
train
nails/module-blog
blog/models/blog_category_model.php
NAILS_Blog_category_model.create
public function create($aData, $bReturnObject = false) { $aCategoryData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aCategoryData['label'] = trim($aData['label']); } if (empty($aData['blog_id'])) { $this->setError('"blog_id" is a required field.'); return false; } else { $aCategoryData['blog_id'] = $aData['blog_id']; } // -------------------------------------------------------------------------- $aCategoryData['slug'] = $this->generateSlug($aData['label']); if (isset($aData['description'])) { $aCategoryData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aCategoryData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aCategoryData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aCategoryData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::create($aCategoryData, $bReturnObject); }
php
public function create($aData, $bReturnObject = false) { $aCategoryData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aCategoryData['label'] = trim($aData['label']); } if (empty($aData['blog_id'])) { $this->setError('"blog_id" is a required field.'); return false; } else { $aCategoryData['blog_id'] = $aData['blog_id']; } // -------------------------------------------------------------------------- $aCategoryData['slug'] = $this->generateSlug($aData['label']); if (isset($aData['description'])) { $aCategoryData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aCategoryData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aCategoryData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aCategoryData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::create($aCategoryData, $bReturnObject); }
[ "public", "function", "create", "(", "$", "aData", ",", "$", "bReturnObject", "=", "false", ")", "{", "$", "aCategoryData", "=", "array", "(", ")", ";", "// --------------------------------------------------------------------------", "// Some basic sanity testing", "if", "(", "empty", "(", "$", "aData", "[", "'label'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'\"label\" is a required field.'", ")", ";", "return", "false", ";", "}", "else", "{", "$", "aCategoryData", "[", "'label'", "]", "=", "trim", "(", "$", "aData", "[", "'label'", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "aData", "[", "'blog_id'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'\"blog_id\" is a required field.'", ")", ";", "return", "false", ";", "}", "else", "{", "$", "aCategoryData", "[", "'blog_id'", "]", "=", "$", "aData", "[", "'blog_id'", "]", ";", "}", "// --------------------------------------------------------------------------", "$", "aCategoryData", "[", "'slug'", "]", "=", "$", "this", "->", "generateSlug", "(", "$", "aData", "[", "'label'", "]", ")", ";", "if", "(", "isset", "(", "$", "aData", "[", "'description'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'description'", "]", "=", "$", "aData", "[", "'description'", "]", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_title'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'seo_title'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_title'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_description'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'seo_description'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'seo_keywords'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ";", "}", "return", "parent", "::", "create", "(", "$", "aCategoryData", ",", "$", "bReturnObject", ")", ";", "}" ]
Creates a new category @param array $aData The data to create the category with @param boolean $bReturnObject Whether to return the full category object (or just the ID) @return mixed
[ "Creates", "a", "new", "category" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/blog/models/blog_category_model.php#L74-L126
train
nails/module-blog
blog/models/blog_category_model.php
NAILS_Blog_category_model.update
public function update($iId, $aData) { $aCategoryData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aCategoryData['label'] = trim($aData['label']); } // -------------------------------------------------------------------------- $aCategoryData['slug'] = $this->generateSlug($aData['label'], $iId); if (isset($aData['description'])) { $aCategoryData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aCategoryData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aCategoryData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aCategoryData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::update($iId, $aCategoryData); }
php
public function update($iId, $aData) { $aCategoryData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aCategoryData['label'] = trim($aData['label']); } // -------------------------------------------------------------------------- $aCategoryData['slug'] = $this->generateSlug($aData['label'], $iId); if (isset($aData['description'])) { $aCategoryData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aCategoryData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aCategoryData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aCategoryData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::update($iId, $aCategoryData); }
[ "public", "function", "update", "(", "$", "iId", ",", "$", "aData", ")", "{", "$", "aCategoryData", "=", "array", "(", ")", ";", "// --------------------------------------------------------------------------", "// Some basic sanity testing", "if", "(", "empty", "(", "$", "aData", "[", "'label'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'\"label\" is a required field.'", ")", ";", "return", "false", ";", "}", "else", "{", "$", "aCategoryData", "[", "'label'", "]", "=", "trim", "(", "$", "aData", "[", "'label'", "]", ")", ";", "}", "// --------------------------------------------------------------------------", "$", "aCategoryData", "[", "'slug'", "]", "=", "$", "this", "->", "generateSlug", "(", "$", "aData", "[", "'label'", "]", ",", "$", "iId", ")", ";", "if", "(", "isset", "(", "$", "aData", "[", "'description'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'description'", "]", "=", "$", "aData", "[", "'description'", "]", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_title'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'seo_title'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_title'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_description'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'seo_description'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ")", "{", "$", "aCategoryData", "[", "'seo_keywords'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ";", "}", "return", "parent", "::", "update", "(", "$", "iId", ",", "$", "aCategoryData", ")", ";", "}" ]
Updates an existing category @param integer $iId The category's ID @param array $aData The data to update the category with @return boolean
[ "Updates", "an", "existing", "category" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/blog/models/blog_category_model.php#L136-L178
train
cogentParadigm/behat-starbug-extension
src/Context/RawStarbugContext.php
RawStarbugContext.replaceTokens
public function replaceTokens($text) { $tokens = $this->macro->search($text); if (empty($tokens)) { return $text; } static $last = []; $replacements = []; foreach ($tokens as $type => $typeTokens) { foreach ($typeTokens as $name => $token) { if ($type == "any") { $value = $this->faker->{$name}; $replacements[$token] = $value; $last[$name] = $value; } elseif ($type == "last") { $replacements[$token] = $last[$name]; } } } $search = array_keys($replacements); $replace = array_values($replacements); return str_replace($search, $replace, $text); }
php
public function replaceTokens($text) { $tokens = $this->macro->search($text); if (empty($tokens)) { return $text; } static $last = []; $replacements = []; foreach ($tokens as $type => $typeTokens) { foreach ($typeTokens as $name => $token) { if ($type == "any") { $value = $this->faker->{$name}; $replacements[$token] = $value; $last[$name] = $value; } elseif ($type == "last") { $replacements[$token] = $last[$name]; } } } $search = array_keys($replacements); $replace = array_values($replacements); return str_replace($search, $replace, $text); }
[ "public", "function", "replaceTokens", "(", "$", "text", ")", "{", "$", "tokens", "=", "$", "this", "->", "macro", "->", "search", "(", "$", "text", ")", ";", "if", "(", "empty", "(", "$", "tokens", ")", ")", "{", "return", "$", "text", ";", "}", "static", "$", "last", "=", "[", "]", ";", "$", "replacements", "=", "[", "]", ";", "foreach", "(", "$", "tokens", "as", "$", "type", "=>", "$", "typeTokens", ")", "{", "foreach", "(", "$", "typeTokens", "as", "$", "name", "=>", "$", "token", ")", "{", "if", "(", "$", "type", "==", "\"any\"", ")", "{", "$", "value", "=", "$", "this", "->", "faker", "->", "{", "$", "name", "}", ";", "$", "replacements", "[", "$", "token", "]", "=", "$", "value", ";", "$", "last", "[", "$", "name", "]", "=", "$", "value", ";", "}", "elseif", "(", "$", "type", "==", "\"last\"", ")", "{", "$", "replacements", "[", "$", "token", "]", "=", "$", "last", "[", "$", "name", "]", ";", "}", "}", "}", "$", "search", "=", "array_keys", "(", "$", "replacements", ")", ";", "$", "replace", "=", "array_values", "(", "$", "replacements", ")", ";", "return", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "text", ")", ";", "}" ]
Replace fake data tokens. @Transform /^(.*)$/
[ "Replace", "fake", "data", "tokens", "." ]
76da5d943773857ad2388a7cccb6632176b452a9
https://github.com/cogentParadigm/behat-starbug-extension/blob/76da5d943773857ad2388a7cccb6632176b452a9/src/Context/RawStarbugContext.php#L39-L62
train
cogentParadigm/behat-starbug-extension
src/Context/RawStarbugContext.php
RawStarbugContext.replaceTableTokens
public function replaceTableTokens(TableNode $input) { $table = $input->getTable(); foreach ($table as $row => $values) { foreach ($values as $idx => $value) { $table[$row][$idx] = $this->replaceTokens($value); } } return new TableNode($table); }
php
public function replaceTableTokens(TableNode $input) { $table = $input->getTable(); foreach ($table as $row => $values) { foreach ($values as $idx => $value) { $table[$row][$idx] = $this->replaceTokens($value); } } return new TableNode($table); }
[ "public", "function", "replaceTableTokens", "(", "TableNode", "$", "input", ")", "{", "$", "table", "=", "$", "input", "->", "getTable", "(", ")", ";", "foreach", "(", "$", "table", "as", "$", "row", "=>", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "idx", "=>", "$", "value", ")", "{", "$", "table", "[", "$", "row", "]", "[", "$", "idx", "]", "=", "$", "this", "->", "replaceTokens", "(", "$", "value", ")", ";", "}", "}", "return", "new", "TableNode", "(", "$", "table", ")", ";", "}" ]
Replace fake data tokens in tables. @Transform table:*
[ "Replace", "fake", "data", "tokens", "in", "tables", "." ]
76da5d943773857ad2388a7cccb6632176b452a9
https://github.com/cogentParadigm/behat-starbug-extension/blob/76da5d943773857ad2388a7cccb6632176b452a9/src/Context/RawStarbugContext.php#L68-L76
train
cogentParadigm/behat-starbug-extension
src/Context/RawStarbugContext.php
RawStarbugContext.gatherContexts
public function gatherContexts(BeforeScenarioScope $scope) { $environment = $scope->getEnvironment(); $this->mink = $environment->getContext('Starbug\Behat\Context\MinkContext'); }
php
public function gatherContexts(BeforeScenarioScope $scope) { $environment = $scope->getEnvironment(); $this->mink = $environment->getContext('Starbug\Behat\Context\MinkContext'); }
[ "public", "function", "gatherContexts", "(", "BeforeScenarioScope", "$", "scope", ")", "{", "$", "environment", "=", "$", "scope", "->", "getEnvironment", "(", ")", ";", "$", "this", "->", "mink", "=", "$", "environment", "->", "getContext", "(", "'Starbug\\Behat\\Context\\MinkContext'", ")", ";", "}" ]
Access other contexts. @BeforeScenario
[ "Access", "other", "contexts", "." ]
76da5d943773857ad2388a7cccb6632176b452a9
https://github.com/cogentParadigm/behat-starbug-extension/blob/76da5d943773857ad2388a7cccb6632176b452a9/src/Context/RawStarbugContext.php#L82-L85
train
refact-be/distext-php
src/Wavy/Distext/Distext.php
Distext.send
public function send($destination, $text) { /** @var Response $response */ $response = $this->browser->post('http://distext.wavy.be/api/sms', array( 'X-Auth-Token' => $this->apiKey, ), json_encode([ 'destination' => $destination, 'text' => $text, ])); if(!$response->isSuccessful()) { $message = $response->getStatusCode() === 401 ? 'Invalid API key' : $response->getReasonPhrase(); throw new \Exception($message); } }
php
public function send($destination, $text) { /** @var Response $response */ $response = $this->browser->post('http://distext.wavy.be/api/sms', array( 'X-Auth-Token' => $this->apiKey, ), json_encode([ 'destination' => $destination, 'text' => $text, ])); if(!$response->isSuccessful()) { $message = $response->getStatusCode() === 401 ? 'Invalid API key' : $response->getReasonPhrase(); throw new \Exception($message); } }
[ "public", "function", "send", "(", "$", "destination", ",", "$", "text", ")", "{", "/** @var Response $response */", "$", "response", "=", "$", "this", "->", "browser", "->", "post", "(", "'http://distext.wavy.be/api/sms'", ",", "array", "(", "'X-Auth-Token'", "=>", "$", "this", "->", "apiKey", ",", ")", ",", "json_encode", "(", "[", "'destination'", "=>", "$", "destination", ",", "'text'", "=>", "$", "text", ",", "]", ")", ")", ";", "if", "(", "!", "$", "response", "->", "isSuccessful", "(", ")", ")", "{", "$", "message", "=", "$", "response", "->", "getStatusCode", "(", ")", "===", "401", "?", "'Invalid API key'", ":", "$", "response", "->", "getReasonPhrase", "(", ")", ";", "throw", "new", "\\", "Exception", "(", "$", "message", ")", ";", "}", "}" ]
Send a text message @param string $destination @param string $text @throws \Exception
[ "Send", "a", "text", "message" ]
2d16604ac066983b4a5e01df0c15bba80dd99b32
https://github.com/refact-be/distext-php/blob/2d16604ac066983b4a5e01df0c15bba80dd99b32/src/Wavy/Distext/Distext.php#L32-L46
train
Vectrex/vxPHP
src/Session/SessionDataBag.php
SessionDataBag.remove
public function remove($key) { if(!array_key_exists($key, $this->data)) { return NULL; } $oldValue = $this->data[$key]; unset($this->data[$key]); return $oldValue; }
php
public function remove($key) { if(!array_key_exists($key, $this->data)) { return NULL; } $oldValue = $this->data[$key]; unset($this->data[$key]); return $oldValue; }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "data", ")", ")", "{", "return", "NULL", ";", "}", "$", "oldValue", "=", "$", "this", "->", "data", "[", "$", "key", "]", ";", "unset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ";", "return", "$", "oldValue", ";", "}" ]
unset key value; returns previously held data @param string $key @return mixed
[ "unset", "key", "value", ";", "returns", "previously", "held", "data" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Session/SessionDataBag.php#L120-L131
train
Vectrex/vxPHP
src/Session/SessionDataBag.php
SessionDataBag.replace
public function replace(array $data) { $this->data = array(); foreach ($data as $k => $v) { $this->data[$k] = $v; } }
php
public function replace(array $data) { $this->data = array(); foreach ($data as $k => $v) { $this->data[$k] = $v; } }
[ "public", "function", "replace", "(", "array", "$", "data", ")", "{", "$", "this", "->", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "data", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}" ]
replace current data array @param array $data
[ "replace", "current", "data", "array" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Session/SessionDataBag.php#L138-L146
train
modulusphp/http
Middleware/TransformsRequest.php
TransformsRequest.cleanData
private function cleanData(array $data) : array { foreach($data as $key => $value) { $data[$key] = $this->replace($key, $value); } return $data; }
php
private function cleanData(array $data) : array { foreach($data as $key => $value) { $data[$key] = $this->replace($key, $value); } return $data; }
[ "private", "function", "cleanData", "(", "array", "$", "data", ")", ":", "array", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "data", "[", "$", "key", "]", "=", "$", "this", "->", "replace", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "data", ";", "}" ]
Loop through the values and pass them to the replace method @param array $data @return array
[ "Loop", "through", "the", "values", "and", "pass", "them", "to", "the", "replace", "method" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Middleware/TransformsRequest.php#L37-L44
train
modulusphp/http
Middleware/TransformsRequest.php
TransformsRequest.replace
private function replace($key, $value) { if (is_array($value)) return $this->cleanData($value); return $this->transform($key, $value); }
php
private function replace($key, $value) { if (is_array($value)) return $this->cleanData($value); return $this->transform($key, $value); }
[ "private", "function", "replace", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "return", "$", "this", "->", "cleanData", "(", "$", "value", ")", ";", "return", "$", "this", "->", "transform", "(", "$", "key", ",", "$", "value", ")", ";", "}" ]
Pass arrays back to the cleanData method and pass everything else to transform @param mixed $key @param mixed $value @return void
[ "Pass", "arrays", "back", "to", "the", "cleanData", "method", "and", "pass", "everything", "else", "to", "transform" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Middleware/TransformsRequest.php#L53-L58
train
lasallecms/lasallecms-l5-lasallecmsemail-pkg
src/Processing/AdminEmailProcessing.php
AdminEmailProcessing.washCreateForm
public function washCreateForm() { // An array to hold the fields we'll neeed to INSERT the record $data = []; // Wash the input fields $data['to_email_address'] = trim($this->request->input('to_email_address')); $data['to_name'] = $this->genericWashText($this->request->input('to_name')); $data['subject'] = $this->genericWashText($this->request->input('subject')); $data['body'] = $this->genericWashText($this->request->input('body')); return $data; }
php
public function washCreateForm() { // An array to hold the fields we'll neeed to INSERT the record $data = []; // Wash the input fields $data['to_email_address'] = trim($this->request->input('to_email_address')); $data['to_name'] = $this->genericWashText($this->request->input('to_name')); $data['subject'] = $this->genericWashText($this->request->input('subject')); $data['body'] = $this->genericWashText($this->request->input('body')); return $data; }
[ "public", "function", "washCreateForm", "(", ")", "{", "// An array to hold the fields we'll neeed to INSERT the record", "$", "data", "=", "[", "]", ";", "// Wash the input fields", "$", "data", "[", "'to_email_address'", "]", "=", "trim", "(", "$", "this", "->", "request", "->", "input", "(", "'to_email_address'", ")", ")", ";", "$", "data", "[", "'to_name'", "]", "=", "$", "this", "->", "genericWashText", "(", "$", "this", "->", "request", "->", "input", "(", "'to_name'", ")", ")", ";", "$", "data", "[", "'subject'", "]", "=", "$", "this", "->", "genericWashText", "(", "$", "this", "->", "request", "->", "input", "(", "'subject'", ")", ")", ";", "$", "data", "[", "'body'", "]", "=", "$", "this", "->", "genericWashText", "(", "$", "this", "->", "request", "->", "input", "(", "'body'", ")", ")", ";", "return", "$", "data", ";", "}" ]
Wash the create form's input fields @return array
[ "Wash", "the", "create", "form", "s", "input", "fields" ]
95db5a59ab322105b9d3681cf9ab1f829c9fdb9f
https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Processing/AdminEmailProcessing.php#L110-L122
train
lasallecms/lasallecms-l5-lasallecmsemail-pkg
src/Processing/AdminEmailProcessing.php
AdminEmailProcessing.prepEmailData
public function prepEmailData($id) { $email = $this->email_message->find($id); // Build the email data // $data is an array $data = []; $data['from_name'] = $email->from_name; $data['from_email_address'] = $email->from_email_address; $data['to_name'] = $email->to_name; $data['to_email_address'] = $email->to_email_address; $data['subject'] = $email->subject; $data['body'] = $email->body; $data['site_name'] = config('lasallecmsfrontend.site_name'); $data['sender_email_address'] = "[email protected]"; return $data; }
php
public function prepEmailData($id) { $email = $this->email_message->find($id); // Build the email data // $data is an array $data = []; $data['from_name'] = $email->from_name; $data['from_email_address'] = $email->from_email_address; $data['to_name'] = $email->to_name; $data['to_email_address'] = $email->to_email_address; $data['subject'] = $email->subject; $data['body'] = $email->body; $data['site_name'] = config('lasallecmsfrontend.site_name'); $data['sender_email_address'] = "[email protected]"; return $data; }
[ "public", "function", "prepEmailData", "(", "$", "id", ")", "{", "$", "email", "=", "$", "this", "->", "email_message", "->", "find", "(", "$", "id", ")", ";", "// Build the email data", "// $data is an array", "$", "data", "=", "[", "]", ";", "$", "data", "[", "'from_name'", "]", "=", "$", "email", "->", "from_name", ";", "$", "data", "[", "'from_email_address'", "]", "=", "$", "email", "->", "from_email_address", ";", "$", "data", "[", "'to_name'", "]", "=", "$", "email", "->", "to_name", ";", "$", "data", "[", "'to_email_address'", "]", "=", "$", "email", "->", "to_email_address", ";", "$", "data", "[", "'subject'", "]", "=", "$", "email", "->", "subject", ";", "$", "data", "[", "'body'", "]", "=", "$", "email", "->", "body", ";", "$", "data", "[", "'site_name'", "]", "=", "config", "(", "'lasallecmsfrontend.site_name'", ")", ";", "$", "data", "[", "'sender_email_address'", "]", "=", "\"[email protected]\"", ";", "return", "$", "data", ";", "}" ]
Prepare the email @param int $id The "email_messages" table's ID field @return array
[ "Prepare", "the", "email" ]
95db5a59ab322105b9d3681cf9ab1f829c9fdb9f
https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Processing/AdminEmailProcessing.php#L253-L270
train
phpffcms/ffcms-core
src/Helper/ModelFilters.php
ModelFilters.isFile
public static function isFile($object, $value): bool { // allow empty fields, "required" option filter that if ($object === null) { return true; } $all = false; // if string is given if (!Any::isArray($value)) { if ($value === '*') { $all = true; } else { $value = [$value]; } } // input file is not object? if ($object === null || !Any::isObj($object)) { return false; } // get guess file type, based on mime-type $type = $object->guessExtension(); if ($type === null) { return false; } return ($all ? true : Arr::in($type, $value)); }
php
public static function isFile($object, $value): bool { // allow empty fields, "required" option filter that if ($object === null) { return true; } $all = false; // if string is given if (!Any::isArray($value)) { if ($value === '*') { $all = true; } else { $value = [$value]; } } // input file is not object? if ($object === null || !Any::isObj($object)) { return false; } // get guess file type, based on mime-type $type = $object->guessExtension(); if ($type === null) { return false; } return ($all ? true : Arr::in($type, $value)); }
[ "public", "static", "function", "isFile", "(", "$", "object", ",", "$", "value", ")", ":", "bool", "{", "// allow empty fields, \"required\" option filter that", "if", "(", "$", "object", "===", "null", ")", "{", "return", "true", ";", "}", "$", "all", "=", "false", ";", "// if string is given", "if", "(", "!", "Any", "::", "isArray", "(", "$", "value", ")", ")", "{", "if", "(", "$", "value", "===", "'*'", ")", "{", "$", "all", "=", "true", ";", "}", "else", "{", "$", "value", "=", "[", "$", "value", "]", ";", "}", "}", "// input file is not object?", "if", "(", "$", "object", "===", "null", "||", "!", "Any", "::", "isObj", "(", "$", "object", ")", ")", "{", "return", "false", ";", "}", "// get guess file type, based on mime-type", "$", "type", "=", "$", "object", "->", "guessExtension", "(", ")", ";", "if", "(", "$", "type", "===", "null", ")", "{", "return", "false", ";", "}", "return", "(", "$", "all", "?", "true", ":", "Arr", "::", "in", "(", "$", "type", ",", "$", "value", ")", ")", ";", "}" ]
Check if field is file or null @param object $object @param $value @return bool
[ "Check", "if", "field", "is", "file", "or", "null" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/ModelFilters.php#L303-L332
train
phpffcms/ffcms-core
src/Helper/ModelFilters.php
ModelFilters.sizeFile
public static function sizeFile($object, $value): bool { // allow empty field, validate on filter 'required' if ($object === null) { return true; } if (!Any::isArray($value)) { $value = [0, $value]; } // input file is not object? if ($object === null || !Any::isObj($object)) { return false; } // get file upload size in bytes $realSize = $object->getClientSize(); if ($realSize === null) { return false; } return $realSize > $value[0] && $realSize <= $value[1]; }
php
public static function sizeFile($object, $value): bool { // allow empty field, validate on filter 'required' if ($object === null) { return true; } if (!Any::isArray($value)) { $value = [0, $value]; } // input file is not object? if ($object === null || !Any::isObj($object)) { return false; } // get file upload size in bytes $realSize = $object->getClientSize(); if ($realSize === null) { return false; } return $realSize > $value[0] && $realSize <= $value[1]; }
[ "public", "static", "function", "sizeFile", "(", "$", "object", ",", "$", "value", ")", ":", "bool", "{", "// allow empty field, validate on filter 'required'", "if", "(", "$", "object", "===", "null", ")", "{", "return", "true", ";", "}", "if", "(", "!", "Any", "::", "isArray", "(", "$", "value", ")", ")", "{", "$", "value", "=", "[", "0", ",", "$", "value", "]", ";", "}", "// input file is not object?", "if", "(", "$", "object", "===", "null", "||", "!", "Any", "::", "isObj", "(", "$", "object", ")", ")", "{", "return", "false", ";", "}", "// get file upload size in bytes", "$", "realSize", "=", "$", "object", "->", "getClientSize", "(", ")", ";", "if", "(", "$", "realSize", "===", "null", ")", "{", "return", "false", ";", "}", "return", "$", "realSize", ">", "$", "value", "[", "0", "]", "&&", "$", "realSize", "<=", "$", "value", "[", "1", "]", ";", "}" ]
Check file size. If is null - will return true @param object $object @param $value @return bool
[ "Check", "file", "size", ".", "If", "is", "null", "-", "will", "return", "true" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/ModelFilters.php#L340-L363
train
quantaphp/container-factories
src/FactoryMap.php
FactoryMap.extended
private function extended(callable $factory, callable ...$extensions): callable { return array_reduce($extensions, function ($factory, $extension) { return new Extension($factory, $extension); }, $factory); }
php
private function extended(callable $factory, callable ...$extensions): callable { return array_reduce($extensions, function ($factory, $extension) { return new Extension($factory, $extension); }, $factory); }
[ "private", "function", "extended", "(", "callable", "$", "factory", ",", "callable", "...", "$", "extensions", ")", ":", "callable", "{", "return", "array_reduce", "(", "$", "extensions", ",", "function", "(", "$", "factory", ",", "$", "extension", ")", "{", "return", "new", "Extension", "(", "$", "factory", ",", "$", "extension", ")", ";", "}", ",", "$", "factory", ")", ";", "}" ]
Return an extension from the given callables. @param callable $factory @param callable ...$extensions @return callable
[ "Return", "an", "extension", "from", "the", "given", "callables", "." ]
5e753d66a18d0ce4418cbf33fe6d6b74948f303d
https://github.com/quantaphp/container-factories/blob/5e753d66a18d0ce4418cbf33fe6d6b74948f303d/src/FactoryMap.php#L69-L74
train
ptlis/grep-db
src/Replace/Replace.php
Replace.replaceDatabase
public function replaceDatabase( Connection $connection, string $databaseName, string $searchTerm, string $replaceTerm, int $batchSize = 100 ): \Generator { $databaseMetadata = (new MetadataFactory())->getDatabaseMetadata($connection, $databaseName); foreach ($databaseMetadata->getAllTableMetadata() as $tableMetadata) { $rowResultList = $this->replaceTable( $connection, $databaseName, $tableMetadata->getTableName(), $searchTerm, $replaceTerm, $batchSize ); foreach ($rowResultList as $rowResult) { yield $rowResult; } } }
php
public function replaceDatabase( Connection $connection, string $databaseName, string $searchTerm, string $replaceTerm, int $batchSize = 100 ): \Generator { $databaseMetadata = (new MetadataFactory())->getDatabaseMetadata($connection, $databaseName); foreach ($databaseMetadata->getAllTableMetadata() as $tableMetadata) { $rowResultList = $this->replaceTable( $connection, $databaseName, $tableMetadata->getTableName(), $searchTerm, $replaceTerm, $batchSize ); foreach ($rowResultList as $rowResult) { yield $rowResult; } } }
[ "public", "function", "replaceDatabase", "(", "Connection", "$", "connection", ",", "string", "$", "databaseName", ",", "string", "$", "searchTerm", ",", "string", "$", "replaceTerm", ",", "int", "$", "batchSize", "=", "100", ")", ":", "\\", "Generator", "{", "$", "databaseMetadata", "=", "(", "new", "MetadataFactory", "(", ")", ")", "->", "getDatabaseMetadata", "(", "$", "connection", ",", "$", "databaseName", ")", ";", "foreach", "(", "$", "databaseMetadata", "->", "getAllTableMetadata", "(", ")", "as", "$", "tableMetadata", ")", "{", "$", "rowResultList", "=", "$", "this", "->", "replaceTable", "(", "$", "connection", ",", "$", "databaseName", ",", "$", "tableMetadata", "->", "getTableName", "(", ")", ",", "$", "searchTerm", ",", "$", "replaceTerm", ",", "$", "batchSize", ")", ";", "foreach", "(", "$", "rowResultList", "as", "$", "rowResult", ")", "{", "yield", "$", "rowResult", ";", "}", "}", "}" ]
Performs a search on all tables in the the provided database, batching queries to the specified batch size. @return \Generator|RowReplaceResult[]
[ "Performs", "a", "search", "on", "all", "tables", "in", "the", "the", "provided", "database", "batching", "queries", "to", "the", "specified", "batch", "size", "." ]
7abff68982d426690d0515ccd7adc7a2e3d72a3f
https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Replace/Replace.php#L51-L74
train
ptlis/grep-db
src/Replace/Replace.php
Replace.replaceTable
public function replaceTable( Connection $connection, string $databaseName, string $tableName, string $searchTerm, string $replaceTerm, int $batchSize = 100 ): \Generator { $connection->query('START TRANSACTION'); $rowCount = 0; $rowSearchResultList = (new Search())->searchTable($connection, $databaseName, $tableName, $searchTerm); foreach ($rowSearchResultList as $rowSearchResult) { $rowCount++; $rowReplaceResult = $this->replaceFields($rowSearchResult, $searchTerm, $replaceTerm); $queryBuilder = $connection->createQueryBuilder(); // Build key => value mapping of replacement data $replacementData = []; foreach ($rowReplaceResult->getFieldResultList() as $fieldReplacementResult) { $replacementData[$fieldReplacementResult->getColumnMetadata()->getColumnName()] = $fieldReplacementResult->getNewValue(); } $queryBuilder ->update( '`' . $rowSearchResult->getTableMetadata()->getDatabaseName() . '`.`' . $rowSearchResult->getTableMetadata()->getTableName() . '`', 'subject' ) ->setParameters($replacementData) ->setParameter('key', $rowSearchResult->getPrimaryKeyValue()); foreach (array_keys($replacementData) as $columnName) { $queryBuilder->set('subject.' . $columnName, ':' . $columnName); } // Update using primary key if (null !== $rowSearchResult->getPrimaryKeyColumn()) { $queryBuilder->where('subject.' . $rowSearchResult->getPrimaryKeyColumn()->getColumnName() . ' = :key'); // Update using original values } else { $whereCount = 0; foreach ($rowReplaceResult->getFieldResultList() as $fieldReplaceResult) { $columnName = $fieldReplaceResult->getColumnMetadata()->getColumnName(); $whereClause = 'subject.' . $columnName . ' = :old_' . $columnName; if (0 === $whereCount) { $queryBuilder->where($whereClause); } else { $queryBuilder->andWhere($whereClause); } $queryBuilder->setParameter('old_' . $columnName, $fieldReplaceResult->getOldValue()); } } // TODO: handle exception $queryBuilder->execute(); if (0 === ($rowCount % $batchSize)) { $connection->query('COMMIT'); $connection->query('START TRANSACTION'); } yield $rowReplaceResult; } if (0 !== ($rowCount % $batchSize)) { $connection->query('COMMIT'); } }
php
public function replaceTable( Connection $connection, string $databaseName, string $tableName, string $searchTerm, string $replaceTerm, int $batchSize = 100 ): \Generator { $connection->query('START TRANSACTION'); $rowCount = 0; $rowSearchResultList = (new Search())->searchTable($connection, $databaseName, $tableName, $searchTerm); foreach ($rowSearchResultList as $rowSearchResult) { $rowCount++; $rowReplaceResult = $this->replaceFields($rowSearchResult, $searchTerm, $replaceTerm); $queryBuilder = $connection->createQueryBuilder(); // Build key => value mapping of replacement data $replacementData = []; foreach ($rowReplaceResult->getFieldResultList() as $fieldReplacementResult) { $replacementData[$fieldReplacementResult->getColumnMetadata()->getColumnName()] = $fieldReplacementResult->getNewValue(); } $queryBuilder ->update( '`' . $rowSearchResult->getTableMetadata()->getDatabaseName() . '`.`' . $rowSearchResult->getTableMetadata()->getTableName() . '`', 'subject' ) ->setParameters($replacementData) ->setParameter('key', $rowSearchResult->getPrimaryKeyValue()); foreach (array_keys($replacementData) as $columnName) { $queryBuilder->set('subject.' . $columnName, ':' . $columnName); } // Update using primary key if (null !== $rowSearchResult->getPrimaryKeyColumn()) { $queryBuilder->where('subject.' . $rowSearchResult->getPrimaryKeyColumn()->getColumnName() . ' = :key'); // Update using original values } else { $whereCount = 0; foreach ($rowReplaceResult->getFieldResultList() as $fieldReplaceResult) { $columnName = $fieldReplaceResult->getColumnMetadata()->getColumnName(); $whereClause = 'subject.' . $columnName . ' = :old_' . $columnName; if (0 === $whereCount) { $queryBuilder->where($whereClause); } else { $queryBuilder->andWhere($whereClause); } $queryBuilder->setParameter('old_' . $columnName, $fieldReplaceResult->getOldValue()); } } // TODO: handle exception $queryBuilder->execute(); if (0 === ($rowCount % $batchSize)) { $connection->query('COMMIT'); $connection->query('START TRANSACTION'); } yield $rowReplaceResult; } if (0 !== ($rowCount % $batchSize)) { $connection->query('COMMIT'); } }
[ "public", "function", "replaceTable", "(", "Connection", "$", "connection", ",", "string", "$", "databaseName", ",", "string", "$", "tableName", ",", "string", "$", "searchTerm", ",", "string", "$", "replaceTerm", ",", "int", "$", "batchSize", "=", "100", ")", ":", "\\", "Generator", "{", "$", "connection", "->", "query", "(", "'START TRANSACTION'", ")", ";", "$", "rowCount", "=", "0", ";", "$", "rowSearchResultList", "=", "(", "new", "Search", "(", ")", ")", "->", "searchTable", "(", "$", "connection", ",", "$", "databaseName", ",", "$", "tableName", ",", "$", "searchTerm", ")", ";", "foreach", "(", "$", "rowSearchResultList", "as", "$", "rowSearchResult", ")", "{", "$", "rowCount", "++", ";", "$", "rowReplaceResult", "=", "$", "this", "->", "replaceFields", "(", "$", "rowSearchResult", ",", "$", "searchTerm", ",", "$", "replaceTerm", ")", ";", "$", "queryBuilder", "=", "$", "connection", "->", "createQueryBuilder", "(", ")", ";", "// Build key => value mapping of replacement data", "$", "replacementData", "=", "[", "]", ";", "foreach", "(", "$", "rowReplaceResult", "->", "getFieldResultList", "(", ")", "as", "$", "fieldReplacementResult", ")", "{", "$", "replacementData", "[", "$", "fieldReplacementResult", "->", "getColumnMetadata", "(", ")", "->", "getColumnName", "(", ")", "]", "=", "$", "fieldReplacementResult", "->", "getNewValue", "(", ")", ";", "}", "$", "queryBuilder", "->", "update", "(", "'`'", ".", "$", "rowSearchResult", "->", "getTableMetadata", "(", ")", "->", "getDatabaseName", "(", ")", ".", "'`.`'", ".", "$", "rowSearchResult", "->", "getTableMetadata", "(", ")", "->", "getTableName", "(", ")", ".", "'`'", ",", "'subject'", ")", "->", "setParameters", "(", "$", "replacementData", ")", "->", "setParameter", "(", "'key'", ",", "$", "rowSearchResult", "->", "getPrimaryKeyValue", "(", ")", ")", ";", "foreach", "(", "array_keys", "(", "$", "replacementData", ")", "as", "$", "columnName", ")", "{", "$", "queryBuilder", "->", "set", "(", "'subject.'", ".", "$", "columnName", ",", "':'", ".", "$", "columnName", ")", ";", "}", "// Update using primary key", "if", "(", "null", "!==", "$", "rowSearchResult", "->", "getPrimaryKeyColumn", "(", ")", ")", "{", "$", "queryBuilder", "->", "where", "(", "'subject.'", ".", "$", "rowSearchResult", "->", "getPrimaryKeyColumn", "(", ")", "->", "getColumnName", "(", ")", ".", "' = :key'", ")", ";", "// Update using original values", "}", "else", "{", "$", "whereCount", "=", "0", ";", "foreach", "(", "$", "rowReplaceResult", "->", "getFieldResultList", "(", ")", "as", "$", "fieldReplaceResult", ")", "{", "$", "columnName", "=", "$", "fieldReplaceResult", "->", "getColumnMetadata", "(", ")", "->", "getColumnName", "(", ")", ";", "$", "whereClause", "=", "'subject.'", ".", "$", "columnName", ".", "' = :old_'", ".", "$", "columnName", ";", "if", "(", "0", "===", "$", "whereCount", ")", "{", "$", "queryBuilder", "->", "where", "(", "$", "whereClause", ")", ";", "}", "else", "{", "$", "queryBuilder", "->", "andWhere", "(", "$", "whereClause", ")", ";", "}", "$", "queryBuilder", "->", "setParameter", "(", "'old_'", ".", "$", "columnName", ",", "$", "fieldReplaceResult", "->", "getOldValue", "(", ")", ")", ";", "}", "}", "// TODO: handle exception", "$", "queryBuilder", "->", "execute", "(", ")", ";", "if", "(", "0", "===", "(", "$", "rowCount", "%", "$", "batchSize", ")", ")", "{", "$", "connection", "->", "query", "(", "'COMMIT'", ")", ";", "$", "connection", "->", "query", "(", "'START TRANSACTION'", ")", ";", "}", "yield", "$", "rowReplaceResult", ";", "}", "if", "(", "0", "!==", "(", "$", "rowCount", "%", "$", "batchSize", ")", ")", "{", "$", "connection", "->", "query", "(", "'COMMIT'", ")", ";", "}", "}" ]
Performs a search on the provided table, batching queries to the specified batch size. @return \Generator|RowReplaceResult[]
[ "Performs", "a", "search", "on", "the", "provided", "table", "batching", "queries", "to", "the", "specified", "batch", "size", "." ]
7abff68982d426690d0515ccd7adc7a2e3d72a3f
https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Replace/Replace.php#L81-L153
train
ptlis/grep-db
src/Replace/Replace.php
Replace.replace
private function replace( ColumnMetadata $columnMetadata, string $searchTerm, string $replaceTerm, string $subject ): FieldReplaceResult { $fieldReplaced = null; foreach ($this->replacementStrategyList as $replacementStrategy) { if ($replacementStrategy->canReplace($searchTerm, $subject)) { $fieldReplaced = $replacementStrategy->replace( $columnMetadata, $searchTerm, $replaceTerm, $subject ); break; } } if (is_null($fieldReplaced)) { throw new \RuntimeException('Error trying to replace "' . $searchTerm . '" with "' . $replaceTerm . '"'); } return $fieldReplaced; }
php
private function replace( ColumnMetadata $columnMetadata, string $searchTerm, string $replaceTerm, string $subject ): FieldReplaceResult { $fieldReplaced = null; foreach ($this->replacementStrategyList as $replacementStrategy) { if ($replacementStrategy->canReplace($searchTerm, $subject)) { $fieldReplaced = $replacementStrategy->replace( $columnMetadata, $searchTerm, $replaceTerm, $subject ); break; } } if (is_null($fieldReplaced)) { throw new \RuntimeException('Error trying to replace "' . $searchTerm . '" with "' . $replaceTerm . '"'); } return $fieldReplaced; }
[ "private", "function", "replace", "(", "ColumnMetadata", "$", "columnMetadata", ",", "string", "$", "searchTerm", ",", "string", "$", "replaceTerm", ",", "string", "$", "subject", ")", ":", "FieldReplaceResult", "{", "$", "fieldReplaced", "=", "null", ";", "foreach", "(", "$", "this", "->", "replacementStrategyList", "as", "$", "replacementStrategy", ")", "{", "if", "(", "$", "replacementStrategy", "->", "canReplace", "(", "$", "searchTerm", ",", "$", "subject", ")", ")", "{", "$", "fieldReplaced", "=", "$", "replacementStrategy", "->", "replace", "(", "$", "columnMetadata", ",", "$", "searchTerm", ",", "$", "replaceTerm", ",", "$", "subject", ")", ";", "break", ";", "}", "}", "if", "(", "is_null", "(", "$", "fieldReplaced", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Error trying to replace \"'", ".", "$", "searchTerm", ".", "'\" with \"'", ".", "$", "replaceTerm", ".", "'\"'", ")", ";", "}", "return", "$", "fieldReplaced", ";", "}" ]
Perform the string replacement on the field. @throws \RuntimeException If the replacement fails.
[ "Perform", "the", "string", "replacement", "on", "the", "field", "." ]
7abff68982d426690d0515ccd7adc7a2e3d72a3f
https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Replace/Replace.php#L186-L210
train
AmericanCouncils/Slimfra
src/Application.php
Application.register
public function register(ServiceProviderInterface $provider, array $values = array()) { $this->registeredProviders[get_class($provider)] = true; parent::register($provider, $values); }
php
public function register(ServiceProviderInterface $provider, array $values = array()) { $this->registeredProviders[get_class($provider)] = true; parent::register($provider, $values); }
[ "public", "function", "register", "(", "ServiceProviderInterface", "$", "provider", ",", "array", "$", "values", "=", "array", "(", ")", ")", "{", "$", "this", "->", "registeredProviders", "[", "get_class", "(", "$", "provider", ")", "]", "=", "true", ";", "parent", "::", "register", "(", "$", "provider", ",", "$", "values", ")", ";", "}" ]
Keep track of registered providers. {@inheritdoc}
[ "Keep", "track", "of", "registered", "providers", "." ]
17f2b8dc71bc0d7aa6da2ac89bee2b1806a3aeb6
https://github.com/AmericanCouncils/Slimfra/blob/17f2b8dc71bc0d7aa6da2ac89bee2b1806a3aeb6/src/Application.php#L53-L58
train
AmericanCouncils/Slimfra
src/Application.php
Application.handleError
public function handleError($errno, $errstr, $errfile, $errline) { if (!$this['debug']) { return; } throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); }
php
public function handleError($errno, $errstr, $errfile, $errline) { if (!$this['debug']) { return; } throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); }
[ "public", "function", "handleError", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ")", "{", "if", "(", "!", "$", "this", "[", "'debug'", "]", ")", "{", "return", ";", "}", "throw", "new", "\\", "ErrorException", "(", "$", "errstr", ",", "0", ",", "$", "errno", ",", "$", "errfile", ",", "$", "errline", ")", ";", "}" ]
A generic error handler, will convert errors into exceptions in debug mode. @param int $errno @param string $errstr @param string $errfile @param int $errline @throws ErrorException
[ "A", "generic", "error", "handler", "will", "convert", "errors", "into", "exceptions", "in", "debug", "mode", "." ]
17f2b8dc71bc0d7aa6da2ac89bee2b1806a3aeb6
https://github.com/AmericanCouncils/Slimfra/blob/17f2b8dc71bc0d7aa6da2ac89bee2b1806a3aeb6/src/Application.php#L103-L110
train
gplcart/ga_report
controllers/Report.php
Report.listReport
public function listReport() { $this->setTitleListReport(); $this->setBreadcrumbListReport(); $this->clearCacheReport(); $this->setData('stores', $this->store->getList()); $this->setData('panels', $this->getPanelsReport()); $default = $this->module->getSettings('ga_report', 'store_id'); $this->setData('ga_store_id', $this->getQuery('ga.update.store_id', $default)); $this->outputListReport(); }
php
public function listReport() { $this->setTitleListReport(); $this->setBreadcrumbListReport(); $this->clearCacheReport(); $this->setData('stores', $this->store->getList()); $this->setData('panels', $this->getPanelsReport()); $default = $this->module->getSettings('ga_report', 'store_id'); $this->setData('ga_store_id', $this->getQuery('ga.update.store_id', $default)); $this->outputListReport(); }
[ "public", "function", "listReport", "(", ")", "{", "$", "this", "->", "setTitleListReport", "(", ")", ";", "$", "this", "->", "setBreadcrumbListReport", "(", ")", ";", "$", "this", "->", "clearCacheReport", "(", ")", ";", "$", "this", "->", "setData", "(", "'stores'", ",", "$", "this", "->", "store", "->", "getList", "(", ")", ")", ";", "$", "this", "->", "setData", "(", "'panels'", ",", "$", "this", "->", "getPanelsReport", "(", ")", ")", ";", "$", "default", "=", "$", "this", "->", "module", "->", "getSettings", "(", "'ga_report'", ",", "'store_id'", ")", ";", "$", "this", "->", "setData", "(", "'ga_store_id'", ",", "$", "this", "->", "getQuery", "(", "'ga.update.store_id'", ",", "$", "default", ")", ")", ";", "$", "this", "->", "outputListReport", "(", ")", ";", "}" ]
Route callback Displays the report page
[ "Route", "callback", "Displays", "the", "report", "page" ]
856a480e394bb3feaeea4785ccccad56abaac499
https://github.com/gplcart/ga_report/blob/856a480e394bb3feaeea4785ccccad56abaac499/controllers/Report.php#L41-L54
train
gplcart/ga_report
controllers/Report.php
Report.getPanelsReport
protected function getPanelsReport() { $settings = $this->module->getSettings('ga_report'); $store_id = $this->getQuery('ga.update.store_id'); if (!empty($store_id)) { $settings['store_id'] = $store_id; } $panels = array(); foreach ($this->report_model->getHandlers() as $handler) { $report = $this->report_model->get($handler, $settings); $data = array( 'content' => array( 'data' => array( // We need so deep nesting for compatibility with dashboard panel templates 'report' => $report, 'handler' => $handler, 'settings' => $settings ) ) ); $panels[$handler['id']] = array('rendered' => $this->render($handler['template'], $data)); } return gplcart_array_split($panels, 3); // Split by columns }
php
protected function getPanelsReport() { $settings = $this->module->getSettings('ga_report'); $store_id = $this->getQuery('ga.update.store_id'); if (!empty($store_id)) { $settings['store_id'] = $store_id; } $panels = array(); foreach ($this->report_model->getHandlers() as $handler) { $report = $this->report_model->get($handler, $settings); $data = array( 'content' => array( 'data' => array( // We need so deep nesting for compatibility with dashboard panel templates 'report' => $report, 'handler' => $handler, 'settings' => $settings ) ) ); $panels[$handler['id']] = array('rendered' => $this->render($handler['template'], $data)); } return gplcart_array_split($panels, 3); // Split by columns }
[ "protected", "function", "getPanelsReport", "(", ")", "{", "$", "settings", "=", "$", "this", "->", "module", "->", "getSettings", "(", "'ga_report'", ")", ";", "$", "store_id", "=", "$", "this", "->", "getQuery", "(", "'ga.update.store_id'", ")", ";", "if", "(", "!", "empty", "(", "$", "store_id", ")", ")", "{", "$", "settings", "[", "'store_id'", "]", "=", "$", "store_id", ";", "}", "$", "panels", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "report_model", "->", "getHandlers", "(", ")", "as", "$", "handler", ")", "{", "$", "report", "=", "$", "this", "->", "report_model", "->", "get", "(", "$", "handler", ",", "$", "settings", ")", ";", "$", "data", "=", "array", "(", "'content'", "=>", "array", "(", "'data'", "=>", "array", "(", "// We need so deep nesting for compatibility with dashboard panel templates", "'report'", "=>", "$", "report", ",", "'handler'", "=>", "$", "handler", ",", "'settings'", "=>", "$", "settings", ")", ")", ")", ";", "$", "panels", "[", "$", "handler", "[", "'id'", "]", "]", "=", "array", "(", "'rendered'", "=>", "$", "this", "->", "render", "(", "$", "handler", "[", "'template'", "]", ",", "$", "data", ")", ")", ";", "}", "return", "gplcart_array_split", "(", "$", "panels", ",", "3", ")", ";", "// Split by columns", "}" ]
Returns an array of report panels @return array
[ "Returns", "an", "array", "of", "report", "panels" ]
856a480e394bb3feaeea4785ccccad56abaac499
https://github.com/gplcart/ga_report/blob/856a480e394bb3feaeea4785ccccad56abaac499/controllers/Report.php#L93-L122
train
Vectrex/vxPHP
src/Routing/DefaultRouteAuthenticator.php
DefaultRouteAuthenticator.handleViolation
public function handleViolation(Route $route) { if(in_array($route, $this->violatingRoutes)) { throw new ApplicationException('Circular redirects detected; aborting.'); } // to avoid circular references all redirects are logged $this->violatingRoutes[] = $route; Session::getSessionDataBag()->set('authViolatingRequest', Request::createFromGlobals()); if($redirect = $route->getRedirect()) { return Application::getInstance()->getRouter()->getRoute($redirect); } else { throw new \RuntimeException(sprintf("No redirect configured for route '%s', which cannot be authenticated.", $route->getRouteId())); } }
php
public function handleViolation(Route $route) { if(in_array($route, $this->violatingRoutes)) { throw new ApplicationException('Circular redirects detected; aborting.'); } // to avoid circular references all redirects are logged $this->violatingRoutes[] = $route; Session::getSessionDataBag()->set('authViolatingRequest', Request::createFromGlobals()); if($redirect = $route->getRedirect()) { return Application::getInstance()->getRouter()->getRoute($redirect); } else { throw new \RuntimeException(sprintf("No redirect configured for route '%s', which cannot be authenticated.", $route->getRouteId())); } }
[ "public", "function", "handleViolation", "(", "Route", "$", "route", ")", "{", "if", "(", "in_array", "(", "$", "route", ",", "$", "this", "->", "violatingRoutes", ")", ")", "{", "throw", "new", "ApplicationException", "(", "'Circular redirects detected; aborting.'", ")", ";", "}", "// to avoid circular references all redirects are logged", "$", "this", "->", "violatingRoutes", "[", "]", "=", "$", "route", ";", "Session", "::", "getSessionDataBag", "(", ")", "->", "set", "(", "'authViolatingRequest'", ",", "Request", "::", "createFromGlobals", "(", ")", ")", ";", "if", "(", "$", "redirect", "=", "$", "route", "->", "getRedirect", "(", ")", ")", "{", "return", "Application", "::", "getInstance", "(", ")", "->", "getRouter", "(", ")", "->", "getRoute", "(", "$", "redirect", ")", ";", "}", "else", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "\"No redirect configured for route '%s', which cannot be authenticated.\"", ",", "$", "route", "->", "getRouteId", "(", ")", ")", ")", ";", "}", "}" ]
handle authentication violation by trying to find a redirecting route @param Route $route @return mixed|Route @throws \vxPHP\Application\Exception\ApplicationException
[ "handle", "authentication", "violation", "by", "trying", "to", "find", "a", "redirecting", "route" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Routing/DefaultRouteAuthenticator.php#L97-L118
train
agentmedia/phine-core
src/Core/Logic/Tree/ListProvider.php
ListProvider.ToArray
function ToArray() { $result = array(); $item = $this->TopMost(); while ($item) { $result[] = $item; $item = $this->NextOf($item); } return $result; }
php
function ToArray() { $result = array(); $item = $this->TopMost(); while ($item) { $result[] = $item; $item = $this->NextOf($item); } return $result; }
[ "function", "ToArray", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "item", "=", "$", "this", "->", "TopMost", "(", ")", ";", "while", "(", "$", "item", ")", "{", "$", "result", "[", "]", "=", "$", "item", ";", "$", "item", "=", "$", "this", "->", "NextOf", "(", "$", "item", ")", ";", "}", "return", "$", "result", ";", "}" ]
Gets the sorted item list @return mixed[] Returns the items in their given order
[ "Gets", "the", "sorted", "item", "list" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Tree/ListProvider.php#L29-L39
train
agentmedia/phine-core
src/Core/Logic/Tree/ListProvider.php
ListProvider.Last
function Last() { $items = $this->ToArray(); $cnt = count($items); return $cnt > 0 ? $items[$cnt -1] : null; }
php
function Last() { $items = $this->ToArray(); $cnt = count($items); return $cnt > 0 ? $items[$cnt -1] : null; }
[ "function", "Last", "(", ")", "{", "$", "items", "=", "$", "this", "->", "ToArray", "(", ")", ";", "$", "cnt", "=", "count", "(", "$", "items", ")", ";", "return", "$", "cnt", ">", "0", "?", "$", "items", "[", "$", "cnt", "-", "1", "]", ":", "null", ";", "}" ]
Gets the last item @return mixed Retuens the last list item
[ "Gets", "the", "last", "item" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Tree/ListProvider.php#L45-L49
train
codeblanche/Web
src/Web/Route/Rules/UriRule.php
UriRule.complexity
public function complexity() { $dynamicPartsCount = substr_count($this->pattern, ':') + substr_count($this->pattern, '?'); return (substr_count($this->pattern, '/') - $dynamicPartsCount) * 100 + $dynamicPartsCount; }
php
public function complexity() { $dynamicPartsCount = substr_count($this->pattern, ':') + substr_count($this->pattern, '?'); return (substr_count($this->pattern, '/') - $dynamicPartsCount) * 100 + $dynamicPartsCount; }
[ "public", "function", "complexity", "(", ")", "{", "$", "dynamicPartsCount", "=", "substr_count", "(", "$", "this", "->", "pattern", ",", "':'", ")", "+", "substr_count", "(", "$", "this", "->", "pattern", ",", "'?'", ")", ";", "return", "(", "substr_count", "(", "$", "this", "->", "pattern", ",", "'/'", ")", "-", "$", "dynamicPartsCount", ")", "*", "100", "+", "$", "dynamicPartsCount", ";", "}" ]
Count the number of pattern segments for this rule.
[ "Count", "the", "number", "of", "pattern", "segments", "for", "this", "rule", "." ]
3e9ebf1943d3ea468f619ba99f7cc10714cb16e9
https://github.com/codeblanche/Web/blob/3e9ebf1943d3ea468f619ba99f7cc10714cb16e9/src/Web/Route/Rules/UriRule.php#L12-L17
train
nice-php/benchmark
src/ResultPruner/StandardDeviationPruner.php
StandardDeviationPruner.prune
public function prune(array $results) { $mean = array_sum($results) / count($results); $deviation = $this->deviations * $this->standardDeviation($results); $lower = $mean - $deviation; $upper = $mean + $deviation; return array_values(array_filter($results, function ($val) use ($lower, $upper) { return $val >= $lower && $val <= $upper; })); }
php
public function prune(array $results) { $mean = array_sum($results) / count($results); $deviation = $this->deviations * $this->standardDeviation($results); $lower = $mean - $deviation; $upper = $mean + $deviation; return array_values(array_filter($results, function ($val) use ($lower, $upper) { return $val >= $lower && $val <= $upper; })); }
[ "public", "function", "prune", "(", "array", "$", "results", ")", "{", "$", "mean", "=", "array_sum", "(", "$", "results", ")", "/", "count", "(", "$", "results", ")", ";", "$", "deviation", "=", "$", "this", "->", "deviations", "*", "$", "this", "->", "standardDeviation", "(", "$", "results", ")", ";", "$", "lower", "=", "$", "mean", "-", "$", "deviation", ";", "$", "upper", "=", "$", "mean", "+", "$", "deviation", ";", "return", "array_values", "(", "array_filter", "(", "$", "results", ",", "function", "(", "$", "val", ")", "use", "(", "$", "lower", ",", "$", "upper", ")", "{", "return", "$", "val", ">=", "$", "lower", "&&", "$", "val", "<=", "$", "upper", ";", "}", ")", ")", ";", "}" ]
Prune the results @param array $results @return array The pruned results
[ "Prune", "the", "results" ]
2084c77dbb88cd76006abbfe85b2b704f6bbd1cf
https://github.com/nice-php/benchmark/blob/2084c77dbb88cd76006abbfe85b2b704f6bbd1cf/src/ResultPruner/StandardDeviationPruner.php#L38-L48
train
nice-php/benchmark
src/ResultPruner/StandardDeviationPruner.php
StandardDeviationPruner.standardDeviation
private function standardDeviation(array $results) { $mean = array_sum($results) / count($results); $initial = 0; $f = function ($carry, $val) use ($mean) { return $carry + pow($val - $mean, 2); }; $sum = array_reduce($results, $f, $initial); $n = count($results) - 1; return $n === 0 ? 0 : sqrt($sum / $n); }
php
private function standardDeviation(array $results) { $mean = array_sum($results) / count($results); $initial = 0; $f = function ($carry, $val) use ($mean) { return $carry + pow($val - $mean, 2); }; $sum = array_reduce($results, $f, $initial); $n = count($results) - 1; return $n === 0 ? 0 : sqrt($sum / $n); }
[ "private", "function", "standardDeviation", "(", "array", "$", "results", ")", "{", "$", "mean", "=", "array_sum", "(", "$", "results", ")", "/", "count", "(", "$", "results", ")", ";", "$", "initial", "=", "0", ";", "$", "f", "=", "function", "(", "$", "carry", ",", "$", "val", ")", "use", "(", "$", "mean", ")", "{", "return", "$", "carry", "+", "pow", "(", "$", "val", "-", "$", "mean", ",", "2", ")", ";", "}", ";", "$", "sum", "=", "array_reduce", "(", "$", "results", ",", "$", "f", ",", "$", "initial", ")", ";", "$", "n", "=", "count", "(", "$", "results", ")", "-", "1", ";", "return", "$", "n", "===", "0", "?", "0", ":", "sqrt", "(", "$", "sum", "/", "$", "n", ")", ";", "}" ]
Returns one standard deviation for the given results @param array $results @return float
[ "Returns", "one", "standard", "deviation", "for", "the", "given", "results" ]
2084c77dbb88cd76006abbfe85b2b704f6bbd1cf
https://github.com/nice-php/benchmark/blob/2084c77dbb88cd76006abbfe85b2b704f6bbd1cf/src/ResultPruner/StandardDeviationPruner.php#L57-L68
train
nails/module-blog
admin/controllers/Tag.php
Tag.index
public function index() { // Page data $this->data['page']->title = 'Blog &rsaquo; Tags'; // -------------------------------------------------------------------------- $data = array(); $data['include_count'] = true; $data['where'] = array(); $data['where'][] = array('column' => 'blog_id', 'value' => $this->blog->id); $this->data['tags'] = $this->blog_tag_model->getAll(null, null, $data); // -------------------------------------------------------------------------- Helper::loadView('index'); }
php
public function index() { // Page data $this->data['page']->title = 'Blog &rsaquo; Tags'; // -------------------------------------------------------------------------- $data = array(); $data['include_count'] = true; $data['where'] = array(); $data['where'][] = array('column' => 'blog_id', 'value' => $this->blog->id); $this->data['tags'] = $this->blog_tag_model->getAll(null, null, $data); // -------------------------------------------------------------------------- Helper::loadView('index'); }
[ "public", "function", "index", "(", ")", "{", "// Page data", "$", "this", "->", "data", "[", "'page'", "]", "->", "title", "=", "'Blog &rsaquo; Tags'", ";", "// --------------------------------------------------------------------------", "$", "data", "=", "array", "(", ")", ";", "$", "data", "[", "'include_count'", "]", "=", "true", ";", "$", "data", "[", "'where'", "]", "=", "array", "(", ")", ";", "$", "data", "[", "'where'", "]", "[", "]", "=", "array", "(", "'column'", "=>", "'blog_id'", ",", "'value'", "=>", "$", "this", "->", "blog", "->", "id", ")", ";", "$", "this", "->", "data", "[", "'tags'", "]", "=", "$", "this", "->", "blog_tag_model", "->", "getAll", "(", "null", ",", "null", ",", "$", "data", ")", ";", "// --------------------------------------------------------------------------", "Helper", "::", "loadView", "(", "'index'", ")", ";", "}" ]
Browse blog tags @return void
[ "Browse", "blog", "tags" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/admin/controllers/Tag.php#L154-L171
train
nails/module-blog
admin/controllers/Tag.php
Tag.create
public function create() { if (!userHasPermission('admin:blog:tag:' . $this->blog->id . ':create')) { unauthorised(); } // -------------------------------------------------------------------------- if ($this->input->post()) { $oFormValidation = Factory::service('FormValidation'); $oFormValidation->set_rules('label', '', 'required'); $oFormValidation->set_rules('description', '', ''); $oFormValidation->set_rules('seo_title', '', 'max_length[150]'); $oFormValidation->set_rules('seo_description', '', 'max_length[300]'); $oFormValidation->set_rules('seo_keywords', '', 'max_length[150]'); $oFormValidation->set_message('required', lang('fv_required')); $oFormValidation->set_message('max_length', lang('fv_max_length')); if ($oFormValidation->run()) { $aInsertData = array(); $aInsertData['blog_id'] = $this->blog->id; $aInsertData['label'] = $this->input->post('label'); $aInsertData['description'] = $this->input->post('description'); $aInsertData['seo_title'] = $this->input->post('seo_title'); $aInsertData['seo_description'] = $this->input->post('seo_description'); $aInsertData['seo_keywords'] = $this->input->post('seo_keywords'); if ($this->blog_tag_model->create($aInsertData)) { $status = 'success'; $message = 'Tag created successfully.'; $this->session->set_flashdata($status, $message); redirect('admin/blog/tag/index/' . $this->blog->id . $this->isModal); } else { $this->data['error'] = 'There was a problem creating the Tag. '; $this->data['error'] .= $this->blog_tag_model->lastError(); } } else { $this->data['error'] = lang('fv_there_were_errors'); } } // -------------------------------------------------------------------------- // Page data $this->data['page']->title = 'Blog &rsaquo; Tags &rsaquo; Create'; // -------------------------------------------------------------------------- // Fetch data $this->data['tags'] = $this->blog_tag_model->getAll(); // -------------------------------------------------------------------------- // Load views Helper::loadView('edit'); }
php
public function create() { if (!userHasPermission('admin:blog:tag:' . $this->blog->id . ':create')) { unauthorised(); } // -------------------------------------------------------------------------- if ($this->input->post()) { $oFormValidation = Factory::service('FormValidation'); $oFormValidation->set_rules('label', '', 'required'); $oFormValidation->set_rules('description', '', ''); $oFormValidation->set_rules('seo_title', '', 'max_length[150]'); $oFormValidation->set_rules('seo_description', '', 'max_length[300]'); $oFormValidation->set_rules('seo_keywords', '', 'max_length[150]'); $oFormValidation->set_message('required', lang('fv_required')); $oFormValidation->set_message('max_length', lang('fv_max_length')); if ($oFormValidation->run()) { $aInsertData = array(); $aInsertData['blog_id'] = $this->blog->id; $aInsertData['label'] = $this->input->post('label'); $aInsertData['description'] = $this->input->post('description'); $aInsertData['seo_title'] = $this->input->post('seo_title'); $aInsertData['seo_description'] = $this->input->post('seo_description'); $aInsertData['seo_keywords'] = $this->input->post('seo_keywords'); if ($this->blog_tag_model->create($aInsertData)) { $status = 'success'; $message = 'Tag created successfully.'; $this->session->set_flashdata($status, $message); redirect('admin/blog/tag/index/' . $this->blog->id . $this->isModal); } else { $this->data['error'] = 'There was a problem creating the Tag. '; $this->data['error'] .= $this->blog_tag_model->lastError(); } } else { $this->data['error'] = lang('fv_there_were_errors'); } } // -------------------------------------------------------------------------- // Page data $this->data['page']->title = 'Blog &rsaquo; Tags &rsaquo; Create'; // -------------------------------------------------------------------------- // Fetch data $this->data['tags'] = $this->blog_tag_model->getAll(); // -------------------------------------------------------------------------- // Load views Helper::loadView('edit'); }
[ "public", "function", "create", "(", ")", "{", "if", "(", "!", "userHasPermission", "(", "'admin:blog:tag:'", ".", "$", "this", "->", "blog", "->", "id", ".", "':create'", ")", ")", "{", "unauthorised", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "if", "(", "$", "this", "->", "input", "->", "post", "(", ")", ")", "{", "$", "oFormValidation", "=", "Factory", "::", "service", "(", "'FormValidation'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'label'", ",", "''", ",", "'required'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'description'", ",", "''", ",", "''", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'seo_title'", ",", "''", ",", "'max_length[150]'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'seo_description'", ",", "''", ",", "'max_length[300]'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'seo_keywords'", ",", "''", ",", "'max_length[150]'", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'required'", ",", "lang", "(", "'fv_required'", ")", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'max_length'", ",", "lang", "(", "'fv_max_length'", ")", ")", ";", "if", "(", "$", "oFormValidation", "->", "run", "(", ")", ")", "{", "$", "aInsertData", "=", "array", "(", ")", ";", "$", "aInsertData", "[", "'blog_id'", "]", "=", "$", "this", "->", "blog", "->", "id", ";", "$", "aInsertData", "[", "'label'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'label'", ")", ";", "$", "aInsertData", "[", "'description'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'description'", ")", ";", "$", "aInsertData", "[", "'seo_title'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'seo_title'", ")", ";", "$", "aInsertData", "[", "'seo_description'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'seo_description'", ")", ";", "$", "aInsertData", "[", "'seo_keywords'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'seo_keywords'", ")", ";", "if", "(", "$", "this", "->", "blog_tag_model", "->", "create", "(", "$", "aInsertData", ")", ")", "{", "$", "status", "=", "'success'", ";", "$", "message", "=", "'Tag created successfully.'", ";", "$", "this", "->", "session", "->", "set_flashdata", "(", "$", "status", ",", "$", "message", ")", ";", "redirect", "(", "'admin/blog/tag/index/'", ".", "$", "this", "->", "blog", "->", "id", ".", "$", "this", "->", "isModal", ")", ";", "}", "else", "{", "$", "this", "->", "data", "[", "'error'", "]", "=", "'There was a problem creating the Tag. '", ";", "$", "this", "->", "data", "[", "'error'", "]", ".=", "$", "this", "->", "blog_tag_model", "->", "lastError", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "data", "[", "'error'", "]", "=", "lang", "(", "'fv_there_were_errors'", ")", ";", "}", "}", "// --------------------------------------------------------------------------", "// Page data", "$", "this", "->", "data", "[", "'page'", "]", "->", "title", "=", "'Blog &rsaquo; Tags &rsaquo; Create'", ";", "// --------------------------------------------------------------------------", "// Fetch data", "$", "this", "->", "data", "[", "'tags'", "]", "=", "$", "this", "->", "blog_tag_model", "->", "getAll", "(", ")", ";", "// --------------------------------------------------------------------------", "// Load views", "Helper", "::", "loadView", "(", "'edit'", ")", ";", "}" ]
Create a new blog tag @return void
[ "Create", "a", "new", "blog", "tag" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/admin/controllers/Tag.php#L179-L244
train
nails/module-blog
admin/controllers/Tag.php
Tag.edit
public function edit() { if (!userHasPermission('admin:blog:tag:' . $this->blog->id . ':edit')) { unauthorised(); } // -------------------------------------------------------------------------- $this->data['tag'] = $this->blog_tag_model->getById($this->uri->segment(6)); if (empty($this->data['tag'])) { show404(); } // -------------------------------------------------------------------------- if ($this->input->post()) { $oFormValidation = Factory::service('FormValidation'); $oFormValidation->set_rules('label', '', 'required'); $oFormValidation->set_rules('description', '', ''); $oFormValidation->set_rules('seo_title', '', 'max_length[150]'); $oFormValidation->set_rules('seo_description', '', 'max_length[300]'); $oFormValidation->set_rules('seo_keywords', '', 'max_length[150]'); $oFormValidation->set_message('required', lang('fv_required')); $oFormValidation->set_message('max_length', lang('fv_max_length')); if ($oFormValidation->run()) { $aUpdateData = array(); $aUpdateData['label'] = $this->input->post('label'); $aUpdateData['description'] = $this->input->post('description'); $aUpdateData['seo_title'] = $this->input->post('seo_title'); $aUpdateData['seo_description'] = $this->input->post('seo_description'); $aUpdateData['seo_keywords'] = $this->input->post('seo_keywords'); if ($this->blog_tag_model->update($this->data['tag']->id, $aUpdateData)) { $this->session->set_flashdata('success', 'Tag saved successfully.'); redirect('admin/blog/tag/index/' . $this->blog->id . $this->isModal); } else { $this->data['error'] = 'There was a problem saving the Tag. '; $this->data['error'] .= $this->blog_tag_model->lastError(); } } else { $this->data['error'] = lang('fv_there_were_errors'); } } // -------------------------------------------------------------------------- // Page data $this->data['page']->title = 'Blog &rsaquo; Catrgories &rsaquo; Edit &rsaquo; ' . $this->data['tag']->label; // -------------------------------------------------------------------------- // Fetch data $this->data['tags'] = $this->blog_tag_model->getAll(); // -------------------------------------------------------------------------- // Load views Helper::loadView('edit'); }
php
public function edit() { if (!userHasPermission('admin:blog:tag:' . $this->blog->id . ':edit')) { unauthorised(); } // -------------------------------------------------------------------------- $this->data['tag'] = $this->blog_tag_model->getById($this->uri->segment(6)); if (empty($this->data['tag'])) { show404(); } // -------------------------------------------------------------------------- if ($this->input->post()) { $oFormValidation = Factory::service('FormValidation'); $oFormValidation->set_rules('label', '', 'required'); $oFormValidation->set_rules('description', '', ''); $oFormValidation->set_rules('seo_title', '', 'max_length[150]'); $oFormValidation->set_rules('seo_description', '', 'max_length[300]'); $oFormValidation->set_rules('seo_keywords', '', 'max_length[150]'); $oFormValidation->set_message('required', lang('fv_required')); $oFormValidation->set_message('max_length', lang('fv_max_length')); if ($oFormValidation->run()) { $aUpdateData = array(); $aUpdateData['label'] = $this->input->post('label'); $aUpdateData['description'] = $this->input->post('description'); $aUpdateData['seo_title'] = $this->input->post('seo_title'); $aUpdateData['seo_description'] = $this->input->post('seo_description'); $aUpdateData['seo_keywords'] = $this->input->post('seo_keywords'); if ($this->blog_tag_model->update($this->data['tag']->id, $aUpdateData)) { $this->session->set_flashdata('success', 'Tag saved successfully.'); redirect('admin/blog/tag/index/' . $this->blog->id . $this->isModal); } else { $this->data['error'] = 'There was a problem saving the Tag. '; $this->data['error'] .= $this->blog_tag_model->lastError(); } } else { $this->data['error'] = lang('fv_there_were_errors'); } } // -------------------------------------------------------------------------- // Page data $this->data['page']->title = 'Blog &rsaquo; Catrgories &rsaquo; Edit &rsaquo; ' . $this->data['tag']->label; // -------------------------------------------------------------------------- // Fetch data $this->data['tags'] = $this->blog_tag_model->getAll(); // -------------------------------------------------------------------------- // Load views Helper::loadView('edit'); }
[ "public", "function", "edit", "(", ")", "{", "if", "(", "!", "userHasPermission", "(", "'admin:blog:tag:'", ".", "$", "this", "->", "blog", "->", "id", ".", "':edit'", ")", ")", "{", "unauthorised", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "$", "this", "->", "data", "[", "'tag'", "]", "=", "$", "this", "->", "blog_tag_model", "->", "getById", "(", "$", "this", "->", "uri", "->", "segment", "(", "6", ")", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "data", "[", "'tag'", "]", ")", ")", "{", "show404", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "if", "(", "$", "this", "->", "input", "->", "post", "(", ")", ")", "{", "$", "oFormValidation", "=", "Factory", "::", "service", "(", "'FormValidation'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'label'", ",", "''", ",", "'required'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'description'", ",", "''", ",", "''", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'seo_title'", ",", "''", ",", "'max_length[150]'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'seo_description'", ",", "''", ",", "'max_length[300]'", ")", ";", "$", "oFormValidation", "->", "set_rules", "(", "'seo_keywords'", ",", "''", ",", "'max_length[150]'", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'required'", ",", "lang", "(", "'fv_required'", ")", ")", ";", "$", "oFormValidation", "->", "set_message", "(", "'max_length'", ",", "lang", "(", "'fv_max_length'", ")", ")", ";", "if", "(", "$", "oFormValidation", "->", "run", "(", ")", ")", "{", "$", "aUpdateData", "=", "array", "(", ")", ";", "$", "aUpdateData", "[", "'label'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'label'", ")", ";", "$", "aUpdateData", "[", "'description'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'description'", ")", ";", "$", "aUpdateData", "[", "'seo_title'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'seo_title'", ")", ";", "$", "aUpdateData", "[", "'seo_description'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'seo_description'", ")", ";", "$", "aUpdateData", "[", "'seo_keywords'", "]", "=", "$", "this", "->", "input", "->", "post", "(", "'seo_keywords'", ")", ";", "if", "(", "$", "this", "->", "blog_tag_model", "->", "update", "(", "$", "this", "->", "data", "[", "'tag'", "]", "->", "id", ",", "$", "aUpdateData", ")", ")", "{", "$", "this", "->", "session", "->", "set_flashdata", "(", "'success'", ",", "'Tag saved successfully.'", ")", ";", "redirect", "(", "'admin/blog/tag/index/'", ".", "$", "this", "->", "blog", "->", "id", ".", "$", "this", "->", "isModal", ")", ";", "}", "else", "{", "$", "this", "->", "data", "[", "'error'", "]", "=", "'There was a problem saving the Tag. '", ";", "$", "this", "->", "data", "[", "'error'", "]", ".=", "$", "this", "->", "blog_tag_model", "->", "lastError", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "data", "[", "'error'", "]", "=", "lang", "(", "'fv_there_were_errors'", ")", ";", "}", "}", "// --------------------------------------------------------------------------", "// Page data", "$", "this", "->", "data", "[", "'page'", "]", "->", "title", "=", "'Blog &rsaquo; Catrgories &rsaquo; Edit &rsaquo; '", ".", "$", "this", "->", "data", "[", "'tag'", "]", "->", "label", ";", "// --------------------------------------------------------------------------", "// Fetch data", "$", "this", "->", "data", "[", "'tags'", "]", "=", "$", "this", "->", "blog_tag_model", "->", "getAll", "(", ")", ";", "// --------------------------------------------------------------------------", "// Load views", "Helper", "::", "loadView", "(", "'edit'", ")", ";", "}" ]
Edit a blog tag @return void
[ "Edit", "a", "blog", "tag" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/admin/controllers/Tag.php#L252-L323
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.addConfiguration
public function addConfiguration(ConfigurationInterface $configuration) { // Clear the parent map. $this->parentMap = null; $id = $configuration->getResourceId(); if (array_key_exists($id, $this->configurations)) { throw new \RuntimeException(sprintf("Configuration for resource '%s' is already registered.", $id)); } $this->configurations[$id] = $configuration; }
php
public function addConfiguration(ConfigurationInterface $configuration) { // Clear the parent map. $this->parentMap = null; $id = $configuration->getResourceId(); if (array_key_exists($id, $this->configurations)) { throw new \RuntimeException(sprintf("Configuration for resource '%s' is already registered.", $id)); } $this->configurations[$id] = $configuration; }
[ "public", "function", "addConfiguration", "(", "ConfigurationInterface", "$", "configuration", ")", "{", "// Clear the parent map.", "$", "this", "->", "parentMap", "=", "null", ";", "$", "id", "=", "$", "configuration", "->", "getResourceId", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "id", ",", "$", "this", "->", "configurations", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "\"Configuration for resource '%s' is already registered.\"", ",", "$", "id", ")", ")", ";", "}", "$", "this", "->", "configurations", "[", "$", "id", "]", "=", "$", "configuration", ";", "}" ]
Adds the resource configuration. @param ConfigurationInterface $configuration @throws \RuntimeException
[ "Adds", "the", "resource", "configuration", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L48-L60
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.get
public function get($id) { if (!$this->has($id)) { throw new \InvalidArgumentException(sprintf('Configuration "%s" not found.', $id)); } return $this->configurations[$id]; }
php
public function get($id) { if (!$this->has($id)) { throw new \InvalidArgumentException(sprintf('Configuration "%s" not found.', $id)); } return $this->configurations[$id]; }
[ "public", "function", "get", "(", "$", "id", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "id", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Configuration \"%s\" not found.'", ",", "$", "id", ")", ")", ";", "}", "return", "$", "this", "->", "configurations", "[", "$", "id", "]", ";", "}" ]
Returns the configuration for the given identifier. @param string $id @throws \InvalidArgumentException @return ConfigurationInterface
[ "Returns", "the", "configuration", "for", "the", "given", "identifier", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L161-L168
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.getAncestors
public function getAncestors(ConfigurationInterface $configuration, $included = false) { $ancestors = []; if ($included) { $ancestors[$configuration->getResourceName()] = $configuration; } while (null !== $configuration->getParentId()) { $configuration = $this->findConfiguration($configuration->getParentId()); $ancestors[$configuration->getResourceName()] = $configuration; } return array_reverse($ancestors); }
php
public function getAncestors(ConfigurationInterface $configuration, $included = false) { $ancestors = []; if ($included) { $ancestors[$configuration->getResourceName()] = $configuration; } while (null !== $configuration->getParentId()) { $configuration = $this->findConfiguration($configuration->getParentId()); $ancestors[$configuration->getResourceName()] = $configuration; } return array_reverse($ancestors); }
[ "public", "function", "getAncestors", "(", "ConfigurationInterface", "$", "configuration", ",", "$", "included", "=", "false", ")", "{", "$", "ancestors", "=", "[", "]", ";", "if", "(", "$", "included", ")", "{", "$", "ancestors", "[", "$", "configuration", "->", "getResourceName", "(", ")", "]", "=", "$", "configuration", ";", "}", "while", "(", "null", "!==", "$", "configuration", "->", "getParentId", "(", ")", ")", "{", "$", "configuration", "=", "$", "this", "->", "findConfiguration", "(", "$", "configuration", "->", "getParentId", "(", ")", ")", ";", "$", "ancestors", "[", "$", "configuration", "->", "getResourceName", "(", ")", "]", "=", "$", "configuration", ";", "}", "return", "array_reverse", "(", "$", "ancestors", ")", ";", "}" ]
Returns all the ancestors configuration. @param ConfigurationInterface $configuration @param bool $included @return ConfigurationInterface[]
[ "Returns", "all", "the", "ancestors", "configuration", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L178-L192
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.getChildren
public function getChildren(ConfigurationInterface $configuration) { $children = []; foreach ($this->configurations as $child) { if ($child->getParentId() === $configuration->getResourceId()) { $children[$child->getResourceName()] = $child; } } return $children; }
php
public function getChildren(ConfigurationInterface $configuration) { $children = []; foreach ($this->configurations as $child) { if ($child->getParentId() === $configuration->getResourceId()) { $children[$child->getResourceName()] = $child; } } return $children; }
[ "public", "function", "getChildren", "(", "ConfigurationInterface", "$", "configuration", ")", "{", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "configurations", "as", "$", "child", ")", "{", "if", "(", "$", "child", "->", "getParentId", "(", ")", "===", "$", "configuration", "->", "getResourceId", "(", ")", ")", "{", "$", "children", "[", "$", "child", "->", "getResourceName", "(", ")", "]", "=", "$", "child", ";", "}", "}", "return", "$", "children", ";", "}" ]
Returns all the children configuration. @param ConfigurationInterface $configuration @return ConfigurationInterface[]
[ "Returns", "all", "the", "children", "configuration", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L201-L212
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.getObjectIdentity
public function getObjectIdentity($object) { foreach ($this->configurations as $config) { if ($config->isRelevant($object)) { return $config->getObjectIdentity(); } } return null; }
php
public function getObjectIdentity($object) { foreach ($this->configurations as $config) { if ($config->isRelevant($object)) { return $config->getObjectIdentity(); } } return null; }
[ "public", "function", "getObjectIdentity", "(", "$", "object", ")", "{", "foreach", "(", "$", "this", "->", "configurations", "as", "$", "config", ")", "{", "if", "(", "$", "config", "->", "isRelevant", "(", "$", "object", ")", ")", "{", "return", "$", "config", "->", "getObjectIdentity", "(", ")", ";", "}", "}", "return", "null", ";", "}" ]
Returns the object identity. @param object $object @return \Symfony\Component\Security\Acl\Domain\ObjectIdentity|null
[ "Returns", "the", "object", "identity", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L231-L240
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.getParentMap
public function getParentMap() { if (null !== $this->parentMap) { return $this->parentMap; } return $this->parentMap = $this->buildParentMap(); }
php
public function getParentMap() { if (null !== $this->parentMap) { return $this->parentMap; } return $this->parentMap = $this->buildParentMap(); }
[ "public", "function", "getParentMap", "(", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "parentMap", ")", "{", "return", "$", "this", "->", "parentMap", ";", "}", "return", "$", "this", "->", "parentMap", "=", "$", "this", "->", "buildParentMap", "(", ")", ";", "}" ]
Returns the hierarchy map. @return array
[ "Returns", "the", "hierarchy", "map", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L247-L254
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.getEventPriorityMap
public function getEventPriorityMap() { if (null !== $this->eventPriorityMap) { return $this->eventPriorityMap; } return $this->eventPriorityMap = $this->buildEventPriorityMap(); }
php
public function getEventPriorityMap() { if (null !== $this->eventPriorityMap) { return $this->eventPriorityMap; } return $this->eventPriorityMap = $this->buildEventPriorityMap(); }
[ "public", "function", "getEventPriorityMap", "(", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "eventPriorityMap", ")", "{", "return", "$", "this", "->", "eventPriorityMap", ";", "}", "return", "$", "this", "->", "eventPriorityMap", "=", "$", "this", "->", "buildEventPriorityMap", "(", ")", ";", "}" ]
Returns the event priority map. @return array
[ "Returns", "the", "event", "priority", "map", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L261-L268
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.buildParentMap
private function buildParentMap() { $map = []; foreach ($this->configurations as $configuration) { if (null !== $parentId = $configuration->getParentId()) { $map[$configuration->getResourceId()] = $parentId; } } ksort($map); return $map; }
php
private function buildParentMap() { $map = []; foreach ($this->configurations as $configuration) { if (null !== $parentId = $configuration->getParentId()) { $map[$configuration->getResourceId()] = $parentId; } } ksort($map); return $map; }
[ "private", "function", "buildParentMap", "(", ")", "{", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "configurations", "as", "$", "configuration", ")", "{", "if", "(", "null", "!==", "$", "parentId", "=", "$", "configuration", "->", "getParentId", "(", ")", ")", "{", "$", "map", "[", "$", "configuration", "->", "getResourceId", "(", ")", "]", "=", "$", "parentId", ";", "}", "}", "ksort", "(", "$", "map", ")", ";", "return", "$", "map", ";", "}" ]
Builds the parent map. @return array
[ "Builds", "the", "parent", "map", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L275-L288
train
ekyna/Resource
Configuration/ConfigurationRegistry.php
ConfigurationRegistry.buildEventPriorityMap
private function buildEventPriorityMap() { $map = []; foreach ($this->configurations as $configuration) { if (0 != $priority = $configuration->getEventPriority()) { $map[$configuration->getResourceId()] = $priority; } } ksort($map); return $map; }
php
private function buildEventPriorityMap() { $map = []; foreach ($this->configurations as $configuration) { if (0 != $priority = $configuration->getEventPriority()) { $map[$configuration->getResourceId()] = $priority; } } ksort($map); return $map; }
[ "private", "function", "buildEventPriorityMap", "(", ")", "{", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "configurations", "as", "$", "configuration", ")", "{", "if", "(", "0", "!=", "$", "priority", "=", "$", "configuration", "->", "getEventPriority", "(", ")", ")", "{", "$", "map", "[", "$", "configuration", "->", "getResourceId", "(", ")", "]", "=", "$", "priority", ";", "}", "}", "ksort", "(", "$", "map", ")", ";", "return", "$", "map", ";", "}" ]
Builds the event priority map. @return array
[ "Builds", "the", "event", "priority", "map", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationRegistry.php#L295-L308
train
ezra-obiwale/dSCore
src/Form/Element.php
Element.getValue
protected function getValue() { if (($this->data == '0' || !empty($this->data)) && !is_object($this->data)) { $value = ($this->parent && is_array($this->data)) ? $this->data[0] : $this->data; } else if ($this->options->default == '0' || !empty($this->options->default)) { $value = $this->options->default; } else if (($this->options->value == '0' || !empty($this->options->value)) && !is_object($this->options->value)) { $value = $this->options->value; } if ($this->options->processValue) { $value = call_user_func($this->options->processValue, $value); } return $value; }
php
protected function getValue() { if (($this->data == '0' || !empty($this->data)) && !is_object($this->data)) { $value = ($this->parent && is_array($this->data)) ? $this->data[0] : $this->data; } else if ($this->options->default == '0' || !empty($this->options->default)) { $value = $this->options->default; } else if (($this->options->value == '0' || !empty($this->options->value)) && !is_object($this->options->value)) { $value = $this->options->value; } if ($this->options->processValue) { $value = call_user_func($this->options->processValue, $value); } return $value; }
[ "protected", "function", "getValue", "(", ")", "{", "if", "(", "(", "$", "this", "->", "data", "==", "'0'", "||", "!", "empty", "(", "$", "this", "->", "data", ")", ")", "&&", "!", "is_object", "(", "$", "this", "->", "data", ")", ")", "{", "$", "value", "=", "(", "$", "this", "->", "parent", "&&", "is_array", "(", "$", "this", "->", "data", ")", ")", "?", "$", "this", "->", "data", "[", "0", "]", ":", "$", "this", "->", "data", ";", "}", "else", "if", "(", "$", "this", "->", "options", "->", "default", "==", "'0'", "||", "!", "empty", "(", "$", "this", "->", "options", "->", "default", ")", ")", "{", "$", "value", "=", "$", "this", "->", "options", "->", "default", ";", "}", "else", "if", "(", "(", "$", "this", "->", "options", "->", "value", "==", "'0'", "||", "!", "empty", "(", "$", "this", "->", "options", "->", "value", ")", ")", "&&", "!", "is_object", "(", "$", "this", "->", "options", "->", "value", ")", ")", "{", "$", "value", "=", "$", "this", "->", "options", "->", "value", ";", "}", "if", "(", "$", "this", "->", "options", "->", "processValue", ")", "{", "$", "value", "=", "call_user_func", "(", "$", "this", "->", "options", "->", "processValue", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Fetches the current value of the element @return mixed
[ "Fetches", "the", "current", "value", "of", "the", "element" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Element.php#L132-L145
train
ezra-obiwale/dSCore
src/Form/Element.php
Element.render
public function render() { if ($this->parent) { if (!static::$count[$this->parent]) static::$count[$this->parent] = 0; static::$count[$this->parent] ++; $this->attributes->id += static::$count[$this->parent]; } ob_start(); ?> <div class="element-group <?= $this->type ?> <?= $this->errors ? 'form-error' : null ?>"> <?php if ($this->options->label): ?> <label for="<?= $this->attributes->id ?>"><?= $this->options->label ?></label> <?php endif; ?> <?= $this->prepare() ?> </div> <?php return ob_get_clean(); }
php
public function render() { if ($this->parent) { if (!static::$count[$this->parent]) static::$count[$this->parent] = 0; static::$count[$this->parent] ++; $this->attributes->id += static::$count[$this->parent]; } ob_start(); ?> <div class="element-group <?= $this->type ?> <?= $this->errors ? 'form-error' : null ?>"> <?php if ($this->options->label): ?> <label for="<?= $this->attributes->id ?>"><?= $this->options->label ?></label> <?php endif; ?> <?= $this->prepare() ?> </div> <?php return ob_get_clean(); }
[ "public", "function", "render", "(", ")", "{", "if", "(", "$", "this", "->", "parent", ")", "{", "if", "(", "!", "static", "::", "$", "count", "[", "$", "this", "->", "parent", "]", ")", "static", "::", "$", "count", "[", "$", "this", "->", "parent", "]", "=", "0", ";", "static", "::", "$", "count", "[", "$", "this", "->", "parent", "]", "++", ";", "$", "this", "->", "attributes", "->", "id", "+=", "static", "::", "$", "count", "[", "$", "this", "->", "parent", "]", ";", "}", "ob_start", "(", ")", ";", "?>\n <div class=\"element-group <?=", "$", "this", "->", "type", "?> <?=", "$", "this", "->", "errors", "?", "'form-error'", ":", "null", "?>\">\n <?php", "if", "(", "$", "this", "->", "options", "->", "label", ")", ":", "?>\n <label for=\"<?=", "$", "this", "->", "attributes", "->", "id", "?>\"><?=", "$", "this", "->", "options", "->", "label", "?></label>\n <?php", "endif", ";", "?>\n <?=", "$", "this", "->", "prepare", "(", ")", "?>\n </div>\n <?php", "return", "ob_get_clean", "(", ")", ";", "}" ]
Render the element for output @return string
[ "Render", "the", "element", "for", "output" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Element.php#L177-L195
train
ekyna/PaymentBundle
Twig/PaymentExtension.php
PaymentExtension.getPaymentStateLabel
public function getPaymentStateLabel($stateOrPayment) { $state = $stateOrPayment instanceof PaymentInterface ? $stateOrPayment->getState() : $stateOrPayment; return $this->translator->trans(PaymentStates::getLabel($state)); }
php
public function getPaymentStateLabel($stateOrPayment) { $state = $stateOrPayment instanceof PaymentInterface ? $stateOrPayment->getState() : $stateOrPayment; return $this->translator->trans(PaymentStates::getLabel($state)); }
[ "public", "function", "getPaymentStateLabel", "(", "$", "stateOrPayment", ")", "{", "$", "state", "=", "$", "stateOrPayment", "instanceof", "PaymentInterface", "?", "$", "stateOrPayment", "->", "getState", "(", ")", ":", "$", "stateOrPayment", ";", "return", "$", "this", "->", "translator", "->", "trans", "(", "PaymentStates", "::", "getLabel", "(", "$", "state", ")", ")", ";", "}" ]
Returns the payment state label. @param string|PaymentInterface $stateOrPayment @return string
[ "Returns", "the", "payment", "state", "label", "." ]
1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1
https://github.com/ekyna/PaymentBundle/blob/1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1/Twig/PaymentExtension.php#L82-L87
train
ekyna/PaymentBundle
Twig/PaymentExtension.php
PaymentExtension.getPaymentStateBadge
public function getPaymentStateBadge($stateOrPayment) { $state = $stateOrPayment instanceof PaymentInterface ? $stateOrPayment->getState() : $stateOrPayment; return sprintf( '<span class="label label-%s">%s</span>', PaymentStates::getTheme($state), $this->getPaymentStateLabel($state) ); }
php
public function getPaymentStateBadge($stateOrPayment) { $state = $stateOrPayment instanceof PaymentInterface ? $stateOrPayment->getState() : $stateOrPayment; return sprintf( '<span class="label label-%s">%s</span>', PaymentStates::getTheme($state), $this->getPaymentStateLabel($state) ); }
[ "public", "function", "getPaymentStateBadge", "(", "$", "stateOrPayment", ")", "{", "$", "state", "=", "$", "stateOrPayment", "instanceof", "PaymentInterface", "?", "$", "stateOrPayment", "->", "getState", "(", ")", ":", "$", "stateOrPayment", ";", "return", "sprintf", "(", "'<span class=\"label label-%s\">%s</span>'", ",", "PaymentStates", "::", "getTheme", "(", "$", "state", ")", ",", "$", "this", "->", "getPaymentStateLabel", "(", "$", "state", ")", ")", ";", "}" ]
Returns the payment state badge. @param string|PaymentInterface $stateOrPayment @return string
[ "Returns", "the", "payment", "state", "badge", "." ]
1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1
https://github.com/ekyna/PaymentBundle/blob/1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1/Twig/PaymentExtension.php#L95-L104
train
ekyna/PaymentBundle
Twig/PaymentExtension.php
PaymentExtension.renderMethodConfig
public function renderMethodConfig(MethodInterface $method) { $output = '<dl class="dl-horizontal">'; foreach ($method->getConfig() as $key => $value) { if (is_array($value)) { continue; } $output .= sprintf('<dt>%s</dt><dd>%s</dd>', $key, $value); } $output .= '</dl>'; return $output; }
php
public function renderMethodConfig(MethodInterface $method) { $output = '<dl class="dl-horizontal">'; foreach ($method->getConfig() as $key => $value) { if (is_array($value)) { continue; } $output .= sprintf('<dt>%s</dt><dd>%s</dd>', $key, $value); } $output .= '</dl>'; return $output; }
[ "public", "function", "renderMethodConfig", "(", "MethodInterface", "$", "method", ")", "{", "$", "output", "=", "'<dl class=\"dl-horizontal\">'", ";", "foreach", "(", "$", "method", "->", "getConfig", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "continue", ";", "}", "$", "output", ".=", "sprintf", "(", "'<dt>%s</dt><dd>%s</dd>'", ",", "$", "key", ",", "$", "value", ")", ";", "}", "$", "output", ".=", "'</dl>'", ";", "return", "$", "output", ";", "}" ]
Renders the method config. @param MethodInterface $method @return string
[ "Renders", "the", "method", "config", "." ]
1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1
https://github.com/ekyna/PaymentBundle/blob/1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1/Twig/PaymentExtension.php#L145-L160
train
jenskooij/cloudcontrol
src/storage/storage/DocumentStorage.php
DocumentStorage.addDocumentFolder
public function addDocumentFolder($postValues) { $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); if ($postValues['path'] === '/') { $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; } else { $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; } $this->repository->getContentRepository()->saveDocument($documentFolderObject, 'published'); $this->repository->getContentRepository()->saveDocument($documentFolderObject, 'unpublished'); }
php
public function addDocumentFolder($postValues) { $documentFolderObject = DocumentFolderFactory::createDocumentFolderFromPostValues($postValues); if ($postValues['path'] === '/') { $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug; } else { $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug; } $this->repository->getContentRepository()->saveDocument($documentFolderObject, 'published'); $this->repository->getContentRepository()->saveDocument($documentFolderObject, 'unpublished'); }
[ "public", "function", "addDocumentFolder", "(", "$", "postValues", ")", "{", "$", "documentFolderObject", "=", "DocumentFolderFactory", "::", "createDocumentFolderFromPostValues", "(", "$", "postValues", ")", ";", "if", "(", "$", "postValues", "[", "'path'", "]", "===", "'/'", ")", "{", "$", "documentFolderObject", "->", "path", "=", "$", "postValues", "[", "'path'", "]", ".", "$", "documentFolderObject", "->", "slug", ";", "}", "else", "{", "$", "documentFolderObject", "->", "path", "=", "$", "postValues", "[", "'path'", "]", ".", "'/'", ".", "$", "documentFolderObject", "->", "slug", ";", "}", "$", "this", "->", "repository", "->", "getContentRepository", "(", ")", "->", "saveDocument", "(", "$", "documentFolderObject", ",", "'published'", ")", ";", "$", "this", "->", "repository", "->", "getContentRepository", "(", ")", "->", "saveDocument", "(", "$", "documentFolderObject", ",", "'unpublished'", ")", ";", "}" ]
Add new document in given path @param array $postValues @throws \Exception
[ "Add", "new", "document", "in", "given", "path" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/DocumentStorage.php#L154-L164
train
jenskooij/cloudcontrol
src/storage/storage/DocumentStorage.php
DocumentStorage.deleteDocumentFolderBySlug
public function deleteDocumentFolderBySlug($slug) { $path = '/' . $slug; $this->repository->getContentRepository()->deleteDocumentByPath($this->repository, $path); $this->repository->getContentRepository()->cleanPublishedDeletedDocuments(); }
php
public function deleteDocumentFolderBySlug($slug) { $path = '/' . $slug; $this->repository->getContentRepository()->deleteDocumentByPath($this->repository, $path); $this->repository->getContentRepository()->cleanPublishedDeletedDocuments(); }
[ "public", "function", "deleteDocumentFolderBySlug", "(", "$", "slug", ")", "{", "$", "path", "=", "'/'", ".", "$", "slug", ";", "$", "this", "->", "repository", "->", "getContentRepository", "(", ")", "->", "deleteDocumentByPath", "(", "$", "this", "->", "repository", ",", "$", "path", ")", ";", "$", "this", "->", "repository", "->", "getContentRepository", "(", ")", "->", "cleanPublishedDeletedDocuments", "(", ")", ";", "}" ]
Delete a folder by its compound slug @param $slug @throws \Exception
[ "Delete", "a", "folder", "by", "its", "compound", "slug" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/DocumentStorage.php#L173-L178
train
jenskooij/cloudcontrol
src/storage/storage/DocumentStorage.php
DocumentStorage.getDocumentFolderBySlug
public function getDocumentFolderBySlug($slug) { if ($slug === '/') { $path = $slug; } else { $path = '/' . $slug; } return $this->repository->getContentRepository()->getDocumentByPath($this->repository, $path, 'unpublished'); }
php
public function getDocumentFolderBySlug($slug) { if ($slug === '/') { $path = $slug; } else { $path = '/' . $slug; } return $this->repository->getContentRepository()->getDocumentByPath($this->repository, $path, 'unpublished'); }
[ "public", "function", "getDocumentFolderBySlug", "(", "$", "slug", ")", "{", "if", "(", "$", "slug", "===", "'/'", ")", "{", "$", "path", "=", "$", "slug", ";", "}", "else", "{", "$", "path", "=", "'/'", ".", "$", "slug", ";", "}", "return", "$", "this", "->", "repository", "->", "getContentRepository", "(", ")", "->", "getDocumentByPath", "(", "$", "this", "->", "repository", ",", "$", "path", ",", "'unpublished'", ")", ";", "}" ]
Retrieve a folder by its compound slug @param $slug @return mixed @throws \Exception
[ "Retrieve", "a", "folder", "by", "its", "compound", "slug" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/DocumentStorage.php#L208-L217
train
froq/froq-acl
src/User.php
User.canRead
public function canRead(string $uri): bool { // /book => all if (in_array(Acl::RULE_ALL, (array) $this->getPermissionsOf($this->getUriRoot($uri)))) { return true; } // /book/detail => all or read $permission = array_filter((array) $this->getPermissionsOf($uri), function($rule) { return ($rule == Acl::RULE_ALL || $rule == Acl::RULE_READ); }); return !empty($permission); }
php
public function canRead(string $uri): bool { // /book => all if (in_array(Acl::RULE_ALL, (array) $this->getPermissionsOf($this->getUriRoot($uri)))) { return true; } // /book/detail => all or read $permission = array_filter((array) $this->getPermissionsOf($uri), function($rule) { return ($rule == Acl::RULE_ALL || $rule == Acl::RULE_READ); }); return !empty($permission); }
[ "public", "function", "canRead", "(", "string", "$", "uri", ")", ":", "bool", "{", "// /book => all", "if", "(", "in_array", "(", "Acl", "::", "RULE_ALL", ",", "(", "array", ")", "$", "this", "->", "getPermissionsOf", "(", "$", "this", "->", "getUriRoot", "(", "$", "uri", ")", ")", ")", ")", "{", "return", "true", ";", "}", "// /book/detail => all or read", "$", "permission", "=", "array_filter", "(", "(", "array", ")", "$", "this", "->", "getPermissionsOf", "(", "$", "uri", ")", ",", "function", "(", "$", "rule", ")", "{", "return", "(", "$", "rule", "==", "Acl", "::", "RULE_ALL", "||", "$", "rule", "==", "Acl", "::", "RULE_READ", ")", ";", "}", ")", ";", "return", "!", "empty", "(", "$", "permission", ")", ";", "}" ]
Can read. @param string $uri @return bool
[ "Can", "read", "." ]
ab1897dea20b16dfd8f0a6349224e94d160a0540
https://github.com/froq/froq-acl/blob/ab1897dea20b16dfd8f0a6349224e94d160a0540/src/User.php#L222-L235
train
froq/froq-acl
src/User.php
User.canWrite
public function canWrite(string $uri): bool { // /book => all if (in_array(Acl::RULE_ALL, (array) $this->getPermissionsOf($this->getUriRoot($uri)))) { return true; } // /book/detail => all or write $permission = array_filter((array) $this->getPermissionsOf($uri), function($rule) { return ($rule == Acl::RULE_ALL || $rule == Acl::RULE_WRITE); }); return !empty($permission); }
php
public function canWrite(string $uri): bool { // /book => all if (in_array(Acl::RULE_ALL, (array) $this->getPermissionsOf($this->getUriRoot($uri)))) { return true; } // /book/detail => all or write $permission = array_filter((array) $this->getPermissionsOf($uri), function($rule) { return ($rule == Acl::RULE_ALL || $rule == Acl::RULE_WRITE); }); return !empty($permission); }
[ "public", "function", "canWrite", "(", "string", "$", "uri", ")", ":", "bool", "{", "// /book => all", "if", "(", "in_array", "(", "Acl", "::", "RULE_ALL", ",", "(", "array", ")", "$", "this", "->", "getPermissionsOf", "(", "$", "this", "->", "getUriRoot", "(", "$", "uri", ")", ")", ")", ")", "{", "return", "true", ";", "}", "// /book/detail => all or write", "$", "permission", "=", "array_filter", "(", "(", "array", ")", "$", "this", "->", "getPermissionsOf", "(", "$", "uri", ")", ",", "function", "(", "$", "rule", ")", "{", "return", "(", "$", "rule", "==", "Acl", "::", "RULE_ALL", "||", "$", "rule", "==", "Acl", "::", "RULE_WRITE", ")", ";", "}", ")", ";", "return", "!", "empty", "(", "$", "permission", ")", ";", "}" ]
Can write. @param string $uri @return bool
[ "Can", "write", "." ]
ab1897dea20b16dfd8f0a6349224e94d160a0540
https://github.com/froq/froq-acl/blob/ab1897dea20b16dfd8f0a6349224e94d160a0540/src/User.php#L242-L255
train
froq/froq-acl
src/User.php
User.redirectIf
public function redirectIf(string $dir, string $to = '/', bool $exit = true): void { if ($this->acl != null) { $app = $this->acl->getService()->getApp(); if ($dir == 'in' && $this->isLoggedIn()) { $app->response()->redirect($to); } elseif ($dir == 'out' && !$this->isLoggedIn()) { $app->response()->redirect($to); } } else { if (headers_sent($file, $line)) { throw new AclException(sprintf("Cannot use '%s()', headers already sent in %s:%s", __method__, $file, $line)); } header('Location: '. trim($to)); if ($exit) { exit(0); } } }
php
public function redirectIf(string $dir, string $to = '/', bool $exit = true): void { if ($this->acl != null) { $app = $this->acl->getService()->getApp(); if ($dir == 'in' && $this->isLoggedIn()) { $app->response()->redirect($to); } elseif ($dir == 'out' && !$this->isLoggedIn()) { $app->response()->redirect($to); } } else { if (headers_sent($file, $line)) { throw new AclException(sprintf("Cannot use '%s()', headers already sent in %s:%s", __method__, $file, $line)); } header('Location: '. trim($to)); if ($exit) { exit(0); } } }
[ "public", "function", "redirectIf", "(", "string", "$", "dir", ",", "string", "$", "to", "=", "'/'", ",", "bool", "$", "exit", "=", "true", ")", ":", "void", "{", "if", "(", "$", "this", "->", "acl", "!=", "null", ")", "{", "$", "app", "=", "$", "this", "->", "acl", "->", "getService", "(", ")", "->", "getApp", "(", ")", ";", "if", "(", "$", "dir", "==", "'in'", "&&", "$", "this", "->", "isLoggedIn", "(", ")", ")", "{", "$", "app", "->", "response", "(", ")", "->", "redirect", "(", "$", "to", ")", ";", "}", "elseif", "(", "$", "dir", "==", "'out'", "&&", "!", "$", "this", "->", "isLoggedIn", "(", ")", ")", "{", "$", "app", "->", "response", "(", ")", "->", "redirect", "(", "$", "to", ")", ";", "}", "}", "else", "{", "if", "(", "headers_sent", "(", "$", "file", ",", "$", "line", ")", ")", "{", "throw", "new", "AclException", "(", "sprintf", "(", "\"Cannot use '%s()', headers already sent in %s:%s\"", ",", "__method__", ",", "$", "file", ",", "$", "line", ")", ")", ";", "}", "header", "(", "'Location: '", ".", "trim", "(", "$", "to", ")", ")", ";", "if", "(", "$", "exit", ")", "{", "exit", "(", "0", ")", ";", "}", "}", "}" ]
Redirect if. @param string $dir In/out direction. @param string $to @param bool $exit @return void
[ "Redirect", "if", "." ]
ab1897dea20b16dfd8f0a6349224e94d160a0540
https://github.com/froq/froq-acl/blob/ab1897dea20b16dfd8f0a6349224e94d160a0540/src/User.php#L264-L284
train
gilbertsoft/typo3-gscacheconfig
Classes/Service/InstallService.php
InstallService.getCleanAdditionalConfiguration
protected function getCleanAdditionalConfiguration($extensionKey) { $newLines = []; // Load content and search for the include if (($content = GeneralUtility::getUrl($this->getConfigurationManager()->getAdditionalConfigurationFileLocation())) !== false) { $currentLines = explode(LF, $content); // Delete the php marker line array_shift($currentLines); // $startFound = false; $endFound = false; foreach ($currentLines as $line) { if (($startFound) && (!$endFound)) { $endFound = (strpos($line, '}') !== false); } elseif ((!$startFound) && (strpos($line, $extensionKey) !== false)) { $startFound = true; $endFound = false; } else { $newLines[] = $line; } } } // Remove blank lines at the end $revLines = array_reverse($newLines); $newLines = []; $lineFound = false; foreach ($revLines as $line) { if ($lineFound || !empty(trim($line))) { $newLines[] = $line; $lineFound = true; } } return array_reverse($newLines); }
php
protected function getCleanAdditionalConfiguration($extensionKey) { $newLines = []; // Load content and search for the include if (($content = GeneralUtility::getUrl($this->getConfigurationManager()->getAdditionalConfigurationFileLocation())) !== false) { $currentLines = explode(LF, $content); // Delete the php marker line array_shift($currentLines); // $startFound = false; $endFound = false; foreach ($currentLines as $line) { if (($startFound) && (!$endFound)) { $endFound = (strpos($line, '}') !== false); } elseif ((!$startFound) && (strpos($line, $extensionKey) !== false)) { $startFound = true; $endFound = false; } else { $newLines[] = $line; } } } // Remove blank lines at the end $revLines = array_reverse($newLines); $newLines = []; $lineFound = false; foreach ($revLines as $line) { if ($lineFound || !empty(trim($line))) { $newLines[] = $line; $lineFound = true; } } return array_reverse($newLines); }
[ "protected", "function", "getCleanAdditionalConfiguration", "(", "$", "extensionKey", ")", "{", "$", "newLines", "=", "[", "]", ";", "// Load content and search for the include", "if", "(", "(", "$", "content", "=", "GeneralUtility", "::", "getUrl", "(", "$", "this", "->", "getConfigurationManager", "(", ")", "->", "getAdditionalConfigurationFileLocation", "(", ")", ")", ")", "!==", "false", ")", "{", "$", "currentLines", "=", "explode", "(", "LF", ",", "$", "content", ")", ";", "// Delete the php marker line", "array_shift", "(", "$", "currentLines", ")", ";", "//", "$", "startFound", "=", "false", ";", "$", "endFound", "=", "false", ";", "foreach", "(", "$", "currentLines", "as", "$", "line", ")", "{", "if", "(", "(", "$", "startFound", ")", "&&", "(", "!", "$", "endFound", ")", ")", "{", "$", "endFound", "=", "(", "strpos", "(", "$", "line", ",", "'}'", ")", "!==", "false", ")", ";", "}", "elseif", "(", "(", "!", "$", "startFound", ")", "&&", "(", "strpos", "(", "$", "line", ",", "$", "extensionKey", ")", "!==", "false", ")", ")", "{", "$", "startFound", "=", "true", ";", "$", "endFound", "=", "false", ";", "}", "else", "{", "$", "newLines", "[", "]", "=", "$", "line", ";", "}", "}", "}", "// Remove blank lines at the end", "$", "revLines", "=", "array_reverse", "(", "$", "newLines", ")", ";", "$", "newLines", "=", "[", "]", ";", "$", "lineFound", "=", "false", ";", "foreach", "(", "$", "revLines", "as", "$", "line", ")", "{", "if", "(", "$", "lineFound", "||", "!", "empty", "(", "trim", "(", "$", "line", ")", ")", ")", "{", "$", "newLines", "[", "]", "=", "$", "line", ";", "$", "lineFound", "=", "true", ";", "}", "}", "return", "array_reverse", "(", "$", "newLines", ")", ";", "}" ]
Returns the lines from AdditionalConfiguration.php file without own additions @param string $extensionKey Extension key
[ "Returns", "the", "lines", "from", "AdditionalConfiguration", ".", "php", "file", "without", "own", "additions" ]
dc6c3131b9e3d714b6c79c802c09ef1d165296d1
https://github.com/gilbertsoft/typo3-gscacheconfig/blob/dc6c3131b9e3d714b6c79c802c09ef1d165296d1/Classes/Service/InstallService.php#L63-L106
train
miknatr/grace-dbal
lib/Grace/SQLBuilder/InsertBuilder.php
InsertBuilder.values
public function values(array $values) { $this->fieldValues = array(); $this->fieldsSql = '?i'; $this->fieldValues[] = array_keys($values); $this->valuesSql = array(); foreach ($values as $v) { if (is_object($v) and $v instanceof SqlValueInterface) { $this->valuesSql[] = $v->getSql(); $this->fieldValues = array_merge($this->fieldValues, $v->getValues()); } else { $this->valuesSql[] = '?q'; $this->fieldValues[] = $v; } } $this->valuesSql = implode(', ', $this->valuesSql); return $this; }
php
public function values(array $values) { $this->fieldValues = array(); $this->fieldsSql = '?i'; $this->fieldValues[] = array_keys($values); $this->valuesSql = array(); foreach ($values as $v) { if (is_object($v) and $v instanceof SqlValueInterface) { $this->valuesSql[] = $v->getSql(); $this->fieldValues = array_merge($this->fieldValues, $v->getValues()); } else { $this->valuesSql[] = '?q'; $this->fieldValues[] = $v; } } $this->valuesSql = implode(', ', $this->valuesSql); return $this; }
[ "public", "function", "values", "(", "array", "$", "values", ")", "{", "$", "this", "->", "fieldValues", "=", "array", "(", ")", ";", "$", "this", "->", "fieldsSql", "=", "'?i'", ";", "$", "this", "->", "fieldValues", "[", "]", "=", "array_keys", "(", "$", "values", ")", ";", "$", "this", "->", "valuesSql", "=", "array", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "v", ")", "{", "if", "(", "is_object", "(", "$", "v", ")", "and", "$", "v", "instanceof", "SqlValueInterface", ")", "{", "$", "this", "->", "valuesSql", "[", "]", "=", "$", "v", "->", "getSql", "(", ")", ";", "$", "this", "->", "fieldValues", "=", "array_merge", "(", "$", "this", "->", "fieldValues", ",", "$", "v", "->", "getValues", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "valuesSql", "[", "]", "=", "'?q'", ";", "$", "this", "->", "fieldValues", "[", "]", "=", "$", "v", ";", "}", "}", "$", "this", "->", "valuesSql", "=", "implode", "(", "', '", ",", "$", "this", "->", "valuesSql", ")", ";", "return", "$", "this", ";", "}" ]
Prepares values for inserting into db @param array $values @return $this
[ "Prepares", "values", "for", "inserting", "into", "db" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/SQLBuilder/InsertBuilder.php#L29-L51
train
Subscribo/klarna-invoice-sdk-wrapped
src/pclasses/sqlstorage.class.php
SQLStorage.getConnection
protected function getConnection($uri) { if ($this->pdo) { return; //Already have a connection } $this->splitURI($uri); try { $this->pdo = new PDO($this->dsn, $this->user, $this->passwd); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { throw new Klarna_DatabaseException('Failed to connect to database!'); } }
php
protected function getConnection($uri) { if ($this->pdo) { return; //Already have a connection } $this->splitURI($uri); try { $this->pdo = new PDO($this->dsn, $this->user, $this->passwd); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { throw new Klarna_DatabaseException('Failed to connect to database!'); } }
[ "protected", "function", "getConnection", "(", "$", "uri", ")", "{", "if", "(", "$", "this", "->", "pdo", ")", "{", "return", ";", "//Already have a connection", "}", "$", "this", "->", "splitURI", "(", "$", "uri", ")", ";", "try", "{", "$", "this", "->", "pdo", "=", "new", "PDO", "(", "$", "this", "->", "dsn", ",", "$", "this", "->", "user", ",", "$", "this", "->", "passwd", ")", ";", "$", "this", "->", "pdo", "->", "setAttribute", "(", "PDO", "::", "ATTR_ERRMODE", ",", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "throw", "new", "Klarna_DatabaseException", "(", "'Failed to connect to database!'", ")", ";", "}", "}" ]
Connects to the DB. @param string|array $uri pclass uri @throws Klarna_DatabaseException If connection could not be established. @deprecated Use the connect method instead. @return void
[ "Connects", "to", "the", "DB", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/sqlstorage.class.php#L240-L254
train
Subscribo/klarna-invoice-sdk-wrapped
src/pclasses/sqlstorage.class.php
SQLStorage.create
public function create() { try { $this->pdo->exec("CREATE DATABASE `{$this->dbName}`"); } catch (PDOException $e) { //SQLite does not support this... } $sql = <<<SQL CREATE TABLE IF NOT EXISTS `{$this->dbName}`.`{$this->dbTable}` ( `eid` int(10) NOT NULL, `id` int(10) NOT NULL, `type` int(4) NOT NULL, `description` varchar(255) NOT NULL, `months` int(11) NOT NULL, `interestrate` decimal(11,2) NOT NULL, `invoicefee` decimal(11,2) NOT NULL, `startfee` decimal(11,2) NOT NULL, `minamount` decimal(11,2) NOT NULL, `country` int(11) NOT NULL, `expire` int(11) NOT NULL ); SQL; try { $this->pdo->exec($sql); } catch (PDOException $e) { throw new Klarna_DatabaseException( 'Table non-existant, failed to create it!' ); } }
php
public function create() { try { $this->pdo->exec("CREATE DATABASE `{$this->dbName}`"); } catch (PDOException $e) { //SQLite does not support this... } $sql = <<<SQL CREATE TABLE IF NOT EXISTS `{$this->dbName}`.`{$this->dbTable}` ( `eid` int(10) NOT NULL, `id` int(10) NOT NULL, `type` int(4) NOT NULL, `description` varchar(255) NOT NULL, `months` int(11) NOT NULL, `interestrate` decimal(11,2) NOT NULL, `invoicefee` decimal(11,2) NOT NULL, `startfee` decimal(11,2) NOT NULL, `minamount` decimal(11,2) NOT NULL, `country` int(11) NOT NULL, `expire` int(11) NOT NULL ); SQL; try { $this->pdo->exec($sql); } catch (PDOException $e) { throw new Klarna_DatabaseException( 'Table non-existant, failed to create it!' ); } }
[ "public", "function", "create", "(", ")", "{", "try", "{", "$", "this", "->", "pdo", "->", "exec", "(", "\"CREATE DATABASE `{$this->dbName}`\"", ")", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "//SQLite does not support this...", "}", "$", "sql", "=", " <<<SQL\n CREATE TABLE IF NOT EXISTS `{$this->dbName}`.`{$this->dbTable}` (\n `eid` int(10) NOT NULL,\n `id` int(10) NOT NULL,\n `type` int(4) NOT NULL,\n `description` varchar(255) NOT NULL,\n `months` int(11) NOT NULL,\n `interestrate` decimal(11,2) NOT NULL,\n `invoicefee` decimal(11,2) NOT NULL,\n `startfee` decimal(11,2) NOT NULL,\n `minamount` decimal(11,2) NOT NULL,\n `country` int(11) NOT NULL,\n `expire` int(11) NOT NULL\n );\nSQL", ";", "try", "{", "$", "this", "->", "pdo", "->", "exec", "(", "$", "sql", ")", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "throw", "new", "Klarna_DatabaseException", "(", "'Table non-existant, failed to create it!'", ")", ";", "}", "}" ]
Attempt to create the database and tables needed to store pclasses. @throws Klarna_DatabaseException If the table could not be created. @return void
[ "Attempt", "to", "create", "the", "database", "and", "tables", "needed", "to", "store", "pclasses", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/sqlstorage.class.php#L291-L321
train
Subscribo/klarna-invoice-sdk-wrapped
src/pclasses/sqlstorage.class.php
SQLStorage.loadPClasses
protected function loadPClasses() { try { $sth = $this->pdo->prepare( "SELECT * FROM `{$this->dbName}`.`{$this->dbTable}`", array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY) ); $sth->execute(); while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) { $this->addPClass(new KlarnaPClass($row)); } $sth->closeCursor(); $sth = null; } catch (PDOException $e) { throw new Klarna_DatabaseException( 'Could not fetch PClasses from database!' ); } }
php
protected function loadPClasses() { try { $sth = $this->pdo->prepare( "SELECT * FROM `{$this->dbName}`.`{$this->dbTable}`", array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY) ); $sth->execute(); while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) { $this->addPClass(new KlarnaPClass($row)); } $sth->closeCursor(); $sth = null; } catch (PDOException $e) { throw new Klarna_DatabaseException( 'Could not fetch PClasses from database!' ); } }
[ "protected", "function", "loadPClasses", "(", ")", "{", "try", "{", "$", "sth", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "\"SELECT * FROM `{$this->dbName}`.`{$this->dbTable}`\"", ",", "array", "(", "PDO", "::", "ATTR_CURSOR", "=>", "PDO", "::", "CURSOR_FWDONLY", ")", ")", ";", "$", "sth", "->", "execute", "(", ")", ";", "while", "(", "$", "row", "=", "$", "sth", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ",", "PDO", "::", "FETCH_ORI_NEXT", ")", ")", "{", "$", "this", "->", "addPClass", "(", "new", "KlarnaPClass", "(", "$", "row", ")", ")", ";", "}", "$", "sth", "->", "closeCursor", "(", ")", ";", "$", "sth", "=", "null", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "throw", "new", "Klarna_DatabaseException", "(", "'Could not fetch PClasses from database!'", ")", ";", "}", "}" ]
Loads the PClasses. @return void @throws KlarnaException
[ "Loads", "the", "PClasses", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/sqlstorage.class.php#L343-L363
train
Subscribo/klarna-invoice-sdk-wrapped
src/pclasses/sqlstorage.class.php
SQLStorage.clear
public function clear($uri) { try { $this->connect($uri); unset($this->pclasses); $this->clearTable(); } catch(Exception $e) { throw new Klarna_DatabaseException( $e->getMessage(), $e->getCode() ); } }
php
public function clear($uri) { try { $this->connect($uri); unset($this->pclasses); $this->clearTable(); } catch(Exception $e) { throw new Klarna_DatabaseException( $e->getMessage(), $e->getCode() ); } }
[ "public", "function", "clear", "(", "$", "uri", ")", "{", "try", "{", "$", "this", "->", "connect", "(", "$", "uri", ")", ";", "unset", "(", "$", "this", "->", "pclasses", ")", ";", "$", "this", "->", "clearTable", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "Klarna_DatabaseException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ")", ";", "}", "}" ]
Drops the database table, to clear the PClasses. @param string|array $uri pclass uri @return void @throws KlarnaException
[ "Drops", "the", "database", "table", "to", "clear", "the", "PClasses", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/sqlstorage.class.php#L461-L472
train
net-tools/core
src/Formatters/Formatter.php
Formatter.closeRow
public function closeRow($last = false) { $this->_strategy->output($this->endRow() . ($last ? '' : $this->rowSeparator())); }
php
public function closeRow($last = false) { $this->_strategy->output($this->endRow() . ($last ? '' : $this->rowSeparator())); }
[ "public", "function", "closeRow", "(", "$", "last", "=", "false", ")", "{", "$", "this", "->", "_strategy", "->", "output", "(", "$", "this", "->", "endRow", "(", ")", ".", "(", "$", "last", "?", "''", ":", "$", "this", "->", "rowSeparator", "(", ")", ")", ")", ";", "}" ]
End the row @param bool $last Indicates whether this is the last row or not
[ "End", "the", "row" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Formatters/Formatter.php#L88-L91
train
net-tools/core
src/Formatters/Formatter.php
Formatter.column
public function column($v, $last = false) { $this->_strategy->output($this->beginColumn() . $v . $this->endColumn() . ($last ? '' : $this->columnSeparator())); }
php
public function column($v, $last = false) { $this->_strategy->output($this->beginColumn() . $v . $this->endColumn() . ($last ? '' : $this->columnSeparator())); }
[ "public", "function", "column", "(", "$", "v", ",", "$", "last", "=", "false", ")", "{", "$", "this", "->", "_strategy", "->", "output", "(", "$", "this", "->", "beginColumn", "(", ")", ".", "$", "v", ".", "$", "this", "->", "endColumn", "(", ")", ".", "(", "$", "last", "?", "''", ":", "$", "this", "->", "columnSeparator", "(", ")", ")", ")", ";", "}" ]
Write a column value for the current row @param string $v Value to output @param bool $last Indicates whether this is the last column of the row or not
[ "Write", "a", "column", "value", "for", "the", "current", "row" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Formatters/Formatter.php#L100-L103
train
net-tools/core
src/Formatters/Formatter.php
Formatter.row
public function row($r, $last = false) { $this->_strategy->output($this->beginRow()); $values = array_values($r); $valuesl = count($values); for ( $i = 0 ; $i < $valuesl ; $i++ ) $this->column($values[$i], $i+1 == $valuesl); $this->_strategy->output($this->endRow() . ($last ? '' : $this->rowSeparator())); }
php
public function row($r, $last = false) { $this->_strategy->output($this->beginRow()); $values = array_values($r); $valuesl = count($values); for ( $i = 0 ; $i < $valuesl ; $i++ ) $this->column($values[$i], $i+1 == $valuesl); $this->_strategy->output($this->endRow() . ($last ? '' : $this->rowSeparator())); }
[ "public", "function", "row", "(", "$", "r", ",", "$", "last", "=", "false", ")", "{", "$", "this", "->", "_strategy", "->", "output", "(", "$", "this", "->", "beginRow", "(", ")", ")", ";", "$", "values", "=", "array_values", "(", "$", "r", ")", ";", "$", "valuesl", "=", "count", "(", "$", "values", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "valuesl", ";", "$", "i", "++", ")", "$", "this", "->", "column", "(", "$", "values", "[", "$", "i", "]", ",", "$", "i", "+", "1", "==", "$", "valuesl", ")", ";", "$", "this", "->", "_strategy", "->", "output", "(", "$", "this", "->", "endRow", "(", ")", ".", "(", "$", "last", "?", "''", ":", "$", "this", "->", "rowSeparator", "(", ")", ")", ")", ";", "}" ]
Write a row @param string[] $r Array of columns values to output @param bool $last Indicates whether this is the last row or not
[ "Write", "a", "row" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Formatters/Formatter.php#L113-L124
train
OxfordInfoLabs/kinikit-core
src/Object/DynamicSerialisableObject.php
DynamicSerialisableObject.__getSerialisablePropertyValue
public function __getSerialisablePropertyValue($propertyName) { try { return parent::__getSerialisablePropertyValue($propertyName); } catch (PropertyNotReadableException $e) { if ($this->__strictMode) { throw $e; } else { return null; } } }
php
public function __getSerialisablePropertyValue($propertyName) { try { return parent::__getSerialisablePropertyValue($propertyName); } catch (PropertyNotReadableException $e) { if ($this->__strictMode) { throw $e; } else { return null; } } }
[ "public", "function", "__getSerialisablePropertyValue", "(", "$", "propertyName", ")", "{", "try", "{", "return", "parent", "::", "__getSerialisablePropertyValue", "(", "$", "propertyName", ")", ";", "}", "catch", "(", "PropertyNotReadableException", "$", "e", ")", "{", "if", "(", "$", "this", "->", "__strictMode", ")", "{", "throw", "$", "e", ";", "}", "else", "{", "return", "null", ";", "}", "}", "}" ]
Override the parent get property value method to be a little more tolerant than the parent @param string $propertyName
[ "Override", "the", "parent", "get", "property", "value", "method", "to", "be", "a", "little", "more", "tolerant", "than", "the", "parent" ]
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Object/DynamicSerialisableObject.php#L131-L142
train
OxfordInfoLabs/kinikit-core
src/Object/DynamicSerialisableObject.php
DynamicSerialisableObject.__getSerialisablePropertyMap
public function __getSerialisablePropertyMap() { $serialisableProperties = parent::__getSerialisablePropertyMap(); $dynamicProperties = $this->__dynamicPropertyMap; $map = array(); foreach ($dynamicProperties as $key => $value) { $map[$key] = $value; } foreach ($serialisableProperties as $key => $value) { $map[$key] = $value; } // Merge our dynamic properties in and return. return $map; }
php
public function __getSerialisablePropertyMap() { $serialisableProperties = parent::__getSerialisablePropertyMap(); $dynamicProperties = $this->__dynamicPropertyMap; $map = array(); foreach ($dynamicProperties as $key => $value) { $map[$key] = $value; } foreach ($serialisableProperties as $key => $value) { $map[$key] = $value; } // Merge our dynamic properties in and return. return $map; }
[ "public", "function", "__getSerialisablePropertyMap", "(", ")", "{", "$", "serialisableProperties", "=", "parent", "::", "__getSerialisablePropertyMap", "(", ")", ";", "$", "dynamicProperties", "=", "$", "this", "->", "__dynamicPropertyMap", ";", "$", "map", "=", "array", "(", ")", ";", "foreach", "(", "$", "dynamicProperties", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "map", "[", "$", "key", "]", "=", "$", "value", ";", "}", "foreach", "(", "$", "serialisableProperties", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "map", "[", "$", "key", "]", "=", "$", "value", ";", "}", "// Merge our dynamic properties in and return.", "return", "$", "map", ";", "}" ]
Get the array of serialisable properties @return array
[ "Get", "the", "array", "of", "serialisable", "properties" ]
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Object/DynamicSerialisableObject.php#L149-L166
train
OxfordInfoLabs/kinikit-core
src/Object/DynamicSerialisableObject.php
DynamicSerialisableObject.__setSerialisablePropertyMap
public function __setSerialisablePropertyMap($propertyMap, $ignoreNoneWritableProperties = false) { // Always ignore any unknown properties in parent as we need to capture these for dynamic purposes $dynamicProperties = parent::__setSerialisablePropertyMap($propertyMap, true); // If none strict, simply merge all properties in the property map into the dynamic property map. if (!$this->__strictMode) { $this->__dynamicPropertyMap = array_merge($this->__dynamicPropertyMap, $dynamicProperties); } else { foreach ($dynamicProperties as $propertyName => $propertyValue) { try { $this->__set($propertyName, $propertyValue); } catch (PropertyNotWritableException $e) { if (!$ignoreNoneWritableProperties) throw $e; } } } }
php
public function __setSerialisablePropertyMap($propertyMap, $ignoreNoneWritableProperties = false) { // Always ignore any unknown properties in parent as we need to capture these for dynamic purposes $dynamicProperties = parent::__setSerialisablePropertyMap($propertyMap, true); // If none strict, simply merge all properties in the property map into the dynamic property map. if (!$this->__strictMode) { $this->__dynamicPropertyMap = array_merge($this->__dynamicPropertyMap, $dynamicProperties); } else { foreach ($dynamicProperties as $propertyName => $propertyValue) { try { $this->__set($propertyName, $propertyValue); } catch (PropertyNotWritableException $e) { if (!$ignoreNoneWritableProperties) throw $e; } } } }
[ "public", "function", "__setSerialisablePropertyMap", "(", "$", "propertyMap", ",", "$", "ignoreNoneWritableProperties", "=", "false", ")", "{", "// Always ignore any unknown properties in parent as we need to capture these for dynamic purposes", "$", "dynamicProperties", "=", "parent", "::", "__setSerialisablePropertyMap", "(", "$", "propertyMap", ",", "true", ")", ";", "// If none strict, simply merge all properties in the property map into the dynamic property map.", "if", "(", "!", "$", "this", "->", "__strictMode", ")", "{", "$", "this", "->", "__dynamicPropertyMap", "=", "array_merge", "(", "$", "this", "->", "__dynamicPropertyMap", ",", "$", "dynamicProperties", ")", ";", "}", "else", "{", "foreach", "(", "$", "dynamicProperties", "as", "$", "propertyName", "=>", "$", "propertyValue", ")", "{", "try", "{", "$", "this", "->", "__set", "(", "$", "propertyName", ",", "$", "propertyValue", ")", ";", "}", "catch", "(", "PropertyNotWritableException", "$", "e", ")", "{", "if", "(", "!", "$", "ignoreNoneWritableProperties", ")", "throw", "$", "e", ";", "}", "}", "}", "}" ]
Set an array of serialisable properties @param array $propertyMap @param boolean $ignoreNoneWritableProperties @return array
[ "Set", "an", "array", "of", "serialisable", "properties" ]
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Object/DynamicSerialisableObject.php#L176-L199
train
beMang/phpgone
core/Middlewares/NotFoundMiddleware.php
NotFoundMiddleware.process
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $errorPageConfig = Config::getInstance()->get('errorPage'); $controllerClass = '\\app\\Controllers\\' . $errorPageConfig[0]; $route = new Route('404', $errorPageConfig[0], $errorPageConfig[1]); $controller = new $controllerClass($route, $request); $response = new Response; ob_start(); $controller->execute(); $responseController = ob_get_clean(); $response->getBody()->write($responseController); $response = $response->withStatus(404); $logger = new Logger(); $logger->info('Error 404, NotFoundMiddleware'); return $response; }
php
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $errorPageConfig = Config::getInstance()->get('errorPage'); $controllerClass = '\\app\\Controllers\\' . $errorPageConfig[0]; $route = new Route('404', $errorPageConfig[0], $errorPageConfig[1]); $controller = new $controllerClass($route, $request); $response = new Response; ob_start(); $controller->execute(); $responseController = ob_get_clean(); $response->getBody()->write($responseController); $response = $response->withStatus(404); $logger = new Logger(); $logger->info('Error 404, NotFoundMiddleware'); return $response; }
[ "public", "function", "process", "(", "ServerRequestInterface", "$", "request", ",", "RequestHandlerInterface", "$", "handler", ")", ":", "ResponseInterface", "{", "$", "errorPageConfig", "=", "Config", "::", "getInstance", "(", ")", "->", "get", "(", "'errorPage'", ")", ";", "$", "controllerClass", "=", "'\\\\app\\\\Controllers\\\\'", ".", "$", "errorPageConfig", "[", "0", "]", ";", "$", "route", "=", "new", "Route", "(", "'404'", ",", "$", "errorPageConfig", "[", "0", "]", ",", "$", "errorPageConfig", "[", "1", "]", ")", ";", "$", "controller", "=", "new", "$", "controllerClass", "(", "$", "route", ",", "$", "request", ")", ";", "$", "response", "=", "new", "Response", ";", "ob_start", "(", ")", ";", "$", "controller", "->", "execute", "(", ")", ";", "$", "responseController", "=", "ob_get_clean", "(", ")", ";", "$", "response", "->", "getBody", "(", ")", "->", "write", "(", "$", "responseController", ")", ";", "$", "response", "=", "$", "response", "->", "withStatus", "(", "404", ")", ";", "$", "logger", "=", "new", "Logger", "(", ")", ";", "$", "logger", "->", "info", "(", "'Error 404, NotFoundMiddleware'", ")", ";", "return", "$", "response", ";", "}" ]
Process method for NotFoundMiddleware @param ServerRequestInterface $request @param RequestHandlerInterface $handler @return ResponseInterface Réponse 404
[ "Process", "method", "for", "NotFoundMiddleware" ]
6da468283880b7f5b28dc3735f8f13c97382710b
https://github.com/beMang/phpgone/blob/6da468283880b7f5b28dc3735f8f13c97382710b/core/Middlewares/NotFoundMiddleware.php#L36-L51
train
Wedeto/IO
src/FileType.php
FileType.getFromFile
public static function getFromFile($path) { if (!($path instanceof File)) $path = new File($path); $ext = $path->getExtension(); $path = $path->getFullPath(); $type = new FileType($ext ?? "", ""); if (empty($type->getMimeType()) && file_exists($path)) $type->setMimeType(mime_content_type($path)); return $type; }
php
public static function getFromFile($path) { if (!($path instanceof File)) $path = new File($path); $ext = $path->getExtension(); $path = $path->getFullPath(); $type = new FileType($ext ?? "", ""); if (empty($type->getMimeType()) && file_exists($path)) $type->setMimeType(mime_content_type($path)); return $type; }
[ "public", "static", "function", "getFromFile", "(", "$", "path", ")", "{", "if", "(", "!", "(", "$", "path", "instanceof", "File", ")", ")", "$", "path", "=", "new", "File", "(", "$", "path", ")", ";", "$", "ext", "=", "$", "path", "->", "getExtension", "(", ")", ";", "$", "path", "=", "$", "path", "->", "getFullPath", "(", ")", ";", "$", "type", "=", "new", "FileType", "(", "$", "ext", "??", "\"\"", ",", "\"\"", ")", ";", "if", "(", "empty", "(", "$", "type", "->", "getMimeType", "(", ")", ")", "&&", "file_exists", "(", "$", "path", ")", ")", "$", "type", "->", "setMimeType", "(", "mime_content_type", "(", "$", "path", ")", ")", ";", "return", "$", "type", ";", "}" ]
Return the mime type based on a file name @param string $path The path to the file @return FileType The File Type for this file
[ "Return", "the", "mime", "type", "based", "on", "a", "file", "name" ]
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/FileType.php#L114-L127
train
Wedeto/IO
src/FileType.php
FileType.isPlainText
public function isPlainText() { $sc_pos = strpos($this->mime_type, ';'); if ($sc_pos !== false) $mime_type = substr($this->mime_type, 0, $sc_pos); else $mime_type = $this->mime_type; // Some application/* types are plain text switch ($mime_type) { case "application/javascript": case "application/json": case "application/xml": return true; } // Assume all text/* files to be plain text return substr($mime_type, 0, 5) === "text/"; }
php
public function isPlainText() { $sc_pos = strpos($this->mime_type, ';'); if ($sc_pos !== false) $mime_type = substr($this->mime_type, 0, $sc_pos); else $mime_type = $this->mime_type; // Some application/* types are plain text switch ($mime_type) { case "application/javascript": case "application/json": case "application/xml": return true; } // Assume all text/* files to be plain text return substr($mime_type, 0, 5) === "text/"; }
[ "public", "function", "isPlainText", "(", ")", "{", "$", "sc_pos", "=", "strpos", "(", "$", "this", "->", "mime_type", ",", "';'", ")", ";", "if", "(", "$", "sc_pos", "!==", "false", ")", "$", "mime_type", "=", "substr", "(", "$", "this", "->", "mime_type", ",", "0", ",", "$", "sc_pos", ")", ";", "else", "$", "mime_type", "=", "$", "this", "->", "mime_type", ";", "// Some application/* types are plain text", "switch", "(", "$", "mime_type", ")", "{", "case", "\"application/javascript\"", ":", "case", "\"application/json\"", ":", "case", "\"application/xml\"", ":", "return", "true", ";", "}", "// Assume all text/* files to be plain text", "return", "substr", "(", "$", "mime_type", ",", "0", ",", "5", ")", "===", "\"text/\"", ";", "}" ]
Check if a mime type is plain text @param string $mime The Mime type @return bool True if the mime type is plaintext, false if it isn't
[ "Check", "if", "a", "mime", "type", "is", "plain", "text" ]
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/FileType.php#L188-L207
train
Wedeto/Util
src/DocComment.php
DocComment.parse
protected function parse() { $lines = explode("\n", $this->comment); $current_annotation = null; $value = null; foreach ($lines as $line) { $line = trim(ltrim($line, "/* \t")); if (preg_match("/^@(\w+)( (.*))?$/", $line, $matches) === 1) { if (!empty($value)) $this->annotations[$current_annotation][] = $value; $current_annotation = $matches[1]; $value = $matches[3] ?? ''; } elseif ($current_annotation !== null) { $value .= "\n" . $line; } else { $this->preamble[] = $line; } } if (!empty($value)) $this->annotations[$current_annotation][] = rtrim($value); }
php
protected function parse() { $lines = explode("\n", $this->comment); $current_annotation = null; $value = null; foreach ($lines as $line) { $line = trim(ltrim($line, "/* \t")); if (preg_match("/^@(\w+)( (.*))?$/", $line, $matches) === 1) { if (!empty($value)) $this->annotations[$current_annotation][] = $value; $current_annotation = $matches[1]; $value = $matches[3] ?? ''; } elseif ($current_annotation !== null) { $value .= "\n" . $line; } else { $this->preamble[] = $line; } } if (!empty($value)) $this->annotations[$current_annotation][] = rtrim($value); }
[ "protected", "function", "parse", "(", ")", "{", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "this", "->", "comment", ")", ";", "$", "current_annotation", "=", "null", ";", "$", "value", "=", "null", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "ltrim", "(", "$", "line", ",", "\"/* \\t\"", ")", ")", ";", "if", "(", "preg_match", "(", "\"/^@(\\w+)( (.*))?$/\"", ",", "$", "line", ",", "$", "matches", ")", "===", "1", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "$", "this", "->", "annotations", "[", "$", "current_annotation", "]", "[", "]", "=", "$", "value", ";", "$", "current_annotation", "=", "$", "matches", "[", "1", "]", ";", "$", "value", "=", "$", "matches", "[", "3", "]", "??", "''", ";", "}", "elseif", "(", "$", "current_annotation", "!==", "null", ")", "{", "$", "value", ".=", "\"\\n\"", ".", "$", "line", ";", "}", "else", "{", "$", "this", "->", "preamble", "[", "]", "=", "$", "line", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "$", "this", "->", "annotations", "[", "$", "current_annotation", "]", "[", "]", "=", "rtrim", "(", "$", "value", ")", ";", "}" ]
Helper method that parses the doc comment
[ "Helper", "method", "that", "parses", "the", "doc", "comment" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DocComment.php#L50-L80
train
Wedeto/Util
src/DocComment.php
DocComment.getAnnotation
public function getAnnotation(string $name, bool $single = true) { $val = $this->annotations[$name] ?? []; return $single ? (count($val) ? reset($val) : null) : $val; }
php
public function getAnnotation(string $name, bool $single = true) { $val = $this->annotations[$name] ?? []; return $single ? (count($val) ? reset($val) : null) : $val; }
[ "public", "function", "getAnnotation", "(", "string", "$", "name", ",", "bool", "$", "single", "=", "true", ")", "{", "$", "val", "=", "$", "this", "->", "annotations", "[", "$", "name", "]", "??", "[", "]", ";", "return", "$", "single", "?", "(", "count", "(", "$", "val", ")", "?", "reset", "(", "$", "val", ")", ":", "null", ")", ":", "$", "val", ";", "}" ]
Get an annotated value for the DocComment @param string $name The name of the annotation @param bool $single Return either the first or all values @return string|array The string when single = true, otherwise all annotations. When single is true, and no annotation was found, null is returned.
[ "Get", "an", "annotated", "value", "for", "the", "DocComment" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DocComment.php#L90-L94
train
Wedeto/Util
src/DocComment.php
DocComment.getAnnotationTokens
public function getAnnotationTokens(string $name) { $val = $this->getAnnotation($name, true); $val = trim(preg_replace("/\s{1,}/", " ", $val)); return !empty($val) ? explode(" ", $val) : []; }
php
public function getAnnotationTokens(string $name) { $val = $this->getAnnotation($name, true); $val = trim(preg_replace("/\s{1,}/", " ", $val)); return !empty($val) ? explode(" ", $val) : []; }
[ "public", "function", "getAnnotationTokens", "(", "string", "$", "name", ")", "{", "$", "val", "=", "$", "this", "->", "getAnnotation", "(", "$", "name", ",", "true", ")", ";", "$", "val", "=", "trim", "(", "preg_replace", "(", "\"/\\s{1,}/\"", ",", "\" \"", ",", "$", "val", ")", ")", ";", "return", "!", "empty", "(", "$", "val", ")", "?", "explode", "(", "\" \"", ",", "$", "val", ")", ":", "[", "]", ";", "}" ]
Get the tokenized annotation - split by whitespace @param string $name The annotation to get the first word from @return array The tokens in the annotation
[ "Get", "the", "tokenized", "annotation", "-", "split", "by", "whitespace" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DocComment.php#L112-L118
train
RocketPropelledTortoise/Core
src/Taxonomy/Repositories/TermRepository.php
TermRepository.cacheTerm
protected function cacheTerm($term_id) { $term = TermContainer::with('translations')->find($term_id); if (!$term || !count($term->translations)) { return false; } $translations = []; foreach ($term->translations as $t) { $translations[$t->language_id] = $t; } $first = $term->translations[0]; $final_term = [ 'term_id' => $term_id, 'vocabulary_id' => $term->vocabulary_id, 'type' => $term->type, ]; if (T::isTranslatable($term->vocabulary_id)) { foreach (I18N::languages() as $lang => $l) { if (array_key_exists($l['id'], $translations)) { $term = $translations[$l['id']]; } else { $term = new TermData(); $term->term_id = $term_id; $term->language_id = $l['id']; $term->title = $first->title; $term->description = $first->description; $term->translated = false; } $final_term['lang_' . $lang] = $term; } } else { $final_term['has_translations'] = false; $final_term['lang'] = $first; } $this->cache->put(self::$cacheKey . $term_id, $final_term, 60 * 0); return $final_term; }
php
protected function cacheTerm($term_id) { $term = TermContainer::with('translations')->find($term_id); if (!$term || !count($term->translations)) { return false; } $translations = []; foreach ($term->translations as $t) { $translations[$t->language_id] = $t; } $first = $term->translations[0]; $final_term = [ 'term_id' => $term_id, 'vocabulary_id' => $term->vocabulary_id, 'type' => $term->type, ]; if (T::isTranslatable($term->vocabulary_id)) { foreach (I18N::languages() as $lang => $l) { if (array_key_exists($l['id'], $translations)) { $term = $translations[$l['id']]; } else { $term = new TermData(); $term->term_id = $term_id; $term->language_id = $l['id']; $term->title = $first->title; $term->description = $first->description; $term->translated = false; } $final_term['lang_' . $lang] = $term; } } else { $final_term['has_translations'] = false; $final_term['lang'] = $first; } $this->cache->put(self::$cacheKey . $term_id, $final_term, 60 * 0); return $final_term; }
[ "protected", "function", "cacheTerm", "(", "$", "term_id", ")", "{", "$", "term", "=", "TermContainer", "::", "with", "(", "'translations'", ")", "->", "find", "(", "$", "term_id", ")", ";", "if", "(", "!", "$", "term", "||", "!", "count", "(", "$", "term", "->", "translations", ")", ")", "{", "return", "false", ";", "}", "$", "translations", "=", "[", "]", ";", "foreach", "(", "$", "term", "->", "translations", "as", "$", "t", ")", "{", "$", "translations", "[", "$", "t", "->", "language_id", "]", "=", "$", "t", ";", "}", "$", "first", "=", "$", "term", "->", "translations", "[", "0", "]", ";", "$", "final_term", "=", "[", "'term_id'", "=>", "$", "term_id", ",", "'vocabulary_id'", "=>", "$", "term", "->", "vocabulary_id", ",", "'type'", "=>", "$", "term", "->", "type", ",", "]", ";", "if", "(", "T", "::", "isTranslatable", "(", "$", "term", "->", "vocabulary_id", ")", ")", "{", "foreach", "(", "I18N", "::", "languages", "(", ")", "as", "$", "lang", "=>", "$", "l", ")", "{", "if", "(", "array_key_exists", "(", "$", "l", "[", "'id'", "]", ",", "$", "translations", ")", ")", "{", "$", "term", "=", "$", "translations", "[", "$", "l", "[", "'id'", "]", "]", ";", "}", "else", "{", "$", "term", "=", "new", "TermData", "(", ")", ";", "$", "term", "->", "term_id", "=", "$", "term_id", ";", "$", "term", "->", "language_id", "=", "$", "l", "[", "'id'", "]", ";", "$", "term", "->", "title", "=", "$", "first", "->", "title", ";", "$", "term", "->", "description", "=", "$", "first", "->", "description", ";", "$", "term", "->", "translated", "=", "false", ";", "}", "$", "final_term", "[", "'lang_'", ".", "$", "lang", "]", "=", "$", "term", ";", "}", "}", "else", "{", "$", "final_term", "[", "'has_translations'", "]", "=", "false", ";", "$", "final_term", "[", "'lang'", "]", "=", "$", "first", ";", "}", "$", "this", "->", "cache", "->", "put", "(", "self", "::", "$", "cacheKey", ".", "$", "term_id", ",", "$", "final_term", ",", "60", "*", "0", ")", ";", "return", "$", "final_term", ";", "}" ]
Puts the term in the cache and returns it for usage @param int $term_id @return array
[ "Puts", "the", "term", "in", "the", "cache", "and", "returns", "it", "for", "usage" ]
78b65663fc463e21e494257140ddbed0a9ccb3c3
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Taxonomy/Repositories/TermRepository.php#L76-L120
train