_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q12600 | GitAuthorExtractor.copyDetection | train | private function copyDetection(array $logItem, array &$fileHistory, GitRepository $git)
{
if ($logItem['criteria'] !== 'C') {
return;
}
$fromLastCommit = $this->commitCollection[$logItem['commit']]['parent'];
$fromFileContent = $this->getFileContent($fromLastCommit . ':' . $logItem['from'], $git);
$fromFileContentLength = \strlen($fromFileContent);
$toFileContent = $this->getFileContent($logItem['commit'] . ':' . $logItem['to'], $git);
$toFileContentLength = \strlen($toFileContent);
if ($fromFileContentLength === $toFileContentLength) {
$fileHistory[\md5($logItem['from'])] = $logItem['from'];
return;
}
$tempFrom =
$this->createTempFile($logItem['commit'] . ':' . $logItem['from'], $fromFileContent);
$tempTo = $this->createTempFile($logItem['commit'] . ':' . $logItem['to'], $toFileContent);
$detector = new Detector(new DefaultStrategy());
$result = $detector->copyPasteDetection([$tempFrom, $tempTo], 5, 35);
if (!$result->count()) {
return;
}
$fileHistory[\md5($logItem['from'])] = $logItem['from'];
} | php | {
"resource": ""
} |
q12601 | GitAuthorExtractor.createTempFile | train | private function createTempFile($name, $content)
{
$tempDir = \sys_get_temp_dir();
$fileName = \md5($name);
$filePath = $tempDir . DIRECTORY_SEPARATOR . 'phpcq-author-validation' . DIRECTORY_SEPARATOR . $fileName;
if (\file_exists($filePath)) {
return $filePath;
}
if (!\file_exists(\dirname($filePath)) && !\mkdir($concurrentDirectory = \dirname($filePath))
&& !is_dir(
$concurrentDirectory
)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
$file = \fopen($filePath, 'wb');
\fwrite($file, $content);
return $filePath;
} | php | {
"resource": ""
} |
q12602 | GitAuthorExtractor.removeTempDirectory | train | private function removeTempDirectory()
{
$tempDir = \sys_get_temp_dir();
$directoryPath = $tempDir . DIRECTORY_SEPARATOR . 'phpcq-author-validation';
if (!\file_exists($directoryPath)) {
return;
}
$directory = \opendir($directoryPath);
while (($file = \readdir($directory)) !== false) {
if (\in_array($file, ['.', '..'])) {
continue;
}
\unlink($directoryPath . DIRECTORY_SEPARATOR . $file);
}
\rmdir($directoryPath);
} | php | {
"resource": ""
} |
q12603 | FileConfigService.save | train | public function save()
{
$this->load();
// Do the work in case we have only changed hash
if ($this->isChanged()) {
@chmod($this->path, 0777);
return file_put_contents($this->path, $this->fileType->render($this->config));
} else {
return true;
}
} | php | {
"resource": ""
} |
q12604 | FileConfigService.store | train | public function store($key, $value)
{
$this->load();
$this->config[$key] = $value;
return true;
} | php | {
"resource": ""
} |
q12605 | FileConfigService.storeMany | train | public function storeMany(array $pair)
{
foreach ($pair as $key => $value) {
$this->set($key, $value);
}
return true;
} | php | {
"resource": ""
} |
q12606 | FileConfigService.get | train | public function get($key, $default = false)
{
$this->load();
if ($this->has($key)) {
return $this->config[$key];
} else {
return $default;
}
} | php | {
"resource": ""
} |
q12607 | FileConfigService.remove | train | public function remove($key)
{
$this->load();
if ($this->exists($key)) {
unset($this->config[$key]);
return true;
} else {
throw new RuntimeException(sprintf('Attempted to read non-existing key "%s"', $key));
}
} | php | {
"resource": ""
} |
q12608 | FileConfigService.load | train | private function load()
{
if ($this->loaded === false) {
if ($this->autoCreate === true) {
if (!is_file($this->path)) {
$this->touch();
}
}
$array = $this->fileType->fetch($this->path);
if (is_array($array)) {
// Keep initial array hash
$this->hash = $this->serializer->buildHash($array);
$this->config = $array;
$this->loaded = true;
return true;
} else {
throw new LogicException(sprintf(
'Required file should return an array and only, not "%s"', gettype($array)
));
}
}
return true;
} | php | {
"resource": ""
} |
q12609 | ServiceLocator.get | train | public function get($service)
{
if ($this->has($service)) {
return $this->container[$service];
} else {
throw new RuntimeException(sprintf(
'Attempted to grab non-existing service "%s"', $service
));
}
} | php | {
"resource": ""
} |
q12610 | ServiceLocator.registerArray | train | public function registerArray(array $instances)
{
foreach ($instances as $name => $instance) {
$this->register($name, $instance);
}
return $this;
} | php | {
"resource": ""
} |
q12611 | ServiceLocator.register | train | public function register($name, $instance)
{
if (!is_string($name)) {
throw new InvalidArgumentException(sprintf(
'Argument #1 $name must be a string, received "%s"', gettype($name)
));
}
$this->container[$name] = $instance;
return $this;
} | php | {
"resource": ""
} |
q12612 | ServiceLocator.has | train | public function has($service)
{
if (!is_string($service)) {
throw new InvalidArgumentException(sprintf(
'Service name must be a string, received "%s"', gettype($service)
));
}
return isset($this->container[$service]);
} | php | {
"resource": ""
} |
q12613 | ServiceLocator.remove | train | public function remove($service)
{
if ($this->has($service)) {
unset($this->container[$service]);
return true;
} else {
trigger_error(sprintf(
'Attempted to un-register non-existing service "%s"', $service
));
return false;
}
} | php | {
"resource": ""
} |
q12614 | Template_Tag.get_pure_post_content | train | public static function get_pure_post_content() {
$post = get_post();
if ( ! $post || ! isset( $post->post_content ) ) {
return;
}
if ( post_password_required( $post ) ) {
return;
}
$extended = get_extended( $post->post_content );
$content = $extended['main'];
return $content;
} | php | {
"resource": ""
} |
q12615 | Template_Tag.pure_trim_excerpt | train | public static function pure_trim_excerpt() {
$raw_excerpt = '';
$text = static::get_pure_post_content();
$text = strip_shortcodes( $text );
$text = str_replace( ']]>', ']]>', $text );
$excerpt_length = apply_filters( 'excerpt_length', 55 );
$excerpt_more = apply_filters( 'excerpt_more', ' […]' );
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
} | php | {
"resource": ""
} |
q12616 | Template_Tag.get_page_templates | train | public static function get_page_templates() {
static $wrappers = [];
if ( $wrappers ) {
return $wrappers;
}
$page_templates = new Model\Page_Templates();
$wrappers = $page_templates->get();
return $wrappers;
} | php | {
"resource": ""
} |
q12617 | ModelResult.last | train | public function last()
{
if ($this->count()) {
$models = $this->getModels();
return $models[$this->count() - 1];
}
return null;
} | php | {
"resource": ""
} |
q12618 | ModelResult.json | train | public function json($fields = array(), $recursive = true)
{
$list = array();
foreach ($this->getModels() as $model) {
$list[] = $model->json($fields, $recursive);
}
return $list;
} | php | {
"resource": ""
} |
q12619 | ModelResult.order | train | public function order($field, $desc = false)
{
if(count($this->models) > 0) {
$instance = $this->reflection->newInstance();
$string = $instance->isString($field);
usort($this->models, function ($a, $b) use ($field, $string) {
if($string) {
return strcmp($a[$field], $b[$field]);
}
return $a[$field] - $b[$field];
});
if ($desc) {
$this->models = array_reverse($this->models);
}
}
return $this;
} | php | {
"resource": ""
} |
q12620 | Question.send | train | public static function send(
Bookboon $bookboon,
array $variables = [],
string $rootSegmentId = ''
) : BookboonResponse {
$url = $rootSegmentId == '' ? '/questions' : '/questions/' . $rootSegmentId;
$bResponse = $bookboon->rawRequest($url, $variables, ClientInterface::HTTP_POST);
return $bResponse;
} | php | {
"resource": ""
} |
q12621 | Book.getThumbnail | train | public function getThumbnail(int $size = 210, bool $ssl = false)
{
$thumbs = [];
foreach ($this->safeGet('thumbnail') as $thumb) {
$thumbs[$thumb['width']] = $thumb['_link'];
}
$sizes = array_keys($thumbs);
while (true) {
$thumbSize = array_shift($sizes);
if ((int) $size <= (int) $thumbSize || count($sizes) === 0) {
return $thumbs[$thumbSize];
}
}
} | php | {
"resource": ""
} |
q12622 | HttpResponse.authenticate | train | public function authenticate($login, $password)
{
if (!isset($this->server['PHP_AUTH_USER'])) {
$this->forbid();
return false;
} else {
if (($this->server['PHP_AUTH_USER'] == $login) && ($this->server['PHP_AUTH_PW'] == $password)) {
return true;
} else {
$this->forbid();
return false;
}
}
} | php | {
"resource": ""
} |
q12623 | HttpResponse.setStatusCode | train | public function setStatusCode($code)
{
$this->headerBag->setStatusCode($code);
$this->statusCode = $code;
return $this;
} | php | {
"resource": ""
} |
q12624 | HttpResponse.enableCache | train | public function enableCache($timestamp, $ttl)
{
// HttpCache alters HeaderBag's state internally
$handler = new HttpCache($this->headerBag);
$handler->configure($timestamp, $ttl);
return $this;
} | php | {
"resource": ""
} |
q12625 | HttpResponse.setContentType | train | public function setContentType($type)
{
$this->headerBag->appendPair('Content-Type', sprintf('%s;charset=%s', $type, $this->charset));
return $this;
} | php | {
"resource": ""
} |
q12626 | TurtleCoind.getBlockTemplate | train | public function getBlockTemplate(int $reserveSize, string $address):JsonResponse
{
$params = [
'reserve_size' => $reserveSize,
'wallet_address' => $address,
];
return $this->rpcPost('getblocktemplate', $params);
} | php | {
"resource": ""
} |
q12627 | ExtraShortcodeParser.TweetHandler | train | public static function TweetHandler($arguments)
{
if (!isset($arguments['id'])) {
return null;
}
if (substr($arguments['id'], 0, 4) === 'http') {
list($unneeded, $id) = explode('/status/', $arguments['id']);
} else {
$id = $arguments['id'];
}
$data = json_decode(file_get_contents('https://api.twitter.com/1/statuses/oembed.json?id=' . $id . '&omit_script=true&lang=en'), 1);
return $data['html'];
} | php | {
"resource": ""
} |
q12628 | Uri.isSamePrimaryResource | train | public function isSamePrimaryResource(Uri $uri)
{
if (!$this->isAbsolute() || !$uri->isAbsolute()) {
throw new \LogicException('Cannot compare URIs: both must be absolute');
}
return $this->primaryIdentifier === $uri->getPrimaryResourceIdentifier();
} | php | {
"resource": ""
} |
q12629 | CollectionSelect2TypeExtension.normalizeOptions | train | protected function normalizeOptions(array $options, array $value)
{
return $options['select2']['enabled']
? array_merge($value, [
'error_bubbling' => false,
'multiple' => false,
'select2' => array_merge($options['select2'], [
'tags' => $options['allow_add'],
]),
])
: $value;
} | php | {
"resource": ""
} |
q12630 | FileEntity.getUniqueName | train | public function getUniqueName()
{
$key = 'uniq';
// Lazy initialization
if (!isset($this->container[$key])) {
$extension = $this->getExtension();
// If extension avaiable, use it
if ($extension) {
$name = sprintf('%s.%s', uniqid(), $extension);
} else {
// Otherwise just filename without extension
$name = uniqid();
}
$this->container[$key] = $name;
}
return $this->container[$key];
} | php | {
"resource": ""
} |
q12631 | SlideshowCMSExtension.updateCMSFields | train | public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$fields->removeByName(array('News', 'NewsID', 'SortOrder'));
$fields->addFieldsToTab(
'Root.Main', array(
TextField::create('Title', $owner->fieldLabel('Title')),
HtmlEditorField::create('Description', $owner->fieldLabel('Description')),
UploadField::create('Image', $owner->fieldLabel('Image')),
)
);
} | php | {
"resource": ""
} |
q12632 | Http.setPutFromRequest | train | public function setPutFromRequest()
{
if ($this->_put === null) {
if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
$this->_put = file_get_contents("php://input");
}
} else {
$this->_put = '';
}
} | php | {
"resource": ""
} |
q12633 | Http.redirectForTrailingSlash | train | public function redirectForTrailingSlash()
{
$config = \Nf\Registry::get('config');
$redirectionUrl = false;
$requestParams = '';
$requestPage = '/' . $this->_uri;
// we don't redirect for the home page...
if ($requestPage != '/' && mb_strpos($requestPage, '/?') !== 0) {
// the url without the params is :
if (mb_strpos($requestPage, '?') !== false) {
$requestParams = mb_substr($requestPage, mb_strpos($requestPage, '?'), mb_strlen($requestPage) - mb_strpos($requestPage, '?'));
$requestPage = mb_substr($requestPage, 0, mb_strpos($requestPage, '?'));
}
if (isset($config->trailingSlash->needed) && $config->trailingSlash->needed == true) {
if (mb_substr($requestPage, - 1, 1) != '/') {
$redirectionUrl = 'http://' . $_SERVER['HTTP_HOST'] . $requestPage . '/' . $requestParams;
}
} else {
if (mb_substr($requestPage, - 1, 1) == '/') {
$redirectionUrl = 'http://' . $_SERVER['HTTP_HOST'] . rtrim($requestPage, '/') . $requestParams;
}
}
if ($redirectionUrl !== false) {
$response = new \Nf\Front\Response\Http();
$response->redirect($redirectionUrl, 301);
$response->sendHeaders();
return true;
}
}
return false;
} | php | {
"resource": ""
} |
q12634 | ParentChild.isChildPost | train | public static function isChildPost($postOrPostId = null)
{
$post = self::getPost($postOrPostId);
if (empty($post)) {
return false;
}
return $post->post_parent > 0;
} | php | {
"resource": ""
} |
q12635 | ParentChild.getNextParentPost | train | public static function getNextParentPost($inSameTerm = false, $excludedTerms = '', $taxonomy = 'category')
{
add_filter('get_next_post_where', [__CLASS__, 'addParentPostToAdjacentSql']);
return get_adjacent_post($inSameTerm, $excludedTerms, false, $taxonomy);
} | php | {
"resource": ""
} |
q12636 | ParentChild.getPreviousParentPost | train | public static function getPreviousParentPost($inSameTerm = false, $excludedTerms = '', $taxonomy = 'category')
{
add_filter('get_previous_post_where', [__CLASS__, 'addParentPostToAdjacentSql']);
return get_adjacent_post($inSameTerm, $excludedTerms, true, $taxonomy);
} | php | {
"resource": ""
} |
q12637 | ParentChild.extractPostId | train | public static function extractPostId($postOrPostId = null)
{
if (is_object($postOrPostId)) {
return property_exists($postOrPostId, 'ID')
? (int) $postOrPostId->ID
: null;
}
if ($postOrPostId > 0) {
return (int) $postOrPostId;
}
return get_the_ID();
} | php | {
"resource": ""
} |
q12638 | Position.createRandomized | train | public function createRandomized($minDistance = -0.005, $maxDistance = 0.005)
{
$newCoordinates = Geo::calculateNewCoordinates($this->latitude, $this->longitude, Random::randomFloat($minDistance, $maxDistance), rand(0,360));
$newAltitude = $this->altitude + round(Random::randomFloat(-2, 2), 2);
$newAccuracy = mt_rand(3, 10);
return new self($newCoordinates[0], $newCoordinates[1], $newAltitude, $newAccuracy);
} | php | {
"resource": ""
} |
q12639 | AjaxChoiceListHelper.extractChoiceLoader | train | protected static function extractChoiceLoader($form)
{
$form = static::getForm($form);
$choiceLoader = $form->getAttribute('choice_loader', $form->getOption('choice_loader'));
return $choiceLoader;
} | php | {
"resource": ""
} |
q12640 | AjaxChoiceListHelper.extractAjaxFormatter | train | protected static function extractAjaxFormatter($form)
{
$form = static::getForm($form);
$formatter = $form->getAttribute('select2', $form->getOption('select2'));
$formatter = $formatter['ajax_formatter'];
if (!$formatter instanceof AjaxChoiceListFormatterInterface) {
throw new UnexpectedTypeException($formatter, 'Fxp\Component\FormExtensions\Form\ChoiceList\Formatter\AjaxChoiceListFormatterInterface');
}
return $formatter;
} | php | {
"resource": ""
} |
q12641 | StringHelper.camelize | train | public static function camelize($string, $delimiter = ' '): string
{
$stringParts = explode($delimiter, $string);
$camelized = array_map('ucwords', $stringParts);
return implode($delimiter, $camelized);
} | php | {
"resource": ""
} |
q12642 | StringHelper.compileAttributeStringFromArray | train | public static function compileAttributeStringFromArray(array $array): string
{
$attributeString = '';
foreach ($array as $key => $value) {
if (null === $value || (\is_bool($value) && $value)) {
$attributeString .= "$key ";
} else if (!\is_bool($value)) {
$attributeString .= "$key=\"$value\" ";
}
}
return $attributeString ? ' ' . $attributeString : '';
} | php | {
"resource": ""
} |
q12643 | IDEntityGrz.getFormatPatternByGostType | train | public static function getFormatPatternByGostType($gost_type)
{
foreach (static::$patterns_and_types_map as $format_pattern => $gost_types) {
foreach ((array) $gost_types as $iterated_gost_type) {
if ($iterated_gost_type === $gost_type) {
return $format_pattern;
}
}
}
} | php | {
"resource": ""
} |
q12644 | IDEntityGrz.getFormatPattern | train | public function getFormatPattern()
{
static $kyr = self::KYR_CHARS;
switch (true) {
// X000XX77_OR_X000XX777
case \preg_match("~^[{$kyr}]{1}\d{3}[{$kyr}]{2}\d{2,3}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_1;
// X000XX
case \preg_match("~^[{$kyr}]{1}\d{3}[{$kyr}]{2}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_2;
// XX00077
case \preg_match("~^[{$kyr}]{2}\d{3}\d{2}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_3;
// 0000XX77
case \preg_match("~^\d{4}[{$kyr}]{2}\d{2}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_4;
// XX000077
case \preg_match("~^[{$kyr}]{2}\d{4}\d{2}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_5;
// X000077
case \preg_match("~^[{$kyr}]{1}\d{4}\d{2}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_6;
// 000X77
case \preg_match("~^\d{3}[{$kyr}]{1}\d{2}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_7;
// 0000X77
case \preg_match("~^\d{4}[{$kyr}]{1}\d{2}$~iu", $this->value) === 1:
return self::FORMAT_PATTERN_8;
}
} | php | {
"resource": ""
} |
q12645 | ImageBag.getPath | train | public function getPath($size)
{
if ($this->isProvided()) {
return $this->locationBuilder->buildPath($this->id, $this->cover, $size);
} else {
throw new RuntimeException('You gotta provide both id and cover to use this method');
}
} | php | {
"resource": ""
} |
q12646 | ImageBag.getUrl | train | public function getUrl($size)
{
if ($this->isProvided()) {
return $this->locationBuilder->buildUrl($this->id, $this->cover, $size);
} else {
throw new RuntimeException('You gotta provide both id and cover to use this method');
}
} | php | {
"resource": ""
} |
q12647 | Between.isValid | train | public function isValid($target)
{
if ($target >= $this->start && $target <= $this->end) {
return true;
} else {
$this->violate(sprintf($this->message, $this->start, $this->end));
return false;
}
} | php | {
"resource": ""
} |
q12648 | DeployTasks.deployBuild | train | public function deployBuild($opts = [
'build-path' => null,
'deploy-type' => 'git',
'include-asset' => [],
])
{
$this->executeCommandHook(__FUNCTION__, 'before');
$build_path = $this->buildPath($opts);
$deploy_type = $opts['deploy-type'];
if (!file_exists($build_path)) {
$this->_mkdir($build_path);
}
$this->executeBuild(__FUNCTION__, $build_path);
$this->executeIncludeAssets($opts['include-asset'], $build_path);
$this->executeCommandHook(__FUNCTION__, 'after');
$continue = !is_null($deploy_type)
? $this->doAsk(new ConfirmationQuestion('Run deployment? (y/n) [yes] ', true))
: false;
if (!$continue) {
return;
}
$this->deployPush([
'build-path' => $build_path,
'deploy-type' => $deploy_type
]);
} | php | {
"resource": ""
} |
q12649 | DeployTasks.deployPush | train | public function deployPush($opts = [
'build-path' => null,
'deploy-type' => 'git',
])
{
$this->executeCommandHook(__FUNCTION__, 'before');
$build_path = $this->buildPath($opts);
if (!file_exists($build_path)) {
throw new DeploymentRuntimeException(
'Build directory does not exist.'
);
}
/** @var DeployBase $deploy */
$deploy = $this->loadDeployTask(
$opts['deploy-type'],
$build_path
);
$this->executeDeploy(__FUNCTION__, $deploy);
$this->executeCommandHook(__FUNCTION__, 'after');
} | php | {
"resource": ""
} |
q12650 | DeployTasks.executeIncludeAssets | train | protected function executeIncludeAssets(array $assets, $build_path)
{
$root_path = ProjectX::projectRoot();
foreach ($assets as $asset) {
$file_info = new \splFileInfo("{$root_path}/{$asset}");
if (!file_exists($file_info)) {
continue;
}
$file_path = $file_info->getRealPath();
$file_method = $file_info->isFile() ? '_copy' : '_mirrorDir';
call_user_func_array([$this, $file_method], [
$file_path,
"{$build_path}/{$file_info->getFilename()}"
]);
}
} | php | {
"resource": ""
} |
q12651 | DeployTasks.executeBuild | train | protected function executeBuild($method, $build_path)
{
$this->say('Build has initialized!');
$this->executeCommandHook($method, 'before_build');
$this->projectInstance()->onDeployBuild($build_path);
$this->executeCommandHook($method, 'after_build');
$this->say('Build has completed!');
return $this;
} | php | {
"resource": ""
} |
q12652 | DeployTasks.executeDeploy | train | protected function executeDeploy($method, DeployBase $deploy)
{
$this->say('Deploy has initialized!');
$deploy->beforeDeploy();
$this->executeCommandHook($method, 'before_deploy');
$deploy->onDeploy();
$this->executeCommandHook($method, 'after_deploy');
$deploy->afterDeploy();
$this->say('Deploy has completed!');
return $this;
} | php | {
"resource": ""
} |
q12653 | DeployTasks.loadDeployTask | train | protected function loadDeployTask($type, $build_path, array $configurations = [])
{
$definitions = $this->deployDefinitions();
$classname = isset($definitions[$type]) && class_exists($definitions[$type])
? $definitions[$type]
: 'Droath\ProjectX\Deploy\NullDeploy';
return (new $classname($build_path, $configurations))
->setInput($this->input())
->setOutput($this->output())
->setBuilder($this->getBuilder())
->setContainer($this->getContainer());
} | php | {
"resource": ""
} |
q12654 | GitProjectAuthorExtractor.hasUncommittedChanges | train | private function hasUncommittedChanges($git)
{
$status = $git->status()->short()->getIndexStatus();
if (empty($status)) {
return false;
}
return true;
} | php | {
"resource": ""
} |
q12655 | Request.sslRedirect | train | public function sslRedirect()
{
if (!$this->isSecure()) {
$redirect = 'https://' . $this->server['HTTP_HOST'] . $this->server['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
} | php | {
"resource": ""
} |
q12656 | Request.getAll | train | public function getAll($separate = true)
{
if ($this->isPost()) {
$data = $this->getPost();
}
if ($this->isGet()) {
$data = $this->getQuery();
}
// Append files also, if we have them
if ($this->hasFiles()) {
$files = $this->getFiles();
} else {
$files = array();
}
if ($separate === false) {
return array_merge($data, $files);
} else {
$result = array();
$result['data'] = $data;
$result['files'] = !empty($files) ? $files : array();
return $result;
}
} | php | {
"resource": ""
} |
q12657 | Request.buildQuery | train | public function buildQuery(array $params, $includeCurrent = true)
{
if ($includeCurrent == true) {
$params = array_replace_recursive($this->getQuery(), $params);
}
return $this->serialize($params);
} | php | {
"resource": ""
} |
q12658 | Request.getFile | train | public function getFile($name = null, $index = 0, $default = false)
{
$files = $this->getFiles($name);
if (isset($files[$index])) {
return $files[$index];
} else {
return $default;
}
} | php | {
"resource": ""
} |
q12659 | Request.hasFiles | train | public function hasFiles($name = null)
{
if (!empty($this->files)) {
// if $name is null, then a global checking must be done
return $this->getFilesbag()->hasFiles($name);
}
// By default
return false;
} | php | {
"resource": ""
} |
q12660 | Request.getFilesbag | train | private function getFilesbag()
{
static $filesBag = null;
if (is_null($filesBag)) {
$filesBag = new FileInput($this->files);
}
return $filesBag;
} | php | {
"resource": ""
} |
q12661 | Request.getSubdomains | train | public function getSubdomains()
{
$current = $this->server['HTTP_HOST'];
$parts = explode('.', $current);
// two steps back
array_pop($parts);
array_pop($parts);
return $parts;
} | php | {
"resource": ""
} |
q12662 | Request.getDomain | train | public function getDomain()
{
$current = $this->server['HTTP_HOST'];
$parts = explode('.', $current);
$zone = array_pop($parts);
$provider = array_pop($parts);
return $provider . '.' . $zone;
} | php | {
"resource": ""
} |
q12663 | Request.getLanguages | train | public function getLanguages()
{
$source = $this->server['HTTP_ACCEPT_LANGUAGE'];
if (strpos($source, ',') !== false) {
$langs = explode(',', $source);
return $langs;
} else {
return array($source);
}
} | php | {
"resource": ""
} |
q12664 | Request.isSecure | train | public function isSecure()
{
return (
(!empty($this->server['HTTPS']) && $this->server['HTTPS'] != 'off') ||
(!empty($this->server['HTTP_HTTPS']) && $this->server['HTTP_HTTPS'] != 'off') ||
$this->server['REQUEST_SCHEME'] == 'https' || $this->server['SERVER_PORT'] == 443
);
} | php | {
"resource": ""
} |
q12665 | Request.hasQueryNs | train | public function hasQueryNs($ns, $key)
{
$data = $this->getQuery($ns);
// If there's no such key, then $data isn't an array, so just make sure
if (is_array($data)) {
return array_key_exists($key, $data);
} else {
// If $data isn't an array, then there's no such key
return false;
}
} | php | {
"resource": ""
} |
q12666 | Request.getQueryNs | train | public function getQueryNs($ns, $key, $default)
{
if ($this->hasQueryNs($ns, $key)) {
$data = $this->getQuery($ns);
if (isset($data[$key])) {
return $data[$key];
}
}
return $default;
} | php | {
"resource": ""
} |
q12667 | Request.getWithNsQuery | train | public function getWithNsQuery($ns, array $data, $mark = true)
{
if ($this->hasQuery($ns)) {
$query = $this->getQuery($ns);
$url = null;
if ($mark === true) {
$url = '?';
}
$url .= http_build_query(array($ns => array_merge($query, $data)));
$url = str_replace('%25s', '%s', $url);
return $url;
} else {
return null;
}
} | php | {
"resource": ""
} |
q12668 | Request.getWithQuery | train | public function getWithQuery(array $data, $mark = true)
{
if ($this->hasQuery()) {
$url = null;
if ($mark === true) {
$url = '?';
}
$url .= http_build_query(array_merge($this->getQuery(), $data));
$url = str_replace('%25s', '%s', $url);
return $url;
} else {
return null;
}
} | php | {
"resource": ""
} |
q12669 | Request.hasQuery | train | public function hasQuery()
{
if (func_num_args() == 0) {
return !empty($this->query);
}
foreach (func_get_args() as $key) {
if (!$this->hasParam($this->query, $key)) {
return false;
}
}
return true;
} | php | {
"resource": ""
} |
q12670 | Request.hasPost | train | public function hasPost()
{
if (func_num_args() == 0) {
return !empty($this->post);
}
foreach (func_get_args() as $key) {
if (!$this->hasParam($this->post, $key)) {
return false;
}
}
return true;
} | php | {
"resource": ""
} |
q12671 | Request.getPost | train | public function getPost($key = null, $default = false)
{
if ($key !== null) {
if (array_key_exists($key, $this->post)) {
return $this->post[$key];
} else {
return $default;
}
} else {
return $this->post;
}
} | php | {
"resource": ""
} |
q12672 | Request.getQuery | train | public function getQuery($key = null, $default = false)
{
if ($key !== null) {
if (array_key_exists($key, $this->query)) {
return $this->query[$key];
} else {
return $default;
}
} else {
return $this->query;
}
} | php | {
"resource": ""
} |
q12673 | SqlCacheEngine.isOutdated | train | private function isOutdated($key, $time)
{
return ($this->getTouchByKey($key) + $this->getKeyTtl($key)) < $time;
} | php | {
"resource": ""
} |
q12674 | SqlCacheEngine.set | train | public function set($key, $value, $ttl)
{
$this->initializeOnDemand();
if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Argument #1 must be a string and only, received "%s"', gettype($key)));
}
$time = time();
if ($this->has($key)) {
$this->cacheMapper->update($key, $value, $ttl);
} else {
$this->cacheMapper->insert($key, $value, $ttl, $time);
}
// For the current request
$this->cache[$key] = array(
ConstProviderInterface::CACHE_PARAM_VALUE => $value,
ConstProviderInterface::CACHE_PARAM_CREATED_ON => $time,
ConstProviderInterface::CACHE_PARAM_TTL => $ttl
);
return true;
} | php | {
"resource": ""
} |
q12675 | SqlCacheEngine.getAll | train | public function getAll()
{
$this->initializeOnDemand();
$result = array();
foreach ($this->cache as $key => $options) {
$result[$key] = $options[ConstProviderInterface::CACHE_PARAM_VALUE];
}
return $result;
} | php | {
"resource": ""
} |
q12676 | SqlCacheEngine.get | train | public function get($key, $default = false)
{
$this->initializeOnDemand();
if ($this->has($key)) {
return $this->cache[$key][ConstProviderInterface::CACHE_PARAM_VALUE];
} else {
return $default;
}
} | php | {
"resource": ""
} |
q12677 | ResponsiveExtension.normaliseViewport | train | protected function normaliseViewport($prefix, array $valid, $value)
{
$value = $this->convertToArray($value);
foreach ($value as $i => $viewport) {
if (!\in_array($viewport, $valid)) {
throw new InvalidConfigurationException(sprintf('The "%s" %s viewport option does not exist. Known options are: "%s"', $viewport, $prefix, implode('", "', $valid)));
}
$value[$i] = sprintf('%s-%s', $prefix, $viewport);
}
return $value;
} | php | {
"resource": ""
} |
q12678 | ElasticsearchAudit.createIndex | train | public function createIndex($index = null)
{
if (!$this->elasticsearch->indices()->exists(['index' => $index['index']])) {
return $this->elasticsearch->indices()->create($index);
}
} | php | {
"resource": ""
} |
q12679 | PhpTasks.phpTravisCi | train | public function phpTravisCi()
{
$this->executeCommandHook(__FUNCTION__, 'before');
$this->getProjectInstance()
->setupTravisCi();
$this->executeCommandHook(__FUNCTION__, 'after');
return $this;
} | php | {
"resource": ""
} |
q12680 | PhpTasks.phpBehat | train | public function phpBehat()
{
$this->executeCommandHook(__FUNCTION__, 'before');
$this->getProjectInstance()
->setupBehat()
->saveComposer()
->updateComposer()
->initBehat();
$this->executeCommandHook(__FUNCTION__, 'after');
return $this;
} | php | {
"resource": ""
} |
q12681 | PhpTasks.phpPhpCs | train | public function phpPhpCs()
{
$this->executeCommandHook(__FUNCTION__, 'before');
$this->getProjectInstance()
->setupPhpCodeSniffer()
->saveComposer()
->updateComposer();
$this->executeCommandHook(__FUNCTION__, 'after');
return $this;
} | php | {
"resource": ""
} |
q12682 | PhpTasks.phpComposer | train | public function phpComposer(array $composer_command, $opts = [
'remote-binary-path' => 'composer',
'remote-working-dir' => '/var/www/html',
])
{
/** @var DrupalProjectType $project */
$instance = $this->getProjectInstance();
$engine = ProjectX::getEngineType();
$binary = $opts['remote-binary-path'];
$command_str = escapeshellcmd(implode(' ', $composer_command));
$working_dir = escapeshellarg($opts['remote-working-dir']);
$command = $this->taskExec("{$binary} --working-dir={$working_dir} {$command_str}");
if ($engine instanceof DockerEngineType) {
$container = $instance->getPhpServiceName('php');
$result = $this->taskDockerComposeExecute()
->setContainer($container)
->exec($command)
->run();
} else {
$result = $command->run();
}
$this->validateTaskResult($result);
return $this;
} | php | {
"resource": ""
} |
q12683 | PhpTasks.phpImportDatabase | train | public function phpImportDatabase($opts = [
'service' => null,
'import_path' => null,
'localhost' => false,
])
{
$this->executeCommandHook(__FUNCTION__, 'before');
/** @var PhpProjectType $instance */
$instance = $this->getProjectInstance();
$service = isset($opts['service'])
? $opts['service']
: $instance->getPhpServiceName();
$instance->importDatabaseToService(
$service,
$opts['import_path'],
true,
$opts['localhost']
);
$this->executeCommandHook(__FUNCTION__, 'after');
} | php | {
"resource": ""
} |
q12684 | PhpTasks.getProjectInstance | train | protected function getProjectInstance()
{
$project = ProjectX::getProjectType();
if (!$project instanceof PhpProjectType) {
throw new \Exception(
'These tasks can only be ran for PHP based projects.'
);
}
$project->setBuilder($this->getBuilder());
return $project;
} | php | {
"resource": ""
} |
q12685 | LazyPDO.getPdo | train | private function getPdo()
{
static $pdo = null;
if (is_null($pdo)) {
$builder = new InstanceBuilder();
$pdo = $builder->build('PDO', $this->args);
}
return $pdo;
} | php | {
"resource": ""
} |
q12686 | BaseHandler.startConversation | train | protected function startConversation(\KeythKatz\TelegramBotCore\Conversation $conversation): void
{
$conversation->setBot($this->bot);
$conversation->setMessage($this->message);
$conversation->start();
} | php | {
"resource": ""
} |
q12687 | BaseHandler.sendMessageReply | train | public function sendMessageReply(bool $quoteOriginal = false): SendMessage
{
$m = $this->bot->sendMessage();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12688 | BaseHandler.sendPhotoReply | train | public function sendPhotoReply(bool $quoteOriginal = false): SendPhoto
{
$m = $this->bot->sendPhoto();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12689 | BaseHandler.sendAudioReply | train | public function sendAudioReply(bool $quoteOriginal = false): SendAudio
{
$m = $this->bot->sendAudio();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12690 | BaseHandler.sendDocumentReply | train | public function sendDocumentReply(bool $quoteOriginal = false): SendDocument
{
$m = $this->bot->sendDocument();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12691 | BaseHandler.sendVideoReply | train | public function sendVideoReply(bool $quoteOriginal = false): SendVideo
{
$m = $this->bot->sendVideo();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12692 | BaseHandler.sendVoiceReply | train | public function sendVoiceReply(bool $quoteOriginal = false): SendVoice
{
$m = $this->bot->sendVoice();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12693 | BaseHandler.sendVideoNoteReply | train | public function sendVideoNoteReply(bool $quoteOriginal = false): SendVideoNote
{
$m = $this->bot->sendVideoNote();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12694 | BaseHandler.sendMediaGroupReply | train | public function sendMediaGroupReply(bool $quoteOriginal = false): SendMediaGroup
{
$m = $this->bot->sendMediaGroup();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12695 | BaseHandler.sendLocationReply | train | public function sendLocationReply(bool $quoteOriginal = false): SendLocation
{
$m = $this->bot->sendLocation();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12696 | BaseHandler.editMessageLiveLocationReply | train | public function editMessageLiveLocationReply(): EditMessageLiveLocation
{
$m = $this->bot->editMessageLiveLocation();
$this->setReplyMarkup($m, false);
return $m;
} | php | {
"resource": ""
} |
q12697 | BaseHandler.stopMessageLiveLocationReply | train | public function stopMessageLiveLocationReply(): StopMessageLiveLocation
{
$m = $this->bot->stopMessageLiveLocation();
$this->setReplyMarkup($m, false);
return $m;
} | php | {
"resource": ""
} |
q12698 | BaseHandler.sendVenueReply | train | public function sendVenueReply(bool $quoteOriginal = false): SendVenue
{
$m = $this->bot->sendVenue();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
q12699 | BaseHandler.sendContactReply | train | public function sendContactReply(bool $quoteOriginal = false): SendContact
{
$m = $this->bot->sendContact();
$this->setReplyMarkup($m, $quoteOriginal);
return $m;
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.